Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Initial SW102 firmware install

Kevin Hester edited this page Aug 10, 2019 · 14 revisions
  • The bad news: The installation is done via a command line tool called openocd, so you'll need to use a windows command shell.
  • The good news: You'll only need to do this once, after this point you can close your unit up and future updates are done via bluetooth.

Install the ST-LINK software

Before connecting the ST-LINK to your machine (Windows or Linux), download the driver here. Scroll down to the bottom of the page to the "GET SOFTWARE" section and download "STSW-LINK009".

Install the OpenOCD software

After installing the ST-LINK driver, we need OpenOCD. OpenOCD is a great free tool that we will use to talk to the SW102 with the ST-LINK. Download the binaries here.

We will use version 20190715, extract the files to a folder.

Download sw102-full-xxx.hex

Of course, you need our firmware. Download the latest version from here into your openocd/bin directory. You will only need the sw102-full-0.19.xxx.hex file for now. For any later updates you'll just use our bluetooth bootloader and update the software via your Android or iOS phone.

Test your electrical connection to the SW102

It's time to connect your ST-LINK, your SW102 and your machine! Your SW102 will turn on and it will take Windows a minute to install the drivers. If you have the SW102 already connected to your battery pack, make sure the battery is OFF while doing this installation. The power for your SW102 will come from the ST-LINK ONLY.

Open a terminal and navigate to the openocd/bin/ folder (tip: open the folder from the explorer and in the path bar type "cmd", a command prompt opens located on the folder directly). Run the following command to start OpenOCD and connect the ST-LINK:

openocd -f ..\share\openocd\scripts\interface\stlink.cfg -f ..\share\openocd\scripts\target\nrf51.cfg

You should then see something like this:

Open On-Chip Debugger 0.9.0 (2019-02-10)
[...]
Info: STLINK V2J17S4 (API V2) VID:PID 0483:3748
Info: Target voltage: 3.237541
Info: nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints

If it instead says:

Error: open failed

That means your ST-LINK is not found via USB

If it says:

Error: init mode failed (unable to connect to the target)

That means there is something wrong with the four wires from the ST-LINK to the SW-102.

After confirming OpenOCD can see your board, press ctrl-C to exit.

Program the firmware into the SW102

Okay - you are now ready to paste in this long command line:

openocd -f ..\share\openocd\scripts\interface\stlink.cfg -f ..\share\openocd\scripts\target\nrf51.cfg -c "init; reset init; nrf51 mass_erase; flash write_image sw102-full-0.19.xxx.hex; verify_image sw102-full-0.19.xxx.hex; echo FLASHED; reset halt; resume; shutdown"

You should see output like the following.

Open On-Chip Debugger 0.10.0+dev-00921-g263deb38 (2019-07-24-09:12)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
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
Info : clock speed 1000 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 2.938277
Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0x000006d0 msp: 0x000007c0
Info : nRF51822-QFAC(build code: A1) 256kB Flash
Info : Flash write discontinued at 0x000007c0, next section at 0x00001000
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg/nrf52.cfg to disable it
Info : Padding image section 1 at 0x0001afe0 with 32 bytes
Info : Flash write discontinued at 0x000334d4, next section at 0x0003ac00
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg/nrf52.cfg to disable it
Info : Padding image section 3 at 0x0003fa54 with 428 bytes
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg/nrf52.cfg to disable it
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg/nrf52.cfg to disable it
FLASHED
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0x000006d0 msp: 0x000007c0
shutdown command invoked

Done!

If all went well you can now see the GUI running on our device (with a simulated motor). If something doesn't work please capture any console output, and describe what happened in a github bug report - we will help.

Clone this wiki locally