2018-01-25 5:07 AM
Hi,
I use STM43L476 and try to use fast flash program to program 256 bytes (
decripted_firmware_data buffer
).The flash area is erased (all 0xFF), but the function
HAL_FLASH_Program always returns with HAL_ERROR and no single bte is programmed.
My system clock is 80MHz.
Any ideas?
address = 0x0800A000;
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST_AND_LAST, address, (uint32_t)&decripted_firmware_data[0]) != HAL_OK)
{ /* Lock the Flash to disable the flash control register access (recommended to protect the FLASH memory against possible unwanted operation) *********/ HAL_FLASH_Lock(); return eFAIL; }Thank you
2018-01-25 6:08 AM
Try calling HAL_FLASH_GetError() to get the flash error code when HAL_FLASH_Program() returns HAL_ERROR.
2018-01-28 1:25 AM
I did, and the errors are:
HAL_FLASH_ERROR_PGA - FLASH Programming Alignment error flag
HAL_FLASH_ERROR_PGS - FLASH Programming Sequence error flag HAL_FLASH_ERROR_FAST - FLASH Fast programming errorThe datasheet states:
Any attempt to write a double word which is not aligned with a double word address will
set PGAERR flag in the FLASH_SR register.What does that mean exactly? the address 0x0800A000 is not double word aligned?
2018-01-29 6:27 AM
The Data parameter to HAL_FLASH_Program() is a uint64_t not uint32_t. Try typing it to a uint64_t.
I use gcc and have Data in a character array; this construct works for me: (uint64_t)(uintptr_t)Data
2018-01-30 2:42 AM
You can pass 32bit value to 64bit parameter. in any case in fast mode you pass address which is always 32bit in this processor.
In any case I tried that too before and it didn't work.
In the examples they mass erase the entire Bank and start the programming from the beginning of the Bank. I run this example successfully, once I changed the address to 0x0800A000 it also failed.... Does fast mode work only from the beginning of the Bank?
I ended up using double word mode instead.
2018-08-03 12:15 PM
I am working with an STM32L496, and I see the exact same behavior, including the exact same flash error bits being set. Is there any resolution to this?
2018-09-12 6:20 AM
try to "FLASH_TYPEPROGRAM_DOUBLEWORD"
2018-10-03 2:49 AM
I got it working, can't remember how, it was a long time ago and I forgot to update the forum :o
From what I see, I use 64 bit data as @Doug Kehn suggested, and optimization changed to medium.
Here is my code:
#pragma optimize=medium
enum ResultEnum ProgramFirmwarePacket(uint32_t programming_address)
{
uint32_t address = 0;
static uint64_t decripted_firmware_data[FIRMWARE_PACKET_SIZE];
uint64_t *programmed_data = (uint64_t *)programming_address;
uint16_t i;
//here I decripted the data and store in decripted_firmware_data :-)
address = programming_address;
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
for (i = 0; i < FIRMWARE_PACKET_SIZE; ++i)
{
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, decripted_firmware_data[i]) != HAL_OK)
{
HAL_FLASH_GetError();
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation) *********/
HAL_FLASH_Lock();
return eFAIL;
}
else
{
if (*(programmed_data + i) != decripted_firmware_data[i])
{
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation) *********/
HAL_FLASH_Lock();
return eFAIL;
}
}
address += sizeof(uint64_t);
}
return eSUCCESS;
}
2022-04-12 10:50 AM
Hi, were you able to get it working with the FLASH_TYPEPROGRAM_FAST_AND_LAST? I have the same problem.
2022-04-12 11:17 AM
https://community.st.com/s/question/0D53W00000ZWpgQSAT/writing-full-flash-page-does-not-work