Closed kroppt closed 4 years ago
Have you tried running the code from this project? If you want, I can give you binaries to test, but you can easily compile yourself. The linker file should be like the one in this repo. Otherwise, the second bank image does not boot. But the pgaerr is not because of that. What are the conditions for PGSERR?
Doh.. one must unlock/lock the flash memory. When I read the documentation I thought that the lack of a "requires unlock" statement means that you don't have to unlock it. I also didn't think of just looking at the linker file in this repository, again doh. Now that I'm on the second bank, I have to figure out this other programming issue, so that I can get back to bank 1.
The discussion about the linker file and system boot loader and so on is here: https://community.st.com/s/question/0D50X0000CEqc1SSQR/dual-boot-on-the-stm32g4-not-quite-working-boot-from-second-bank-fails?t=1591957302322
Glad you found out! The PGSERR hinted at that, I had a slight suspicion :)
Unfortunately I cannot get it working still. I tried your project, but when I press the button, it reaches the end of the FLASH erase function, on either FLASH_PageErase
call or return status
.
After that, the stack trace is something like (shallowest to deepest):
<signal handler called>() at 0xfffffff9
Break at address "0xfffffffe"
<signal handler called>() at 0xfffffff1
Break at address "0xfffffffe"
In retrospect, this is what was happening on my own tests, I just thought that I was getting these issue because of where I placed the FLASH unlock.
I thought it might be your configuration or something like that, so I created a new project and copied the main code over, along with configuring the interrupts for FLASH and GPIO, setting up B1 and LD2. Even then, it still crashes with roughly the same stack trace.
So, I think my problem in fact is something different than what I described in the original post. I was getting errors related to the memory not having been flashed, because I didn't unlock the memory before flashing. It is when I do it correctly that it crashes.
I added the current binary. I really recommend trying if it works with that.
The binary has the same problem. I was using the ST-LINK Utility, and the the "core state" locks up when I press the button. Since I had it open, I did a full chip erase and the results were still the same.
Do you happen to have other hardware to check?
If you can try with STM32CubeIDE, you could check at which point the lock up happens.
I don't currently have more hardware on me. I had used STM32CubeIDE before, and as stated above, it would usually happen at the end of the FLASH erase function.
OK I found that the issue does not happen with another G4. I must conclude that G4 was just broken all along...
My code to test dual bank boot loading ended up being pretty much the same as yours, since there is really only one way to do it. I referenced your code to make sure that I didn't miss anything, but as far as I can tell it's the same.
When programming, there is an error.
HAL_Flash_GetError()
returns binary10100000
Bits 5 and 7 (0-indexed) are:FLASH_FLAG_PGAERR
(FLASH Programming alignment error flag)FLASH_FLAG_PGSERR
(FLASH Programming sequence error flag)According to the manual RM0440:
PGAERR
is set if one of the following conditions occurs:This occurs immediately when writing, where the offset is 0, i.e. address 0x08040000 is 'misaligned'.
I have not been able to find the linker discussion you talked about on the ST community website. Perhaps that is the solution to this.