I am trying to get a hello world over USB working:
Spew a counter value over USB to the PC where an app using libusb is picking that up.
Problem is I do not speak SMT32's HAL speak yet so I feel lost in the woods - remember this is my first SMT32 project.
I use CubeMX to generate the code and Atollic True Studio as IDE.
In CubeMX I've configured the USB as Device only (deselected SOF and VBUS) - kept all defaults.
The USB_DEVICE middleware I have set to HID because that is easiest to get working on Windows - also all defaults.
I also do not know the details on how USB works. Turns out that these are too many unknowns to be able to quickly get this going.
Hence I turn to you.
Found an USB sample in STM32Cube/Repository but that only shows basically the same code I get from CubeMX: it init's the USB but does not send anything (great sample guys!)
I don't know what calls to use to actually send some data over USB (and can't find a CubeMX/HAL example).
I have tried some (last one was USBD_CtlSendData), but they made getting the descriptors fail on the PC or returned error codes...
I would really appreciate some pointers:
- to CubeMX/HAL documentation
- an example of using USB with an F4 (or similar) that actually does something
- what type of USB config is simplest and fastest - and how to set that up?
I have seen lots of other (custom) libraries, but I really would like to keep the dependencies down and not involve other stuff.
Also, I hear everybody bash HAL - I would like to see for myself
Added to MX_USB_DEVICE_Init()
USBD_LL_OpenEP(&hUsbDeviceFS, 1, USBD_EP_TYPE_BULK, 64);
main.c
...
MX_USB_DEVICE_Init();
long counter = 0;
while (1)
{
USBD_StatusTypeDef result = USBD_CtlSendData(&hUsbDeviceFS, (uint8_t*)&counter, sizeof(counter));
if (result == USBD_OK)
counter++;
}
...
*) removed all the green code markers