3 years, 4 months ago.

How do I read flash memory?

I have a project where I need to read arbitrary data from my .hex file. How do I do this? AFAIK, there is a flat memory model. If this is true, how do I find the starting address of flash on any Mbed system? I already know the relative address within my hex file. I'm doing this on the Micro:bit (Mbed 2)

The meta data from the hex file is stripped away once you flash it to the target where it becomes plain binary data stored in flash.

To clarify, you are asking about reading binary data from flash memory into RAM?

How is this data you need to read getting into the file? You are compiling the program and producing the hex file, so you must be putting this data in there? This hex file is coming from mbed online compiler? Wouldn't inserting big blocks of data into program memory at a specific location require modifying the linker script to reserve space for it? Without this you can't really control where this data goes can you? What mechanism is being used to define the location of this data in program memory space?

When people want to access flash memory it is usually to save runtime data. The thing to look for would be a flash driver for your target. Mbed os 5 seems to have a flash API but mbed 2 does not seem to have this. You will need to dig through the source files to see if a flash driver is implemented at a lower level specifically for your target. Or you might be able to find a flash driver code snippet elsewhere for nRF51822 that would work.

Someone can correct me, but a quick search shows for the microbit shows it uses Nordic nRF51822, and the datasheet shows program memory starting at 0x00000000. Unless you have a bootloader, or custom linker script, that should be the first line of your program.

posted by Graham S. 25 Mar 2018
Be the first to answer this question.