Electrical – Can VHDL read binary files i.e non text files

hex filemodelsimvhdl

I have a binary file which represents memory contents of a memory device. I want to load these into my testbench. The hex file obviously is not text file thus no concept of line break and carriage return exists in it.

The problem is that as far as I can see, VHDL only reads text files aka ASCII files. I cannot find a way to read binary files.

The file has no structure as such, all contents in it are to be loaded into std_logic_vector array which shall obviously require parsing.

Best Answer

Firstly, hex file are text files. Secondly, I have found it easier to write scripts to parse the external files in VHDL, than to use VHDLs limited text processing capabilities.

Another option you have is to use some of the RAM of the FPGA. You can configure the RAM using your hex file. This is perfect if you are testing internal memory.

A cautionary note: text IO is not supported by many IDEs for synthesis, even though it is in the VHDL spec. I once lost a few hours parsing text in VHDL only to find it will not synthesize.

Edit I know this is not an answer to the original question, but I wanted to point out that there are better tools for the task. You can save yourself a lot of headaches by using a parsing library.