I need to program several boards with a firmware: a number too small for serious batch/factory programming, but a number too high doing this with the debugger. I want this:
- Connect the board with the debug probe and power it
- Run a script to flash the program and run it
- Disconnect and restart step 1.
With “Command Line Programming and Debugging with GDB” I have pretty much everything in place. So I only need to combine things to a solution. Because it different depending if using the P&E Multilink or Segger J-Link, I have covered both methods. I’m using the Eclipse based Kinetis Design Studio v3.0.0, but a command line gdb installation could be used too.
I’m using the following batch file to start the P&E GDB server, followed by starting the gdb client. Change paths accordingly:
REM Start P&E GDB Server with single session call "cmd /c start C:\Freescale\KDS_3.0.0\eclipse\plugins\com.pemicro.debug.gdbjtag.pne_184.108.40.206504092111\win32\pegdbserver_console.exe -startserver -singlesession -device=Freescale_K6x_K64FN1M0M12" REM start gdb with script C:\Freescale\KDS_3.0.0\arm-none-eabi-gdb -x gdbScript.txt
The option -singlesession to the P&E server is a nice feature: it will terminate the server after the session is finished. I’m using the Freescale K64F in above example, so make sure the -device option matches your target.
The gdb uses the option -x uses this gdb script file:
# gdbscript.txt: script for gdb. Run it with # gdb -x <commandFile> # disable confirmation messages (y or no): set confirm off # connect to P&E gdb server: target remote localhost:7224 # reset target: monitor reset # load symbols for application (not necessary for flashing only): # file MyProject/Debug/MyProject.elf # load application: load MyProject/Debug/MyProject.elf # detach from target. As a side effect, this will start it: detach # quit gdb: quit
With the Segger J-Link, I need to launch the GDB server first (make sure it not already running):
In a separate cmd/shell window, I run a script:
c:\Freescale\KDS_3.0.0\toolchain\bin\arm-none-eabi-gdb.exe -x gdbscript.txt
The script has the following content to load the file, run it and then disconnect:
# gdb script target remote localhost:2331 monitor device MK64FN1M0xxx12 monitor reset load ./Debug/FRDM-K64F_FreeRTOS_8.2.1.elf # load symbols, not necessary for flashing only # file ./Debug/FRDM-K64F_FreeRTOS_8.2.1.elf monitor go disconnect quit
Make sure you update the device and target image/path settings.
The difference to the P&E version is that the Segger J-Link server keeps running. I have not found a way to make that part automated.
There is no IDE or complicated setup necessary to batch program a set of board: all what is needed are some gdb scripts, and I can program and run one board after each other in a series of boards.
Happy Programming 🙂
Small point… Isn’t the ‘file’ command redundant/unnecessary here?
Isn’t it for specifying the file from which symbolic debug info will be loaded (usually the same file specified in the command – but not necessarily) in order to debug interactively?
And since this is batch load mode with no debugging it’s not needed?
Might speed things up a little to omit it?
Yes, good point! The ‘file’ command is not necessary for flashing only. I had it in there because I used that sequence for debugging too. I have updated the post to reflect this. Thanks!
Thanks Erich – and apologies for the garbled post! Edit my original to make it legible and delete my other one below if you like.
Yes, I have done that. No problem, happened to myself many times too….
You could also use Segger’s JLink Commander. All you have to do is write a batch file like this:
C:\SAGIDE\Debugger\JLink_V500c\JLink.exe -Device STM32F103VC -CommanderScript download.jlink
and download.jlink like this:
loadbin .\xy.bin 0x8000000
verifybin .\xy.bin 0x8000000
savebin memoryDumb.bin 0x8000000 0x8000
This way you dont even have to start gdb. It’s also possible to write multiple bin files or just erase the memory 🙂
thanks for sharing your script! If using only J-Link, using the commander is a very convenient way to do things like this.
Pingback: Updating Segger Tools in Eclipse Kinetis Design Studio | MCU on Eclipse
Hi Erich, great post! Thank you!
Is it possibile to serialize the elf? With many nodes it could be useful!
Can you explain what you mean with ‘serialize’?
Hi Erich, with serialize I mean program every node with a different “MAC address”. MAC address that I set in the program as a const.
You could use a script to connect to different J-Link probes, each programming its own device. But if you want to connect multiple devices on a ‘bus’, then you need to use JTAG Daisy-Chaining.
Pingback: Flashing and Restoring the Hexiwear Firmware | MCU on Eclipse