[SOLVED] linux blue pill arduino DFU, my notes

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
Post Reply
holla2040
Posts: 3
Joined: Mon Nov 21, 2016 6:34 pm

[SOLVED] linux blue pill arduino DFU, my notes

Post by holla2040 » Sun May 21, 2017 12:55 am

Folks,

I spent about 4 hours screwing around with my new blue pill STM32F103 boards and have them functioning, here's my notes

ubuntu 16.04 x86
arduino 1.8.2

I first removed .arduino15 directory, kind of drastic but needed a fresh start.
added https://github.com/stm32duino/BoardMana ... index.json to preferences
used board manager to install STM32F1xx Cores

I installed the STM32duino bootloader using FTDI serial,
downloaded generic_boot20_pc13.bin from stm32duino bootloader github site
https://github.com/rogerclarkmelbourne/ ... 1/binaries

boot0 to 1, ftdi to pa9 and pa10, then
/home/holla/.arduino15/packages/STM32/tools/STM32Tools/2017.1.19/tools/linux/serial_upload ttyUSB0 {upload.altID} {upload.usbID} ~/Downloads/generic_boot20_pc13.bin

set board for perpetual bootloader mode, LED blinks fast for a sec then slower. You have to use the reset button to upload using IDE.

Then set IDE to port to "STM32duino booloader", now it works.

Here's the kicker that took a couple hours to figure out. In order for IDE to upload using the STM32duino booloader reliably, you have to first load a sketch with Serial.begin, so the chip's CDC serial will get loaded, then enumerated by linux. Otherwise the board reset command in maple_upload script can't reset the board back into bootloader mode, got it? I hope so, this took forever to figure out. Also, my linux enumerate function takes about 10 seconds for /dev/ttyACM0 to show up after my board starts. So you have to wait a bit before opening the serial port. Whew!

Also, if you get an error message with new sketches

core/syscalls_stm32.c.o: No such file or directory

restart arduino IDE. This file isn't copied correctly with new sketches. Restarting the IDE, builds into a new /tmp directory.

Good luck!

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

Re: linux blue pill arduino DFU, my notes

Post by ag123 » Sun May 21, 2017 6:59 am

there is some additional fixes needed
http://www.stm32duino.com/viewtopic.php?f=16&p=26659

Code: Select all

ATTRS{idProduct}=="1001", ATTRS{idVendor}=="0110", MODE="664", GROUP="plugdev"
ATTRS{idProduct}=="1002", ATTRS{idVendor}=="0110", MODE="664", GROUP="plugdev"
ATTRS{idProduct}=="0003", ATTRS{idVendor}=="1eaf", MODE="664", GROUP="plugdev" SYMLINK+="maple", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idProduct}=="0004", ATTRS{idVendor}=="1eaf", MODE="664", GROUP="plugdev" SYMLINK+="maple", ENV{ID_MM_DEVICE_IGNORE}="1"
those

Code: Select all

ENV{ID_MM_DEVICE_IGNORE}="1"
, prevents linux modem manager from treating the /dev/ttyACMx llines as a modem and tries to initialize it
it fixes the 'freezes' with the serial terminal for me

i tend to upload the sketches using dfu-util manually e.g.

Code: Select all

>dfu-util -l
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [1eaf:0003] ver=0201, devnum=10, cfg=1, intf=0, path="3-4", alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000", serial="LLM 003"
Found DFU: [1eaf:0003] ver=0201, devnum=10, cfg=1, intf=0, path="3-4", alt=1, name="STM32duino bootloader v1.0  Upload to Flash 0x8005000", serial="LLM 003"
Found DFU: [1eaf:0003] ver=0201, devnum=10, cfg=1, intf=0, path="3-4", alt=0, name="STM32duino bootloader v1.0  ERROR. Upload to RAM not supported.", serial="LLM 003"

Code: Select all

>dfu-util -a 2 -R -D sketch.bin
dfu-util 0.9                                                                                         
                                                                                                     
Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 1eaf:0003
Run-time device DFU version 0110
Claiming USB DFU Interface...
Setting Alternate Setting #2 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0110
Device returned transfer size 1024
Copying data from PC to DFU device
Download        [=========================] 100%        15960 bytes
Download done.
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
Done!
Resetting USB to switch back to runtime mode
the arduino ide normally creates a folder /tmp/arduino_build_nnnnn and the compiled sketch.bin file is found in there

"perpetual boot loader mode" requires setting boot0 high *during* the 6 fast blinks, i'm using maple mini which has a button tied to boot0 that makes it manageable to do that
but on blue pill i think that's simply a jumper. a way i'd guess is to connect a 2-way 3 connector switch to select between 0 and 1 on the boot0 jumper.

another way that could be attempted is to re-compile the boot loader to treat boot1 as the "perpetual boot loader" button
http://www.stm32duino.com/viewtopic.php?f=16&t=1549
in that way you could have the board in perpetual boot loader mode simply setting the boot1 jumper
this won't work with boot0 as boot0 would drop stm32f103 into uart update mode which requires a usb-uart dongle, the exception is if you can set boot0 high *during* the 6 fast blinks shortly after reset

User avatar
RogerClark
Posts: 7485
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: linux blue pill arduino DFU, my notes

Post by RogerClark » Sun May 21, 2017 7:24 am

If the BluePill was initially empty, and was flash with the bootloader, what is supposed to happen is that its supposed to wait in DFU mode for the first upload.

Looking at the code, Serial.begin() gets called in

https://github.com/rogerclarkmelbourne/ ... up.cpp#L97

But perhaps this is not doing what I expected it to do

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

Re: linux blue pill arduino DFU, my notes

Post by ag123 » Sun May 21, 2017 7:48 am

@roger
yup if the sketch isn't there or is simply erased, it is simply dfu mode, it seemed that way for me with the bootloader binary for maple mini

it seemed you have created a boot loader binary
https://github.com/rogerclarkmelbourne/ ... 1/binaries
generic_boot20_pb12.bin
Testing using Boot1 to control force the bootloader to wait indefinit…

---
to users who would like to try out using Boot1 as the 'perpetual boot loader' pin, you may like to try out roger's generic_boot20_pb12.bin boot loader
that may help users using blue pill boards in which Boot0 and Boot1 are simply jumpers

cbrake
Posts: 3
Joined: Fri Aug 11, 2017 10:07 pm

Re: linux blue pill arduino DFU, my notes

Post by cbrake » Fri Aug 11, 2017 10:11 pm

RogerClark wrote:
Sun May 21, 2017 7:24 am
If the BluePill was initially empty, and was flash with the bootloader, what is supposed to happen is that its supposed to wait in DFU mode for the first upload.

Looking at the code, Serial.begin() gets called in

https://github.com/rogerclarkmelbourne/ ... up.cpp#L97

But perhaps this is not doing what I expected it to do
My experience installing on a blue pill is that I had to have:

Serial.begin(BAUD);
Serial.println("test");

in my first arduino program, or I could not load new programs after the first one was flashed in dfu mode. After I programmed the first arduino program, I could then remove the Serial... code lines and it would re-program fine over /dev/ttyAM0.

I could also be losing my mind .... ;-)

Would be glad to run more tests if its any help.

Cliff

User avatar
RogerClark
Posts: 7485
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: linux blue pill arduino DFU, my notes

Post by RogerClark » Fri Aug 11, 2017 10:15 pm

The latest version of the bootloader has been combined with a sketch which has USB .

So after installing the latest bootloader, you should get a USB serial device, and if you open the serial terminal, you will see the congratulation message displayed , repeatedly...

cbrake
Posts: 3
Joined: Fri Aug 11, 2017 10:07 pm

Re: linux blue pill arduino DFU, my notes

Post by cbrake » Mon Aug 14, 2017 2:08 pm

RogerClark wrote:
Fri Aug 11, 2017 10:15 pm
The latest version of the bootloader has been combined with a sketch which has USB .

So after installing the latest bootloader, you should get a USB serial device, and if you open the serial terminal, you will see the congratulation message displayed , repeatedly...
I have the latest version of
https://github.com/rogerclarkmelbourne/ ... 0_pc13.bin

install on a bluepill. After I boot, this is the only new USB device I see (under Linux):

[2053058.468195] usb 1-1.5.5: new full-speed USB device number 80 using ehci-pci

lsusb:
Bus 001 Device 080: ID 1eaf:0003

I don't see any /dev/ttyAC* at this point.

I can then install a blink sketch. I have since learned that I don't need to have the Serial.* lines (I'm not sure what I was doing wrong before). After I install the first sketch, I then see the /dev/ttyACM0 device.

When should I see the congratulation message?

Does this blog post still describe the bootloader, or has it changed significantly since then?

http://www.rogerclark.net/arduino-stm32 ... l-and-dfu/

Thanks,
Cliff

User avatar
RogerClark
Posts: 7485
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: linux blue pill arduino DFU, my notes

Post by RogerClark » Mon Aug 14, 2017 9:38 pm

Use the binaries folder, not the bootloader_only_binaries.

The binaries folder has always been the folder where the distribution binaries are kept.

Perhaps I need to hide the bootloader only binaries for people who specifically only want to replace the bootloader without disturbing any existing sketch code

cbrake
Posts: 3
Joined: Fri Aug 11, 2017 10:07 pm

Re: linux blue pill arduino DFU, my notes

Post by cbrake » Tue Aug 15, 2017 12:38 pm

Thanks for the clarification -- yes, I had the wrong bootloader installed. I now get the /dev/ttyACM0 after BL install.

Post Reply