== Issue encountered when flashing firmware from linux som => stm32h735x mcu
Proposed solution below with patch attached and tested for my stm32H735 MCU with stm32flash v 0.7
On checking the source code in dev_table.c indeed MCU stm3273X is part of the array list stm32_dev_t devices[] but an invalid check in stm32_init( ) causes it to fail
Hi, thanks for the bug report and the suggested patch. However I don't understand the attached patch. Apparently it is not the same patch as was used in your testing. What is wrong in the original code that makes it an "invalid check"?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Tormod,
It turns out that there is a possible race condition or corruption which is overwriting one of the dev structures while traversing the device list. This causes the search loop of device ID list, to terminate early when checking the value of stm->dev->id, making the code think the MCU device ID is not found.
It's a bit tricky to track this down, as issue occurs randomly. I narrowed it down after several attempts to capture debug details - with a watchpoint enabled for it. as shown below, it shows the point of device list traversed and at device index list 9 turns out 0x0.
`
.....
< .. downsized device list iterations.. >
(gdb) watch stm->dev->id
Hardware watchpoint 5: stm->dev->id
(gdb) n
563 fprintf(stdout,">>>> Checking device id: 0x%03x\n", stm->dev->id);
(gdb) n
Checking device id: 0x414
564 if (stm->dev->id == 0x00)
(gdb) n
566 ++stm->dev;
(gdb) n
Hardware watchpoint 5: stm->dev->id <<<<<<
Old value = <unreadable> <<<<<<
New value = 0 <<<<<< Corrupted </unreadable>
stm32_init (port=0xaaaaaaac0300 <port_serial>, init=1 '\001') at stm32.c:562
562 while (stm->dev->id != 0x00 && stm->dev->id != stm->pid) {
(gdb) n
569 fprintf(stdout,">>>> stm->dev->id = %d", stm->dev->id);</port_serial>
It's possible some code is writing past the end of a buffer, memory corruption.
I am also running with valgrind for memory analysis, if anything I'll let you know .
( fyi - stm32flash run in arm64 bit environment, hardware platform - imx93 som )
Details of issue:
Error: Unknown/unsupported device (Device ID: 0x483)
MCU - stm32h735
stm32flash - v 0.7
== Issue encountered when flashing firmware from linux som => stm32h735x mcu
Proposed solution below with patch attached and tested for my stm32H735 MCU with stm32flash v 0.7
== Analysis:
== Proposed solution:
I have fixed the issue with a simple patch to fix this invalid device id check.
Tested firmware flashing after applying my patch: (ignore debug prints of dev list)
Enclosed pls find patch attached
Hi, thanks for the bug report and the suggested patch. However I don't understand the attached patch. Apparently it is not the same patch as was used in your testing. What is wrong in the original code that makes it an "invalid check"?
Hi Tormod,
It turns out that there is a possible race condition or corruption which is overwriting one of the dev structures while traversing the device list. This causes the search loop of device ID list, to terminate early when checking the value of stm->dev->id, making the code think the MCU device ID is not found.
It's a bit tricky to track this down, as issue occurs randomly. I narrowed it down after several attempts to capture debug details - with a watchpoint enabled for it. as shown below, it shows the point of device list traversed and at device index list 9 turns out 0x0.
`
.....
< .. downsized device list iterations.. >
(gdb) watch stm->dev->id
Hardware watchpoint 5: stm->dev->id
(gdb) n
563 fprintf(stdout,">>>> Checking device id: 0x%03x\n", stm->dev->id);
(gdb) n
Hardware watchpoint 5: stm->dev->id <<<<<<
Old value = <unreadable> <<<<<<
New value = 0 <<<<<< Corrupted </unreadable>
stm32_init (port=0xaaaaaaac0300 <port_serial>, init=1 '\001') at stm32.c:562
562 while (stm->dev->id != 0x00 && stm->dev->id != stm->pid) {
(gdb) n
569 fprintf(stdout,">>>> stm->dev->id = %d", stm->dev->id);</port_serial>
(gdb) p/x stm->dev->id
$5 = 0x0 <<<<<
(gdb) p/x stm->pid
$6 = 0x483
(gdb) n
571 if (!stm->dev->id) {
(gdb) n
572 fprintf(stderr, "Unknown/unsupported device (Device ID: 0x%03x)\n", s
(gdb) n
Unknown/unsupported device (Device ID: 0x483)
573 fprintf(stdout,"error case: stm->dev->id = %d", stm->dev->id);
(gdb) n
574 stm32_close(stm);
(gdb) info locals
len = 2 '\002'
val = 146 '\222'
buf = "\001\004\203\001\002\021!1Dcs\202\222\252\000\000\n\000\000\000\000\000\000\000\003\00\000\000\000P\367\377\377\377\377\000\000XB\252\252\252\252\000\000P\367\377\377\377\377\000\377\377\377\000\000 \367\377\377\377\377\000\000\320\377\377\377\200\377\377\377P\367\377\377000P\367\377\377\377\377\000\000 \367\377\377\377\377\000\000\320\377\377\377\200\377\377\377ts 16 times>, "d\000\000\000\000\000\000\000\003\000\000\000\006\000\000\000\000\000\000\000\77\000\000\000\000\000\000\000\000\000\377\377\377\377\377\377\377\000\377\377\377\000\377\37\377\377\360\377\360\377\000\000\000\000\000\000\000\000(\000\254\252\252\252\000\000"...
stm = 0xaaaaaaac2400
i = 12
new_cmds = 0
version = 49 '1'
(gdb) p/x stm->pid
$7 = 0x483
(gdb) p/x stm->dev->id
$8 = 0x0 <<<<< dev->id = 0x0
(gdb) p/x stm->dev
$9 = 0xaaaaaaabecb8
(gdb) p/x stm->dev->id
$10 = 0x0
(gdb) p/x stm->option1
$11 = 0x0
(gdb) p/x stm->option2
$12 = 0x0
(gdb) p/x stm->port
$13 = 0xaaaaaaac0300
(gdb) p/s stm->port
$14 = (struct port_interface *) 0xaaaaaaac0300 <port_serial>`</port_serial>
It's possible some code is writing past the end of a buffer, memory corruption.
I am also running with valgrind for memory analysis, if anything I'll let you know .
( fyi - stm32flash run in arm64 bit environment, hardware platform - imx93 som )