2020-06-20 11:07 AM
I am writing an application and bootloader to STM32H7.
I append some data to the end of the application. My bootloader needs to be able to read this appended data.
When my bootloader first writes the application via (erase->write to memory).
When the system resets for the first time the bootloader is able to read the appended data. When the system resets for a second time it seems that the sector containing the appended data is resetting to 0xFF for all bytes and thus deleting the appended data + some application memory.
Note that the sector containing the appended data is in the start of bank 2, whereas all prior code is in bank 1.
How can I solve/debug this?
2020-06-20 12:57 PM
Take a note that FLASH cannot reset to 0xFF by some accidental write. It needs to be erased, which takes seconds and during that time memory accesses, including code execution, from that bank are stalled.
2020-06-20 02:37 PM
So current my flash write is done like so:
1) taskENTER_CRITICAL()
2) HAL_FLASH_Unlock();
3) HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, ..., ...)
4) HAL_FLASH_Lock();
5) taskEXIT_CRITICAL()
6) Verify Flash Content
7) NVIC_SystemReset()
...
(mcu resets)
...
8) Verify flash content
9) Jump to app
Steps 1-7 only happen during update and steps 8-9 are supposed to happen frequently.
The problem is that steps 8-9 works correctly when run the first time. The second time step 8-9 is run the memory sector is reset to 0xFF when I did not erase anything and this is the issue. To my understanding if the HAL_FLASH_Lock() command returns HAL_OK then the flash has had enough time to lock.
On a tangent I think this error might be because of the way my memory map is setup.
In my .ld file for the application flash region is setup as follows:
FLASH (rx) : ORIGIN = 0x8060200, LENGTH = 1270000
The sector starts at 0x8000000 but I wanted to place some data in the first 512 bytes and so I shifted application flash by 512 bytes. Is this correct? Could this cause the issue which happens at the boundary of the 2 banks? This is consistent with the fact that bank 1 memory is intact, but bank 2 is reset. Now I am beginning to wonder whether an application flash can overflow from bank 1 to bank 2.