This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Placing variables in ROM

I'm targeting a STM32. How can I define a large array of data in ROM?

Also, is it possible to somehow "attach" a HEX file to a project so that when the project is loaded into the target...it automatically places those bytes into the ROM?

  • Declare your data as const, to inform the compiler that you do not need to be able to modify it.

    The best way to handle your hex data is probably to use a tool to convert it into a C array, and then let the compiler process the C file with the array.

    You might be able to use the post-build step to concatenate the linked hex file with your hex file, but then the hex file must have the correct offset. Note also that a hex file normally ends with an "end" record which should be removed before you concatenate the next hex file. Some programs processes all records of a hex file, but some programs stops when they see the end record, and issue an error message if they get to the end of the file without finding any end record.

    If you concatenate the hex files, then the offset of your hex file will control the storage address, so your program will have to set a pointer to an absolute address. If you convert your data to a C array, then you can use the name of this array to find what address the data got linked to.