Skip to content

Instantly share code, notes, and snippets.

@cibomahto
Last active March 28, 2020 13:09
Show Gist options
  • Save cibomahto/6d599b04fbb5257684a1f8e08fbb4e37 to your computer and use it in GitHub Desktop.
Save cibomahto/6d599b04fbb5257684a1f8e08fbb4e37 to your computer and use it in GitHub Desktop.
Use Raspberry Pi 3 as a SWD for STM32F4
  1. Start with this raspberry pi image (Raspbian Buster Lite):

https://www.raspberrypi.org/downloads/raspbian/

2020-02-13-raspbian-buster-lite.img

  1. Enable WiFi by adding 'wpa_supplicant.conf' to the boot partition:

country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1

network={ ssid="NETWORK-NAME" psk="NETWORK-PASSWORD" }

  1. Enable ssh by adding an empty 'ssh' file to the boot partition:

touch ssh

  1. Boot the pi, and check the router to determine the IP address, then SSH into it

  2. Use 'sudo raspi-config', and under the 'Interfacing Options' menu, enable SSH at boot.

  3. Update packages and install git:

sudo apt update sudo apt upgrade apt install git autoconf libtool libusb-1.0-0-dev

  1. Download and build openocd

git clone git://git.code.sf.net/p/openocd/code openocd cd openocd

./bootstrap ./configure --enable-sysfsgpio --enable-bcm2835gpio make sudo make install

sudo openocd -f interface/raspberrypi2-native.cfg
-c "bindto 0.0.0.0; transport select swd"
-c "adapter speed 1000"
-f target/stm32f4x.cfg

Pin connections: Raspberry Pi: header pin: 23 (gpio 11) -> SWCLK header pin: 22 (gpio25) -> SWDIO header pin: 25 -> GND header pin: 26: (gpio7) -> RESET (trst)

NOTE: pin1 is on the opposite side of the board from the Ethernet port!

pinout diagram: https://www.raspberrypi.org/documentation/usage/gpio/

Note: For trst support:

cp /usr/local/share/openocd/scripts/interface/raspberrypi2-native.cfg raspberrypi2-native-trst.cfg

uncomment line 32, 'reset_config trst_only'

then run: sudo openocd -f raspberrypi2-native-trst.cfg
-c "bindto 0.0.0.0; transport select swd"
-c "adapter speed 1000"
-f target/stm32f4x.cfg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment