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:

  2. Install OpenOCD variant with SPI

a) from here:

-OR- from here:

c) Download jimctl and put it in OpenOCD folder:

  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):


  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


  3. Run OpenOCD to flash your STM32 MCU with the Banana PI :


Feel free to ask questions / make comments :slight_smile:

1 Like