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: 171
Joined: Mon Oct 26, 2015 8:16 am

Re: Serial-only USB boot loader

Post by jcw » Tue Nov 10, 2015 8:14 pm

Code is here - https://github.com/jeelabs/embello/tree ... tm32f1init - docs to follow later this week.
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.
There will be many different ways to upgrade & replace boot loaders, I expect. And more to come, no doubt.
But we have to be careful, IMO - this is the sort of "capability" which can massively confuse newcomers.
This particular one (now called "stm32f1init") is really only meant as last resort, or when you start with next to nothing.

Onwards, to the next level!

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

Re: Serial-only USB boot loader

Post by jcw » Tue Nov 10, 2015 8:21 pm

RogerClark wrote:But I dont think its a lot to ask to buy usb to serial.
True. But there are road blocks everywhere: then you need to get stm32flash going, or stm32loader.py, etc.
It really depends on where people a're coming from, and what tools they have lying around.

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

Re: Serial-only USB boot loader

Post by Rick Kimball » Tue Nov 10, 2015 8:33 pm

jcw wrote:Code is here - https://github.com/jeelabs/embello/tree ... tm32f1init - docs to follow later this week.
Neat, are you going to post the bootloader code? I wouldn't mind porting this to a msp430 launchpad
-rick

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

Re: Serial-only USB boot loader

Post by jcw » Tue Nov 10, 2015 8:47 pm

Yes, I'll definitely post it - but the new USB serial boot loader is not a sketch, it's a libopencm3 project with a makefile.
And it's only marginally usable so far (it still requires manual reset to pick up a new upload).

I do have a little "bin2h" tool to turn any binary file into a .h file suitable for this stm32f1init utility.
The idea being to collect header files and insert the proper one in the sketch.
I'll add the Maple v3 boot loader header.

Here's the "bin2h.c" code I'm using on OSX (should also work on Linux). Inlined below for now:

Code: Select all

// Convert a binary file to a format usable as data inside C source code.
// -jcw, 2015-11-09

#include <stdio.h>

int main (int argc, const char** argv) {
    if (argc != 2) {
        fprintf(stderr, "usage: bin2h infile >outfile\n");
        return 1;
    }

    FILE* inf = fopen(argv[1], "rb");
    if (inf == 0) {
        perror(argv[1]);
        return 2;
    }

    int width = 0;
    while (!feof(inf)) {
        width += printf("%d,", fgetc(inf));
        if (width > 75 || feof(inf)) {
            putchar('\n');
            width = 0;
        }
    }

    return 0;
}
Compile as "gcc -o bin2h bin2h.c", run as "./bin2h mybootloader.bin >boot-mybootloader-v01.h" or something.

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

Re: Serial-only USB boot loader

Post by jcw » Tue Nov 10, 2015 8:52 pm

Ooh, msp430 Launchpad would be nice, tons of those in people's drawers too, I suppose.
How much free flash does it have? If there's enough room, you could stash a BMP image in there.

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

Re: Serial-only USB boot loader

Post by Rick Kimball » Tue Nov 10, 2015 9:01 pm

jcw wrote:Ooh, msp430 Launchpad would be nice, tons of those in people's drawers too, I suppose.
The ones that are sitting in people's draws probably have 2k of flash / 128bytes ram (g2231) or maybe they have the msp430g2553 which has 16K flash / 512bytes ram. BMP is kind of big, I don't see that fitting on any of the cheap devices
$ arm-none-eabi-size blackmagic
text data bss dec hex filename
51660 156 2036 53852 d25c blackmagic
At one point I had thought about trying to fit it on an msp430, I took out all the non essential code, (jtag/usb etc). Just what was required to handle SWD on specific chips, (at that time i was thinking LPC1114FN28) I compiled it up and it came out greater than 32k .. so I stopped.
Last edited by Rick Kimball on Tue Nov 10, 2015 9:48 pm, edited 1 time in total.
-rick

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

Re: Serial-only USB boot loader

Post by RogerClark » Tue Nov 10, 2015 9:24 pm

JeanClaude

There are definitely some people on the forum who are capable to build using via Makefile etc

I can think if at least 3 or 4 people straight away.

I can test compile on Windows 7 if you want, as its my main OS, (though I do run OSX and Linux)

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

Re: Serial-only USB boot loader

Post by jcw » Tue Nov 10, 2015 9:36 pm

Oops - I wasn't doubting that for one second! Sorry, I've been in the "for noobs" mindset too long.

Ok, I'll think of a name and a spot to put it. Somehow, "Usb Serial Bootloader" doesn't cut it, I think :)
I wasn't trying to keep this to myself. Will report here as soon as it's online.

Meanwhile, I've added the binary data for Maple boot 2.0 to stm32f1init. Untested.

And yeay, I've finally got a board which Maple-boots as it should here: std "Baite" Maple Mini clone, as pre-loaded.
The only quirk is that I seem to need to press the reset button after an upload. Otherwise fine, also resets/re-flashes.

Update - there's more to it than the USB serial boot, for getting things to actually work: it also needs a new board entry to compile sketches at 8KB offset (like Maple, at least for now). And stm32flash has to be tweaked to talk to the CDC-ACM device. Hmm... the backlog is piling up :(

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

Re: Serial-only USB boot loader

Post by RogerClark » Tue Nov 10, 2015 10:13 pm

Hmm... the backlog is piling up :(
I know the feeling ;-)

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

Re: Serial-only USB boot loader

Post by jcw » Wed Nov 11, 2015 1:07 am

The stm32f1init sketch now also compiles ON an STM32F103 µC, using h/w serial with h/w even parity.
Well... at least it launches on Maple Mini and Nucleo F103, which means those could also be used as boot-the-bootloader setups.
Haven't tried hooking either of these boards up to a target yet, though.

Lastly, I've converted the BMP-jc66 binary, so with a bit of luck this can now also be flashed - the sketch should fit on F103xB's.
Again, untested, but it's there for the brave/early/adventurous soul/bird/adopter who wants to give this a try.
The only missing link is to figure out the wiring connections between the stm32f1init and target boards, I think.

If you try this out, please let me know how it goes. Would like to document a couple of these scenarios in the next few days.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests