Banana Pi BPI-M4: How to use it as an STM32/ARM MCU programmer (SWD over SPI) (tutorial)

Did you know you can use the Banana Pi BPI-M4 as an STM32 / ARM MCU programmer/debugger (SWD over SPI)? Here’s how it works:

  1. Activate SPI in the kernel as described here: https://wiki.banana-pi.org/Getting_Started_with_M4#Enable_SPI

  2. Install OpenOCD variant with SPI

a) from here: https://www.pcbway.com/blog/technology/OpenOCD_on_Raspberry_Pi__Better_with_SWD_on_SPI.html

-OR- from here: https://github.com/lupyuen/openocd-spi

c) Download jimctl and put it in OpenOCD folder: https://github.com/spiderkeys/jimtcl

  1. Connect Banana-PI and STM32 MCU via 3-wire SPI as follows (left is Banana PI with SPI pins, right is your MCU with SWD pins):

image

  1. In downloaded OpenOCD code, change (SPI mode to 1 and speed to 500 Khz) in file ‘src/jtag/drivers/bcm2835spi.c’ as follows:

    static uint8_t mode = 1;

    static uint speed_khz = 500;

  2. Compile OpenOCD:

    ./bootstrap (when building from the git repository)

    ./configure --enable-sysfsgpio --enable-bcm2835spi --enable-cmsis-dap

    make

  3. Run OpenOCD to flash your STM32 MCU with the Banana PI : https://www.pcbway.com/blog/technology/OpenOCD_on_Raspberry_Pi__Better_with_SWD_on_SPI.html

Screenshot%20from%202021-12-14%2019-12-09

Feel free to ask questions / make comments :slight_smile:

1 Like