modm-io / modm

modm: a C++23 library generator for AVR and ARM Cortex-M devices
https://modm.io
Mozilla Public License 2.0
733 stars 132 forks source link

Nucleo L3 programming fails #79

Closed strongly-typed closed 5 years ago

strongly-typed commented 6 years ago

Working example modm at 4ae989ee0

scons program verbose=1
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
openocd -s "/XXXXXXXXXXXXXXXXXXX/src/modm/openocd" -f "board/st_nucleo_f3.cfg" -c "init" -c "reset halt" -c "flash write_image erase build/src.elf" -c "reset halt" -c "mww 0xE000EDF0 0xA05F0000" -c "shutdown"
Open On-Chip Debugger 0.10.0+dev-00449-g4999c9d9 (2018-07-06-10:23)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v29 API v2 SWIM v18 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.262426
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0800180c msp: 0x20000be0
auto erase enabled
Info : device id = 0x10016438
Info : flash size = 64kbytes
Info : Padding image section 1 at 0x080001e8 with 8 bytes
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000be0
Warn : no flash bank found for address 0x10000000
wrote 14336 bytes from file build/src.elf in 0.807490s (17.338 KiB/s)
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0800180c msp: 0x20000be0
shutdown command invoked
scons: done building targets.

Non-working example, after updating modm to ea7a3008a

scons program verbose=1
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
openocd -f "XXXXXXXXXXXXXXX/src/modm/openocd.cfg" -c "modm_program build/release/src.elf"
Open On-Chip Debugger 0.10.0+dev-00449-g4999c9d9 (2018-07-06-10:23)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
program_debug
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v29 API v2 SWIM v18 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.264000
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
adapter speed: 950 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080018a0 msp: 0x20000be0
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
** Programming Started **
auto erase enabled
Info : device id = 0x10016438
Info : flash size = 64kbytes
Info : Padding image section 1 at 0x080001e8 with 8 bytes
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000be0
Warn : no flash bank found for address 0x10000000
wrote 14336 bytes from file build/release/src.elf in 0.654982s (21.375 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000be0
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000be0
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000be0
Error: checksum mismatch - attempting binary compare
diff 0 address 0x10000000. Was 0xe0 instead of 0x00
diff 1 address 0x10000001. Was 0x0b instead of 0x00
diff 2 address 0x10000003. Was 0x20 instead of 0x00
diff 3 address 0x10000004. Was 0x0d instead of 0x00
diff 4 address 0x10000005. Was 0x18 instead of 0x00
diff 5 address 0x10000007. Was 0x08 instead of 0x00
diff 6 address 0x10000008. Was 0xf5 instead of 0x00
diff 7 address 0x10000009. Was 0x18 instead of 0x00
diff 8 address 0x1000000b. Was 0x08 instead of 0x00
diff 9 address 0x1000000c. Was 0xf5 instead of 0x00
diff 10 address 0x1000000d. Was 0x18 instead of 0x00
diff 11 address 0x1000000f. Was 0x08 instead of 0x00
diff 12 address 0x10000010. Was 0xf5 instead of 0x00
diff 13 address 0x10000011. Was 0x18 instead of 0x00
diff 14 address 0x10000013. Was 0x08 instead of 0x00
diff 15 address 0x10000014. Was 0xf5 instead of 0x00
diff 16 address 0x10000015. Was 0x18 instead of 0x00
diff 17 address 0x10000017. Was 0x08 instead of 0x00
diff 18 address 0x10000018. Was 0xf5 instead of 0x00
diff 19 address 0x10000019. Was 0x18 instead of 0x00
diff 20 address 0x1000001b. Was 0x08 instead of 0x00
diff 21 address 0x1000001c. Was 0xf5 instead of 0x00
diff 22 address 0x1000001d. Was 0x18 instead of 0x00
diff 23 address 0x1000001f. Was 0x08 instead of 0x00
diff 24 address 0x10000020. Was 0xf5 instead of 0x00
diff 25 address 0x10000021. Was 0x18 instead of 0x00
diff 26 address 0x10000023. Was 0x08 instead of 0x00
diff 27 address 0x10000024. Was 0xf5 instead of 0x00
diff 28 address 0x10000025. Was 0x18 instead of 0x00
diff 29 address 0x10000027. Was 0x08 instead of 0x00
diff 30 address 0x10000028. Was 0xf5 instead of 0x00
diff 31 address 0x10000029. Was 0x18 instead of 0x00
diff 32 address 0x1000002b. Was 0x08 instead of 0x00
diff 33 address 0x1000002c. Was 0xf5 instead of 0x00
diff 34 address 0x1000002d. Was 0x18 instead of 0x00
diff 35 address 0x1000002f. Was 0x08 instead of 0x00
diff 36 address 0x10000030. Was 0xf5 instead of 0x00
diff 37 address 0x10000031. Was 0x18 instead of 0x00
diff 38 address 0x10000033. Was 0x08 instead of 0x00
diff 39 address 0x10000034. Was 0xf5 instead of 0x00
diff 40 address 0x10000035. Was 0x18 instead of 0x00
diff 41 address 0x10000037. Was 0x08 instead of 0x00
diff 42 address 0x10000038. Was 0xf5 instead of 0x00
diff 43 address 0x10000039. Was 0x18 instead of 0x00
diff 44 address 0x1000003b. Was 0x08 instead of 0x00
diff 45 address 0x1000003c. Was 0x99 instead of 0x00
diff 46 address 0x1000003d. Was 0x16 instead of 0x00
diff 47 address 0x1000003f. Was 0x08 instead of 0x00
diff 48 address 0x10000040. Was 0xf5 instead of 0x00
diff 49 address 0x10000041. Was 0x18 instead of 0x00
diff 50 address 0x10000043. Was 0x08 instead of 0x00
diff 51 address 0x10000044. Was 0xf5 instead of 0x00
diff 52 address 0x10000045. Was 0x18 instead of 0x00
diff 53 address 0x10000047. Was 0x08 instead of 0x00
diff 54 address 0x10000048. Was 0xf5 instead of 0x00
diff 55 address 0x10000049. Was 0x18 instead of 0x00
diff 56 address 0x1000004b. Was 0x08 instead of 0x00
diff 57 address 0x1000004c. Was 0xf5 instead of 0x00
diff 58 address 0x1000004d. Was 0x18 instead of 0x00
diff 59 address 0x1000004f. Was 0x08 instead of 0x00
diff 60 address 0x10000050. Was 0xf5 instead of 0x00
diff 61 address 0x10000051. Was 0x18 instead of 0x00
diff 62 address 0x10000053. Was 0x08 instead of 0x00
diff 63 address 0x10000054. Was 0xf5 instead of 0x00
diff 64 address 0x10000055. Was 0x18 instead of 0x00
diff 65 address 0x10000057. Was 0x08 instead of 0x00
diff 66 address 0x10000058. Was 0xf5 instead of 0x00
diff 67 address 0x10000059. Was 0x18 instead of 0x00
diff 68 address 0x1000005b. Was 0x08 instead of 0x00
diff 69 address 0x1000005c. Was 0xf5 instead of 0x00
diff 70 address 0x1000005d. Was 0x18 instead of 0x00
diff 71 address 0x1000005f. Was 0x08 instead of 0x00
diff 72 address 0x10000060. Was 0xf5 instead of 0x00
diff 73 address 0x10000061. Was 0x18 instead of 0x00
diff 74 address 0x10000063. Was 0x08 instead of 0x00
diff 75 address 0x10000064. Was 0xf5 instead of 0x00
diff 76 address 0x10000065. Was 0x18 instead of 0x00
diff 77 address 0x10000067. Was 0x08 instead of 0x00
diff 78 address 0x10000068. Was 0xf5 instead of 0x00
diff 79 address 0x10000069. Was 0x18 instead of 0x00
diff 80 address 0x1000006b. Was 0x08 instead of 0x00
diff 81 address 0x1000006c. Was 0xf5 instead of 0x00
diff 82 address 0x1000006d. Was 0x18 instead of 0x00
diff 83 address 0x1000006f. Was 0x08 instead of 0x00
diff 84 address 0x10000070. Was 0xf5 instead of 0x00
diff 85 address 0x10000071. Was 0x18 instead of 0x00
diff 86 address 0x10000073. Was 0x08 instead of 0x00
diff 87 address 0x10000074. Was 0xf5 instead of 0x00
diff 88 address 0x10000075. Was 0x18 instead of 0x00
diff 89 address 0x10000077. Was 0x08 instead of 0x00
diff 90 address 0x10000078. Was 0xf5 instead of 0x00
diff 91 address 0x10000079. Was 0x18 instead of 0x00
diff 92 address 0x1000007b. Was 0x08 instead of 0x00
diff 93 address 0x1000007c. Was 0xf5 instead of 0x00
diff 94 address 0x1000007d. Was 0x18 instead of 0x00
diff 95 address 0x1000007f. Was 0x08 instead of 0x00
diff 96 address 0x10000080. Was 0xf5 instead of 0x00
diff 97 address 0x10000081. Was 0x18 instead of 0x00
diff 98 address 0x10000083. Was 0x08 instead of 0x00
diff 99 address 0x10000084. Was 0xf5 instead of 0x00
diff 100 address 0x10000085. Was 0x18 instead of 0x00
diff 101 address 0x10000087. Was 0x08 instead of 0x00
diff 102 address 0x10000088. Was 0xf5 instead of 0x00
diff 103 address 0x10000089. Was 0x18 instead of 0x00
diff 104 address 0x1000008b. Was 0x08 instead of 0x00
diff 105 address 0x1000008c. Was 0xf5 instead of 0x00
diff 106 address 0x1000008d. Was 0x18 instead of 0x00
diff 107 address 0x1000008f. Was 0x08 instead of 0x00
diff 108 address 0x10000090. Was 0xf5 instead of 0x00
diff 109 address 0x10000091. Was 0x18 instead of 0x00
diff 110 address 0x10000093. Was 0x08 instead of 0x00
diff 111 address 0x10000094. Was 0xf5 instead of 0x00
diff 112 address 0x10000095. Was 0x18 instead of 0x00
diff 113 address 0x10000097. Was 0x08 instead of 0x00
diff 114 address 0x10000098. Was 0xf5 instead of 0x00
diff 115 address 0x10000099. Was 0x18 instead of 0x00
diff 116 address 0x1000009b. Was 0x08 instead of 0x00
diff 117 address 0x1000009c. Was 0xf5 instead of 0x00
diff 118 address 0x1000009d. Was 0x18 instead of 0x00
diff 119 address 0x1000009f. Was 0x08 instead of 0x00
diff 120 address 0x100000a0. Was 0xf5 instead of 0x00
diff 121 address 0x100000a1. Was 0x18 instead of 0x00
diff 122 address 0x100000a3. Was 0x08 instead of 0x00
diff 123 address 0x100000a4. Was 0xf5 instead of 0x00
diff 124 address 0x100000a5. Was 0x18 instead of 0x00
diff 125 address 0x100000a7. Was 0x08 instead of 0x00
diff 126 address 0x100000a8. Was 0xf5 instead of 0x00
diff 127 address 0x100000a9. Was 0x18 instead of 0x00
More than 128 errors, the rest are not printed.
embedded:startup.tcl:477: Error: ** Verify Failed **
in procedure 'modm_program'
in procedure 'program' called at file "/XXXXXXXXXXXXXXXXXXXXXXXXXX/src/modm/openocd.cfg", line 4
in procedure 'program_error' called at file "embedded:startup.tcl", line 522
at file "embedded:startup.tcl", line 477
scons: *** [openocd_run] Error 1
scons: building terminated because of errors.
cat modm/openocd.cfg
add_script_search_dir modm/openocd
source [find board/st_nucleo_f3.cfg]
proc modm_program { SOURCE } {
    program $SOURCE verify
    reset halt
    mww 0xE000EDF0 0xA05F0000
    shutdown
}

proc program_release {} {
    modm_program build/release/src.elf
}
proc program_debug {} {
    modm_program build/debug/src.elf
}
strongly-typed commented 6 years ago

Ok, seems to be more related to OpenOCD. Using program instead of flash write_image erase causes the warning

Warn : no flash bank found for address 0x10000000

and subsequently the verify does not work. 0x10000000 is the CCM SRAM.

rleh commented 6 years ago

@chris-durand got a similar error on a STM32F7 board some days ago. I think it was a OpenOCD related bug; programming actually works, only verification fails.

strongly-typed commented 6 years ago

Yes, can confirm that even with the old command (flash write_image) the verify_image does not work. Now running OpenOCD Open On-Chip Debugger 0.10.0+dev-00527-g724fddcb (2018-09-07-12:21)

rleh commented 6 years ago

Does the flash verification work with OpenOCD 0.10.0+dev-00527-g724fddcb (2018-09-07-12:21)?

strongly-typed commented 6 years ago

No, it doesn't. (But the code is on the chip and is doing very well.)

I can program an verify a STM32F103 (on a blue pill)

➜  src git:(master) ✗ scons program
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
.----OpenOCD--- build/release/src.elf
'-------------> stm32f103c8t
Open On-Chip Debugger 0.10.0+dev-00527-g724fddcb (2018-09-07-12:21)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
none separate
program_debug
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.202623
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080018e0 msp: 0x20000be0
** Programming Started **
auto erase enabled
Info : device id = 0x20036410
Info : flash size = 64kbytes
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000be0
wrote 4096 bytes from file build/release/src.elf in 0.294507s (13.582 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000be0
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20000be0
verified 3952 bytes in 0.138989s (27.767 KiB/s)
** Verified OK **
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000468 msp: 0x20000be0
shutdown command invoked
scons: done building targets.
rleh commented 6 years ago

Removing the verify argument from the OpenOCD command would fix the issue:


proc modm_program { SOURCE } {
-   program $SOURCE verify
+   program $SOURCE
    reset halt

But we better investigate why OpenOCD is trying to verify (and program?) SRAM at 0x10000000.

salkinium commented 5 years ago

Hm, I thought verifying would make programming more safe, but if this is the broken status of OpenOCD, then maybe we should remove it?

salkinium commented 5 years ago

I'm closing this, please open a PR if this OpenOCD bug is too annoying.

salkinium commented 5 years ago

HA! This isn't a bug in OpenOCD 🤦‍♂️. #AlwaysBlameOtherSoftwareFirst

This happens when placing the vector table into RAM (which is done by default on F3/F7) and the linkerscript didn't define the .vector_ram sections as (NOLOAD), so OpenOCD tried to verify it, which is of course difficult, since the memory is only copied during startup. PR is in works.