Question
STM32F205 - Store byte array in FLASH
Posted on August 01, 2013 at 10:33
Hi,
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 */ FLASH_Unlock(); /* Clear pending flags (if any) */ FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); /* 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 */ FLASH_Lock(); return FALSE; } tempAddress++; } /* Lock flash memory */ FLASH_Lock(); 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 helpMarco