简体   繁体   中英

How can I store characters in flash memory STM32F4 HAL with C++?

So I have a buffer:

uint32_t buff[2];
buff[0] = 12;
buff[1] = 13;
...

I can write this to the flash memory with the method:

HAL_FLASH_Program(TYPEPROGRAM_WORD, (uint32_t)(startAddress+(i*4)), *buff)

The definition of HAL_FLASH_Program is:

HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)

That works perfectly. Now is there a way I can store chars instead or ints?

You can use HAL_FLASH_Program with TYPEPROGRAM_BYTE to write a single 1-byte char.

If your data is a bit long (a struct, a string...), you can also write the bulk with TYPEPROGRAM_WORD , or even TYPEPROGRAM_DOUBLEWORD (8 bytes at a time), and then either complete with single bytes as needed or pad the excess with zeros. That would certainly be a bit faster, but maybe it's not significant for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM