Skip to main content
Nchun.1
Associate III
February 5, 2024
Solved

Hard Fault exception is occurring while programming in FAST mode for saving data in stm32G0 Memory

  • February 5, 2024
  • 1 reply
  • 1516 views

Hi community,

I am observing Hardfault exception when trying to program internal flash of stm32g030k6t6 MCU in FAST mode . is there anyother FLASH registers i need to enable ?

I have attached the code here 

static void write_data_to_application(void)
{
	//uint32_t *flash_address = (uint32_t *)FLASH_USER_END_ADDR ;

	uint32_t flash_address = 0x08007C00 ;

	HAL_StatusTypeDef status = HAL_OK;

	HAL_FLASH_Unlock();

	status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, (uint32_t)flash_address, (uint64_t)0xDEAD1731);

	HAL_FLASH_Lock();
}

 Thanks 

Narendra C

@TDK 

Best answer by TDK

That's still an invalid argument. Why do you want to use FLASH_TYPEPROGRAM_FAST? Your use case is clearly better suited to FLASH_TYPEPROGRAM_DOUBLEWORD as you aren't programming 256 bytes.

1 reply

TDK
Super User
February 5, 2024

> status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, (uint32_t)flash_address, (uint64_t)0xDEAD1731);

This is a bogus call. 0xDEAD1731 is not the location of 256 bytes of data, as required for fast programming.

Probably you want to stick with FLASH_TYPEPROGRAM_DOUBLEWORD and program 64-bits at a time.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Nchun.1
Nchun.1Author
Associate III
February 6, 2024

Hello @TDK ,

I am able to save data in Flash with FLASH_TYPEPROGRAM_DOUBLEWORD . but Hard fault exception is still exists even passing arguments correctly with  FLASH_TYPEPROGRAM_FAST

Kindly help 

 

Nchun1_1-1707195623454.pngNchun1_2-1707195666832.png

 

Thanks & Regards

Narendra C

TDK
TDKAnswer
Super User
February 6, 2024

That's still an invalid argument. Why do you want to use FLASH_TYPEPROGRAM_FAST? Your use case is clearly better suited to FLASH_TYPEPROGRAM_DOUBLEWORD as you aren't programming 256 bytes.

"If you feel a post has answered your question, please click ""Accept as Solution""."