Modifying USB Firmware

Hello,
I am working on a project where I emulate a USB device using the Photon. The project was completed on the Core and now I am trying to port it to the Photon; However, I have spent a few days trying to figure out how everything is built/linked together and cannot seem to get my changes to work. On the Core, I modified the usb firmware directly but this time I would like to (if possible) have the changes in the application folder by including the USB firmware.

Whenever I include USB files (I’ve tried usbd_core.h, usb_hal.h, and usbd_usr.h) everything compiles fine but whenever I try to actually call functions (USBD_Init(), SPARK_USB_Setup(), or USBD_USR_Init()) I get:

application.cpp:34: undefined reference to <function>

Where “function” is any of the above initialization functions I try. The appropriate libraries are being linked in the GCC build string, so there is something with the way the build is setup that I do not understand.

Any information that could shed light on this situation would be helpful.

Thank you.

Edit: For more clarity, my changes to the Core were done before the Photon was released, so it was using the solitary Core firmware.

Hi @fscottc8!

The photon uses dynamic linking to separate the application and system firmware, so these internal functions are not directly available to the application. If your device doesn’t need to connect to the cloud, then you can build using the local toolchain and add MODULAR=n to the build command to revert to static linking as used on the core.

You’ll find more details in the build documentation in the firmware repo. :smile:

Thanks,
mat.

Interesting, could you share some more about your project, or is it too confidential :sunglasses:?

Hello @mdma,
Thank you for the quick reply! I played around with trying to build some more and was unsuccessful. Using MODULAR=n did cause the build to be statically linked; However, even with the headers and the platform library being included libplatform.a (where I believe the usbd_core object files are at) is not pulled in.

I am building from the /main folder, using: make v=1 PLATFORM=photon MODULAR=n APP=emulator

Interestingly enough, if I exclude application.h, the build will complete, even though I still do not see libplatform.a

@ScruffR

I would feel comfortable sharing an overview. On the core I re-wrote some of the USB firmware to emulate a HID device. I was able to add specific protocols to allow for communication to an application via USB. I also added a TCP/IP server so that I could interface with the Core, via an Android app, to manipulate output to the application it was interfacing with.

I see, this is something I’ve been looking into too.
But mainly in the direction of HID keyboard and mouse support, which already is on the Particle ToDo (even with dedicated spark_wiring_[...].h/.cpp files) and so I’ve put my own efforts on halt for now :wink:

But unfortunately more important things keep pushing that feature down the priority list at Particle.

On the other hand if demand is increasing, that feature might regain attention.

And I’d like to repeat my proposal for composite HID support (keyboard and/or mouse and/or serial and/or raw HID and/or …) in the direction of @satishgn (and marginally to @mdma) :wink:

Something is there but seems unavailable for non-local build :weary:


@fscottc8: Any additional HID devices for the wish list?

1 Like

@fscottc8, @ScruffR, you can put me down as a very interested party for USB HID support!

There was a bit of chatter about USB HID with @satishgn et al some time back, but it seems to have dropped off the radar.

Am sure that there are other pressing priorities at the moment for team Particle (e.g. am personally hanging out for multi-threading and timer support), but if we could have some timeline to when it might be delivered, that would be great.