Serial-only USB boot loader

Bootloader for boards that don't have the addition hardware found on the Maple mini, which resets the USB
jcw
Posts: 170
Joined: Mon Oct 26, 2015 8:16 am

Re: Serial-only USB boot loader

Postby jcw » Mon Nov 09, 2015 5:23 pm

Yep, exactly. Could do this with a $2.30 Arduino Nano clone off eBay, for example.
And optionally modify the code a bit, say to add a board-type ID before flashing it.
There's also a unique H/W ID in each µC, it can be used to distinguish multiple units.

That's 2 bytes µC type (0x410 etc), 2 bytes board ID, 12 bytes h/w ID = 16 byte "tag".
The boot loader could report these for a read from some "impossible" address, perhaps.

-jcw

User avatar
mrburnette
Posts: 1769
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Serial-only USB boot loader

Postby mrburnette » Mon Nov 09, 2015 8:10 pm

jcw wrote:Yep, exactly. Could do this with a $2.30 Arduino Nano clone off eBay, for example.
<...>



Just saved you $0.40:

http://www.aliexpress.com/wholesale?productId=32341832857

These are the CH340 USB-serial chips and no cable. Perhaps the eBay one has the cable... I'm sure that for the $2 ballpark there is not an actual FTDI chip.

Ray

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

Re: Serial-only USB boot loader

Postby RogerClark » Mon Nov 09, 2015 9:12 pm

I have managed to flash the bootloader using a Uno, but it was more by fluke than design.

The issue is that I think the internal bootloader uses Even Parity by default, and Software serial does not support this ( as far as I can tell) on AVR.

I found if I set the baud rate to 56k, and used the default settings, in software serial, I could use the Uno as a serial bridge.
But slower or faster speeds would not work.

I had considered if there was a way to get a Uno to act like a Black Magic Probe, and connect via swd, but I didnt have time to continue looking into this.

There is also the option to update the bootloader using a sketch that contains the binary of the new bootloader ( as an array).

We already have this, but it only works ( at the moment) if the new bootloader is not bigger than the old one. Otherwise you would end up overwriting the sketch that is flashing the bootloader.

BTW. As an aside, RedBearLab use Avrdude as the upload program for their arduino compatible stuff, and implement the protocol in a MCU ( I cant remember what they use but its not a stm32)


I dont have any problems with using Avrdude, in fact its a great idea, but getting people to change the pre installed bootloader in the maple mini, may be an uphill struggle.

jcw
Posts: 170
Joined: Mon Oct 26, 2015 8:16 am

Re: Serial-only USB boot loader

Postby jcw » Tue Nov 10, 2015 10:20 am

To continue on my own post:
what cheap boards are out there which work in the IDE out of the box? Which ones are the really common ones?

The boards I see as most suitable for turning into a "boot loader bootstrap" (bolobo?) are:

* Arduino Uno
* Nucleo F103RB
* Maple Mini

These should all work with the Arduino IDE out of the box, so if you happen to have one of these and upload a yet-to-be-written sketch to them, you will then be able to load a boot loader into your own target board of choice (at least for STM32F10x µCs). This will use the STM32's ROM-based serial boot loader.

It needs 3 wires to the target board (RX/TX/GND) and a description how to manually put the target board into the proper boot mode.

It would be nice to have a few versions of this sketch, e.g. one with the current Maple v2 boot loader, and one with the new USB Serial Loader I'm working on (both are under 8 KB). On boards with at least 128 KB flash, a third useful option IMO, would be a version which flashes Rick's BMP build.

The adventure continues...

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

Re: Serial-only USB boot loader

Postby RogerClark » Tue Nov 10, 2015 10:31 am

The Uno or its predecessor are probably the most widely used of the Arduino boards

I'd recommend that you focus on getting a reliable way to flash the bootloader using that board.

However, I'm not sure its going to be that easy, because of the lack of parity control with software serial.

You can of course use the hardware serial on the Uno, but you loose debug to the PC if you have to use that.

People could of course buy a $3 USB to Serial, but I agree that if we could reflash using hardware people already have, it would be easier.

BTW. If you are considering using a Maple mini to flash another board, I think using the BMP may be one option.

I"m looking at building a verison of the BMP that is loaded by the existing bootloader in the Maple mini into address 0x8005000 (just in case they have the old bootloader in the Maple mini)

I'm in the process of forking the BMP and adding the GD32, but doing a Maple mini version is next on my list, but the vector table and linker script would need to be changed, and its 3rd on my list of priorities for the BMP.

1) GD32 in my repo
2) binaries for GD32 in my repo
3) Generic STM32 in my repo (based on Rick's j66_coreboard)
4) binaries for j66 in my repo
5) Maple mini without bootloader
6) Maple mini with existing bootloader


However I have not had much time to work on this today, as I helped Rick out with his nRF51822 stuff for a while today, and its been a busy day with work, and I'm not a "night owl" ;-)

So it will need to wait until tomorrow

But if you do a Maple mini version of the BMP, especially one that runs with the existing bootloader, in the next 10 hours, let me know, as it will save me having to do it ;-)

jcw
Posts: 170
Joined: Mon Oct 26, 2015 8:16 am

Re: Serial-only USB boot loader

Postby jcw » Tue Nov 10, 2015 12:40 pm

RogerClark wrote:However, I'm not sure its going to be that easy, because of the lack of parity control with software serial.

Awww, right. It can probably be hacked in, but that more or less rules out the Uno as first test setup.
A bit unfortunate - this means you need a working STM32 type board to re-flash another one with a boot loader.
Ultimately, I'd like to have a "clean" upgrade path from a Uno to various blank STM32 boards.

Thx.

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

Re: Serial-only USB boot loader

Postby zmemw16 » Tue Nov 10, 2015 6:27 pm

why does it have to be fast for a potentially once only happening?
after that you have the egg.

so maybe it could be bit banged?

stephen ducks down behind big wall. :D

jcw
Posts: 170
Joined: Mon Oct 26, 2015 8:16 am

Re: Serial-only USB boot loader

Postby jcw » Tue Nov 10, 2015 7:19 pm

Bit-banged sending is easy, it's the reception that is more tricky. And that's exactly what SoftwareSerial does.

I've hacked up a modified version of SoftwareSerial which sends out even parity, and ignores the incoming extra parity bit.
Getting this going on an ATmega is actually the best option for me after all. Here's output from an ATmega328 sketch:

Code: Select all

[stm32f1init] boot-usbSerial-v01.h

(When you see a question mark, RESET your TARGET board!)

  Connecting? .. OK
Boot version: 0x22
   Chip type: 0x410
Unprotecting: OK
    Resuming? ...... OK
     Erasing: OK
     Writing: ........................... OK
        Done: 6661 bytes uploaded.

So as you can see, this does indeed work.

Had to add the "read unprotect" on a brand new blue-pill board I'm using for this test, erase kept failing without it.
But the target board ends up in a weird mode, so I have to reset it AGAIN during the "resume" message, which also re-syncs.

Is this normal, i.e. having to unprotect, and then having to manually reset to proceed afterwards?
I assume that once unprotected, future writes can just mass-erase, but I haven't checked that yet.
Last edited by jcw on Tue Nov 10, 2015 7:45 pm, edited 2 times in total.

jcw
Posts: 170
Joined: Mon Oct 26, 2015 8:16 am

Re: Serial-only USB boot loader

Postby jcw » Tue Nov 10, 2015 7:40 pm

mrburnette wrote:Just saved you $0.40: http://www.aliexpress.com/wholesale?productId=32341832857

Wow. This has now probably become the cheapest way to get initial code into an empty STM32F103 !

Considerably less that the official price of an STM32F103C8 chip, in fact. What a curious world we live in...

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

Re: Serial-only USB boot loader

Postby RogerClark » Tue Nov 10, 2015 7:53 pm

umm

That link just takes me to a search on Aliexpress.

The product still active?


@jcw

Well done for hacking sw serial to do even parity.

I dont think there is any harm to unprotect, even every time.
The only board that I have that arrived protected was a STLInk dongle, which I then reflashed with the bootloader, and it worked fine even though it was a STM32L03 I think !!

But I only needed to do it once.

I'm not sure its such a big deal for someone to need a usb to serial converter or even a STLink.
The STM32 board will be a new board for them, and if they have been doing any research they will know that unless its a Maple mini, they need to flash the firmware.

Well, no, I suppose we have people on this forum who have bought a Blue Pill etc as the vendor claimed Arduino compatibility, but with no bootloader.

But I dont think its a lot to ask to buy usb to serial.

One thing that you may want to consider is updating the bootloader on the Maple mini via a sketch.
We already have this, to update from the old maple bootloader.

But this would only work if you new bootloader was not larger than the existing one


Return to “Generic bootloader”

Who is online

Users browsing this forum: No registered users and 1 guest