F4 DFU bootloader

Post here first, or if you can't find a relevant section!
victor_pv
Posts: 1652
Joined: Mon Apr 27, 2015 12:12 pm

F4 DFU bootloader

Post by victor_pv » Sat Aug 26, 2017 8:50 pm

Roger, I modified Chriss bootloader to work on the F407, enumerate on reset like we normally do, and currently to wait ten seconds if there is a sketch on flash, and indefinitely if there is nothing in the sketch base address that resembles a top of the stack pointer.
The sketches need to be compiled for 0x08004000
I am attaching the bin file for the 407.
It should work with stack in normal RAM or CCMRAM.
I have tested the bootloader with the debugger, what I haven't done yet is upload a sketch using it, because I do not know what tool can be used. The board gets detected as an STM DFU device.
I have never used the STM DFU uploads, took me a while to even find the driver I had to load to Windows, but the DFuse tool doesn't take normal BIN files.
The bootloader currently takes under 13KB, but since the first page is 16KB, the whole page is reserved, and the sketch can is uploaded starting on the second page (0x08004000)
F4Bootloader.zip
(9.7 KiB) Downloaded 5 times

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

Re: F4 DFU bootloader

Post by RogerClark » Sat Aug 26, 2017 9:04 pm

Thanks Victor

I downloaded Chris's files but could not get them to build at all in True Studio. But I think this could be because I only have an old version installed

Did it build straight away for you, or did you need to change something in the True Studio project files.

Re; Uploading in DFUse format
Ah, that could be problematic.

i remember trying to use STMs DFUse tool but, like you say, it does not take binaries.

Did you try using Zadig to replace STs driver with the WinUSB driver, and then use the 64 bit dfu-until ( for Windows) which is in the tools folder of my repo?

I did manage to upload to the built in bootloader by doing those two steps.
Because the new version of dfu-util does not seem to work with linusb-win32 which the Maple DFU is compatible with.

I did try loading the WinUSB driver for the Maple VID PID but it does not seem to work

Ps you can use Wei-simple.exe to install WinUSB, you just use "type=0" instead of "type=1"

But make sure you manually uninstall the driver first before updating a device to WinUSB as I am not sure Wei-simple or Zadig remove existing drivers

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

Re: DFU bootloader in F4

Post by RogerClark » Sat Aug 26, 2017 9:32 pm

BTW.

I did also setup the tool chain etc on a Linux VM to build @devan's bootloader, did a test build for the F1, and start to make the changes necessary for the F4, but the backup registers code was not compatible with the F4 and I think I got a load of other compile errors when I tried to build for the F4, so I had to park the code as I did not have time to figure out what was wrong.

I will probably just remove the backup registers code, as it's not initially needed, but I think there were other things that prevented it compiling for the F4 :-(

victor_pv
Posts: 1652
Joined: Mon Apr 27, 2015 12:12 pm

Re: F4 DFU bootloader

Post by victor_pv » Sat Aug 26, 2017 9:57 pm

I tried to build with Eclipse, didn't work, downloaded new Eclipse, didn't work, and after a while wasting my time, I decided it was simpler to download SystemWorkbench, that's what the project was made for originally, and that worked fine.
Then I made a few changes for the F407, since there is a few differences, but I probably spent 1/10 of the time doing those changes, vs what I spent trying to get it to compile in the normal Eclipse...

I'll try those steps you mention to upload. If you have a chance to load the bin to a board and see if it gets detected with your drivers that will help too.

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

Re: DFU bootloader in F4

Post by RogerClark » Sat Aug 26, 2017 10:07 pm

Hi Victor

I've just dug out my Blue F4 board, so I'll see if if you binary works .

Re: Eclipse

I had the same issues with True Studio.

I think perhaps it has missing some build targets.

I'll download SystemWorkbench as well

Thanks

Roger

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

Re: F4 DFU bootloader

Post by RogerClark » Sat Aug 26, 2017 10:16 pm

Installed the bootloader and I can see it on USB

And I have the WinUSB driver already installed for that VID/PID

So I now need to modify the LibMaple F4 code to build with that offset

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

Re: F4 DFU bootloader

Post by RogerClark » Sat Aug 26, 2017 11:12 pm

Victor as this thread is no longer about the internal bootloader, I've split it

FYI

I'm currently modifying the libmaple F4 to handle having a different Vector offset passed from boards.txt

I've written all the code , but I am still testing it at the moment (i.e its not working !)

victor_pv
Posts: 1652
Joined: Mon Apr 27, 2015 12:12 pm

Re: F4 DFU bootloader

Post by victor_pv » Sat Aug 26, 2017 11:22 pm

You need to also modify the linker script to start from 8004000.
I did that, but forgot about the vector, good that you mentioned it, but had some other problems, so I'm about to try in a different computer.

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

Re: F4 DFU bootloader

Post by RogerClark » Sat Aug 26, 2017 11:31 pm

OK

I've got the vector table offset working with Libmaple F4

I added a bootloader menu to the generic , it currently still says "stm32duino bootloader" , but thats because I've not had time to change it ;-)

Its a bit of a hack as for some reason I had to define the vector stuff for all boards even though there a added a ifndef into libmaple.h where it defined the USER_ADDR_ROM value, which is used in boards.cpp

The bootloader seems to hold for about 15 secs then jumps to the code and is flashing my LED

I now need to work on uploading via DFU

PS. Yes. I added a new linker file

See attached
Attachments
libmaple_f4_vect_offset.zip
(5.86 KiB) Downloaded 3 times

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

Re: F4 DFU bootloader

Post by RogerClark » Sat Aug 26, 2017 11:34 pm

PS. I hope that zip contains all the changes

Note. I only added the file for the Generic F4, as I'm using the "Blue F4" board at the moment for testing

PPS.

We need to add the code to toggle USB DP when the sketch runs, as it looks like the PC does not recognise the USB Serial device when the bootloader jumps to the application code.

Perhaps we can do that in the bootloader as my PC permanently shows the USB DFU device when my Blink sketch is running

Post Reply