-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM32G491: programming flash error, non-erased value. #1310
Comments
NB: if we erase the entire product and reflash boot block, application and parameter regions, flashing reports no issue with non-erased values. But the erasure of the UDF bootblock and parameters is kinda destructive. |
@salyzyn Unfortunately I can't reproduce this with a STM32G431 Nucleo-32 board under similar conditions. |
I believe this issue may be related to the STM32G491 having 512KB of flash, STM32G431 only has 128KB. The report I provided was for a flash image that breached the 256KB 'bank' boundary. Which now that I see that, i have my suspicions. I have internal flash code in my application that uses the top 16KB of flash to simulate nonvolatile memory through a journaling filesystem. The problem is that the necessary manifest defines are left undefined in the HAL headers when the overarching config indicates the product is not in dual-bank mode, yet they are essential for access when in that fixed dual bank mode despite the config. We have to check the actual device's configuration. Hence why I have the #ifndef references below. The chips are shipped out in dual-bank mode and since stlink and IDE do not have a capability to switch it out of that mode, I have to be sensitive to this state. Since I found my workaround as cited below to calculate the appropriate Bank and Sectors used when erasing and flashing, I never stepped aside and used alternate tools to switch the STM32G491 into single bank mode, hence your problem in the tool. There is a performance advantage because writes/erasures to the second bank do not block MPU cycles for read accesses to the first bank, or so they say in the documentation, although for the most part not an issue since the STM32G491 also has a program cache that it hits instead of hitting flash. I hope the following helps identify what I believe to be the issue. NB: I do not complain in my code if I try to write content to flash that is already there, but since there is a CRC, one can not correct it (change just the 1s to 0s if it takes it) of course like we can do in other products without CRC protection of flash. My code will accept changing 1s to 0s, in other product's flash, other than STM32G491, but of course never supports changing 0s to 1s without an intervening block erase.
|
Hi! I have the same issue with STM32G491RET and code which is larger than 256kbyte. I use the latest git version compiled for yocto linux and an ST-Link V3. I'll try to switch to single bank via STM32CubeProg today and see if that helps. Regards, |
@salyzyn We currently have no dual-bank support implemented for this device - that's for sure. |
stM32g4 has three flash options, Category 2, 3 and 4, the stm32g491 is Category 4. in Category 3 block size is 2K for dual bank, and 4K for single bank, whereas Category 4 is 2K for both single and dual bank configurations. What a wild ride. Is there anything I can do to help? |
@salyzyn Indeed... I need to gain an overview first of what is currently supported in the codebase and what is missing. Please give me a few days for that. Do you have a L0 device as well or know anybody? |
I only have f429 and g491. No L0 device. I am hitting the road tomorrow, so dev work from campgrounds. Do you think sending you a NUCLEO-G491RE will help? PM me deets and hopefully can send you something from mouser? |
Thanks for the kind offer. I may find the specific Nucleo board at work when looking at it's specs, will check soon. |
@salyzyn Try this:
I'm not sure if that fixes it, but both steps at least seem to be part of the solution. I further noticed that option byte programming support seems absent for this device. |
... the board at work is a Nucleo-G474RE 😒 - whatever, as it has dualbank as well, i'll give it a try to see what is happening. |
@salyzyn: I could reproduce the observed behaviour and found a reason for it. 🎉
|
Just got internet/laptop. sounds like you have the solution without my help ;-> Thanks! Does your solution work for the stm32g474 (a category 3 device, where the block size changes 2k/4k depending on bank selection mode) in either mode (READ_BIT(FLASH->OPTR, OB_USER_DBANK) returning true or false)? It might be the more complex chip to manage. The stm32g491/stm32g4a1 are a category 4 devices, which AFAIK only means the block size remains constant 2k regardless if in single bank or dual bank mode, all else is similar I suspect, but by no means am I an expoit(sic) |
You are welcome. Can you verify the result on your side? I plan to look at the STM32G474 case this weekend. |
It does work on the Nucleo-G474RE as well. The lengthy debug output shows nothing remarkable, so I'm skipping it here.
|
@salyzyn I'm now waiting for your verification, before committing the proposed fixes, which would then close this issue per automation. Please report back as soon as you were able to do your testing. |
The |
@salyzyn I can reproduce this now on a Nucleo-G431KB (STM32G43x_G44x):
The error derives from here (L1393ff):
... but I couldn't make out the reason yet. It may have to do with alignment indeed tough. |
Make full erase, then by STM32CubeProgrammer check what was really flashed. |
@victor-dryad I think I've made at least a little progress on my side: Leaving out
--> I need a smaller binary. How stupid. 🙈 Here is the second attempt with a 64 KiB binary:
We should retry this on a STM32G491 with the latest |
To set up a right test for current issue, a device from this serie with 256 or 512KiB (2 or 4 * 128) is needed. |
Additional testing on a Nucleo-G474RE confirms the result by @salyzyn :
with this .bin file ending:
|
The error seems to derive from
... and it looks like, as if only single bank devices are addressed here. |
With the same approach as above, this now leads to:
|
st-flash 1.7.0-294-gd4b53b0 Problem still exists, please PM me and I will arrange to send you a stm32g491 development board |
@salyzyn This is still a very kind offer, but I must admit that I'm not able to spend any time to dig into things deeper at the moment, so it wouldn't change anything really. Paid work takes precedence. |
Ubuntu 22.04 (linux)
any v1.7.0 version of st-flash exhibits the problem as shipped in ubuntu, and then we built v1.7.0-263-g8de2b4d latest from git pull and reproduced.
NUCLEO-G491RE with on-board STLink/V3. Chip is an STM32G491RE6.
$ st-info --probe
Found 1 stlink programmers
version: V3J10
serial: 0009002C4D46501020383832
flash: 524288 (pagesize: 2048)
sram: 114688
chipid: 0x479
dev-type: STM32G49x_G4Ax
Happens even if we round the size of the flash image up to the next 2Kbyte boundary. Some other flashing bugs with same WB/G0/G4/L5/U5 system indicated fill to 16 byte boundary solved their unrelated issue, we tried 16, 512 and 2048 byte 0xFF roundup to the image size.
NB: an sboot _stm32 bootblock resides at 0x8000000, and runs the executable at 0x8004000. We have similar flash issue if we KISS and drop the UDF bootblock and run on iron at 0x8000000, albeit with slightly more chances of success to run with the borken(sic) flash report. We do correct SCB->VTOR, so no FUD there.
$ st-flash st-flash --connect-under-reset --debug write build/NUCLEO-G491RE.checked 0x8004000
st-flash 1.7.0-263-g8de2b4d
2023-04-29T10:48:28 INFO common.c: STM32G49x_G4Ax: 112 KiB SRAM, 512 KiB flash in at least 2 KiB pages.
file build/NUCLEO-G491RE.checked md5 checksum: b6f199bd74a22ad196b2974f40d2d9, stlink checksum: 0x01c4ab4c
2023-04-29T10:48:28 INFO common_flash.c: Attempting to write 284672 (0x45800) bytes to stm32 address: 134234112 (0x8004000)
. . .
-> Flash page at 0x8049000 erased (size: 0x800)
2023-04-29T10:48:31 INFO flashloader.c: Starting Flash write for WB/G0/G4/L5/U5
. . .
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_write_debug32 0xffffffff to 0x080497ec
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_read_debug32 0x000000a8 at 0x40022010
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_write_debug32 0xffffffff to 0x080497f0
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_read_debug32 0x000000a8 at 0x40022010
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_write_debug32 0xffffffff to 0x080497f4
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_read_debug32 0x000000a8 at 0x40022010
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_write_debug32 0xffffffff to 0x080497f8
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_read_debug32 0x000000a8 at 0x40022010
139/139 pages written
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_write_debug32 0xffffffff to 0x080497fc
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_read_debug32 0x000000a8 at 0x40022010
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_read_debug32 0x000000a8 at 0x40022010
2023-04-29T10:42:37 ERROR common_flash.c: Flash memory contains a non-erased value
2023-04-29T10:42:37 ERROR common_flash.c: Flash programming error: 0x000000a0
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_read_debug32 0x080049ad at 0x08004004
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_write_reg
2023-04-29T10:42:37 DEBUG common.c: *** stlink_run ***
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_read_reg
2023-04-29T10:42:37 DEBUG read_write.c: (16) ***
2023-04-29T10:42:37 DEBUG common.c: data_len = 8 0x8
80 00 00 00 00 00 00 01
2023-04-29T10:42:37 DEBUG usb.c: r_idx (16) = 0x01000000
stlink_fwrite_flash() == -1
2023-04-29T10:42:37 DEBUG common.c: *** stlink_exit_debug_mode ***
2023-04-29T10:42:37 DEBUG read_write.c: *** stlink_write_debug32 0xa05f0000 to 0xe000edf0
Expected the device to flash and run. Sometimes it does run if code is changed and positions moves, but flakey. When we flash with the built-in tools with STM32cubeIDE, the same binary flashes and runs appropriately independently or under the debugger.
The text was updated successfully, but these errors were encountered: