Using Linux instead of a SerPlus Feb 2017

Uploading code to an STM32 ARM µC is a bit of a chicken-and-egg problem. The traditional setup uses JTAG (or more likely: 2-wire SWD), but this requires a JTAG programmer such as an ST-Link or a Black Magic Probe.

As you will know by now, all STM32 µC’s also include a serial boot loader in ROM, which requires toggling the RESET and BOOT0 pins in just the right sequence. You can do this manually, but that can become very tedious after a few times.

SerPlus was created for just this reason: a custom-programmed F103 board, which talks to the host over USB, and to a target board over serial, with DTR tied to RESET and RTS to BOOT0:

But that requires a SerPlus, onto which you also need to flash the proper firmware. Catch 22!

There’s another option, if you have a USB-serial interface, such as a modified BUB, which connects DTR and RTS to pins 1 and 5 on the FTDI connector, respectively (for orientation: pin 6 is ground). In that case, we can use a standard OSS utility called ser2net to perform the Telnet <=> RTS/DTR translation for us (as well as selecting even parity during uploads):

This is in fact a pretty convenient setup to use from any O/S: use Folie on your development machine, whatever it is, right next to your source files, and connect to Linux over the network:

folie -p

This sets up a network connection (assuming here that the Linux box has IP address, and connects to port 2000.

Before we can use this, we’ll need to do a bit of one-time setup on the Linux box:

  1. install ser2net with: sudo apt-get install ser2net

  2. edit the ser2net configuration file (/etc/ser2net.conf), commenting out all the existing settings by inserting a “#” in front, and adding one line with the following text in it:

    2000:telnet:600:/dev/ttyUSB0:115200 8DATABITS NONE 1STOPBIT

    (replace “ttyUSB0” by whatever you need for your USB interface board)

  3. after saving, reload the configuration: sudo /etc/init.d/ser2net reload

That’s it, the Folie command shown above will now connect over the network:

$ folie -p
[connected to]
Mecrisp-Stellaris RA 2.3.3 with M0 core for STM32L053C8 by Matthias Koch
64 KB <jnz> 3238022C ram/flash: 4920 14192 free ok

You now have the equivalent of a networked SerPlus - which in turn would be an excellent opportunity to get and re-flash a Blue Pill and turn it into a spare real SerPlus for local use!

Weblog © Jean-Claude Wippler. Generated by Hugo.