My Pyboard V1.1 is always powered from an external 5V power supply connected to V+.
However, when I start my program and it tries to send the first HID packet I get a hard fault if the USB isn't connected. If the USB is connected, everything works fine.
I haven't found a way to sense whether USB is connected; the PA9 (USB_VBUS) pin is high whether USB is connected or not (verified with an oscilloscope on R10). I've tried looking at various STM32 USB OTG_FS registers with no success.
My HID initialization code looks like this:
Code: Select all
pyb.usb_mode('VCP+HID', hid=(1, 2, 3, 8,
bytes([0x05, 0x01, 0x09, 0x04, 0xa1, 0x01, 0x09, 0x01,
0xa1, 0x00, 0x09, 0x30, 0x09, 0x31, 0x09, 0x32,
0x25, 0x7f, 0x15, 0x81, 0x75, 0x08, 0x95, 0x03,
0x81, 0x02, 0xc0, 0xc0])))
Code: Select all
# Send joystick report. Values are -127 to +127.
# hid = pyb.USB_HID()
# hid.send((x, y, z))
Thanks!