AnsweredAssumed Answered

IAP USART Questions

Question asked by AndyOlivares on Jul 2, 2014
Latest reply on Jul 4, 2014 by AndyOlivares
Hi everyone:

I've been playing with "STM32F4xx_AN3965_V1.0.0" which is IAP over USART with my STM32F4Discovery board. I managed to port all the relevant code to work with this board and it's running quite fine.

The bootloader is downloading .BIN files using the YModem protocol, writing them into FLASH memory and booting to the user code afterwards, so everything fine here.

One of my tests consisted in create a binary file of 1032192 bytes which is the full programable FLASH space that we can program as user code according to the IAP application that saves the first 0x4000 bytes for the bootloader itself (0x8004000-0x80FFFFFF).
The test file started with a 0x55 byte followed by 0xAA bytes and ending with a 0x55 byte again. I did this to easily identify the start/end of the file and its contents.
So, I programmed the FLASH using the IAP application and using the prevously created test file and after a while, it was programmed fine (according to the application).
After that, I opened up STLinkV2 flash utility to check if the file was programmed as expected and it mostly did except for the last 4 bytes (read as 0xFFFFFFFF). In other words, I found the first 0x55 byte at address 0x8004000, followed by a lot of 0xAA bytes, but I didn't find the last 0x55 byte.

Debugged the code trying to find out what went wrong, and after a couple of debugging sessions I found the following line in file "flash_if.c" (line 93):

for (i = 0; (i < DataLength) && (*FlashAddress <= (USER_FLASH_END_ADDRESS-4)); i++)

Please note the text in bold. As I understand, it programs all flash except all 4 last bytes of it. I really don't understand why it is made the way it is.
I removed the "-4" and retried the programming process, and this time all bytes where programmed fine and I was able to see the last 0x55 byte at the end of the flash memory space, which seems to be the correct behaviour for me.

So, is there anything I should worry about having removed the "-4" from that line of code? Is there any special purpose for the last 4 bytes of flash? Am I missing something here? Does anybody know why the "-4" on that line of code?

Thank you so much for your answers.