After struggling with the previous post, I decided to do something fun. Without any planning, I ended up using a Seeeduino XIAO as a USB to serial converter.
I wanted to revisit the obligatory blink sketch on a "blue pill" (STM32F103C8) obtained last July. Initially all attempts at flashing new firmware on that board using a direct USB connection failed. Luckily, it was relatively easy to load the firmware onto the STM32 flash memory using the serial port (PA9 is RX and PA10 is TX). The LED connected to pin PC13 flashing at the correct frequency confirmed that the board was not a dud. And since there was a working serial connection, it was a simple matter to start a terminal and display messages sent from the blue pill. The sketch is nothing fancy.
Every two seconds, the LED is flashed on for a specified number of times or "beats". The asymetric on and off times confirmed that the built in LED is turned on when pin PC13 is set LOW. Setting different values for the BEATS macro made it easy to check that a new version of the sketch had been successfully flashed on the STM32. The output in the terminal was not very exciting but again it confirmed that everything was working.
Following the suggestion of many, I purchased an ST-LINK-V2 in-circuit debugger/programmer, not the real thing but the ubiquitous cheap version that can be seen to the right. That was a good decision, because flashing the blue pill became a very simple task. There's no fiddling with jumpers and pressing the reset button. Uploading to a STM32 with the ST-LINK is just as simple as uploading to an ESP8266 board such as the D1 Mini or nodeMCU. But beyond that, as the name suggest, it is possible to fully debug a sketch using the ST-LINK. Breakpoints can be set, the value of variables can be viewed or set, single stepping though the program is possible and so on. There's one little downside. To have access to the serial port of the blue pill from a terminal emulator on the desktop, it remains necessary to connect the board to a USB-Serial adapter.
This second time around, all the USB-Serial converters were either connected to a project or lost in some parts box. On the other hand there was a cute Seeeduino XAIO at hand. It has both a USB port and a hardware serial port on pins A6 (Tx) and A7 (Rx) (see Seeeduino XIAO Serial Communication Interfaces (SERCOM)), so why not try to use is a USB-serial converter.
When connected over USB, the XIAO shows up on the desktop as a USB and serial device.
Because there are no string descriptors for the
idProduct, it is not immediately obvious that
2886:802f is the XIAO. If the list of all USB devices is displayed with the
lsusb before connecting the XAIO to the desktop and then again after connecting it, it will be easy to spot the new USB device and the new TTY device. Just to make sure, a verbose listing will confirm that the XIAO is connected.
To use the XAIO as as serial device all I had to do was to connect 3 wires for the serial link between the XIAO and the STM32. Do NOT connect the two device Vcc pins together as each device is indepently powered by the desktop USB port to which it is connected.
Not shown above is a Dupont wire from another ground pin on the blue pill which is only used to reset the XIAO when it needs to be put in programming mode. After completing the wiring, the correct software had to be created and flashed on the XAIO. This was quite easy.
Once that was downloaded to the XIAO, it was possible to see the blue pill output to its Serial device.
It is relavely easy to write a string to the STM32 over the serial connection using a terminal emulator on the desktop. The STM32 will respond by echoing each line of text received to the terminal. It will be more responsitve if all timing delays are removed from the blink sketch.
Here is the output displayed on the terminal connected to
/dev/ttyACM0. The first string typed into the terminal was "hi" which was done at the same time as the blue pill was blinking its LED and writing to the same serial link.
The second string, "hello" was typed in the 3 or 4 seconds between LED flashes so the input from the keyboard and the echo from the blue pill, preceeded with "Rx :" are clearly visible. That's very good, it works. Note that once the second blink sketch is flashed on the STM32, it is possible to disconnect the ST-LINK programmer. Of course, it will then be necessary to provide power to the blue pill from the XIAO. Either the 3.3 volts or 5 volts lines can be connected together, just don't mix them up. Sending 5 volts to a device expecting 3.3 volts will not give a good result.
The next test seemed obvious: update the blue pill firmware using the serial protocol with the XIAO as the USB to serial adapter. Unfortunately, this did not work.
According to the output displayed on the terminal, acknowledgement of command 0x01 was not provided by the XIAO. In any case, that was a long shot.
For those who would like to replicate this experiment, here is the configuration file,
platformIO.ini, for the blink project on the blue pill.
It does not seem to matter which board definition is used,
bluepill_f103c8. And here is the configuration file for the terminal project on the XIAO
I'll end with a reference to an entry in the Seeed Wiki: How to use Seeeduino XIAO to log in to your Raspberry PI. It is basically the same as what is done above except that the XIAO is connected to the serial port of a Raspberry Pi. When comparing the two terminal programs, don't forget that
Serial refer to the same device.
// Alias Serial to SerialUSB #define Serial SerialUSB
Those are the two last lines of the
variant.h file in the Seeed fork of the "Arduino Core for SAMD21 and SAMD51 CPU". On my Linux desktop system, that file is found in the
.platformio/packages/framework-arduino-samd-seeed/variants/XIAO_m0/ directory in my home directory.