Question
STM32G071 Flash write word cause HardFault handler
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!
