cancel
Showing results for 
Search instead for 
Did you mean: 

Discovery stm32f429i I want to write text and dates to Flash

Study Yahoo
Associate III
Posted on November 10, 2017 at 03:25

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>

0690X0000060PCBQA2.png

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on November 10, 2017 at 03:34

Thank you for your reply.

Is the date format the same?

View solution in original post

4 REPLIES 4
Posted on November 10, 2017 at 03:31

So use a uint32_t* pointer and advance it with each write

char str[] = 'Hello World!';

uint32_t *p = (

uint32_t *)str;

    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, *p++) == HAL_OK)

    {

      Address = Address + 4;

    }

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 10, 2017 at 03:34

Thank you for your reply.

Is the date format the same?

Posted on November 10, 2017 at 03:44

Thank you for your reply.

Is the date format the same?

After writing text and date in flash memory

Lead Text and date, move to buffer or variable

I want to write to usb stick memory sequentially.

If you have a similar sample, I would appreciate your support.

Have a nice day!

Posted on November 10, 2017 at 05:15

>>

Is the date format the same?

It is all just bytes of data in memory, the processor doesn't distinguish if it is a greeting or a time stamp. The routine you have writes 32-bit words, a collection of four 8-bit bytes.

Create and manipulate strings with strcpy(), strcat(), sprintf(), etc

char str[] = 'Backup generator failed to start 2017-11-09 09:32';

uint32_t *p = (uint32_t *)str;

uint32_t WordCount = (strlen(str) + 3) / 4; // 32-bit words in string

while (WordCount--)

{

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, *p++) == 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();

}

}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..