nRF5 SDK  v15.0.0
Choose documentation:
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
USB CDC ACM module
This information applies to the nRF52840 SoC only.

This module covers basic implementation of the USB Communications Device Class (CDC) Abstract Control Model (ACM). The class has been defined in the following specification documents:

Abstract Control Model (ACM) is in fact a subclass of the Communications Device Class (CDC).

Interfaces

The ACM subclass describes the bidirectional communication flow popularly known as Virtual Serial Port. The class has two interfaces:

  • COMM interface that contains one IN endpoint. The COMM interface is used to notify the host about serial state. Notifications can be sent by app_usbd_cdc_acm_serial_state_notify API call.
  • DATA interface that contains one IN and one OUT bulk endpoint. The DATA interface allows to send or receive bulk data.

Sending and receiving data

Sending of data is performed by the app_usbd_cdc_acm_write function. When all data is sent, event APP_USBD_CDC_ACM_USER_EVT_TX_DONE is generated and a new chunk of data can be sent.

There are two ways to receive data. First one is the app_usbd_cdc_acm_read function. Class instance has internal receive buffer, to extract data from it the library client must provide number of bytes to read and a buffer to store them. Next action should be based on return value:

Second option to use for receiving is app_usbd_cdc_acm_read_any function. It is very similar to previous one but it returns data as quick as any data is available, even if the given buffer was not totally full. Return values and their meaning are the same, but this function cannot use double buffering. To check the number of bytes really read use app_usbd_cdc_acm_rx_size function