'make flash' via jlink - crazyflie doesn't boot

Post here to get support
Post Reply
theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

'make flash' via jlink - crazyflie doesn't boot

Post by theseankelly »

Hey Forum

Poking around with the SWD interface on the debug board I just received.

Setup details:
I'm using the STM32F4 discovery's J-link interface as my debugger, hooked up to the crazyflie debug adapter, hooked up to a CF2. I'm running natively on windows (via some combination of cygwin and eclipse). This is all properly set up and running using OpenOCD, etc. (I know this for a fact because I'm able to load firmware via the radio and then connect and step in eclipse via SWD)

I'm trying to build and deploy firmware via the SWD interface -- I've done 'make DEBUG=1 CLOAD=0' followed by 'make flash'. The flashing goes through and succeeds, but the CF2 ends up sitting with a single blue light, doing nothing. I'm also not able to enter the bootloader via long-pressing the button any longer.

Here's the output from openOCD on the flash command:
Sean@txtmsgbreakup ~/projects/crazyflie/official_repos/crazyflie-firmware
$ make flash
openocd -d2 -f interface/stlink-v2.cfg -f target/stm32f4x_stlink.cfg -c init -c targets -c "reset halt" \
-c "flash write_image erase cf2.elf" -c "verify_image cf2.elf" -c "reset run" -c shutdown
Open On-Chip Debugger 0.9.0 (2015-05-19-12:06)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
debug_level: 2
WARNING: target/stm32f4x_stlink.cfg is deprecated, please switch to target/stm32f4x.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : clock speed 1800 kHz
Info : STLINK v2 JTAG v14 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.892490
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
TargetName Type Endian TapName State
-- ------------------ ---------- ------ ------------------ ------------
0* stm32f4x.cpu hla_target little stm32f4x.cpu running
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080002bc msp: 0x20005000
auto erase enabled
Info : device id = 0x10016413
Info : flash size = 1024kbytes
target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x20000042 msp: 0x20005000
wrote 262144 bytes from file cf2.elf in 9.438923s (27.122 KiB/s)
target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20005000
target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20005000
verified 178344 bytes in 1.703063s (102.265 KiB/s)
shutdown command invoked
Thinking I perhaps managed to hose the bootloader on my CF, I decided to try to rebuild and went back to the crazyflie2-stm-bootloader project to reflash it (also via SWD) and sure enough the self test went off without a hitch as soon as the flash completed (With no need to re-flash the actual firmware).

Kind of feels like I'm missing an obvious step here -- should I expect a firmware loaded via 'make flash' to boot just the same as if I flashed via radio? The fact that it sends a shutdown after flashing would explain why the firmware doesn't run, but I would have expected power cycling via the pushbutton to start up normally.

Thanks
Sean
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: 'make flash' via jlink - crazyflie doesn't boot

Post by chad »

I'm a neophyte with embedded systems, so take my words with a grain of salt.

I know (from having done it myself) that passing CLOAD=0 to make will compile firmware that stomps on the bootloader. It sounds like you were already able to get the bootloader re-flashed though, so that's good!

The Makefile is set up to use STLink-V2 and I saw a wiki page that mentions the need to manually enter the flashing command line and to edit the Eclipse config if you're using something else (like JLink). I'm not sure exactly what you have to change though... Maybe that's the issue for you?
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: 'make flash' via jlink - crazyflie doesn't boot

Post by theseankelly »

Thanks Chad.

I actually am using a STLink-v2 and not a jlink (whoops!) so my targets should be correct.

Furthermore, I also tried "make CLOAD=1 DEBUG=0" and then "make flash" -- same story. The flash succeeds, but then the copter doesn't boot. Also, if the flash was actually clobbering the bootloader, then when I re-flash the bootloader I would end up clobbering the firmware -- but everything works fine when I re-flash the bootloader. I suspect something else is going on here.
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.
Johny
Beginner
Posts: 2
Joined: Tue Feb 02, 2016 12:12 pm

Re: 'make flash' via jlink - crazyflie doesn't boot

Post by Johny »

theseankelly wrote: Wed Feb 03, 2016 3:53 am
Furthermore, I also tried "make CLOAD=1 DEBUG=0" and then "make flash" -- same story. The flash succeeds, but then the copter doesn't boot. Also, if the flash was actually clobbering the bootloader, then when I re-flash the bootloader I would end up clobbering the firmware -- but everything works fine when I re-flash the bootloader. I suspect something else is going on here.
Hi theseankelly,
were you able to find the reason for this behaviour? I believe I am going through the same. Always have to re-flash the bootloader after flashing the firmware via SWD in order for the crazyflie to boot. I'm also using an STM32F4 discovery's J-link.
Is it possible that while flashing the firmware with SWD, It is firstly erasing the complete memory and then when flashing it its writting in the correct address space(so the bootloader being flashed after does not mess up with the firmware)?
Thanks
Regards
theseankelly
Expert
Posts: 153
Joined: Mon Dec 28, 2015 3:23 pm
Contact:

Re: 'make flash' via jlink - crazyflie doesn't boot

Post by theseankelly »

What you stated is correct. When "make flash" runs, openOCD is using the 'autoerase' option which causes all flash from the start through the end of the image to be erased (including the bootloader). Then when the bootloader is flashed, only the portion used by the bootloader is erased, preserving the main firmware.

I never bothered to get all the way to the root cause, but here's my best guess: The image is offset to 0x8004000 at link time and flashed to the start of flash, so the "used" portion of the flash actually starts at 0x80000000, and so 'autoerase' blows away the bootloader. If this is true, a fix could be to not apply the offset to 0x8004000 at link time and instead use openocd commands to flash to an offset (as opposed to flashing an offset binary to the start of flash). Or don't use the autoerase option and instead add scripts in the makefile to flash the specific sectors needed starting at 0x8004000 through the size of the image. Again, though, this is a complete guess and you'd need to stare at the linker map and makefiles to see :)

If you're doing this frequently for debugging/stepping purposes, a quick workaround is to build with CLOAD=0 and then the firmware image will load at the start of flash. You'll have to rebuild with CLOAD=1 and reflash the bootloader when you want to go back to normal though.
http://www.thejumperwire.com
Tips, tutorials, and science about DIY electronics, drones, and embedded software.
Johny
Beginner
Posts: 2
Joined: Tue Feb 02, 2016 12:12 pm

Re: 'make flash' via jlink - crazyflie doesn't boot

Post by Johny »

Thanks for the tip! :)

I've had the crazyflie for a while but only now started to dig deeper into it.
I guess I'll go with the workaround you proposed for the time being because anyway, for the purpose of debbuging my changes to the firmware I dont really need the bootloader, so I guess I could load the firmware to the start of the flash.
Cheers!
Post Reply