This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Including raw binary data in MSP430 Firmware

Other Parts Discussed in Thread: MSP430F5528

Hello,

I want to include about 16KB of raw data in the firmware of my application, using the MSP430F5528.

My application code is about 32KB so there should be enough space in the Flash, however I do not know how I can include the data, which are in the form of a binary file.

I have thought of either creating a 16KB uint8_t array which is initialised to the desired values read directly from the raw file at compile time, or including the raw data in the final firmware by pointing to it somehow from the CCS linker command file.

I have not however managed to find how exactly I could do either of the above.

If it's important, the data is the firmware for a secondary chip I am using and which must be loaded to the chip on startup.

The final firmware must be in .TXT form, suitable for programming though the USB BSL.


Thank you in advance,

Giannis

  • I don't think the links above will really help.

    My recommendation is to write a simple program (C, Java, whatever floats your boat) to read in the binary file and output a .C file that contains a const array.

    You can then place that const array either in a fixed position in flash, or just let it be built in with the application. The const qualifier should allocate it to Flash and not copy it into RAM during startup. You can verify that by looking at the link map file output.

  • Hi Brian,

    Ialready did it as you have suggested, used bin2h to convert the binary file to a C array, added the const qualifier (otherwise the linker tried to place the variable to RAM and run out of space) and everything is working now!

    Thanks for the quick replies.

    Giannis

  • Depending on the source of the data, and how often you need to change it during development, it might be convenient to do something like that:

    const unsigned char data[]={
    #include “data.csv”
    };

    Data can be exported in CSV format by many applications, such as Excel.

  • Jens-Michael Gross said:
    const unsigned char data[]={
    #include “data.csv”
    };

    That's an interesting solution!

    However, it makes me wonder if Excel puts a comma on the last data item of each row so that multi-row exports would compile in correctly. I may have to investigate that myself.

  • Excel doesn’t put a comma there if there is no used cell in the next column. Or multiple ones if there once have been used cells in surplus columns. So to ge the trailing comma, simply put a format change in a cell past the last column. (one cell is enough, you don’t need to set the whole column).
    Worse, Excel uses the global system settings and doesn’t let you specify the separator. Which in a German Windows means a semicolon. Also, it ignores the setting if the list separator is the same as the decimal separator.
    They should call the output format SSV (somehow separated values) instead of CSV.

    However, while working on a project, the system can be adjusted in a way that it works fine, except one thing: the last row will get a comma at its end too. Either you edit it away, or you live with one additional array element, by putting an additional ‘0’ right after the #include.

     When writing the firmware for our power laser supply, I had to deal with lookup tables for the external NTC sensors. And in our bio impedance analysis project (for pigs), I created sine tables for the DAC this way. Using this approach was really making things convenient.

**Attention** This is a public forum