cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine STM32WB flash user space size and boundaries?

lsw
Associate II

Hello,

I am trying to store as much data as I can into STM32WB55RGV6 flash.

So far I've figured out that main memory span addresses 0x08000000 - 0x080FFFFF.

I also know that CPU2 reserve some space at the end of the main memory and I am able to read the address at which it starts - this gives me last safe address to use.

However I cannot seem to figure out how to find the addresses occupied by main program code which is somewhere at the beginning of the main memory.

I've written test code that program flash from CPU2 secure sector, all the way down to 0x08000000 which runs fine until hardware fault is thrown upon write attempt below 0x08000000 or when some parts of main program code is overwritten.

During this experiment HAL_FLASH_Program never return any errors.

My goal is to read what is the first (looking from bottom up) safe address to write to in flash so I can safely store as much data as possible.

6 REPLIES 6
Remi QUINTIN
ST Employee

The first safe address to write your main program is 0x8000000.

The first address to be executed after booting by the M4 core is located at 0x8000000 whether it is an _OTA FW or any other SW.

Thanks for your reply but its not quite what I meant.

In my setup I do have OTA flashed at 0x08000000 and main program at 0x08007000 and this is all fine. What I need to know is where exactly in flash does main program end, so I can use the rest of flash for storing measurement data.

Remi QUINTIN
ST Employee

One way would be for the OTA FW to keep the size of the new updated application or at least the last sector used for this update via a static variable located in SRAM.

What if someone doesn't use OTA? Is there no way to find this information in main application?

How does user supposed to know how much flash is available for custom data storage?

Remi QUINTIN
ST Employee

I think another possibility would be to create a specific section (in the linker file) placed at the end of the application with a dedicated magic word that would indicate the last bytes of the application.

Then the application would look for this magic number and once found would be able to determine the address and the next sector that could be used to store data.

You could even create a section starting with this magic word and place at a sector boundary with the proper size required to store the application data.

Do this data needs to be persistent after reset. If not I would recommend to store this data in the backup SRAM. That would avoid accessing the Flash memory to often.

Piranha
Chief II

Linker script can write the size or the end address of the firmware in the unused entries of the vector table.