2018-04-19 08:19 PM
I didn't find a way to do a byte program on my STM32L4 , there is a doubleword program exist in the stm32l4xx_hal_flash.c file.
How can i do that , read the doubleword out first and modify one byte and do a doubleword program .
Is it correct ?
thanks
Solved! Go to Solution.
2018-04-20 06:54 AM
>>So the flash is not suitable for the data storage purpose.
Well not low bandwidth byte streams. There you'd need to record 64-bit for each byte you want to store. Here you could use two blocks one where you record the bytes, and when you fill that with the sparse data you pack into the second using 1/8th the space.
The more practical method for configuration data is to have a structure, cache that to RAM, and then update as a whole to FLASH as required.
2018-04-19 08:35 PM
I add two more program cases word and byte as below :
if(TypeProgram == FLASH_TYPEPROGRAM_DOUBLEWORD)
{ /* Program double-word (64-bit) at a specified address */ FLASH_Program_DoubleWord(Address, Data); prog_bit = FLASH_CR_PG; } if(TypeProgram == FLASH_TYPEPROGRAM_WORD) // i add { /* Program word (32-bit) at a specified address */ FLASH_Program_Word(Address, Data); prog_bit = FLASH_CR_PG; } if(TypeProgram == FLASH_TYPEPROGRAM_BYTE) // i add { /* Program byte (8-bit) at a specified address */ FLASH_Program_Byte(Address, Data); prog_bit = FLASH_CR_PG; }functions like as below :
static void FLASH_Program_Word(uint32_t Address, uint32_t Data)
{ /* Check the parameters */ assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));/* Set PG bit */
SET_BIT(FLASH->CR, FLASH_CR_PG); /* Program the word */ *(__IO uint32_t*)Address = (uint32_t)Data;}static void FLASH_Program_Byte(uint32_t Address, uint8_t Data)
{ /* Check the parameters */ assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));/* Set PG bit */
SET_BIT(FLASH->CR, FLASH_CR_PG); /* Program the byte */ *(__IO uint32_t*)Address = (uint8_t)Data;}Is it correct ?
thanks
2018-04-19 11:31 PM
Using the code i post , I found the byte or word program does not work .
Only the
doubleword program work , Does the STM32L4 does not support the other program ?
thanks
2018-04-19 11:46 PM
Set the unused bytes, i.e. the bytes of the word you do not want to program, to 0xFF.
No Cortex M platform I know supports byte-wise programming for the internal Flash.
2018-04-20 06:36 AM
Oh !! No .
I got a program error return. Since the data before i program is not 0xFF .
According to user manual written , the Flash status register bit 'PROGERR' which mean as below :
Set by hardware when a double-word address to be programmed contains a value different from 0xFFFF FFFF before program.
It looks like the data i program need to follow the below two conditions:
1. Must be program in double word alignment .
2. Data can't contain other value than 0xFFFF FFFF before i program.
So the flash is not suitable for the data storage purpose.
I think i need to read/write the data to SRAM and find a good timing to store them to the flash before device turn off.
2018-04-20 06:54 AM
>>So the flash is not suitable for the data storage purpose.
Well not low bandwidth byte streams. There you'd need to record 64-bit for each byte you want to store. Here you could use two blocks one where you record the bytes, and when you fill that with the sparse data you pack into the second using 1/8th the space.
The more practical method for configuration data is to have a structure, cache that to RAM, and then update as a whole to FLASH as required.