I'm trying to determine how much FLASH memory will be available for my user application. I'm using an STM32WB55RG. I don't do this quite often so I could use some help
I got clues from different sources but i'm not sure which one is correct :
If someone is willing to explain to me what is the correct procedure and what is wrong with the others, that would be really valuable for me!
The easiest way: if there is a stack, then the first secure sector indicates the maximum size of user space.
Get SFSA register and multiply by 0x1000.
Assuming a stack update, subtract the stack size and bootloader size from this value.
This will be what you need.
Thanks for the answer Vyacheslav ! 🙂
Ok so I have SFSA = 0xCB, given your calculation this gives me 812kB available. This is close to what I found by adding the size of the files : FUS + stack_ble (838kB availaible). Just for the info, do you have any idea what is missing in this calculus ?
Also, assuming a stack update. Do you know how much flash size should be reserved for the stack so we have a safe way to be sure there will be no future conflic with our user app ?
For first question - answer by link from Remi Quintin begins as "A 1MB Flash device has a specific context: ...".
There is a strange memory situation in 1M chip 🙂
About second question: use AN5185 #2.1.1 "Operation instructions". My answer to Remi at the specified link.
If you read the whole thread, can it help you?
Personally, I use the algorithm as described in AN5185 #2.1.1 "Operation instructions" and everything works for me.
Your calculation is correct for the BLE stack alone => SFSA = 0xCB (BLE stack + FUS). This means indeed 838kB available for a user application.
Then if you want to use a BLE + Thread Stack , which is the biggest one (493KB => 496 KB for the 4K alignment = 0x7C000), a minimum of 56KB (0xE000 for the FUS) + 496 KB (0x7C000 for the RF stack) is required. This leads to a total 0x8A000 bytes to be reserved at the top of the Flash memory => 0x08100000 - 0x8A000 = 0x08076000 => Start address SFSA = 0x76. So this let a total of 0x76000 x 4KB = 483328 Bytes for a user application.
For any of the RF stack used, if you want to add the OTA feature, then you have to add the OTA application size (loaded at the begining of the 1MB Flash memory) which is 0x7000 = 28672 KBytes. The user application targeted to be updated through OTA should be loaded at address 0x7000. And so the maximum size allowed for it if you use the biggest RF stack (BLE + Thread) is 483328 KB - 28672 KB = 454656 KB (0x6F000).
Hope those calculations clarify your view.