11 years, 3 months ago.

Firmware Download over secondary USB (D+/D-)

Hi, I have a working product where I'm using the USB-HID to communicate with a PC. The mbed is docked on a motherboard and put into a box - so I'm using USB D-/D+ to an own USB connector for USB - the onboard micro-USB is not accessable from outside. So far I have been needed to open the box and connect the micro-USB connector instead and download new FW. This is not acceptable when I'm about to deploy this product.

I'm thinking of two alternatives: 1. Making my USB port to become an USB Flash drive instead of the micro-USB. Is that possible ?? In the bes tof world I would like to have that dynamically as well - activated by a command through my USB-HID protocol.

2. Writing own FW DL handling as part of my USB-HID protokoll. Downloading the complete binary file and write it to LocalFilesystem. It will go quite slow I guess because of the HID speed limitaions - but that is OK. I have looked at the FW DL via ETH that exist in this forum - but it's not really the same thing. I'm also worried about the timing with writing into flash or if it's enough RAM to store the file in between - downloading the complete file - checking it with checksums and then start a filesystem flash write.

Has anyone done something like this before ?? Any help is highly appreciated.

BR Henrik

2 Answers

11 years, 3 months ago.

Hi Henrik,

Nice to see a new USBHID application :)

Your question is very interesting. I think that you can easily write your own protocol on top of HID to download a file into the LocalFilesystem. You just have to reset the target after the transfer finished.

You can "reset" the target by:

  • pressing the reset button
  • sending a break command on the virtual serial port (this is using the existing USB port that you cannot access)
  • calling mbed_interface_reset() from your program

I did not understand very well your first alternative.

Cheers, Sam

Accepted Answer

I think Henriks first alternative is to alternate the USB D+/D- between MSD and HID behaviour. Still leaves you with need to reset.

Options to force a reset may be using an mbed pin (maybe adding some hardware) to control the nR pin and let the mbed reset itself or maybe use a semihosting call (I think there was one to reset mbed?). Obviously, you can always just switch the whole system on/off manually after an update.

posted by Wim Huiskamp 18 Jan 2013

resetting the MBED from within your code is easy enough. make this declaration

extern "C" void mbed_reset();

Then when you want to reset call

mbed_reset();
posted by David Godfrey 21 Jan 2013

Hi Guys, Thanks a lot for your input.

First - the reset is not an issue, this is an USB product and I have no problem forcing it to be unplugged after/during a FW Update. (It's a complete different story with an ETH connected device which could open up for remote upgrade...) But anyway the reset functionality seems to be easy solvable.

Regarding my no# 1 alternative Wim has understanded it - I want to be able to switch between being a "flash drive" (MSD) and having my default HID behaviour. Is that possible to do during runtime or during a restart of the complete device ?? That would be the by far simplest solution! 1.2 solution is partly a challenge to make the binary file downloadable over HID - but that I can manage. I'm more concerned about where to put the file regarding memory sizes and timing - my quick test with writing to localhostfile was that it was too slow to use directly from withing the USB routine - I think I need to store the file in RAM in between. Any thoughts or ideas around this ?? (But please help me with #1 alternative above first ... :) )

BR Henrik

posted by Henrik Löfgren 21 Jan 2013

Hi Henrik,

Concerning the swapping between MSD and HID I am afraid that it is not possible dynamically with the current usb stack. What you can use is a composite device (MSD + HID). I published an example of a such device: http://mbed.org/users/samux/code/USBMSD_SD_HID_HelloWorld/.

posted by Samuel Mokrani 21 Jan 2013

Hi all, I have now re-started this work - and I gave up on the MSD part. I have now succesfully implemented file download over USB-HID, using LocalFileSystem. The file is absolutely correct and just waiting in the filesystem to be loaded - but that doesn't work... I searched the forum some more and it seems like the timestamp ("2008-01-01 12:00") is giving me problems. What is the latest status for this - how do I make the "magic chip" to choose my new downloaded file ?? Is there a way to change the timep stamp now ?? Please don't say I did all of the USB-HID file download part for nothing ...

posted by Henrik Löfgren 19 Mar 2013

Hi again, I have now solved the issue - after some searching in the forum. I had missed that the filename must be changed - found that in a FirmwareUpdater thread. Now I have a working firmware download over USB-HID - quite nice. Thanks anyway.

posted by Henrik Löfgren 19 Mar 2013
11 years, 3 months ago.

sry - this should be removed...