SparkFun Forums 

Where electronics enthusiasts find answers.

Open source ARM Debugger
By rogerclark

I'm trying to script OpenOCD to upload to Flash (write to flash) for a nRF51822

Currently I have been running the openocd exe then telnetting and issueing the commands
Code: Select all
flash write_image erase myfile.hex 0

However, I'd really like to be able to script this up, so its run automatically.

I know I can probably do this my piping the commands into telnet, but as OpenOCD seems to be able to have commands (or possibly just one command) passed with the --command option, I was hoping that either I could pass commands on the command line, or possibly run a commands script.

The command script is not ideal as the filename of the hex file to flash changes depending on the project, so ideally I'd like to pass commands

But I've tried a few things and even the basics like
openocd --command halt

doesnt seem to work.

So I'm obviously doing something completely wrong.

Perhaps I need to use GDB, but in which case I don't know how to tell gdb to do the flash write_image erase, as it only seems to have the mass_erase command, and this isnt ideal as it will wipe the whole MCU including the bootloader.

By alexandrehdk
You can create a batch script that receive the filename to be flashed, create/recreate your script to be executed, start OpenOCD, and finally, run gdb, passing the script as argument.
By rogerclark


I was hoping to avoid needing a script, as the script would need to be created every time I need to upload, as the filename will be different each time (well for different programs)

In the interim, since I posted 10 days ago, I have found a solution by using GDB directly, as you can pass multiple commands to GDB on the command line and it executes them in order

But thanks for replying, as I may need to use OpenOCD in the future for something else