AnsweredAssumed Answered

STM32F205 - Store byte array in FLASH

Question asked by Marco Cresseri on Aug 1, 2013
Latest reply on Sep 18, 2014 by kimtys.juozas
I need to store a byte array in the STM32F205 flash memory. I've followed an approach that was working on a STM32F103 mcu, but now it doesn't work anymore.
The problem is that the first call to the FLASH_ProgramByte works correctly and returns FLASH_COMPLETE, but int the next iteration of the loop it returns FLASH_ERROR_PROGRAM.
My code is the following:

#define FLASH_SECTOR_BASE_ADDRESS 0x080c0000

int WriteArray(const uint8_t * dataBuffer, uint32_t dataSize, uint32_t dataAddressOffset)
     uint32_t     tempAddress;
     FLASH_Status     result;

     /* Compute temporary address */
     tempAddress = FLASH_SECTOR_BASE_ADDRESS + dataAddressOffset;
     /* Unlock flash memory */

     /* Clear pending flags (if any) */  
     /* Copy data into flash memory */
     for (uint32_t i = 0; i < dataSize; i++)
          /* Program byte */
          result = FLASH_ProgramByte(tempAddress, dataBuffer[i]);
          if (result != FLASH_COMPLETE)
               /* Lock flash memory */
               return FALSE;

     /* Lock flash memory */
     return TRUE;

I've also tried with FLASH_ProgramHalfWord() with an address increment of 2 and with FLASH_ProgramWord() with an address increment of 4, but the problem is the same.

Thank you for your help