cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4's flash write error, PGS and PGP error flags set at startup

MGall.11
Associate III

Dear all,

I'm working on a project based on STM32F479 microcontroller and I'm using STM32CubeIDE as IDE. The system uses an RTOS (in particular FreeRTOS) and I have reserved a working area into the microcontroller's flash memory to store system information. I have experienced a strange behaviour when I write to the microcontroller's flash using HAL function HAL_FLASH_Program. Inside main, before starting the RTOS scheduler, all the write operations to the flash work correctly. After starting the scheduler, the very first write operation (using the same HAL function) fails beacuse PGSERR and PGPERR flags in Flash status register (0x0C) are set. It seems that, after starting the scheduler, some error flags remain pending in the status register.

In order to solve the issue I clear those flags before the write operation. Everything works, but the strange thing is that this behaviour only occurs at the very first write operation after starting the scheduler. I would like to know if this is an unexpected behaviour. Moreover I would like to understand if it could be due to a flash programming operation by IDE and JTAG.

Best regards.

2 REPLIES 2

Hello @MGall.1​ ,

Try to perform a stack overflow check. If the main task in the environment or another task exceeds the available stack space, unpredictable behavior will occur.

BeST Regards,

Walid

MGall.11
Associate III

Hi Walid,

I'm pretty sure it's not a stack overflow since I have enabled stack overflow check from FreeRTOS configuration. If a stack overflow happens it will be catched by the corresponding hook function and I'll be able to inspect it.

BR,

Massimo