2021-04-16 02:58 AM
I can't write word data to specific Page flash use LL driver.
This is my test function for testing.
void flash_word_test(uint32_t addr,uint32_t val)
{
uint32_t page;
ErrorStatus status;
DEBUG_PRINT("\nWrite value: 0x%x to address: 0x%x\n",val,addr);
status = FLASH_Unlock();
if(status == ERROR)
{
DEBUG_PRINT("Flash Can't Unlock!\n");
return;
}
page = FLASH_GetPage(addr);
FLASH_PageErase(page);
/* If operation is completed or interrupted, disable the Page Erase Bit */
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
status = FLASH_WaitForLastOperation(1000);
if(status == ERROR)
{
DEBUG_PRINT("Page erase err!\n");
return;
}
FLASH_Program_Fast(addr, val);
/* If the program operation is completed, disable the PG or FSTPG Bit */
CLEAR_BIT(FLASH->CR, FLASH_TYPEPROGRAM_FAST);
FLASH_Lock();
DEBUG_PRINT("Read value: 0x%x to address: 0x%x\n",read_word(addr),addr);
}
This code run to: *(uint32_t *)dest = *(uint32_t *)src; inFLASH_Program_Fast(addr, val) function
and go to HardFault_Handler.
Thanks for reading!
2021-04-22 03:04 AM
Hi @Hoang Loc ,
I would like to come back to this question, in case you still need help.
Reviewing STM32CubeG0 package, I noted the following:
I think that the third point is the cause of the issue you are facing.
Could you please take into consideration these points and let me know if this helped you?
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.