0

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

1 Answers1

1

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

Flexz
  • 686
  • 1
  • 3
  • 13
  • You are a legend my friend :) i tried with sysfsgpio driver, connected the STM32 to GPIO 0 and GPIO 2 and it worked :) Then I also tried the linuxgpiod driver and got error that debug interface is not found (linuxgpiod). Checked the linux kernel version and it is 4.14.111. I guess in that case i should use sysfsgpio? – user1396057 Jan 24 '23 at 19:41
  • @user1396057 that's right, use sysfsgpio if it works. I've updated the answer. Perhaps your openocd is an older version, since linuxgpiod appeared in the Opeocd source tree only in 2020. – Flexz Jan 25 '23 at 05:20
  • I have one more question. The challenge is that i have [NanoHat Oled](https://wiki.friendlyelec.com/wiki/index.php/NanoHat_OLED#:~:text=NanoHat%20OLED%20is%20a%20small,factor%20as%20FriendlyElec's%20NanoPi%20NEO.) on top of the NanoPi and it is connected to almost all of the pins on the NanoPi. The only pins left are the Debug port pins (UART0). Can i somehow connect SWCLK and SWDIO pins for the STM32 to those debug port pins or can i use the same pins like in your answer or do i have to get loose of NanoHat Oled if i want to flash the STM32 over NanoPi? – user1396057 Jan 25 '23 at 07:32
  • UART0 have no linux gpio numbers mapped, it is either actively used by the system, or have no associated gpio number. So I don't think, using UART0 is possible. Looking at the pinout of the Oled Hat, most of the GPIO pins are not connected, NC. You can solder SWD wires directly to the NanoPi board or Oled hat, use any NC pin. Or search for other hat, that both exposes pins and allows stack connection of the oled hat. – Flexz Jan 25 '23 at 07:57
  • Ok, so i could solder SWD wires to the pins 0 and 2 directly on the NanoHat Oled... but is there a chance that this would interfere with the NanoHat operation in any way (since they are connected to NanoHat too)? – user1396057 Jan 25 '23 at 11:00
  • Do you mean GPIO0&2? It may not work correctly, since Oled board uses exacly those pins for the buttons, K1-K3. Pick any unconnected gpio pins, as I wrote earlier, e.g. pins 19,21 (logical numbers 64, 65). – Flexz Jan 25 '23 at 11:30
  • Sorry yes, i meant GPIO0&2. Ok i can see from wiki that K1, K2 and K3 buttons are using GPIO0&2&3. If nothing else, now i know how to read the pin description tables better :) Sir, thank you very much for the help, i think i get it from here on :) – user1396057 Jan 25 '23 at 18:55
  • Actually one more thing while we are at it... When I try to use the same cfg only for STM32F4 instead of STM32F1. It is getting flashed and everything seems to be ok but the openocd throws an error. Can i ignore that or it is something to worry about? - Error: Translation from khz to adapter speed not implemented Error executing event reset-start on target stm32f4x.cpu: embedded:startup.tcl:1187: Error: in procedure 'program' called at file "openocd.cfg", line 12 in procedure 'ocd_process_reset' in procedure 'ocd_process_reset_inner' called at file "embedded:startup.tcl", line 1187 – user1396057 Jan 26 '23 at 10:41
  • If it is flashed and verified without erros, then you can ignore other messags. Openocd sometimes reports errors, which, in fact, are just warnings. – Flexz Jan 26 '23 at 11:12