USB CDC ACM

I am trying to set up usb cdc and use the virtual COM port for logging. Please find my code below.

Issue - The LED part of the code works fine but when dongle is connected to PC the virtual com p[ort is not enumerated.

#include <stdbool.h>
#include <stdint.h>

#include "nrf.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"

#include "app_error.h"

#include "app_usbd.h"
#include "app_usbd_cdc_acm.h"


#define		LED_GREEN		NRF_GPIO_PIN_MAP(0,6)		


static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * P_inst,
									app_usbd_cdc_acm_user_event_t event);

#define		CDC_ACM_COM_INTERFACE		0
#define		CDC_ACM_COM_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


APP_USBD_CDC_ACM_GLOBAL_DEF(m_app_cdc_acm,
							cdc_acm_user_ev_handler,
							CDC_ACM_COM_INTERFACE,
							CDC_ACM_DATA_INTERFACE,
							CDC_ACM_COM_EPIN,
							CDC_ACM_DATA_EPIN,
							CDC_ACM_DATA_EPOUT,
							APP_USBD_CDC_COMM_PROTOCOL_AT_V250
);

static char m_tx_buffer[NRF_DRV_USBD_EPSIZE];



static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * P_inst,
									app_usbd_cdc_acm_user_event_t event)	{
	
	//	app_usbd_cdc_acm_t const * p_cdc_acm = app_usbd_cdc_acm_class_get(p_inst);

	switch(event)	{
		case APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN:
			break;
		case APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE:
			break;
		case APP_USBD_CDC_ACM_USER_EVT_TX_DONE :
			break;
		case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
			break;
	}
	

}


static void usbd_user_ev_handler(app_usbd_event_type_t event)	{
	switch(event)	{
		case APP_USBD_EVT_POWER_DETECTED:
			if(!nrf_drv_usbd_is_enabled())	{
				app_usbd_enable();
			}
			break;
		case APP_USBD_EVT_POWER_REMOVED:
			app_usbd_stop();
			break;
		default:
			break;
	}
}




/**
 * @brief Function for application main entry.
 */






int main(void)	{

	ret_code_t ret;
	static int frame_counter;

	static const app_usbd_config_t m_usbd_config = {
		
		.ev_state_proc = usbd_user_ev_handler
	};

	ret = app_usbd_init(&m_usbd_config);
	APP_ERROR_CHECK(ret);

	app_usbd_class_inst_t const *class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
	ret = app_usbd_class_append(class_cdc_acm);
	APP_ERROR_CHECK(ret);


	app_usbd_enable();
	app_usbd_start();



	nrf_gpio_cfg_output(LED_GREEN);
	nrf_gpio_pin_set(LED_GREEN);



    for (;;)	{
		nrf_gpio_pin_toggle(LED_GREEN);
		nrf_delay_ms(1000);

		size_t size = sprintf(m_tx_buffer, "LED is toggled: %u\r\n", frame_counter);
		ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size);
		
		if(ret == NRF_SUCCESS)	{
			frame_counter++;
		}
	}
}
/** @} */

Parents Reply Children
No Data
Related