STMicroelectronics / STM32CubeWL

STM32Cube MCU Full FW Package for the STM32WL series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on boards provided by ST (Nucleo boards)
Other
99 stars 52 forks source link

FLASH_IF_INT_CLEAR_ERROR causes to hard fault #77

Open fozayDost opened 9 months ago

fozayDost commented 9 months ago

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.

TOUNSTM commented 9 months ago

Hello @fozayDost,

Thank you for this report. We will get back to you as soon as we analyze it further. This may take some time. Thank you for your comprehension.

With regards,

ebanorafael commented 7 months ago

Hi,

From the registers from the flash peripheral you've posted I've seen that the bit CFGBSY from SR register is set.

Some time ago I've had a similar problem (busfault escalated to hardfault with this bit set).

This may help you somehow, if it is still a problem after all the time this issue is opened.