USB Bootloader

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
mobyfab
Posts: 452
Joined: Sat Nov 19, 2011 6:47 pm
Location: Versailles, France
Has thanked: 12 times
Been thanked: 18 times

USB Bootloader

Postby mobyfab » Sat Jan 04, 2014 4:36 am

Hey,

I just finished writing a USB bootloader and a GUI to operate it. (based on some code from mabl and demos)

You will need to install the provided drivers manually to use it. Only tested on win7 x64 so far, will do linux later on.

https://github.com/mobyfab/ChibiOS-Bootloader

Let me know if it works for you, any feedback is appreciated!

Thanks!

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: USB Bootloader

Postby Tectu » Sat Jan 04, 2014 6:41 pm

This looks very promising!
Good job as always, mobyfab ;)


~ Tectu

DEHiCKA
Posts: 17
Joined: Thu Feb 21, 2013 8:13 am
Has thanked: 4 times
Been thanked: 3 times

Re: USB Bootloader

Postby DEHiCKA » Sat Jan 04, 2014 7:29 pm

Fabien, hi! Just flashed your bootloder.
I can connect to the device from GUI, but every commnad results in
"WinUsb_ReadPipe" ERROR_SEM_TIMEOUT 121

Code: Select all

New Transfer Thread
***[ bool __thiscall MainWindow::Connect(void) ]***
***[ bool __thiscall QUsb::GetDeviceHandle(struct _GUID,void **) ]***
Device path:  \

***[ bool __thiscall QUsb::GetWinUSBHandle(void *,void **) ]***
***[ bool __thiscall QUsb::GetUSBDeviceSpeed(void *,unsigned char *) ]***
Device speed: 1 (Low speed).

***[ bool __thiscall QUsb::QueryDeviceEndpoints(void *,struct QUsb::PIPE_ID *) ]
***
Bulk OUT Endpoint index: 0 Pipe type: Bulk Pipe ID: 0x03.

Bulk IN Endpoint index: 1 Pipe type: Bulk Pipe ID: 0x83.

***[ int __thiscall QUsb::read(class QByteArray *,unsigned int) ]***
"WinUsb_ReadPipe" ERROR_SEM_TIMEOUT 121
***[ int __thiscall QUsb::write(class QByteArray *,unsigned int) ]***
Sent 5 / 5 bytes: "AF:EB:A5:05:44"
***[ int __thiscall QUsb::read(class QByteArray *,unsigned int) ]***
"WinUsb_ReadPipe" ERROR_SEM_TIMEOUT 121

Then I flashed user_app manually. I've got composite USB and CDC, but bootloader GUI still can't do anything with it.
Shell works on CDC, but no commands are recognized. It always answers "<command> ?"

mobyfab
Posts: 452
Joined: Sat Nov 19, 2011 6:47 pm
Location: Versailles, France
Has thanked: 12 times
Been thanked: 18 times

Re: USB Bootloader

Postby mobyfab » Sat Jan 04, 2014 8:11 pm

mhhh seems like it's using the wrong endpoints. should be 0x01 and 0x81, not 0x03 and 0x83.

I will have to hardcode them I guess. Are you sure it's running the bootloader and not the user app?

You need to reset the mcu for the bootloader to not launch the user app. (you can do this with stlink)
You can also send the 0xAB byte to the bulk interface (endpoint 3), it will trigger a reset.

DEHiCKA
Posts: 17
Joined: Thu Feb 21, 2013 8:13 am
Has thanked: 4 times
Been thanked: 3 times

Re: USB Bootloader

Postby DEHiCKA » Sat Jan 04, 2014 9:24 pm

I've erased flash by st-link and flased bootloader again. Then I flashed user app by GUI, this time it's flashed, but with errors.

Code: Select all

New Transfer Thread
***[ bool __thiscall MainWindow::Connect(void) ]***
***[ bool __thiscall QUsb::GetDeviceHandle(struct _GUID,void **) ]***
Device path:  \

***[ bool __thiscall QUsb::GetWinUSBHandle(void *,void **) ]***
***[ bool __thiscall QUsb::GetUSBDeviceSpeed(void *,unsigned char *) ]***
Device speed: 1 (Low speed).

***[ bool __thiscall QUsb::QueryDeviceEndpoints(void *,struct QUsb::PIPE_ID *) ]
***
Bulk OUT Endpoint index: 0 Pipe type: Bulk Pipe ID: 0x01.

Bulk IN Endpoint index: 1 Pipe type: Bulk Pipe ID: 0x81.

***[ int __thiscall QUsb::read(class QByteArray *,unsigned int) ]***
"WinUsb_ReadPipe" ERROR_SEM_TIMEOUT 121
***[ int __thiscall QUsb::write(class QByteArray *,unsigned int) ]***
Sent 5 / 5 bytes: "AF:EB:A5:05:44"
***[ int __thiscall QUsb::read(class QByteArray *,unsigned int) ]***
Received 2 of 2 Bytes: "50:01"
Writing flash
File size 45396
***[ int __thiscall QUsb::write(class QByteArray *,unsigned int) ]***
Sent 9 / 9 bytes: "AF:EB:A1:09:54:B1:00:00:49"
***[ int __thiscall QUsb::read(class QByteArray *,unsigned int) ]***
Received 2 of 2 Bytes: "50:10"
Erase OK
Writing from "0x0" to "0xb154"
Read 96 Bytes from disk
***[ int __thiscall QUsb::write(class QByteArray *,unsigned int) ]***
Sent 105 / 105 bytes: "AF:EB:A3:69:00:00:00:00:00:04:00:20:81:42:00:08:41:43:00:
08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43
:00:08:41:43:00:08:71:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:44:00:08:4
1:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:
08:41:43:00:08:CE"
***[ int __thiscall QUsb::read(class QByteArray *,unsigned int) ]***
Received 1 of 1 Bytes: "50"
Read 96 Bytes from disk
***[ int __thiscall QUsb::write(class QByteArray *,unsigned int) ]***
Sent 105 / 105 bytes: "AF:EB:A3:69:60:00:00:00:41:43:00:08:41:43:00:08:41:43:00:
08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43
:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:4
1:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:08:41:43:00:
08:41:43:00:08:26"
***[ int __thiscall QUsb::read(class QByteArray *,unsigned int) ]***
Received 1 of 1 Bytes: "72"
Transfer done

So no USB CDC, not BULK, and reflashing bootloader did not help. I need to manually erase page at 0x08004000 to make bootloader to work again.

mobyfab
Posts: 452
Joined: Sat Nov 19, 2011 6:47 pm
Location: Versailles, France
Has thanked: 12 times
Been thanked: 18 times

Re: USB Bootloader

Postby mobyfab » Sat Jan 04, 2014 10:05 pm

I'm fine tuning the delays right now, check the code in an hour. :)

I have just completed the linux version and tested it.

mobyfab
Posts: 452
Joined: Sat Nov 19, 2011 6:47 pm
Location: Versailles, France
Has thanked: 12 times
Been thanked: 18 times

Re: USB Bootloader

Postby mobyfab » Sat Jan 04, 2014 10:44 pm

Done, I have updated the drivers and the GUI binary.

You have to reinstall the drivers. (uninstall devices and delete driver, reinstall using new driver files)

I have tested it under windows and linux, it should work fine now :)

mobyfab
Posts: 452
Joined: Sat Nov 19, 2011 6:47 pm
Location: Versailles, France
Has thanked: 12 times
Been thanked: 18 times

Re: USB Bootloader

Postby mobyfab » Sun Jan 05, 2014 2:32 am

Image

This is what the bootloader looks like, it's based on my QStlink2 app. :)


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 2 guests