OpenGround – Part 3 – SWD/ST-Link debugger

Disclosure: This post may contain affiliate links, meaning I get a commission if you decide to make a purchase through my links, at no cost to you.

By | September 16, 2016

This is the third post of my series documenting the development of a custom firmware for the FS-i6s transmitter. In my previous post i wrote about how to connect to the target using the DFU bootloader mode. This time we will use a different way to connect to the STM32F0: We will connect a ST-Link debugger to the swd connector.

ST-Link debugging

The STM32 series can be programmed and debugged by using a ST-Link debugger (you can get one e.g. here). You need to connect four wires for this: SWDIO, SWCLK, NRST and GND. See my first post in this series for the FS-i6s pinout. Before we can proceed make sure to have the st-link utils installed (see my installation tutorial).

Remove the batteries and connect the programmer. As i did not have the matching plug for the connector J4 i soldered a cable to the four testpoints. Once you have the wires connected you have to reinsert the batteries and to power up the transmitter by pushing the power buttons for 5s.

In order to test the debugger we will make a backup of the firmware. Execute the following command to dump the flash contents to a file:

st-flash --reset read flysky_fsi6s_dump_stlink.bin 0x8000000 0x20000

Ok, save this file to a save location. The next steps will erase all flash contents! This will erase the default firmware from flash, proceed only if you are sure you want to do that 😉

Blink!

As we have full flash access now we can try to run our own code on the stm32. You can check out the code from my github repository. Check out the led toggle tag and build the code (this requires the arm gcc toolchain to be installed):

git clone https://github.com/fishpepper/OpenGround.git
git checkout part1_led_toggle
make

After the code was compiled we can now flash the code to our transmitter. The makefile has a nice macro for that, you can flash the target by executing:

make flash

The background LED should now start blinking…

6 thoughts on “OpenGround – Part 3 – SWD/ST-Link debugger

  1. kowsalya

    sudo restart udev
    the above command is not getting executed
    it says(sudo: restart: command not found)

    Reply
    1. fishpepper Post author

      This was a typo, please try
      sudo udevadm control --reload

      Reply
  2. Santiago Perez-Cacho

    Hi Fishpepper,
    The matching connectors for the SWD port J4 are JST ZH 1.5 mm pitch 5-pin connectors and you can find them on eBay with wires already attached for around 6€ for 20 units. This allows to flash and debug the radio without soldering.

    Reply

Leave a Reply to fishpepper Cancel reply

Your email address will not be published. Required fields are marked *