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

Modifying USB CDC example

Hi there,

I am trying to modify the USB CDC ACM example to work as a USB CCID. Right now the main issue that I'm facing is macros on top of macros.

It's perfectly understandable that it's easy and straightforward to have macros that you can use to programatically generate and document source code,
however if I want to modify this device's USB descriptors, it's hard and inconvenient to follow the thread of macros.

Is there a way to see what the following macro that is used in the USB CDC ACM example will get evaluated to?

APP_USBD_CDC_ACM_GLOBAL_DEF(m_app_cdc_acm,
                            cdc_acm_user_ev_handler,
                            CDC_ACM_COMM_INTERFACE,
                            CDC_ACM_DATA_INTERFACE,
                            CDC_ACM_COMM_EPIN,
                            CDC_ACM_DATA_EPIN,
                            CDC_ACM_DATA_EPOUT,
                            APP_USBD_CDC_COMM_PROTOCOL_AT_V250
);

I've tried using `gcc -E main.c` but this would obviously fail because there are includes missing...

How can I print out the "text" representation of what `m_app_cdc_acm` will look like before compiling stage?

Thank you in advance.

  • Okay, coming back to answer my own question.

    If you add -H parameter to Optimization flags like

    # Optimization flags
    OPT = -O3 -g3 -H

    Then recompile the code. You will get a failure during linking, but then you can go to `_build` folder and open main.c.o file with your text editor and it will contain C code with all macros and definitions evaluated and expanded.

    In case anyone is interested what does m_app_cdc_acm look like after evaluating macro, here it is;

    static uint8_t m_app_ccid_ep =  { ((((NRF_DRV_USBD_EPIN2) >> 16) & 0x01) ? (((NRF_DRV_USBD_EPIN2) & 0xFF00) >> 8) : 0x10) };
    static app_usbd_cdc_acm_data_t m_app_ccid_data; 
    const app_usbd_cdc_acm_t m_app_ccid = 
    { 
        .specific = 
        { 
            .p_data = &m_app_ccid_data, 
            .p_class_methods = &app_usbd_cdc_acm_class_methods, 
            .iface = 
            { 
                .cnt = 2, 
                .config = 
                { 
                    { 
                        .number = 0, 
                        .ep_cnt = 1, 
                        .ep_offset = (0 ) * sizeof(app_usbd_class_ep_conf_t) + ((2 - 0) * sizeof(app_usbd_class_iface_conf_t)) 
                    }, 
                    { 
                        .number = 1, 
                        .ep_cnt = 2, 
                        .ep_offset = (0 + (2 - 1)) * sizeof(app_usbd_class_ep_conf_t) + ((2 - 1) * sizeof(app_usbd_class_iface_conf_t)) 
                    }, 
                }, 
                .ep = 
                { 
                    {
                        (nrf_drv_usbd_ep_t) (NRF_DRV_USBD_EPIN2)
                    }, 
                    {
                        (nrf_drv_usbd_ep_t) (NRF_DRV_USBD_EPIN1)}, 
                        {
                            (nrf_drv_usbd_ep_t) (NRF_DRV_USBD_EPOUT1)}, 
                } 
            }, 
            .inst = 
            { 
                .user_ev_handler = cdc_acm_user_ev_handler, 
                .comm_interface = 0, 
                .comm_epin = 0, 
                .data_interface = 1, 
                .data_epin = NRF_DRV_USBD_EPIN1, 
                .data_epout = NRF_DRV_USBD_EPOUT1, 
                .protocol = 0, 
                .p_ep_interval = &m_app_ccid_ep 
            } 
        } 
    }
    ;

    I could still use some pointers on how to properly modify cdc example to show up as CCID device. Slight smile

  • Hi Calculon,

      Is there any update in USB CCID class implementation. Have you completed it?

    Pls let me know that. 

Related