Bootloader updated to speed up dfu complete to sketch run time

Information on the latest releases
User avatar
RogerClark
Posts: 5470
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Bootloader updated to speed up dfu complete to sketch run time

Postby RogerClark » Sun Nov 13, 2016 10:14 am

Guys

Using code from @devan, and some additions I've written, I've improved the time taken by the bootloader between the upload finishing and the sketch running.

The time has been decreased, by using a BKP register, which survives a MCU reset, to store whether the MCU has just handled an DFU upload.
In which case when the bootloader is reset by DFU-Util on the PC, the code no longer needs to go through the normal startup process of flashing the LED and waiting for a timeout; but instead it can jump straight to the code that checks for a valid sketch and jump to that address.

Initially I tried to just jump to the sketch address when the bootloader got a DFU Reset, but this seemed to prevent the USB in the sketch from working.

So using a modified version of @devan's code, meant that I didnt need to worry about cleaning up all the registers and hardware etc that the bootloader uses, but instead the MCU can be reset as normal.

Note. It may be possible to clean the MCU and jump stright to the user code, but I doubt its going to noticeably faster as the code now doesn't do a lot apart from initialise, before going straight to the code that jumps to the sketch.

In addition to the speed up, the code also checks for another magic number in BKP_10, which locks it in perpetual bootloader mode.
But I'll need to update the core to take advantage of this, and to improve cold boot speed, I'd need to reduce the timeouts in the bootloader to take advantage of the change to the core.

i.e. we could set much lower DFU Wait timout's for cold boot, as for sketch uploads, the value in BKP_10 would lock the bootloader in perpetual bootloader mode (waiting for DFU upload) hence it wouldnt matter what the cold boot timeout was.

However we can't make cold boot really short, except on boards like the Maple mini, which have a button to put the bootloader into "Perpetual" mode, otherwise if the sketch has crashed, it would be very hard to reset the board at the right time for DFU to work (as there would be a narrow timeout window)


One other thought which may partially get around this problem, is that most generic boards have jumpers on both Boot0 and Boot1, but Boot1 has no effect if Boot0 is LOW

So we could use Boot1 as a switch to indicate to the bootloader that it needs to enter perpetual bootloader mode (continuously wait for DFU). This would be an easy change to the bootloader code, as we'd need need to set PB2 as Button on generic boards.

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

Re: Bootloader updated to speed up dfu complete to sketch run time

Postby RogerClark » Sun Nov 13, 2016 10:26 am

Update

Just tested using PB2 (Boot1) on my Black Pill as a way to enter perpetual bootloader, and it seems to work fine.

stevestrong
Posts: 894
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Bootloader updated to speed up dfu complete to sketch run time

Postby stevestrong » Sun Nov 13, 2016 11:02 am

Roger, it sounds great. Do we get new bootloaders for maple mini and blue pill, too?

EDIT
It just came in my mind: does this affect in any way the current USB serial code in core? I saw in some places the "magic" sequence...

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

Re: Bootloader updated to speed up dfu complete to sketch run time

Postby RogerClark » Sun Nov 13, 2016 7:59 pm

Stev

I recompiled them all, and upload to my repo.

But I didnt reduce the cold boot timeouts yet, except on the Black Pill.

Re:Magic number

Its a magic number in a BKP ( battery backed up register) and does not effect the USB at all.

@Devan used 0x424C for his magic number ( but I am not sure why he chose that particular number)
My additional feature uses 0x424D ( just because I it doesnt really matter what the number is, as long as its different from 424C)

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

Re: Bootloader updated to speed up dfu complete to sketch run time

Postby ag123 » Fri Apr 07, 2017 11:08 pm

after a good long time on stock bootloaders, i finally flashed STM32duino bootloader ! (after getting a clone st-link v2 'new toy')
dfu on the STM32duino bootloader is *fantastically fast* (compared to stock installed by vendor)
flashing a 64k file via dfu takes a mere 3.3 secs! and is smaller footprint
thanks much for all the efforts and enhancements that makes it this good :D
& to ahull your st-link v2 guide is simply awesome - just works
https://github.com/rogerclarkmelbourne/ ... from-Linux
:lol:

User avatar
ahull
Posts: 1423
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Bootloader updated to speed up dfu complete to sketch run time

Postby ahull » Sat Apr 08, 2017 10:19 am

ag123 wrote:...
& to ahull your st-link v2 guide is simply awesome - just works
https://github.com/rogerclarkmelbourne/ ... from-Linux
:lol:

Glad it helped. :D
- Andy Hull -

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

Re: Bootloader updated to speed up dfu complete to sketch run time

Postby ag123 » Sat Apr 08, 2017 11:58 am

the fun part is that i'm playing with a maple mini (clone) & initially while not checking file size i flashed a 1m file on the maple mini via dfu. the maple mini goes 'dead', even the classic dfu blinky stop flashing. connecting to usb don't respond and power led went dark.i thought oops bricked !
in a panic i re-flashed the bootloader via open-ocd - st-linkv2 & it comes back to live - de-bricked
:lol:

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

Re: Bootloader updated to speed up dfu complete to sketch run time

Postby ag123 » Tue Apr 11, 2017 6:44 pm

oh and back to this topic, i'd think 'abusing' boot1 is an interesting idea, i.e. boot DFU if boot0 is cleared and boot1 is set, otherwise goto sketch, may help for button handicapped boards, but i like that maple mini 'perpetual' button please keep it, in future people reviewing the st manuals would wonder where this new 'feature' comes from as in the manuals boot: 0-0 flash, 1-0 system, 1-1 ram and we added 0-1 dfu :lol:


Return to “Builds and Announcements”

Who is online

Users browsing this forum: No registered users and 2 guests