Skip to content

Programming Debugging the pyboard using ST Link v2

johnthagen edited this page Apr 17, 2019 · 10 revisions


The STM32F4 chip on the pyboard can be programmed and debugged using C or C++. The underlying MicroPython firmware is compiled this way. But given the relative size and simplicity of the pyboard, it makes for an interesting alternative to the STM32F4DISCOVERY. The pyboard has a smaller footprint (64-pin vs. 100-pin package) as well significantly less peripheral chips on the board.

The pyboard does, however, lack an onboard, pre-wired ST-Link/v2 programmer that a board like the STM32F4DISCOVERY has. This makes it a bit more inconvenient to target using C/C++, but this page explains how to overcome this.


Software Setup

Before any hardware is set up, let's first set up a new C project from which to develop. Download STM32CubeMX and when creating a new project, select STM32F405RG from the product selector.

You can now configure IO pins, interrupts, etc. Selecting Generate Code will generate an entire C project based on the configured IDE settings.

One such configuration that has been tested in using CLion and it's OpenOCD plugin.

Hardware Setup

Connect the pyboard USB connector to a USB power adapter (not your development host).

Connect the ST-Link/v2 USB cable to your development host.

From the micropython README:

connect the 3V3 pin to the P1/DFU pin with a wire (on PYBv1.1 they are next to each other on the bottom left of the board, second row from the bottom).

This is needed because the programming pins on the pyboard are shared with LEDs, so if the MicroPython firmware it running, it conflicts with the ST-Link/v2 programming.

In the following diagram, P1/DFU is labelled BOOT0.


Next, connect the following pins from the ST-Link/v2 to the pyboard. Refer to the ST-Link/v2 User Manual. Pin 1 on the ST-Link/v2 is the lower left corner of the connecter if you hold the ST-Link/v2 such that the labels are correctly oriented.

ST-Link/V2        | pyboard v1.1
----------------- | -------------
PIN1  (VAPP)      -> 3V3
PIN7  (TMS_SWDIO) -> PA13 (X21-2)
PIN9  (TCK_SWCLK) -> PA14 (X20-2)
PIN13 (TDO_SWO)   -> PB3  (X17-1) (Optional debug serial)
PIN15 (NRST)      -> RST
PIN20 (GND)       -> GND


You can now program/debug using any software that supports the ST-Link/v2. One such program is OpenOCD.

$ openocd -f board/stm32f4discovery.cfg -c "program app.elf" -c reset -c shutdown

Debugging has been tested to work under CLion using the OpenOCD plugin and gcc-arm-embedded toolchain.


Clone this wiki locally
You can’t perform that action at this time.