2016-02-04 03:08 AM
I am in the process of making a USB device that is both a mass storage device (with SD card on SDIO) and a custom HID device. Eventually it will run on an STM32F405RGTx, but for now we're running it on an STM32F4DISCOVERY board (so a 407, should not matter that much).
I have already come a long way. The MSC device works flawlessly, albeit slow (but what do you expect on FS? :) ) and I have managed to integrate a custom HID into it. I did this by making my own instance of a USBD_ClassTypeDef and distribute the function calls to either USBD_MSC or USBD_CUSTOM_HID where appropriate. The thing that does NOT work yet, is the IN transfers from the HID device (receiving OUT works). The debugger tells me that when I try to send a report, the PDC ISR is constantly called. Apparently the reason for the IRQ is not lifted. To be able to investigate, I also took the CUSTOM HID part in isolation, which worked,.... until I changed the endpoints to 0x82/0x02 or basically any other value than 0x81/0x01. In the composite device, the MSC has endpoints 0x81/0x01 and the CUSTOM HID has 0x82/0x02, so there is the difference that apparently broke the functioning of CUSTOM HID. Now, I have seen quite a number of projects with multiple endpoints on this site, so apparently I missed something. Perhaps just changing the defines for the endpoint numbers is not enough, and the endpoint number is defined somewhere else as well, for instance. Another thing that struck me was the bit assignment in the OTG_FS_DAINT register: bit16=ep0, bit18=ep3, where I would expect bit16-31 = ep0-15, but apparently not. This discrepancy only exists for OUT endpoints, so it seems irrelevant, but I still find it strange. Does this problem make sense to anyone? :) #stm32 #msc #hid #usb2016-02-06 05:53 AM
> Perhaps just changing the defines for the endpoint numbers is not enough, and the endpoint number is defined somewhere else as well, for instance.
Each IN endpoint should have its own TX FIFO assignment. You'll add another code line for TX FIFO for EP2 IN. On STM32Cube library, here is the part of the source to be modified.usbd_conf.c
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
{
...
HAL_PCDEx_SetRxFiFo(&hpcd, 0x80); // common RX FIFO
HAL_PCDEx_SetTxFiFo(&hpcd, 0, 0x20); // EP0 IN
HAL_PCDEx_SetTxFiFo(&hpcd, 1, 0x20); // EP1 IN
HAL_PCDEx_SetTxFiFo(&hpcd, 2, 0x20); // EP2 IN <------
return USBD_OK;
}
> bit16=ep0, bit18=ep3
bit18 = ep2
You'll find such mistakes everywhere in the datasheet.
Tsuneo
2016-02-08 06:47 AM
Hi Tsuneo,
Thanks for your reply. This:>>
HAL_PCDEx_SetTxFiFo(&hpcd, 2, 0x20); // EP2 IN <------
was indeed what was missing. After some toying around with the fifo sizes I managed to get it working. Thanks!