I'm trying to write some bytes of data at the specific region in the flash using HAL_FLASH_Program (uint32_t TypeProgram, uint32_t Address, uint32_t Data). But my current understanding of from HAL user manual at 19.2.7 UM1749 "Program word at a specified address" is unclear what does it mean? how can i write bytes eg: char* demo="nucleo"
into memory
char* demo="nucleo";
int main(){
.
.
ScratchWrite(FLASH_SCRATCH_START, demo);
.
.
}
uint32_t ScratchWrite(uint32_t destination, uint32_t *p_source)
{
HAL_FLASH_Unlock();
/* Write the buffer to the memory */
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,destination, p_source );
HAL_FLASH_Lock();
return status;
}
HAL_FLASH_Program
allows you to write given number of bytes under specified address. First function argument uint32_t TypeProgram
controls how large the chunk you want to write is. The possibilites are:
#define FLASH_TYPEPROGRAM_BYTE ((uint32_t)0x00U) /*!< Program byte (8-bit) at a specified address */
#define FLASH_TYPEPROGRAM_HALFWORD ((uint32_t)0x01U) /*!< Program a half-word (16-bit) at a specified address */
#define FLASH_TYPEPROGRAM_WORD ((uint32_t)0x02U) /*!< Program a word (32-bit) at a specified address */
#define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x03U) /*!< Program a double word (64-bit) at a specified address */
So in case of your question, FLASH_TYPEPROGRAM_WORD writes 32-bit (4 byte) value under specified address. For example:
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, 0x8010000, *(uint32_t*)demo);
will write "nucl"
under address 0x8010000
.
How large the chunks you want to program with HAL_FLASH_Program
are is totally up to you and will affect performance if you choose small chunks ( FLASH_TYPEPROGRAM_BYTE
for example) when programming large portion of flash.
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.