2023-08-04 02:53 AM
Hello all,
When I run the code, it works as expected, but when I unplug and then plug-in again, the system halts and when I debug it, it is like the USB_IRQHandler() is being called in succession very fast as if the IRQ pending bit is not reset. The value if the USB->ISTR register is seen 0 and NVIC->ICPR[USB_IRQn] is also seen 0. I can't figure out who is triggering the USB and why the pending bit is not reset after the interrupt handling.
I appreciate any help from you
I am using stm32CubeMX auto generated code for Keil using USB Middleware
I have attached the setting of the StmCubeMX project
2023-08-04 06:31 AM
I have found the cause but I don't know how it causes the problem
Since in the USB Middleware, in the function "USBD_CUSTOM_HID_Setup", the command "CUSTOM_HID_REQ_GET_REPORT" is not implemented! I replaced the setup function by by custom setup function in which, for the command "CUSTOM_HID_REQ_GET_REPORT", it serves it itself but for the rest, it calls the original setup function. I did as follows:
static uint8_t USBD_CUSTOM_HID_Setup_GET_REPORT_implement(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); static int8_t CUSTOM_HID_Init_FS(void) return (USBD_OK); ... static uint8_t USBD_CUSTOM_HID_Setup_GET_REPORT_implement(USBD_HandleTypeDef *pdev, if ((req->bmRequest & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_CLASS && |
I did the above mentioned modification in order that, I do not change the generated library from the stm32CubeMx, so that, after every code regeneration from the Stm32CubeMx, I don't have to modify this part again.
But somehow this code doesn't work when the USB connection is unplugged and plugged in again and it gets crazy!
I would still appreciate if anyone explain it!
Thanks in advance
2023-08-04 07:15 AM
I have found the cause!
After plugging in again, the function "CUSTOM_HID_Init_FS" is called again, but this time, the value of "USBD_CUSTOM_HID.Setup" has already been changed. So by copying it again, the original setup function is lost!!!
Very studpid!
The solution would be like this:
static int8_t CUSTOM_HID_Init_FS(void) return (USBD_OK); |
2023-08-10 01:51 AM
Hello AbbasK,
If understood you are trying to implement the CUSTOM_HID_REQ_GET_REPORT,
please note that this feature has been already implemented and part of our latest device lib v2.11.2 available under github stm32_mw_usb_device/Class/CustomHID/Src/usbd_customhid.c at master · STMicroelectronics/stm32_mw_usb_device · GitHub
Regards