Ubuntu 14.04LTS blue pill bootloader

Bootloader for boards that don't have the addition hardware found on the Maple mini, which resets the USB
matthurd
Posts: 4
Joined: Sat Jan 02, 2016 3:26 pm

Ubuntu 14.04LTS blue pill bootloader

Postby matthurd » Sat Jan 02, 2016 3:42 pm

Hi all,

Just started tonight with the STM32 on a generic "blue pill" board for building up a STEM school project for my wife's school.

Most things are working brilliantly. Much appreciated the effort put into this.

Using Arduino 1.6.5r5 64-bit on Ubuntu 14.04LTS on my laptop.

USB to blue pill works nicely.
Flashing via
"./stm32flash -w ~/src/repos/STM32duino-bootloader/STM32F1/binaries/generic_boot20_pc13.bin /dev/ttyUSB0"
works fine.

Then after attaching usb-micro cable; disconnecting usb/serial foo; and, reprogramming a sketch (a pc13 blinker) when restarted, no problem, but further reprogramming is not possible. It hangs at this point:

Code: Select all

Failed to open serial device.
dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
dfu-util: Cannot set alternate interface
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Opening DFU capable USB device...
ID 1eaf:0003
Run-time device DFU version 0110
Claiming USB DFU Interface...
Setting Alternate Setting #2 ...


Whereas just before, the first and only time:

Code: Select all

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%        14268 bytes
Download done.
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
Done!
Resetting USB to switch back to runtime mode


Nothing I seem to do lets it reprogram, but if I reflash I get the same behaviour. That is, works the initial time and then never again.

Does anything have to be in the sketch to ensure it can handle the next upload, or is there something else I'm missing. Hmmm, I think I'm using head from the repo which may be an issue perhaps?

Any suggestions would be most welcome to this STM32 newbie.

Thanks again and kind regards,

--Matt.
matthurd (at) acm.org

fredbox
Posts: 84
Joined: Tue Jul 07, 2015 4:44 pm

Re: Ubuntu 14.04LTS blue pill bootloader

Postby fredbox » Sat Jan 02, 2016 6:28 pm

Your experience with that board matches mine. After you upload your blink sketch, unless the serial port becomes available, you cannot upload anything through the USB port. There is another thread on here where I modified my board to add a reset circuit to deal with this issue. Others have reported that uploading through USB works ok without modification.

After you upload your blink sketch, try temporarily connecting a 1K resistor from PA12 to GND. Then look at the output from dmesg and you should see /dev/ttyACM0. Once that happens, set the port in the IDE and you can upload again.

I think the issue could be that the USB_DISC pin in Arduino_STM32/STM32F1/variants/generic_stm32f103c/board/board.h is pointing to PB10 instead of PA12.

Code: Select all

#define BOARD_USB_DISC_DEV        GPIOB
#define BOARD_USB_DISC_BIT        10


Hopefully, someone with more knowledge of this code can verify if this is correct.

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

Re: Ubuntu 14.04LTS blue pill bootloader

Postby RogerClark » Sat Jan 02, 2016 8:55 pm

Guys

Yes.
Reset is via serial.

If the board is not enumerating as a serial device it's impossible to reset it.

Just do a simple sketch that prints an incrementing number once a second and check you see this in the terminal.

On Linux and OSX I wrote a small program to send the reset sequence via serial to the board.

If you look in the upload script, you should be able to run the reset binary from the command line, and see if the board resets.
There is a parameter to set a delay after resetting, to allow the USB to re enumerate, so you could try changing that if you can see the board resetting when you run the reset script manually.

I know on OSX a few people needed to vary the reset delay to get it to work for them. So it's worth investigating

BTW. although those definitions are incorrect and should be changed. I think for when the Generic Bootloader is defined, it uses had coded values instead of those defines.

matthurd
Posts: 4
Joined: Sat Jan 02, 2016 3:26 pm

Re: Ubuntu 14.04LTS blue pill bootloader

Postby matthurd » Sun Jan 03, 2016 3:00 am

Hi guys,

I've tried to avoid the hardware hack for just now, but I've seen some curious behaviour worth commenting on just in case it is a clue to behaviour.

I've played around with the delays in the tools/linux/maple_upload bash script by varying the delay on line 29:

Code: Select all

"${DIR}/upload-reset" ${dummy_port_fullpath} 750


If I modify the line to 100. It doesn't load via the IDE.
If I modify the line to 1000. It loads randomly about 20% of the time. That is 6 times out of 30.
If I use 10000. It never works. But somewhere between half and two thirds of the time it upload-reset is not run as it runs quickly and it reports "Failed to open serial device."

Going back to 1000 ms delay in the script, all the failures (tens), except one, were when the upload-reset failed to open the serial device.

I might look at a crude hack of looping around upload-reset until it succeeds to see if that at least pretends it works.

Anyway, I thought I'd share in case there may be some insight from that.

Thanks again for the replies. I'll look at the extra resister later. Kind regards,

--Matt
matthurd (at) acm.org

matthurd
Posts: 4
Joined: Sat Jan 02, 2016 3:26 pm

Re: Ubuntu 14.04LTS blue pill bootloader

Postby matthurd » Sun Jan 03, 2016 3:21 am

Hi,

Yes, the horrible hack of looping if upload-reset fails in the maple_upload script for linux works. I haven't had it fail yet.

This is the hack:

Code: Select all

"${DIR}/upload-reset" ${dummy_port_fullpath} 1000
upres=$?
while [[ $upres != 0 ]]; do
  sleep 0.5
  "${DIR}/upload-reset" ${dummy_port_fullpath} 1000
  upres=$?
done


Unfortunately, sometimes that means a 5 to 20 second wait with 10-40 failure messages, but it always seems to work.

Just FYI,

--Matt.
matthurd (at) acm.org

fredbox
Posts: 84
Joined: Tue Jul 07, 2015 4:44 pm

Re: Ubuntu 14.04LTS blue pill bootloader

Postby fredbox » Sun Jan 03, 2016 4:39 am

This sounds like the modemmanager / unknown PID/VID issue. See this thread.
There are two workarounds listed - uninstall modemmanager or create a custom rules file for the bootloader PID/VID.

matthurd
Posts: 4
Joined: Sat Jan 02, 2016 3:26 pm

Re: Ubuntu 14.04LTS blue pill bootloader

Postby matthurd » Sun Jan 03, 2016 7:40 am

Thanks I tried removing the modemmanager but it then always fails trying ttyUSB0 whereas it used to try ttyACM0 and succeed. This many not at all be related removing modemmanger though and a few minutes of fooling around did not find a cure. I'll have to look at it a bit later to see if I can get it to work again.

Thanks again and regards,

--Matt.


Return to “Generic bootloader”

Who is online

Users browsing this forum: No registered users and 2 guests