raspberry-pistm32openocdnanopi

Flashing STM32F1 from NanoPi Neo over openocd


I am trying to flash STM32F1 from linux on the NanoPi Neo with openocd. The problem i have is i can't use any of the interfaces such as interface/raspberrypi2-native.cfg because i use NanoPi and not Raspberry Pi and I don't have the knowledge to write my own cfg.

The goal is to have STM32F1 (pins SWCLK and SWIO) connected to NanoPi GPIO pins but i don't know which pins and how to write a cfg that would enable me that.

I assume this is possible to do because there are plenty tutorials to do it with Raspberry pi eg. this one.

Thank you for your help.

I successfully flashed STM32F1 if i connected it over the ST-Link V2 connector with that cfg:

source [find interface/stlink.cfg]
transport select hla_swd
set CHIPNAME stm32f1x
source [find target/stm32f1x.cfg]

init
targets
reset halt

program blink_5000_stm32f1.bin 0x08000000 verify reset exit

stm32f1x lock 0

shutdown

Solution

  • raspberrypi2-native.cfg targets bcm2835gpio interface, BCM2835 chip, that is found on the earlier RPi boards. NanoPi Neo is based on Allwinner H3, which, most likely, is not compatible.

    Fortunatelly, in the current OpenOCD, there are two interface drivers, capable of bind-banging using raw GPIO access - sysfsgpio and linuxgpiod. Of cource these pins must not be used by other drivers.

    sysfsgpio

    Uses sysfs and marked as legacy, since sysfs is deprecated from Linux kernel version v5.3. linuxgpiod is recomended as a replacement.

    Example interface configuration file is sysfsgpio-raspberrypi.cfg, it targets the same older RPi models:

    adapter driver sysfsgpio
    
    # Each of the JTAG lines need a gpio number set: tck tms tdi tdo
    # Header pin numbers: 23 22 19 21
    sysfsgpio jtag_nums 11 25 10 9
    
    # Each of the SWD lines need a gpio number set: swclk swdio
    # Header pin numbers: 23 22
    sysfsgpio swd_nums 11 25
    

    If you use SWD, then only swd_nums needs to be altered. In the orignal config GPIO11 (pin 23) is SWCLK, and GPIO25 (header pin 25) is SWDIO. According to the layout you may use, for example, GPIO0 (header pin 11) for SWCLK and GPIO2 (pin 13) for SWDIO:

    sysfsgpio swd_nums 0 2

    linuxgpiod

    This one is newer and a preferrend driver, using access to GPIO through libgpiod since Linux kernel version v4.6. However, if openocd or linux kernel was built without it, you can either update the system or fall back to sysfsgpio.

    Example config file is dln-2-gpiod.cfg, it could be altered the same way - just change the pins for SWCLK and SWDIO.

    Disclaimer: I don't have NanoPi Neo and can't try it myself