cancel
Showing results for 
Search instead for 
Did you mean: 

Writing data to flash - from bin file

matthew
Associate II
Posted on August 15, 2014 at 12:09

Hello everybody.

I am having trouble writing data to the STM32F0 flash. 

I would like to store a look-up-table in a page of flash. My intention is to flash this in during production, so I have added it to the appropriate memory section of the bin file, which I then flash in using ST-Link.

However, when my code interprets the values they have been converted to ASCII. eg if I store a 0, my code reads it as 0x30.

Does anyone have any suggestions for storing the data in a correct hex format?

Thank you in advance

Matt
6 REPLIES 6
matthew
Associate II
Posted on August 15, 2014 at 12:59

I see my issue.

I've manually entered the values in a text editor, which has automatically encoded in ASCII.

I can write a script to decode and store in raw binary format; but does anyone have a better suggestion?

Matt

Osto
Senior
Posted on August 15, 2014 at 13:18

Dear Matt,

Try to open your file with Notepad++ (freeware) or windows editor (notepad.exe). If you see clear text data then you have a hex file and not a bin file.

If you see a lot of garbage and only few readable text then you have a bin file.

If you have a hex file (readable text) then you need only to say to load as hex file. in this case you need to rename the file to extension .hex then st-link knows how to manage that.

Why your compiler/assembler creates a bin file with hex-file data, I cant see with the information you post here but I'm sure there is only a small wrong configuration.

Regards
Posted on August 15, 2014 at 14:07

I can write a script to decode and store in raw binary format; but does anyone have a better suggestion?

You can program in C right, and use standard file IO like fopen/fwrite/fclose?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
matthew
Associate II
Posted on August 15, 2014 at 14:16

Thank you for your answers.

I just need to output the values in hex, I've implemented the C file functions.

Matt

Posted on August 15, 2014 at 14:25

The ST-Link utilities can read binary files directly, or you can provide that data in .HEX format (Intel or Motorola)

I would suggest you generate your data, and .BIN file, using a PC based C compiler, would take a minute. You could do it with a Hex Editor, but honestly that sounds like more work.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
matthew
Associate II
Posted on August 15, 2014 at 14:36

Yes, you are correct.

I used excel to calculate the values of a LUT, copied the data into a text file and flashed it.

Thus, started scratching my head when the algorithm using the LUT churned out random values!

Matt