Debugging SWAN MCU

Introduction

In order to create the version of Sensor Tutorial, which uses the PlatformIO IDE I need to verify my understanding of the process of using the SWD Programmer & Debugger. This is a self imposed task, which might be of value to other community members.

I believe that each successive upload of a “sketch” requires resetting the MCU, process explained in Programming Swan without the STLink-V3Mini)

Press and hold the BOOT button on the Swan, press and release RESET, then release BOOT to cause the Swan to jump into its boot loader mode.

Image 1 - graphical context showing reseting the MCU to bootstrap mode.

This reboot is required to allow that the connection between my development machine (micro USB cable , green marker 1) be used in a dual mode (interactive and programmatic, where the default mode is _interactive_.

IS THE TEXT ABOVE CORRECT???


My development system

Image 2 - my development system

Debugging with PlatformIO IDE

I plan to use STLINK-V3MINI hardware, expecting that it will provide me the ability to use the MCU in both interactive and programmatic mode, without having to reset the Swan MCU every time, I change the code (firmware)

The STLINK-V3MINI is a stand-alone debugging and programming mini probe for STM32 microcontrollers, like the Swan SwAN MCY Use the JTAG/SWD interfaces to connect to the Swan via its onboard connector for simple programming or debugging.

image
Image 3 - STLINK-V3MINI as sold by Blues Wireless

Questions

1

Is the STLINK-V3MINI on Image 3 functionally the same as STLINK-V3 Modular in-Circuit debugger and Programmer for STM32/STM8 sold on Amazon? What would be the benefit of using one over the other?

image

Image 4 - STLINK-V3 Modular-Circuit-debugger-Programmer

2

Is there a detailed description how to connect this hardware to the Swan board ? Just looking at Image 3 or Image 4 does not give such information.



While they are not functionally the same (see below), they both work with the Swan, though the V3MINI is far less expensive.

If you’re interested in a more detailed comparison, see this resource (PDF) from ST. I’ll copy the relevant feature lists for both here:

STLINK-V3SET key features
• Standalone probe with modular extensions
• Self-powered through a USB connector (Micro-B)
• USB 2.0 high-speed compatible interface
• Device firmware upgrade support (DFU)
• JTAG/Serial Wire Debug (SWD) specific features:
– 3 V to 3.6 V application voltage support and 5 V tolerant inputs
– Flexible flat cables STDC14 to MIPI10/STDC14/MIPI20 (connectors with 1.27 mm pitch)
– JTAG communication support
– SWD and Serial Wire Viewer (SWV) communication support
• SWIM-specific features (only available with the adapter board MB1440):
– 1.65 V to 5.5 V application voltage support
– SWIM header (2.54 mm pitch)
– SWIM low-speed and high-speed modes support

STLINK-V3MINI key features
• Standalone probe
• Approximately 15 × 30 mm2 high-density integration PCB
• Delivered with 1.27 mm pitch STDC14 debug connector and STDC14 to STDC14 flexible flat cable
• Self-powered through a USB connector (Micro-B)
• USB 2.0 high-speed compatible interface
• Device firmware upgrade support (DFU)
• JTAG/Serial Wire Debug (SWD) specific features:
– 3 V to 3.6 V application voltage support and 5 V tolerant inputs
– JTAG communication support
– SWD and Serial Wire Viewer (SWV) communication support
• Virtual COM port (VCP) specific features:
– 3 V to 3.6 V application voltage support on the UART interface and 5 V tolerant inputs
– VCP frequency up to 15 MHz
• Drag-and-drop flash memory programming of binary file
• Two color LEDs: communication, power
• Includes STDC14 signals protection

Great question, and we should have a callout for this in the guide. I’ve made a note for us to do so.

Between the BOOT and RST buttons on the swan, there’s a JTAG connector, highlighted below. You’ll want to take the ribbon connector that came with the V3MINI (or V3SET if that’s what you have) and plug one end into the STLINK and one end into this port on the swan. It only fits one way, the notch at the bottom of the cable mates with the notch on the connector on the swan.

I could not wait to see the response to my questions on debugging-swan-mcu, so you just made me very happy, @bsatrom .

1 Like

Hello Sir, Just a Thanks for the post. I am a beginner, well not complete, but have been working with the Swan and notecarrier. I am following along at least working at finding the time. Thanks

1 Like

Hello, @bsatrom (and @jesenjim).

The STLINK-V3MINI arrived and I tried immediately to use it in its role as a debugger. My understanding of Brandon’s ‘how to connect STLINK-V3MINI’ is best described with the following image:

A textual description is: The STLINK-V3MINI is connected with USB-C connector to my laptop. The other end of the flat cable is connected to the Swan board’s JTAG connector.

Using this setup, I powered the system (plugged the usb cable into my laptop), and both red and green light on came on). What are the meaning of these lights?

I tried to upload the BLINK program (using PlatformIO IDE (VScode based) and the upload failed with the message:

dfu-util: No DFU capable USB device available

Well, of course, I should have changed the upload protocol to be stlink so I have now the platformio.ini defined as:

[env:bw_swan_r5]
platform = ststm32
board = bw_swan_r5
upload_protocol = stlink
framework = arduino
build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
monitor_speed = 115200
lib_deps = 
  Wire
  blues/Blues Wireless Notecard@^1.3.18

Building this system succeeded, however the upload failed with the following description

Executing task: platformio run --target upload 

Processing bw_swan_r5 (platform: ststm32; board: bw_swan_r5; framework: arduino)
------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/bw_swan_r5.html
PLATFORM: ST STM32 (15.4.1) > BluesWireless Swan R5
HARDWARE: STM32L4R5ZIY6 120MHz, 640KB RAM, 2MB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-arduinoststm32 @ 4.20200.221104 (2.2.0) 
 - framework-cmsis @ 2.50700.210515 (5.7.0) 
 - tool-dfuutil @ 1.11.0 
 - tool-openocd @ 2.1100.211028 (11.0) 
 - tool-stm32duino @ 1.0.1 
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Wire @ 1.0
|-- Blues Wireless Notecard @ 1.3.18
|   |-- Wire @ 1.0
Building in release mode
Checking size .pio/build/bw_swan_r5/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.6% (used 3988 bytes from 655360 bytes)
Flash: [          ]   1.4% (used 28712 bytes from 2097152 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, mbed, serial, stlink
CURRENT: upload_protocol = stlink
Uploading .pio/build/bw_swan_r5/firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-17-00:18)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
Error: target voltage may be too low for reliable debugging
Error: init mode failed (unable to connect to the target)
in procedure 'program'
** OpenOCD init failed **
shutdown command invoked

Questions:

  1. Is my system configuration correct - including the content of he platformio.ini
  2. Without STLINK-V3MINI hardware, I had to manually reset the SWAN board to enable boot loader mode. Is this still needed with STLINK-V3MINI hardware?
  3. What is the proper interpretation of my failure to upload the code to Swan?

Please consider this semi-urgent as my progress in setting the system up is seemingly very slow. Lack of the documentation docs is part of my difficulties :grinning:

Hey @adriatic,

Make sure you are also powering the Swan via its USB connector. The STLINK does not provide power to the device, hence the Error: target voltage may be too low for reliable debugging message.

Otherwise, your configuration looks good and you do not need to reset the Swan before programing each time, as you do when using DFU over the USB serial connection.

Brandon

1 Like

Quick and informative answer - thank you @bsatrom :heart_eyes:

The power issue resolution states the best possible explanation with an easy fix (in my current situation - a software guy, seeing a failure described as target voltage may be too low for reliable debugging, makes me very worried.

Verified parts of the functionality of STLINK: I do not need to reset the Swan before programming it each time.

In order to move ahead to use the platformIO IDE to debug the “standard sample” (Blink). The platformIO supports hundreds of boards, (and related components), so finding something that is as close to Blues Wireless configuration like mine (see the picture above, in this post), clearly requires some research. As a hardware bozo, I am not the best candidate for such task. So, can offer a deal: is someone helps me find the complete settings for platformIO IDE to debug that Blink sample, I will pick it up and expand to details needed to Blues Wireless beginners.

This tutorial How to use the PlatformIO debugger on the ESP32 using an ESP-prog seems pretty close to fit in the Blues Wireless specific tutorial, but I would prefer not to have terms like “ESP32 using an ESP-prog” and use "Swan and STlink instead.