AnsweredAssumed Answered

Discovery stm32f429i I want to write text and dates to Flash

Question asked by Study Yahoo on Nov 10, 2017
Latest reply on Nov 10, 2017 by Clive One

Hello I am looking at the STM32F429 Discovery board Flash memory sample source as below.

I'm recording Hex values in flash memory.


The sample is to be input with a value of 4 bytes Hex ((uint32_t) 0x12345678).
Tell me how to write text (hello world) and date (2017-11-09) to Flash memory

Thank you.

Have a nice day!!

 

==============================  sample source  ===================================

 

#define FLASH_USER_START_ADDR   ADDR_FLASH_SECTOR_2   /* Start @ of user Flash area */

#define FLASH_USER_END_ADDR     ADDR_FLASH_SECTOR_23  +  GetSectorSize(ADDR_FLASH_SECTOR_23) -1 /* End @ of user Flash area : sector start address + sector size -1 */
#define DATA_32                 ((uint32_t)0x12345678)
  EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
  EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
  EraseInitStruct.Sector = FirstSector;
  EraseInitStruct.NbSectors = NbOfSectors;
while (Address < FLASH_USER_END_ADDR)
  {
    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, DATA_32) == HAL_OK)
    {
      Address = Address + 4;
    }
    else
    { 
      /* Error occurred while writing data in Flash memory. 
         User can add here some code to deal with this error */
        /*
          FLASH_ErrorTypeDef errorcode = HAL_FLASH_GetError();
        */
      Error_Handler();
    }
  }
<Memory Debugging>

Outcomes