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

Initial SW102 firmware install

Niklas edited this page Aug 16, 2019 · 14 revisions
  • The bad news: Opening the SW102 and soldering the debug wires is tedious.
  • 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.

Open the SW102

This procedure is quite doable, but you must read these instructions and work carefully and slowly.

(Optional) Remove the keypad PCB from the case

If you feel you want better access for soldering, you can carefully remove the keypad circuit board from the case and use your fingernail to unlatch the ribbon cable on the back connector. You'll need to reattach the cable afterwards, but it makes it easier for you to access the pads for soldering.

Solderless connection to debug pads

If you don't have a solder iron at hand you can also program the SW102 by a solderless programming method. For this you need
2.54 to 2.0mm Jumper Wires like this one
2.0mm pitch pin header like this one

Seperate four wires and put the pin header into the 2.0mm end like on this picture:


Attach the wires to the ST-LINK as follows:

SW102 ST-LINK
GND GND
CLK SWCLK
DIO SWDIO
3V3 3.3V VERY IMPORTANT DO NOT ACCIDENTALLY CONNECT TO 5V

Start the Windows Tool, hit 'f' and the tool waits 10 seconds so you can get prepared by pressing the pin header against the debug pad (watch the orientation!):

Temporarily solder the wires for programming

If you are more into soldering you can install four wires, each about 1" long. You should select wires that fit the cable that comes with your ST-LINK programmer. You can solder these wires with the circuit board in-place if you are careful, or you can slide the circuit board out of the case for soldering, but be careful of the short ribbon cable that connects the board to the screen circuit board. Steps to follow:

  • Use a very fine tip soldering iron. Something similar to this. This is especially true if you are soldering the wires with the circuit board inside the case.
  • Before soldering the wires 'tin' each of the four pads with solder. By this we mean, use the tip of your soldering iron to melt a small dot of solder onto each of the pads. You can then tap that dot with your soldering iron to make sure it takes a pleasing round shape. The four pads are vertically on the right side of the keypad PCB. From top to bottom they are "GND, CLK, DIO, 3V3".
  • Take your four temporary 1" long wires and tin one end of each wire with a little bit of solder.
  • For each wire, hold it against the pad and heat the wire with the soldering iron until the wire and solder melt to the pad.
  • Use a magnifying glass to make sure you haven't shorted any pads/wires together
  • Attach the wires to the ST-LINK as follows:
SW102 ST-LINK
GND GND
CLK SWCLK
DIO SWDIO
3V3 3.3V VERY IMPORTANT DO NOT ACCIDENTALLY CONNECT TO 5V
  • After programming (per these instructions) and once you see that the device GUI starts up, you'll know that you will never need to do this ST-LINK step again. At that point use your soldering iron to remove the four wires, close up the unit and confirm that all the buttons work before gluing the device closed again (with a tiny amount of weak glue).

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".

Stand Alone Programming for Windows

For Windows we packed a stand alone flash program. Download this zip file and unzip it somewhere on your computer. Download the latest full version hex file from here into the unzipped "SW102_First_Install_Windows" folder.
Now you can hit "start.bat" and follow the instructions on the screen!
Common error message are:

No STLink connected at all (or no drivers installed):

Connection to the SW102 wrong or bad:

If everything went well it should look like this:

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.

Legacy Manual Installation (Skip this if you use the tool above)

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 20190210, 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