I'm developing a firmware for a custom board based on a STM32F415xx microcontroller.
The application must read a file from the on-board SD card, parse it and save some data into the microcontroller flash.
This is working fine only the first time I write the firmware on the microcontroller.
Starting from next time it doesn't work anymore, because a few (about 20) stored values are different than the expected ones. The wrong values are always at the same addresses. If I try to move the base address but the behavior is exactly the same.
If, for example, I try to write value 0x4D I read back 0x49.
Obviously the sector I'm using doesn't contains the firmware data.
I'm using FLASH_ProgramByte in order to store the data and I erase the sectors before the write operation. The erase function is working because I checked the flash and it is filled with 0xFF. I'm also sure that the file parsing function works because the first time everything is fine.