Photon - USB Host Mode

Adding the header causes a circular reference of headers - one way to break that is to remove usb_hal.h from hw_config.h. It doesn’t appear to be needed.

With that, plus adding a #ifndef MIN/#endif around the MIN macro in usb_defines.h creates a successful build.

@mdma, I understand completely that those header files shouldn’t be exposed through the HAL, however i’m not really sure how else to accomplish this to enable USB host.

I’ve tried a few different approaches (both working):

  • Modified firmware directly as seen in this Github branch (https://github.com/rac146/firmware). Sample program (usbHID) calling 2 functions through the HAL to enable and process USB Host commands. This works, but callbacks to the user/application code are not possible since everything is in the firmware. I verified this works by adding LOG debug commands to the callbacks in the firmware.

  • As an experiment, moved ALL USB host code to the user/application directory as seen in this other Github branch (https://github.com/rac146/firmware1). Slight firmware modifications. Sample program (usbHID) calling same 2 functions to enable and process USB Host commands, but this time calling the functions directly instead of through the HAL. This only works if the firmware is compiled with MODULAR=n because the host code is making other hardware calls that aren’t available in the HAL. This approach does allow callbacks to work in the application code. Sample program will print mouse/keyboard commands through Serial1.

What would be the correct approach to fully integrate this feature into the modular firmware? At the moment, the second approach works best for what I’m trying to do - I have control over the code I need to develop a custom driver and implement callbacks. There doesn’t seem to be a way to fully isolate the USB host code from the firmware without using MODULAR=n.

1 Like

Sounds like great progress!

There’s a 3rd alternative - either extend existing functions or add new ones to the dynalib HAL USB interface. These changes would allow the application to register the callbacks, while also keeping the code in the system layer.

1 Like

Hi guys! Any news on this? I would like to connect an UART LCD to the Photon USB.
I will provide the 5v and gnd with a different cable, but I would like to use the USB/Serial to comunicate with the LCD, because my tx/rx pins are already connected to an rs485 interface.
Thanks, Flavio

I would say this wouldn’t work even with the USB Host Mode.
USB Serial is something rather different than what you’d expect from an RX/TX serial interface - hence it’s also called Virtual COM Port.
It’ll still work via the exchange of USB reports.

The client device would need to be able to perform the USB enumeration process.

So I’d say, you need to look for another solution.

1 Like

Thanks for the answer. What do you think about this?


It should be an USB host with a UART…

FTDI is the manufacturer to go to when you want a definetly working USB/UART bridge.

But again the UART communication is going via the dedicated pins and only gets bridged to USB.

What display are you planning to connect to your device? Maybe there are other routes to look at.

The nextion

Has anyone added CDC-ACM HOST to the Photon build? I’d really like the Photon to be able to enumerate a few external hardware devices that communicate over USBCOM to the connected host. This interface is MUCH faster than the USART (115KB) as I’m sure you all know. I’ve downloaded the STM32 support files from STM and I’d like to get this working if anyone knows how to move forward. I’m extremely new to the Photon but not to STM development (specifically on the IAR Embedded Workbench).

Thank you! :slight_smile:

@rac146, did you ever get this fully fleshed out?

I would love to use a Particle Photon to build a USB gateway to APC UPS’s with USB ports. It would appear that the protocol the smaller APC UPS’s use has been standard since 2003 when they first started putting USB ports on them instead of RS232. I have UPS installs where there is wifi available, but the UPS is nowhere near an actual PC of any kind and I really want to monitor the status remotely (particularly just to know when the battery needs replacement…some of these installs are in remote cabinets where you would never hear the beep).

It looks like a Particle Photon with IFTTT firmware and then extended to support USB Host (which I’m wondering if you’d even need the +5V hack since the UPS is already a powered device…I know you’d need a custom cable still, though) would be perfect.

Thoughts?

–Donnie

@djb_rh, did you ever find a solution?

I need a development board with USB host mode and BLE support. Can I use a Xenon or RedBear Uno to communicate with a USB device?

1 Like