2021-02-17 08:28 AM
Hi !
I try to write 2048 Bytes at once to flash.
I do a page erase first of page 31.
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Banks = FLASH_BANK_1 ;
EraseInitStruct.Page = 31;
EraseInitStruct.NbPages = 1;
the description of the HAL library is not clear, what do they mean with "Fast program a 32 row double-word (64-bit) at a specified address.".
I understand a double word as 32 bit, but the HAL comment says 64 bit?
What do they mean with 32 row ? 32 x double word?
its confusing.
my device is a 65k device STM32G431C8T
PageData is a buffer of 2048 Bytes (uint8_t).
FLASH_EEPROM_BASEADDR = 0x0800F800.
When i execute flash_page_write(FLASH_EEPROM_BASEADDR,(uint64_t*)PageData);
i get HAL_ERROR wirh error code 1010100000
flash_status flash_page_write(uint32_t address, uint64_t *data) {
HAL_FLASH_Unlock();
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST_AND_LAST, address, *data)
!= HAL_OK) {
return FLASH_ERROR_WRITE;
}
HAL_FLASH_Lock();
return FLASH_OK;
}
Thank you
2021-02-17 08:39 AM
Hi, i am using a stm32f105 but maybe take a look inside your HAL_FLASH_Program() declaration, specifically the FLASH_Type_Program argument.
I only get this options and i believe you should be using FLASH_TYPEPROGRAM_DOUBLEWORD
#define FLASH_TYPEPROGRAM_HALFWORD 0x01U /*!<Program a half-word (16-bit) at a specified address.*/
#define FLASH_TYPEPROGRAM_WORD 0x02U /*!<Program a word (32-bit) at a specified address.*/
#define FLASH_TYPEPROGRAM_DOUBLEWORD 0x03U /*!<Program a double word (64-bit) at a specified address*/
best of lucks
2021-02-17 11:05 PM
i got the correct options, but am not able to execute them .
FLASH_TYPEPROGRAM_DOUBLEWORD works correctly but i would like to write a whole page at once.
#define FLASH_TYPEPROGRAM_DOUBLEWORD 0x00U /*!< Program a double-word (64-bit) at a specified address.*/
#define FLASH_TYPEPROGRAM_FAST 0x01U /*!< Fast program a 32 row double-word (64-bit) at a specified address.
And another 32 row double-word (64-bit) will be programmed */
#define FLASH_TYPEPROGRAM_FAST_AND_LAST 0x02U /*!< Fast program a 32 row double-word (64-bit) at a specified address.
And this is the last 32 row double-word (64-bit) programmed */
2021-02-18 12:19 AM
Where did you found those defines?
I only have them in stm32_hal_legacy.h and they dont have any value in them
2021-02-18 01:31 AM
stm32g4xx_hal_flash.h
2021-02-18 01:55 AM
Maybe is a family specific flash option, i have no idea why this is not working for you and i cannot replicate it sorry.
2022-04-12 10:48 AM
Hi, did you find the solution? I have the same problem. FLASH_TYPEPROGRAM_DOUBLEWORD works fine, but I can not make it work with FLASH_TYPEPROGRAM_FAST_AND_LAST nor FLASH_TYPEPROGRAM_FAST.
2022-04-12 11:16 AM
Those two have specific sequencing expectations.
You have the STM32G4, or something else?
2022-04-12 01:38 PM
Yes, I have a STM32G491KE
2022-04-12 02:26 PM
This is my read on the docs, not having a G4 to hand
flash_status flash_page_write(uint32_t address, uint64_t *data)
{
int i;
i = 2048 / 256; // PAGE SIZE vs ROW SIZE
if (address % 2048) return(FLASH_ERROR_ALIGN); // id10T check for page alignment
HAL_FLASH_Unlock();
// Clear OPTVERR bit set on virgin samples
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
// Clear all FLASH errors flags before starting write operation
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
while(i--) // Rows Remaining
{
if (i)
{
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, address, data) != HAL_OK)
{
HAL_FLASH_Lock();
return(FLASH_ERROR_WRITE);
}
}
else // Last Row in Page
{
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST_AND_LAST, address, data) != HAL_OK)
{
HAL_FLASH_Lock();
return(FLASH_ERROR_WRITE);
}
}
Address += 256; // Advance by Row
data += 256 / sizeof(uint64_t);
}
HAL_FLASH_Lock(); // sourcer32@gmail.com
return(FLASH_OK);
}