STM32CubeWL icon indicating copy to clipboard operation
STM32CubeWL copied to clipboard

FLASH_IF_INT_CLEAR_ERROR causes to hard fault

Open fozayDost opened this issue 10 months ago • 2 comments

Hello guys,

During flash update operation, i sometimes got hard fault. Here is some information :

Board : Custom board with STM32WLE5JCIX based LoRa-E5 (not module). IDE : STM32CubeIDE

I am using Lorawan, GNSS, power modes (stop mode) and TIMER_IF functions to wake up periodically to read accelerometer.

Error production steps : 1- Board is low power state 2- Send downlink signal to board in order to trigger flash update. 3- Board wake up for sending data over LoRa (TX) 4- After sending data board receiving data over LoRa (RX) 5- Board got my message and try to update the flash with the procedure below :

a- FLASH_IF_Erase to erase the flash b- FLASH_IF_WRİTE to write the flash c- Reset the board if necessary

` struct flashVariables flashWrite;

if (FLASH_IF_Erase((void *)&__CONFIG_START, USER_FLASH_PAGE_SIZE) == FLASH_IF_OK)
     {

	flashWrite.opModeCurVar = opModeCur;
	flashWrite.tasmaIdVar = tasmaId;
	flashWrite.zThreshVar = zThreshold;
	flashWrite.zUptimeThreshVar = zUptimeThreshold;
	flashWrite.flashCheck = 0x55;
	FLASH_IF_Write((void *)&__CONFIG_START, (const void *)&flashWrite, sizeof(struct flashVariables));
}

if (flashUpdateTriggered >= 2)
{
	HAL_Delay(1000);
	NVIC_SystemReset();
}

flashUpdateTriggered = 0;`

__CONFIG_START is defined in .ld file as :

MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 254K FCONF(r) : ORIGIN = 0x0803F800, LENGTH = 2K }

and user page size is : #define USER_FLASH_PAGE_SIZE 0x800

By the way, it is working without problem most of the times. I got the error maybe 1/20 trial. I have tested it in a loop like erase-write-read and i could not cause the error.

This is the error stack, HAL_FLASH_LOCK causes the hard fault especially READ_BIT line.

/* verify Flash is locked */ if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) == 0U) { status = HAL_ERROR; }

FlashError

FlashError2

FlashError3

I could not find a way to handle the problem anymore. Could someone help me with this.

fozayDost avatar Sep 21 '23 09:09 fozayDost