This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to implement RL USB custom code

Hello,
I am new to RL and am trying to implement a USB custom class for device operation. Now I have a question about how to implement Bulk-OUT handling codes.

My project is Cortex-M4 (STM32F407) using USB FS device function. I have added usbd_cls.c to my project as well as adding USB_CM3.lib and other device specific drivers and configs. I can now override device descriptor and config descriptor, and any other class request impl. But I can't see how to implement Bulk-Out handler that hooks for any in-coming Bulk-Out packets. The template usbd_cls.c looks like having only request handler's template but not such skeleton for Bulk-Out handling.

Is thre any good example code regarding this?
My KEIL version is 4.7 PRO using RTX and RL for USB.

Thanks,
Makoto

Parents
  • > how to implement Bulk-Out handler that hooks for any in-coming Bulk-Out packets.
    .. using RTX and RL for USB

    To your code, add an endpoint callback routine (task) for the OUT endpoint, like
    __task void USBD_RTX_EndPoint1 (void);

    Change the endpoint number in above subroutine name to the bulk OUT one.
    - The stack automatically creates a task using this routine (os_tsk_create - USBD_RTX_TaskInit() in C:\Keil\ARM\RV31\INC\usb_lib.c).

    When an OUT transaction completes on the OUT endpoint, the USB ISR (OTG_FS_IRQHandler() in usbh_stm32f40x.c) raises an event by isr_evt_set(USBD_EVT_OUT), targeting to above callback task. Therefore, this callback task waits for this event using os_evt_wait_or( USBD_EVT_OUT ).

    To retrieve a packet from the OUT endpoint,
    uint32_t USBD_ReadEP (uint32_t EPNum, uint8_t *pData)
    is available in usbh_stm32f40x.c

    Tsuneo

Reply
  • > how to implement Bulk-Out handler that hooks for any in-coming Bulk-Out packets.
    .. using RTX and RL for USB

    To your code, add an endpoint callback routine (task) for the OUT endpoint, like
    __task void USBD_RTX_EndPoint1 (void);

    Change the endpoint number in above subroutine name to the bulk OUT one.
    - The stack automatically creates a task using this routine (os_tsk_create - USBD_RTX_TaskInit() in C:\Keil\ARM\RV31\INC\usb_lib.c).

    When an OUT transaction completes on the OUT endpoint, the USB ISR (OTG_FS_IRQHandler() in usbh_stm32f40x.c) raises an event by isr_evt_set(USBD_EVT_OUT), targeting to above callback task. Therefore, this callback task waits for this event using os_evt_wait_or( USBD_EVT_OUT ).

    To retrieve a packet from the OUT endpoint,
    uint32_t USBD_ReadEP (uint32_t EPNum, uint8_t *pData)
    is available in usbh_stm32f40x.c

    Tsuneo

Children
  • Tsuneo-san,

    Thank you for the advice!
    Adding an EP1's handler task did solve the issue, I much appreciate your advice!

    I added the task handler for EP address 0x01 (BULK-OUT) like this, and now Bulk-OUT handling works perfectly:

    __task void USBD_RTX_EndPoint1 (void) { OS_RESULT result; static uint8_t bulkout_data[256]; uint32_t cnt; for(;;) { result = os_evt_wait_or( USBD_EVT_OUT, 0xffff); if( result == OS_R_EVT) { cnt = USBD_ReadEP( 0x01, bulkout_data); if( cnt > 0) { ... } }

    // never comes here os_tsk_delete_self ();
    }

    By the way, to make work USB_ReadEP(), I had to modify #define USBD_EP_NUM to a specific value for the USB device of class. Actually my device is USBTMC (Test & Measurement class) so I needed to manually define USBD_EP_NUM to 3 in the usb_config_FS.c (otherwise left as 0.) However the Wizard UI for this config does not provide a chance to set USBD_EP_NUM when selecting custom class. I dont know why...

    Thanks
    Makoto