RAK3172 - FLASH Erase Timeout in HAL stm32wlxx_hal_flash WaitForLastOperation

Hi, we followed this tutorial to develop the firmware for a custom board.

Everything works apart from a HAL_TIMEOUT issue with the stm32wlxx_hal_flash.c FLASH_WaitForLastOperation(uint32_t Timeout) method.

During setup a default config struct is successfully written to flash using the following sequence of HAL calls: HAL_FLASH_Unlock → HAL_FLASHEx_Erase → HAL_FLASH_Program [DOUBLEWORD] → HAL_FLASH_Lock.

The device runs as Class C (It’s mains connected) and receives config updates via downlinks. During the OnRxData interrupt the LMHandlerAppData is parsed and the config parameter reconciled, actioned and updated. Intermittently the FLASH_WaitForLastOperation fails with a HAL_TIMEOUT waiting for the CR register to be cleared [FLASH_FLAG_CFGBUSY] before the erase occurs.

We have tried disabling interrupts and refreshing the watchdog throughout the sequence above, but the problem persists.

The intermittent nature of the problem seems to imply IRQs, we have tried clearing the error flags prior to the erase using _HAL_FLASH_CLEAR_FLAG but the FLASH_FLAG_CFGBSY appears and causes the 1s timeout in the wait for last operation.

FLASH_LATENCY_1 is referenced in the HAL_RCC_ClockConfig the HSE is TCXO - to flash the speed is 32Mhz.

Has anyone encountered similar FLASH issues with the ? Any help greatly appreciated.

Thanks Tim

Welcome to the forum @Tim

We cannot support the STMicroelectronics source codes. For such questions, please contact STM directly.

Thank you for the welcome @beegee

It’s not a problem - turns out the FLASH write hard fault only happens when the MQ8 UBLOX GNSS receiver is powered.

We are planning to move to RU13