Skip to main content
Marco Cresseri
Associate
Aug 1, 2013 8:33 AM UTC
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 help

Marco
    This topic has been closed for replies.

    12 replies

    Tesla DeLorean
    Guru
    Sep 17, 2014 11:54 AM UTC
    Posted on September 17, 2014 at 13:54

    I wrote this replay to this old post, because I don't find any other post that matches to my problem, that I have ''solved'', but do not understand why.

    Well your code fragment never sets My_FLASHStatus, but one might presume that a write might fail if the flash array has not been erased before you attempt to write, or rewrite, data to it.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    juozas
    Associate II
    Sep 18, 2014 11:09 AM UTC
    Posted on September 18, 2014 at 13:09

    Thank you very much for pointing to my error. I have attached full source code of my subroutine - for those who will be interested to use my achievement.

    Best regards.

    ________________

    Attachments :

    MyWriteByteBufferToFlashMemory.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0bZ&d=%2Fa%2F0X0000000beO%2FBZqrTgFBXqAdDNExNdr3OBh.3s8PsQVUAyqLzABptf0&asPdf=false