Is there a preferred way to flash STM32 Nucleo board with stlink? #1546
-
Hi guys, I'm still wrapping my head around the Unfortunately I can't find an example of using labgrid to flash a Same goes for flashing arduino board with prepared I have found the Any advice on how to approach such a task? If I've missed some place in documentation or example that explains this please point me to the right place :-) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
We use labgrid with boards running Linux, so we have tools like Perhaps the Driver for So to support these boards/MCUs in labgrid, you'd have to write corresponding Driver and Resource classes. |
Beta Was this translation helpful? Give feedback.
-
Hi, I am a little late to the party, but on my end I managed to flash stm32 device through openocd Here is what I have in my environment file: tools:
openocd: '/opt/zephyr-sdk-0.16.8/sysroots/x86_64-pokysdk-linux/usr/bin/openocd'
targets:
main:
resources:
- RawSerialPort:
name: shell_zephyr
port: /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTAD1ABG-if00-port0
- USBDebugger:
match:
ID_PATH: pci-0000:08:00.0-usb-0:1.2
drivers:
- SerialDriver:
name: shell_zephyr_driver
txdelay: 0.001
bindings:
port: shell_zephyr
- OpenOCDDriver:
config: 'boards/vossloh/pmdb/support/openocd.cfg'
search: 'boards/vossloh/pmdb/support'
load_commands:
- 'init'
- 'targets'
- 'reset init'
- 'flash write_image erase {filename}'
- 'reset run'
- 'shutdown' And I have the following class to manage flashing my device: """LabGrid helper to manage OpenOCDDriver."""
import os
import labgrid
class OpenOCD:
"""Object to manipulate OpenOCDDriver Instance from LabGrid."""
def __init__(self, target: labgrid.Target) -> None:
self.target = target
self.openocddriver = self.target.get_driver('OpenOCDDriver')
def load(self, filename: str) -> None:
"""Load firmware on target."""
assert os.path.isfile(filename), f"Firmware {filename} not found"
self.openocddriver.load(filename)
def reset(self) -> None:
"""Reset Target."""
reset_cmds = []
reset_cmds.append("init")
reset_cmds.append("targets")
reset_cmds.append("reset init")
reset_cmds.append("reset run")
reset_cmds.append("shutdown")
self.openocddriver.execute(reset_cmds) |
Beta Was this translation helpful? Give feedback.
-
I finally went with flashscript. On the Exporter machine I've installed the {% for idx, sysfs in [
('1', 'pci-0000:00:14.0-usb-0:2.1.1:1.2'),
...
('7', 'pci-0000:00:14.0-usb-0:2.4:1.2')
] %}
usbhub-port{{idx}}:
location: 'Desk @ Home'
nucleo_uart:
cls: USBSerialPort
match:
ID_PATH: '{{sysfs}}'
nucleo_flashable:
cls: USBFlashableDevice
match:
SUBSYSTEM: 'usb'
ID_PATH: '{{sysfs}}'
{% endfor %} Now on the Client side it's a bit more complicated: I prepared a directory with firmware to flash ans simple flash script: #! /bin/bash
echo "Erasing ..."
st-flash --freq 8000 --connect-under-reset erase
echo "Erasing done"
echo "Flashing..."
st-flash --freq 8000 --format binary --connect-under-reset write ./zephyr.bin 0x8000000
echo "... done" I used
To flash from Python script the environment file looks something like this: targets:
nucleo:
resources:
RemotePlace:
name: 'nucleo'
drivers:
- SerialDriver:
name: 'nucleo_serial_driver'
timeout: 5.0
bindings:
port: 'nucleo_uart'
- FlashScriptDriver:
script: 'nucleo-flasher'
images:
nucleo-flasher: './flasher.sh' |
Beta Was this translation helpful? Give feedback.
-
I marked my reply as an answer, but @nvincent-vossloh answer also solves the question. Unfortunately I can't mark two replies as answers. |
Beta Was this translation helpful? Give feedback.
I finally went with flashscript.
On the Exporter machine I've installed the
st-link
from github . My config for the Exporter goes something along these lines:Now on the Client side it's a bit more complicated:
I prepared a directory with firmware to flash ans simple flash script: