2017-11-09 06:25 PM
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 memoryThank 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>
Solved! Go to Solution.
2017-11-09 07:34 PM
Thank you for your reply.
Is the date format the same?
2017-11-09 06:31 PM
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;
}
2017-11-09 07:34 PM
Thank you for your reply.
Is the date format the same?
2017-11-09 07:44 PM
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 variableI want to write to usb stick memory sequentially.If you have a similar sample, I would appreciate your support.
Have a nice day!
2017-11-09 09:15 PM
>>
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 stringwhile (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(); } }