2020-05-08 08:13 AM
Im on that new CubeIDE, all updated. My MCU is f103.
Making hid device, which should have a few reports, more than 1. So, i edited report descriptor, added reportID, added second report. Windows recognizes it just fine.
But what a surprise, second report getting to the host ok, while first one - not so much. Why.
No need to search too much.
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
uint8_t *report,
uint16_t len)
{
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassData;
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (hhid->state == HID_IDLE)
{
hhid->state = HID_BUSY;
USBD_LL_Transmit(pdev,
HID_EPIN_ADDR,
report,
len);
}
}
return USBD_OK;
}
How nice is that. Lets try to figure out what is going on. (skipping that bizarre happy code, always returning "ok", i saw that reported on that forum multiple times, but why would ST care... )
First time u call it, function will pass pointer to data, it will get copied into PMA.
But if u call it second time, it will return same OK, without actually doing anything.
Waiting for BUSY will not help, that flag get up only when data transfer actually begins.
Correction, flag went down after transition end, but function do not tell u if it start transmission or not.
So yah. Ether place delays, or go edit library functions, monitor if data was delivered(USBD_HID_DataIn callback).
Compare that to some other vendors approach, when u get callback like GetInReport...
So am i missing something here? is there some other, correct and easy way to do multiple reportIDs, without editing library functions or placing delays?
I dont want to edit library functions bcs it will be rewritten by cube.
***
add
custom hid template is diferent
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
uint8_t *report,
uint16_t len)
{
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (hhid->state == CUSTOM_HID_IDLE)
{
hhid->state = CUSTOM_HID_BUSY;
USBD_LL_Transmit(pdev, CUSTOM_HID_EPIN_ADDR, report, len);
}
else
{
return USBD_BUSY;
}
}
return USBD_OK;
}