This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

USB COM CDC on android

Hi everyone!

I have recently implemented USB CDC on a custom NRF52840 device with SDK 15.0 and got it to work with Windows, Mac, and Linux OS. However, when I try it on an Android device I can't seem to get it to connect and send/receive any data. I can see the device by using any USB serial terminal application available on play store, such as,  Serial terminal or USB Serial terminal. The device appears in the list and can see the correct PID/VID, but as I establish a connection with the device I receive an error that the controlTransfer failed, can't seem to find anything about this error somewhere when searching on android forums.

My question is whether I have to do anything in the software to enable the device to communicate with an Android device? It is working without any problems on all other operative systems that I have tried on but not on Android devices. Have also tried different adapters and three different Android devices and all show the same error. 

I really appreciate any help I could get

Best regards

Hadi

Parents
  • UPDATE:

    I tested the original USBD CDC ACM example and seem to work, but the application that I have made does not work with Android. When comparing the two applications, the only difference in the code is that I had not added nrf_drv_clock_init, app_usbd_power_events_enable, and some of the defines related to nrf power are set to 0. I tried to add these and change the defines but the application fail during init of the usbd

    When calling nrf_drv_clock_init, I get <error> app: Fatal error

    If I am using a softdevice should I still call nrf_Drv_clock_init?

    I have also these configurations in sdk config, could this be the cause of the application failing?

    // <0=> NRF_CLOCK_LF_SRC_RC 
    // <1=> NRF_CLOCK_LF_SRC_XTAL 
    // <2=> NRF_CLOCK_LF_SRC_SYNTH 
    
    #ifndef NRF_SDH_CLOCK_LF_SRC
    #define NRF_SDH_CLOCK_LF_SRC 1
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval. 
    #ifndef NRF_SDH_CLOCK_LF_RC_CTIV
    #define NRF_SDH_CLOCK_LF_RC_CTIV 0
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_RC_TEMP_CTIV - SoftDevice calibration timer interval under constant temperature. 
    // <i> How often (in number of calibration intervals) the RC oscillator shall be calibrated
    // <i>  if the temperature has not changed.
    
    #ifndef NRF_SDH_CLOCK_LF_RC_TEMP_CTIV
    #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_ACCURACY  - External clock accuracy used in the LL to compute timing.
     
    // <0=> NRF_CLOCK_LF_ACCURACY_250_PPM 
    // <1=> NRF_CLOCK_LF_ACCURACY_500_PPM 
    // <2=> NRF_CLOCK_LF_ACCURACY_150_PPM 
    // <3=> NRF_CLOCK_LF_ACCURACY_100_PPM 
    // <4=> NRF_CLOCK_LF_ACCURACY_75_PPM 
    // <5=> NRF_CLOCK_LF_ACCURACY_50_PPM 
    // <6=> NRF_CLOCK_LF_ACCURACY_30_PPM 
    // <7=> NRF_CLOCK_LF_ACCURACY_20_PPM 
    // <8=> NRF_CLOCK_LF_ACCURACY_10_PPM 
    // <9=> NRF_CLOCK_LF_ACCURACY_5_PPM 
    // <10=> NRF_CLOCK_LF_ACCURACY_2_PPM 
    // <11=> NRF_CLOCK_LF_ACCURACY_1_PPM 
    
    #ifndef NRF_SDH_CLOCK_LF_ACCURACY
    #define NRF_SDH_CLOCK_LF_ACCURACY 7
    #endif

  • Hi,

    I have went further with debugging the application and can't seem to get it to work. I have a question regarding  how to get it to communicate with an Android device.

    Do I need to init nrf_drv_clock and enable power event handler in order to connect to device on android? 

    Currently I run these two functions after I have initialized usbd_init:

    app_usbd_enable();
    app_usbd_start();

    But the custom board can't connect to my android device

    UPDATE:

    I found the problem !

    Somehow the defined interface for the HID and CDC was not valid, had to change them to:

    /**
     * @brief USB cdc interfaces
     */
    
    #define CDC_ACM_COMM_INTERFACE  0
    #define CDC_ACM_COMM_EPIN       NRF_DRV_USBD_EPIN2
    
    #define CDC_ACM_DATA_INTERFACE  1
    #define CDC_ACM_DATA_EPIN       NRF_DRV_USBD_EPIN1
    #define CDC_ACM_DATA_EPOUT      NRF_DRV_USBD_EPOUT1
    
    /**
     * @brief USB composite interfaces
     */
    #define APP_USBD_INTERFACE_KBD   3
    #define HID_COMM_EPIN NRF_DRV_USBD_EPIN3

    /Hadi

Reply
  • Hi,

    I have went further with debugging the application and can't seem to get it to work. I have a question regarding  how to get it to communicate with an Android device.

    Do I need to init nrf_drv_clock and enable power event handler in order to connect to device on android? 

    Currently I run these two functions after I have initialized usbd_init:

    app_usbd_enable();
    app_usbd_start();

    But the custom board can't connect to my android device

    UPDATE:

    I found the problem !

    Somehow the defined interface for the HID and CDC was not valid, had to change them to:

    /**
     * @brief USB cdc interfaces
     */
    
    #define CDC_ACM_COMM_INTERFACE  0
    #define CDC_ACM_COMM_EPIN       NRF_DRV_USBD_EPIN2
    
    #define CDC_ACM_DATA_INTERFACE  1
    #define CDC_ACM_DATA_EPIN       NRF_DRV_USBD_EPIN1
    #define CDC_ACM_DATA_EPOUT      NRF_DRV_USBD_EPOUT1
    
    /**
     * @brief USB composite interfaces
     */
    #define APP_USBD_INTERFACE_KBD   3
    #define HID_COMM_EPIN NRF_DRV_USBD_EPIN3

    /Hadi

Children
No Data
Related