2021-10-04 06:49 AM
Hi community..
I have the following code :
bool FLASH_WriteDoubleWord(uint32_t flashAddress, uint64_t Data)
{
FLASH_Unlock();
/*clear some flag*/
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );
//FLASH_Erase_Sector(2, 2);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );
/* Program the user Flash area word by word */
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, (uint32_t)&flashAddress, Data) != HAL_OK)
{
FLASH_Lock();
return false;
}
FLASH_Lock();
return true;
}
where
static uint32_t address_test = 0x08008000;
static uint64_t data_test = 0xAAAAAAAA;
I don't understand why the erase part is working instead HAL_FLASH_Program it is not writing the data in the expected address.
Can you please tell me why in your opinion?
Thanks a lot.
Simone
2021-10-05 12:56 AM
Yes... The function is returning an error... I will try to print out the flags status
2021-10-05 02:20 AM
i tried in this way
bool FLASH_WriteDoubleWord(uint32_t flashAddress, uint64_t Data)
{
FLASH_Unlock();
FLASH_EraseSectors(2, 1); /*working*/
HAL_Delay(500);
FLASH_Unlock();
HAL_Delay(500);
/* Program the user Flash area word by word */
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, (uint32_t) flashAddress, Data) != HAL_OK) /*not working*/
{
Turn_on_red_led();
FLASH_Lock();
return false;
}
FLASH_Lock();
return true;
}
Now I don't get the erro from HAL but when I check the flash the values is not written as expected.
2021-10-05 02:32 AM
Read the relevant sections of a reference manual? RM0368 section 3.5.2 explains your "problem" very clearly.
***Edited by moderation: please refrain from using inflammatory language***
2021-10-05 02:35 AM
Thanks Piranha...
RM0368 section 3.5.2 explains your "problem" very clearly...
Can you make a recap about what this point is saying?
Thanks a lot
2021-10-10 01:20 PM
No, I will not read for you. You have the document and section number - go and read it!