2023-10-11 12:56 AM
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
2023-10-13 08:51 AM
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
2023-10-16 12:46 AM
Hello @Aziz BRIGUI,
sure! I forgot to say that I'm erasing the whole flash before those API calls.
I use the massErase() API!
2023-10-17 06:58 AM
Hello @FValm.1 ,
Could you attach your project here so that we can investigate further ?
Thanks,
Aziz
2023-10-19 12:43 AM
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
2023-10-19 12:52 AM
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?