Serial-only USB boot loader

STM32duino bootloader aka Maple bootloader
Post Reply
jcw
Posts: 171
Joined: Mon Oct 26, 2015 8:16 am

Re: Serial-only USB boot loader

Post by jcw » Sun Nov 08, 2015 9:48 pm

Thx - still getting to grips with boards.txt & parameters.txt ...
I can reproduce the failure from the cmd line now.

Well, it seems that - unlike stm32loader.py - stm32flash does not like a virtual USB port at all:

Code: Select all

$ ../../../macosx/stm32flash/stm32flash /dev/cu.usbmodemD5D4C5E3 
stm32flash 0.4

http://stm32flash.googlecode.com/

Error probing interface "serial_posix"
Cannot handle device "/dev/cu.usbmodemD5D4C5E3"
Failed to open port: /dev/cu.usbmodemD5D4C5E3
That's the serial USB port on my BMP (it fails with /dev/tty.* as well).

I just tried the latest source from sourceforge, and that too refuses to open every USB port I try.
Oh, wait - an FTDI adapter works. So maybe stm32flash isn't compatible with CDC-ACM ports?
It always amazes me what sort of road-blocks one bumps into, sure didn't expect this one!

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

Re: Serial-only USB boot loader

Post by RogerClark » Sun Nov 08, 2015 10:13 pm

Last time I looked stm32flash was not being actively maintained, it languished on sourceforge for ages, without any updates, dispite people noting bugs.

I forget if I had to fix anything other than it only accepting ports named tty.

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

Re: Serial-only USB boot loader

Post by jcw » Sun Nov 08, 2015 10:30 pm

No worries. There's are some tty control settings differences, when I ignore one of the checks, stm32flash proceeds.
It does make a few more requests to the boot loader than what it supports so far, so need to add a bit more functionality in.
Getting there...

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

Re: Serial-only USB boot loader

Post by RogerClark » Sun Nov 08, 2015 10:41 pm

OK.

Its always the same with S/W development... You can always end up with problems from the area you least expect.

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

Re: Serial-only USB boot loader

Post by jcw » Mon Nov 09, 2015 12:12 am

Ok, got a first test upload going through the IDE using a hacked stm32flash. Mostly by disabling a few checks and features.

The stm32flash utility is considerably more elaborate than we need it to be here (and not just for this USB serial boot loader, I believe). As far as I can tell, all we need is an erase + write into a contiguous area of flash memory, optional read-back for verification, and then a jump to the base address. And this on Windows and POSIX systems, for at least real and virtual serial ports.

In summary: apart from having to press the reset button, the basics of uploading and running a sketch through this new boot loader seems to work. At least as proof of concept. No handover of serial USB from the boot loader to the sketch yet, that's still a big TODO.

I'll ponder a bit on a way forward. A small portable scripting environment which does serial I/O would be enough for this simple task (e.g. Lua, JimTcl). Basic text manipulation and launch could also help simplify the boards/platform.txt situation, though it's a bit of a stretch to start changing all that. I'll have a look at the ESP-Arduino setup. Maybe we can share some approaches with them. Too bad this whole Arduino IDE thing isn't a bit more modular.

Thanks Roger, for your help, tips, pointers, and background info - it was just the right mix to keep me from getting stuck :)

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

Re: Serial-only USB boot loader

Post by RogerClark » Mon Nov 09, 2015 1:03 am

Hi Jean-Claude

Sounds like you have made amazing progress.

Looking at what the ESP guys are doing is a good idea. They seem to have an upload plugin for the Arduino IDE.

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

Re: Serial-only USB boot loader

Post by jcw » Mon Nov 09, 2015 12:27 pm

Let's talk about the boot protocol for a moment. I have the STM32 serial protocol working for uploads, but this depends on either stm32loader.py (which requires Python to be installed) or stm32flash (which requires some changes, and will need to be re-compiled for Win/Mac/Lin32/Lin64).

An alternative is to have the boot loader act as STK500-compatible boot loader, as used on ATmega chips. This would mean that "avrdude" can be used for uploads, which is well-supported and maintained, and part of the standard Arduino IDE install, hence effortless for us. The emulation is slightly tricky, as the boot loader has to ignore things like "fuses", and report itself as some sort of fake AVR µC to be accepted by avrdude.

Tools like avrdude, stm32flash, etc solve the important problem of talking to serial devices in raw mode, on Windows, Mac, and Linux.

Sooo... what if the boot loader did indeed adopt the STK500 protocol for uploads? Seriously. What would be the drawbacks?

And while I'm at it: why can't we avoid the whole issue of selecting the right chip type, memory size, board model, manually? Why can't we just select a serial interface, and ASK the attached board what µC type it is and what board type even? It would be trivial for a boot loader to report this. Shouldn't we be stepping out of the stone age by now? :)

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

Re: Serial-only USB boot loader

Post by mrburnette » Mon Nov 09, 2015 1:37 pm

jcw wrote: <...>
And while I'm at it: why can't we avoid the whole issue of selecting the right chip type, memory size, board model, manually? Why can't we just select a serial interface, and ASK the attached board what µC type it is and what board type even? It would be trivial for a boot loader to report this. Shouldn't we be stepping out of the stone age by now? :)
Normally, I'm the negative voice on the forum about moving too fast or too many changes at once - but
I really like the idea of falling back on AVRDUDE to perform the upload. And I particularly like the idea of having the bootloader report an ID that can be traced to a unique configuration. Perhaps my years in corporate IT is giving me a sense of comfort in that the technology could prevent much error-prone user interaction.

Now the downside to this is that the bootloader is not the same bootloader that comes on the Maple Mini. I think we can move beyond this since I have long ago gone to bootloader 2.0 to recover the 4K of SRAM held captive by the original bootloader.

But, the implication is that the new user must install the correct bootloader onto their board. A slip-up in identifying the correct bootloader will most likely be trouble at a later date. There is such a proliferation of bootloaders, I can see some newbies getting hung-up here. I really wish the ArduinoIDE had the ability to render in the editor graphic images such that the selection of a bootloader for a specific board configuration could display a representative JPG/GIF.

So far, I think your idea is far more positive than the negatives... it will mean that a significant amount of documentation be added (and maintained) in the WiKi.


Ray

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

Re: Serial-only USB boot loader

Post by jcw » Mon Nov 09, 2015 2:05 pm

Thanks, Ray - lots of encouragement in your comments, from where I stand...

I've been battling boot load chickens-and-eggs for years now. First on ATmega chips, and now the whole circus again on STM32.

If we could settle on say up to 3 boards for people to use as "boot loader installers", then a page on the web with exact info on how to wire things up to install (over ROM-based serial) a specific boot loader on a second board would be feasible. It gets confusing, but say you take a standard Arduino Uno, connect it with a few wires to your own board (STM32, LPC, whatever), put your own board in serial-upload mode, and upload a special installer sketch via the IDE to the Uno. After that, your own board ends up with the proper boot loader (which could be any of numerous types, Maple DFU, USB serial, wireless, etc).

I've been through this mess several times, the important challenge IMO is to end up with brief and clear instructions.

The only thing we need is an easy starting point, i.e. a board supported by the IDE, with a few spare I/O pins.
This is the unavoidable part: you need ONE board to install a boot loader on a SECOND one.
But I'd like to stress that they don''t need to be the same. A Uno could program a Maple Mini just fine.

To rephrase: what cheap boards are out there which work in the IDE out of the box? Which ones are the really common ones?

(this same approach can also be used to install Rick's BMP build on most STM32F103C8's, BTW)

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

Re: Serial-only USB boot loader

Post by Rick Kimball » Mon Nov 09, 2015 4:52 pm

If the bootloader is small enough, maybe you could make an arduino sketch that contains the bootloader binary as an array of bytes.

The sketch would take those binary bytes and upload them via the ROM based stm32 factory serial bootloader. As it is a sketch that is only going to use serial communication and gpio pins ( to toggle the the chip into bootload mode ) it would be easy to port to any board running an arduino port. It could be an arduino board, teensy, stm32, texas instruments .. etc

-rick
Last edited by Rick Kimball on Mon Nov 09, 2015 6:20 pm, edited 1 time in total.
-rick

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest