usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post your cool example code here.
Post Reply
ag123
Posts: 806
Joined: Thu Jul 21, 2016 4:24 pm

usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by ag123 » Sun Oct 29, 2017 10:38 am

misplaced my st-link, so i coded as follows:

Code: Select all

#include "Arduino.h"
#include <usb_serial.h>
#include <HardwareSerial.h>

int ledPin = LED_BUILTIN;

void setup() {
   //initialize the ledPin as an output:
   pinMode(ledPin, OUTPUT);
   digitalWrite(ledPin, HIGH);
   Serial.begin();
   //AN3155: stm32 usart boot loader requires even parity
   Serial1.begin(115200,SERIAL_8E1);
}

void loop() {

	if(Serial1.available()) {
		digitalWrite(ledPin, HIGH); // blink the led for traffic
		while(Serial1.available()) {
			char c = Serial1.read();
			Serial.write(c);
		}
		digitalWrite(ledPin, LOW);
	}

	if(Serial.available()) {
		digitalWrite(ledPin, HIGH); // blink the led for traffic
		while(Serial.available()) {
			char c = Serial.read();
			Serial1.write(c);
		}
		digitalWrite(ledPin, LOW);
	}

	delay(1);//sleep for 1ms
}
the led blinking pins codes are not needed and you could remove them if they bother,
i compile the above sketch in eclipse and flashed it with dfu-util, but it could just have been the arduino ide.

next get this
https://github.com/jsnyder/stm32loader

and i flashed a boot loader on the other maple mini, somehow it isn't perfect and i've to occasionally retry a few times.
but otherwise it works for me in linux

i'm using USART1 PA9, PA10, so connect them similar to this, swapping the PA9 TX, PA10 RX between 2 devices
https://medium.com/@paramaggarwal/progr ... 3cec0dbc86
i found it rather convenient to connect GND - GND between devices
and for the maple mini (clone) there is the VIN pin for 5V
so i connect VIN to the other VIN
then i simply connect the dongle to usb cable and it power up both boards
if the other device is separately powered, then the pins needed are simply PA9 TX, PA10 RX (swap between dongle & target) and GND-GND

and don't forget, set boot0 (on target) and press reset
for maple mini hold the user button (boot0), press and release reset (but don't let go on the user button yet)
and then let go the user button, the blinks from the in flash boot loader would not run which tells you that it is in the serial boot loader
Last edited by ag123 on Sat Dec 16, 2017 11:41 am, edited 1 time in total.

User avatar
zoomx
Posts: 541
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by zoomx » Mon Nov 06, 2017 11:26 am

If you manage the DTR signal you can use this dongle to flash an Arduino Pro mini.

ag123
Posts: 806
Joined: Thu Jul 21, 2016 4:24 pm

Re: usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by ag123 » Mon Nov 06, 2017 1:57 pm

i'm thinking about trying to pass the usart parameters from the usb side to the uart side. However, it seemed this would either need some changes in the usb serial classes e.g. to respond to the usb control messages e.g. set line coding - setting DTE rate (i.e. baud rate), number of stop bits, parity type and number of data bits as well as the line control states e.g. set line control state (RTS and DTR). another way is possibly to interpret AT commands. i'm not too sure which would be better and perhaps most 'seamless' which would hopefully allow some kind of 'driverless' usb-serial dongle implementation.

User avatar
zoomx
Posts: 541
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by zoomx » Mon Nov 06, 2017 2:35 pm

The idea is to replicate the DTR state on a pin.
Unfortunately I have no idea how to do that!

ag123
Posts: 806
Joined: Thu Jul 21, 2016 4:24 pm

Re: usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by ag123 » Mon Nov 06, 2017 2:45 pm

i did a round of googling and run into this funky but seemingly useful document / app note from ST, and even more interestingly it is stamped 'loudly' with obsolete products watermarks
http://www.st.com/resource/en/applicati ... 126651.pdf
but i guess some info remain evergreen simply because it is so widely used :mrgreen:

ag123
Posts: 806
Joined: Thu Jul 21, 2016 4:24 pm

Re: usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by ag123 » Mon Nov 06, 2017 3:01 pm

zoomx wrote:
Mon Nov 06, 2017 2:35 pm
The idea is to replicate the DTR state on a pin.
Unfortunately I have no idea how to do that!
well if you look at the usb cdc 1.1 or 1.2 specs docs
http://www.usb.org/developers/docs/devclass_docs/
https://cscott.net/usb_dev/data/devclass/usbcdc11.pdf (amazingly 19 jan 1999 old)

there are some usb-cdc control messages in particular SETLINECODING, GETLINECODING (around p57 section 6.2.12 that deals with setting stop bits / parity and data bits as well as p58 SetControlLineState that deals with RTS and DTR
as USB cdc really don't use those RS232 control messages / signals, in effect these usb control messages can be used to emulate RS232 in software

and with that 'funky' app note from ST
http://www.st.com/resource/en/applicati ... 126651.pdf
it shows an early example of the use of those usb control messages in the context of the USB CDC device class

then the most important rather undocumented piece of the puzzle is actually from microsoft
USB serial driver (Usbser.sys)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

i'm halfway guessing now that if we program a sketch to work that way using those USB CDC control messages, we could pass the emulated parity, stop bits, byte sizes as well as DTR, RTS messages into actual HardwareSerial class signals driving the usart in effect making it a usb-serial/uart dongle

then on the desktop/laptop/host Usbser.sys would 'automagically' handle it as a usb-serial (i.e. usb-uart) dongle/device, this may literally help achieve the 'driverless' objective since Usbser.sys is pretty much distributed with every copy of windows and supported natively by drivers in linux / mac os etc

User avatar
Rick Kimball
Posts: 1058
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by Rick Kimball » Mon Nov 06, 2017 8:40 pm

You might want to look at the blackmagic probe code:

https://github.com/blacksphere/blackmag ... acm.c#L422

It handles the configuration settings properly.

In fact, even if you don't use the blackmagic gdb debugger, the usb serial port it provides makes a great usb serial dongle.
-rick

ag123
Posts: 806
Joined: Thu Jul 21, 2016 4:24 pm

Re: usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by ag123 » Tue Nov 07, 2017 2:03 pm

thanks rick, i'd give it a shot, i'm thinking it is a rather good idea that we can simply flash a sketch and have a usb-serial (uart) dongle with blue pill / maple mini

there are various peripherals such as those pn532 nfc card readers that could benefit from such a sketch as well
https://www.ebay.com/sch/i.html?_nkw=nf ... 2&_sacat=0
https://dangerousthings.com/wp-content/ ... l_V3-1.pdf
as well as some gps modules which may benefit as well
https://www.ebay.com/sch/i.html?_nkw=gps+uart&_sop=15
https://github.com/disq/i2c-gps-nav

the nice thing that's perhaps evolving all along is that things like usb-serial dongles are becoming *software*, simply flash it and you have a usb-serial dongle, flash another sketch, the same blue pill / maple mini takes a new role

zmemw16
Posts: 1489
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: usb-serial dongle with maple mini or bluepill - for flashing bootloader

Post by zmemw16 » Wed Nov 08, 2017 1:30 am

are there fpga's around that can handle analogue signals ?
then you know what's coming next, a generic pcb and socket with ota rewrite and then it'll be finding the s/c or o/c in the wiring harness.

once upon a time a hardware engineer, then for a time software & hardware engineer, ultimately a software engineer.
all in 30 or so years

google yields
It is said that family firms go from "clogs to clogs in three generations", an aphorism based on the observation that it takes one generation to found a business, the next to build it, and the third to spend it. Although only around 10-15% do make it beyond three generations, there is no inevitably to this sequence.3 Jul 2003
stephen

Post Reply