cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 In-Application Programming for updating the configuration variables

KVenk.1
Associate III

Hi,

I have a STM32L4R5ZI based system that has some configuration parameters to be set based on the customer requirements. I want to make those settings being at customer place. I will not be having any compiler to modify the code for updating these settings. Instead just using the serial converter and IAP, I should be able to update those settings in the code that resides in the flash memory. How to achieve this ?

I came across Application note "AN4657 - STM32 in-application programming (IAP) using the USART" and I implemented it on l4R5ZI nucleo and understood how to upload/download the code using the bootloader (IAP code).

But my doubt is, how to use IAP and update only the certain variables ? I couldnt locate any application note on this. If am right, this can be achieved by storing all the configuration variables in seperate page of the flash. Using IAP, we shall first update those variables in the page. Ensure the Application code accesses those variables by reading from that particular flash page where it is updated by IAP. This way both the IAP and Application code can access the configuration variables. Is this the way ?

4 REPLIES 4
TDK
Guru

You cannot erase individual FLASH locations like you can do with RAM. You can only erase pages.

You'll need to store the setting in a separate flash page from the rest of the program. To update, store those settings in RAM, erase the FLASH page, and then rewrite the settings to FLASH. This is a basic scheme. One can implement a more advanced scheme which writes several times to the same page, uses the last settings written, and erases the page only when it gets full.

If you feel a post has answered your question, please click "Accept as Solution".
KVenk.1
Associate III

Ok, makes sense. What if the Application code wants to access that variable during the time the IAP code stores it in RAM and update the flash ?

If you have tasks running asynchronously, you’ll need to ensure the correct settings are read. Probably storing things in RAM is easiest and only reading from flash at the start.
Power-off in the middle of updating is also another corner case you’ll need to handle (or consciously ignore). Using two flash pages and ping ponging between them can eliminate this risk.
If you feel a post has answered your question, please click "Accept as Solution".
KVenk.1
Associate III

That makes sense, TDK. Let me try it out and update. Thanks for your inputs.