AnsweredAssumed Answered

STM32L4 USB OTG host driver for CDC-NCM

Question asked by krestan.michal.001 on Dec 18, 2017

I'd like to ask for some help with developing a driver for STM32L4 USB host connected with LTE module as a device, which enumerates as CDC-ACM and CDC-NCM device. I've used code generated from Cube and added the required class. So far enumeration works and I can send/recieve data via CDC-ACM by sending AT commands, but CDC-NCM does not work. I'm quite new with developing host driver and I need to help and confirm few points:

1) in errata for STM32L476 USB OTG is stated to avoid interruption of write to OTG fifo - there is no protection in cube generated code, I have modified in stm32l4xxll_usb.c following:

HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len, uint8_t dma)


  /* Prevent unused argument(s) compilation warning */



  __disable_irq();// <------------------ added to stop interrupts from OTG during write to FIFO

  uint32_t count32b= 0 , index= 0;

  count32b =  (len + 3) / 4;

  for (index = 0; index < count32b; index++, src += 4)


    USBx_DFIFO(ch_ep_num) = *((__packed uint32_t *)src);


  __enable_irq();// <--------------- enable interrupts again

  return HAL_OK;




Is the above modification correct and required?


2) my LTE module has 13 interfaces (several CDC-ACM and one CDC-NCM). I'm using only one CDC-ACM (2 bulk endpoints + 1 interrupt notification endpoint) and another 3 endpoints for CDC-NCM. Since the notification endpoints are interrupt type, what is the correct pooling procedure? In fact I don't need notification endpoint for CDC-NCM, but how the host driver from Cube handles this if I open a pipe for this endpoint with endpoint type interrupt and I ever call any function USBH_InterruptReceiveData? I've found if I've not been calling USBH_InterruptReceiveData in a required interrupt pooling interval, then the comunication on CDC-ACM and/or CDC-NCM has stalled at some point.


3) what is the correct procedure to call USBH_BulkReceiveData on bulk endpoints? It looks like if I call this in a loop, then probably the Cube driver is sending IN tokens all the time and this halts the communication with any other endpoints. If I was calling USBH_BulkReceiveData in a loop and anytime between I tried to send data via output bulk endpoint, then out data has never been sent. What is the correct procedure to receive any data on bulk endpoints?


4) is it required to pool USBH_Process after enumeration in a shortest intervals or if this call is not made for 500ms or more it may cause stalling some endpoints (i.e. interrupt endpoints)? I'm talking only about the situation when I've no data to sent to the device and the device only may look to get some IN tokens since the pooling interval required for all of the notification endpoints is 4.


At the end I can see sending IP packets over CDC-NCM, however it looks like the module does not read the data correctly and does not send anything to the mobile network. Does anyone have any experience by making CDC-NCM driver? I appreciate any help, I've dump of the usb communication when I connect the module to my PC and everything is working with the PC.