cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G071 Flash write word cause HardFault handler

Hoang Loc
Associate II

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!

1 REPLY 1
Amel NASRI
ST Employee

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:

  • there is no flash LL driver
  • FLASH_Program_Fast should be used to Fast program a 32 row double-word (64-bit) at a specified address
  • Second parameter of this API isn't the value to be programmed, but the address where the data to program are stored

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.