Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

If you made your own board, post here, unless you built a Maple or Maple mini clone etc
User avatar
Just4Fun
Posts: 32
Joined: Tue Mar 05, 2019 8:09 am
Location: Dark side of the Moon
OS: Linux, Win7, Win10
IDE: Arduino 1.8.5, 1.8.9
Core: Roger's, STM official
Board: Custom
Contact:

Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by Just4Fun » Sun Aug 25, 2019 9:52 am

I wanted a simple way to automate the Arduino IDE upload using the serial bootloader inside every STM32 MCU.

The objective was to use the official ST core without modifications.

After some analysis I've done a simple circuit (a couple of transistors and a few passives) that seems do the job, driving NRST and BOOT0 to start the internal serial bootloader (you have to select the serial bootloader in the IDE).

I've tested it with the current core version 1.6.1 using Arduino IDE 1.8.5 and 1.8.9 under Windows 7, Windows 10 and Linux (Linux require a little modification in the "boards.txt" file).

This method can be virtually used on every STM32 MCU!

Here a demo using a modified STM32F030F4 board (Arduino IDE 1.8.5 under Win 10):


Here an other "automated" upload using the serial bootloader:


Next step will be design a board with a STM32F030R8 with this circuit.

I'll publish all the details after more testing...

User avatar
Vassilis
Posts: 165
Joined: Wed Feb 27, 2019 5:09 pm
Answers: 2
Location: Thessaloniki, Greece
OS: Linux, Win10, MacOS
IDE: Arduino 1.8.9
Core: Roger, STM official
Board: Bluepill, Maple mini, STM32F4xx
Contact:

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by Vassilis » Sat Aug 31, 2019 2:36 pm

Very nice !
A schematic diagram of your circuit would be useful.
-Vassilis Serasidis

User avatar
Just4Fun
Posts: 32
Joined: Tue Mar 05, 2019 8:09 am
Location: Dark side of the Moon
OS: Linux, Win7, Win10
IDE: Arduino 1.8.5, 1.8.9
Core: Roger's, STM official
Board: Custom
Contact:

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by Just4Fun » Sat Aug 31, 2019 4:06 pm

Yes, of course... I just want make some more test before... may be I'll change some detail on the road...

User avatar
zoomx
Posts: 52
Joined: Tue Mar 05, 2019 8:10 am
Location: Mt Etna - Italy
OS: Windows 7 & 10
IDE: 1.8.8
Core: Roger & STM official
Board: Bluepill, Maple mini

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by zoomx » Mon Sep 02, 2019 7:17 am

+1!

ag123
Posts: 196
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by ag123 » Thu Nov 07, 2019 6:27 am

+1 :D

racemaniac
Posts: 38
Joined: Tue Mar 26, 2019 10:01 am
Location: Belgium
OS: Windows
IDE: Visual studio + Visual GDB
Core: Cube MX
Board: All + custom

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by racemaniac » Thu Nov 07, 2019 1:11 pm

+1 :twisted:

User avatar
Just4Fun
Posts: 32
Joined: Tue Mar 05, 2019 8:09 am
Location: Dark side of the Moon
OS: Linux, Win7, Win10
IDE: Arduino 1.8.5, 1.8.9
Core: Roger's, STM official
Board: Custom
Contact:

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by Just4Fun » Thu Nov 07, 2019 4:03 pm

:D
Guys, see the schematic attached on this post...

I've implemented it on that one new board so more testing will be more easy.

For Arduino IDE on windows: "Linux" jumper open;
For Arduino IDE on Linux: "Linux" jumper closed.

Only for Arduino IDE under Linux, you have to add "XXXX.serial.disableDTR=true" in the boards.txt file (in the directory /home/username/.arduino15/packages/STM32/hardware/stm32/1.6.1 or as it is called on your host), where XXXX is the identifier of the selected board (for a Generic F030F4 board is GenF0.serial.disableDTR=true).

Remember that you have two choices of behavior:

1: if you want an auto reboot after the upload you * must * leave the serial monitor (or the plotter) opened before to upload (just in a background window) also if your sketch doesn't use it;

2: if you want just upload
and then * manually * reset to reboot leave the serial monitor (and the plotter) off.



Important note: the autoreset circuit works using a CH340G serial-USB adapter. Using different chips may not work due the different driver implementation.
Remember that it is for the ST core only (I mean... I've only tested with that...).


SPRG Key (Serial PRoGramming): this is a "one button" serial upload launcher. Pressing it the STM32 reset and enter in the "serial bootloader" mode without messing with jumpers. It can be used i.e. with the serial upload ST utility. After the upload the STM32 can reboot in "normal" mode (executing the user program from flash).

User avatar
Squonk42
Posts: 73
Joined: Wed Feb 27, 2019 5:17 pm
Location: Boredaux, France
OS: Linux
IDE: Arduino, Sloeber, Emacs
Core: Roger's, STM official, bare metal
Board: All
Contact:

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by Squonk42 » Fri Nov 08, 2019 5:45 am

Why not use something simpler like the the ESP32 Weemos?
https://wiki.wemos.cc/_media/products:d ... v1.0.0.pdf
IO0 controls the boot mode on the ESP32.

ag123
Posts: 196
Joined: Thu Mar 07, 2019 6:15 am
Location: Singapore
OS: linux
IDE: eclipse, arduino 1.8.5
Core: Roger's
Board: Maple mini, Bluepill

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by ag123 » Fri Nov 08, 2019 11:04 am

i think those st-link dongles has access to the reset pin. in fact i tend to use 'connect under reset' to get pass write protected (debug pin disabled) boards.
but i'd think uart with uart and boot0 is a nice alternative. the reason is that you can use it 'arduino like' i.e. to flash the sketch set boot0, toggle reset.
then it runs in 'normal' mode as a usb-serial interface.

the thing is there is still a lot of merits to use usb itself, hence this is useful as a 'fall back'.

OT:
as for usb, i think we are not really exploring the depths of it. i'd think in part usb protocols is kind of complicated and often it takes sniffing packets to decipher the packets. and with usb one often need to deal with complicated state machines to keep state of the connection. the extremely verbose but not necessarily straightforward and often incomplete usb specs that you can find on usb.org doesn't help.
e.g. for usb mass storage, if you read the bulk only transport specs, it would look easy. the trouble is the specs totally miss out mentioning that in the real world it is SCSI over USB, i.e. you need to decode the SCSI commands instead.
and the highly opaque SD cards commands doesn't help if one wants to implement a usb-sd card controller
similarly HID is just as verbose and hard to understand.
but usb is still an important 'technology' that i'd think we'd need to adopt which would make a stm32f* a true generic usb device. i.e. usb to anything usb-serial, usb-irda, usb-ethernet, usb-bluetooth, usb-serial-gps, usb-nfc, usb-audio, usb-camera, usb-video, usb-hid keyboard, usb-hid mouse, usb-hid vr controller, usb-hid *, usb-mass storage et. al.
one weird wacky thinking is that with usb-hid, one can make 'artificially intelligent' (aka 'smart') keyboard and mouse. imagine make the keyboard & mouse do machine learning so that it does prediction, would that keyboard or mouse eventually do 'move ahead' or even 'move autonomous'? an interesting and probably unexplored arena
another irrelevant note though, these days parallel ports and serial ports are missing from computers, almost all of them. usb for now is still there, but it seemed there is a movement to usb C, not sure how soon that adoption would become widespread. the 'lost' of parallel ports and serial ports makes 'old technologies' like linux-cnc (http://linuxcnc.org/) (PC does GCODE intepretation and control) a little less relevant, today's world is literally dominated by micro-controller driven G-CODE controllers e.g. GRBL, and all those 3d printing firmwares (Marlin, Reprep, Repetier etc)
stm32-style usb controllers may be a revolution in the evolution, we are in the age of the software usb device, a usb device where its role is determined by the firmware you install on it ! (we are already there with stm32duino)

User avatar
Just4Fun
Posts: 32
Joined: Tue Mar 05, 2019 8:09 am
Location: Dark side of the Moon
OS: Linux, Win7, Win10
IDE: Arduino 1.8.5, 1.8.9
Core: Roger's, STM official
Board: Custom
Contact:

Re: Arduino autoreset (DTR/RTS) with the internal serial bootloader of any STM32 MCU

Post by Just4Fun » Sat Nov 09, 2019 4:16 pm

Squonk42 wrote:
Fri Nov 08, 2019 5:45 am
Why not use something simpler like the the ESP32 Weemos?
Hi Squonk42,
I started from the circuit suggested by Espriff for the ESP8266, that should be the same used for the ESP32 you mentioned. But seeing the behavior of RTS/DTR when using the ST core I ended up that it needed modifications. More, the RTS/DTR behavior is different when a linux host is used with the ST core. I think that the ESP8266/ESP32 cores use a proper script to drive RTS/DTR signals.
ag123 wrote:
Fri Nov 08, 2019 11:04 am
the thing is there is still a lot of merits to use usb itself, hence this is useful as a 'fall back'.
Hi ag123,
This circuit is mainly intended for those STM32 without USB I/O as the STM32F030 family. I was curious to find a way as in the original Arduino Uno board. Anyway it should work for any STM32.

Post Reply