Skip to main content
FValm.1
Associate III
October 11, 2023
Question

FLASH status with error bits after operation with sendOprtionBytesCommand() and writeMemory() API

  • October 11, 2023
  • 3 replies
  • 2108 views

Hello,
I have implemented a little project with a nucleo board with STM32G474RE MPU. The purpose is to manage the firmware upgrade, written in the user flash, from a PC connected via USB interface. The MPU, when boots up, start in the DFU modality since the boot0 pin is high (nSWBOOT pin is also high the first time) and so the program starts from system memory. The PC connects with the DFU, parse an hex file, transforms it  into a bin file and writes the flash directly using the API: sendOprtionBytesCommand() and writeMemory(). After doing that the PC switch the MPU to the user flash calling the API: execute(0x08000000).
MPU at this point should modify the option bytes so that all following reset will start from user flash. And that is achieved by setting nSWBOOT0 to 0 and nBOOT0 to 1. There are HAL specific API that can be called to perform  that task. But the problem is that, when the program in user flash starts, there are already errors in the flash status register and this makes these specific API returning with error.
Actually the status flash register has value 0xF0 which means the following bits are set:

WRPERR
PGAERR
SIZEERR
PSGERR

I don't know why this is happening since the API called from PC, to program the flash, are all returning with no error. Any hints? 
Thank you all for your suggests

 

 

This topic has been closed for replies.

3 replies

Aziz BRIGUI
Technical Moderator
October 13, 2023

Hello @FValm.1,

 

Please make sure flash memory is erased before calling writeMemory() API (The API doesn't erase the flash before writing). That might be what's causing the issue.

 

Hope this helps,

Aziz

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
FValm.1
FValm.1Author
Associate III
October 16, 2023

Hello @Aziz BRIGUI,

sure! I forgot to say that I'm erasing the whole flash before those API calls.
I use the massErase() API!

Aziz BRIGUI
Technical Moderator
October 17, 2023

Hello @FValm.1 ,

Could you attach your project here so that we can investigate further ?

Thanks,

Aziz

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
FValm.1
FValm.1Author
Associate III
October 19, 2023

Hello @Aziz BRIGUI 
the maximum allowed size is very small for the attachments... My ST project is about 13 Mb zipped... and zipped file is not allowed. While the Visual Studio zipped project is about 130 MB

FValm.1
FValm.1Author
Associate III
October 19, 2023

Anyway I have seen that if I clear the bits, that I have mentioned in my previous comment, at the start of the program running in the MPU,  then I can change the option bytes succesfully. Could it be correct doing that clearing operation or do I have to fear any side effect?