USB CDC ACM class

nRF5 SDK v17.0.2

nRF52840 only: Module with types, definitions and API used by CDC ACM class. More...

Modules

USB CDC ACM internals
nRF52840 only: Internals of the USB ACM class implementation.
USB CDC ACM class configuration
CDC class descriptors
nRF52840 only: Descriptors used in the USB CDC class implementation.A group of macros used to initialize CDC descriptors
CDC class types
nRF52840 only: Variable types used by the CDC class implementation.

Data Structures

struct app_usbd_cdc_acm_t
CDC ACM class instance type. More...

Macros

#define APP_USBD_CDC_ACM_DEFAULT_DESC (comm_interface,comm_epin,data_interface,data_epin,data_epout)
Default CDC ACM descriptors. More...
#define APP_USBD_CDC_ACM_GLOBAL_DEF (instance_name,user_ev_handler,comm_ifc,data_ifc,comm_ein,data_ein,data_eout,cdc_protocol)
Global definition of app_usbd_cdc_acm_t class instance. More...

Typedefs

typedef enum
app_usbd_cdc_acm_user_event_e
app_usbd_cdc_acm_user_event_t
Events passed to user event handler. More...

Functions

static app_usbd_class_inst_t
const *
app_usbd_cdc_acm_class_inst_get ( app_usbd_cdc_acm_t const *p_cdc_acm)
Helper function to get class instance from CDC ACM class. More...
static app_usbd_cdc_acm_req_t * app_usbd_cdc_acm_class_request_get ( app_usbd_cdc_acm_t const *p_cdc_acm)
Helper function to get cdc_acm specific request from cdc_acm class. More...
static app_usbd_cdc_acm_t const * app_usbd_cdc_acm_class_get ( app_usbd_class_inst_t const *p_inst)
Helper function to get cdc_acm from base class instance. More...
ret_code_t app_usbd_cdc_acm_write ( app_usbd_cdc_acm_t const *p_cdc_acm, const void *p_buf, size_t length)
Writes data to CDC ACM serial port. More...
size_t app_usbd_cdc_acm_rx_size ( app_usbd_cdc_acm_t const *p_cdc_acm)
Returns the amount of data that was read. More...
size_t app_usbd_cdc_acm_bytes_stored ( app_usbd_cdc_acm_t const *p_cdc_acm)
Returns the amount of data that was stored into internal buffer. More...
ret_code_t app_usbd_cdc_acm_read ( app_usbd_cdc_acm_t const *p_cdc_acm, void *p_buf, size_t length)
Reads data from CDC ACM serial port. More...
ret_code_t app_usbd_cdc_acm_read_any ( app_usbd_cdc_acm_t const *p_cdc_acm, void *p_buf, size_t length)
Read any data from CDC ACM port up to given buffer size. More...
ret_code_t app_usbd_cdc_acm_serial_state_notify ( app_usbd_cdc_acm_t const *p_cdc_acm, app_usbd_cdc_acm_serial_state_t serial_state, bool value)
Serial state notification via IN interrupt endpoint. More...
ret_code_t app_usbd_cdc_acm_line_state_get ( app_usbd_cdc_acm_t const *p_cdc_acm, app_usbd_cdc_acm_line_state_t line_state, uint32_t *value)
Control line value get. More...

Detailed Description

nRF52840 only: Module with types, definitions and API used by CDC ACM class.

References:

  • "Universal Serial Bus Class Definitions for Communications Devices" Revision 1.2, November 3, 2010
  • "Universal Serial Bus Communications Class Subclass Specification for PSTN Devices" Revision 1.2, February 9, 2007

Macro Definition Documentation

#define APP_USBD_CDC_ACM_DEFAULT_DESC ( comm_interface,
comm_epin,
data_interface,
data_epin,
data_epout
)
Value:
APP_USBD_CDC_IAD_DSC (comm_interface, \
APP_USBD_CDC_COMM_INTERFACE_DSC(comm_interface, \
APP_USBD_CDC_HEADER_DSC(0x0110) \
APP_USBD_CDC_CALL_MGMT_DSC(0x03, data_interface) \
APP_USBD_CDC_ACM_DSC(0x02) \
APP_USBD_CDC_UNION_DSC(comm_interface, data_interface) \
APP_USBD_CDC_COM_EP_DSC(comm_epin, NRF_DRV_USBD_EPSIZE ) \
APP_USBD_CDC_DATA_INTERFACE_DSC(data_interface, 0, 0) \
APP_USBD_CDC_DATA_EP_DSC(data_epin, data_epout, NRF_DRV_USBD_EPSIZE )

Default CDC ACM descriptors.

Parameters
comm_interface COMM interface number.
comm_epin COMM interface IN endpoint.
data_interface DATA interface number.
data_epin DATA interface IN endpoint.
data_epout DATA interface OUT endpoint.
#define APP_USBD_CDC_ACM_GLOBAL_DEF ( instance_name,
user_ev_handler,
comm_ifc,
data_ifc,
comm_ein,
data_ein,
data_eout,
cdc_protocol
)
Value:
user_ev_handler, \
comm_ifc, \
data_ifc, \
comm_ein, \
data_ein, \
data_eout, \
cdc_protocol) \

Global definition of app_usbd_cdc_acm_t class instance.

Parameters
instance_name Name of global instance.
user_ev_handler User event handler (optional).
comm_ifc Interface number of cdc_acm control.
data_ifc Interface number of cdc_acm DATA.
comm_ein COMM subclass IN endpoint.
data_ein DATA subclass IN endpoint.
data_eout DATA subclass OUT endpoint.
cdc_protocol CDC protocol app_usbd_cdc_comm_protocol_t
Note
This macro is just simplified version of APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL .

Typedef Documentation

Events passed to user event handler.

Note
Example prototype of user event handler:
void cdc_acm_user_ev_handler( app_usbd_class_inst_t const * p_inst,

Enumeration Type Documentation

Serial line state.

Enumerator
APP_USBD_CDC_ACM_LINE_STATE_DTR

Line state bit DTR.

APP_USBD_CDC_ACM_LINE_STATE_RTS

Line state bit RTS.

Serial state notifications.

Enumerator
APP_USBD_CDC_ACM_SERIAL_STATE_DCD

Notification bit DCD.

APP_USBD_CDC_ACM_SERIAL_STATE_DSR

Notification bit DSR.

APP_USBD_CDC_ACM_SERIAL_STATE_BREAK

Notification bit BREAK.

APP_USBD_CDC_ACM_SERIAL_STATE_RING

Notification bit RING.

APP_USBD_CDC_ACM_SERIAL_STATE_FRAMING

Notification bit FRAMING.

APP_USBD_CDC_ACM_SERIAL_STATE_PARITY

Notification bit PARITY.

APP_USBD_CDC_ACM_SERIAL_STATE_OVERRUN

Notification bit OVERRUN.

Events passed to user event handler.

Note
Example prototype of user event handler:
void cdc_acm_user_ev_handler( app_usbd_class_inst_t const * p_inst,
Enumerator
APP_USBD_CDC_ACM_USER_EVT_RX_DONE

User event RX_DONE.

APP_USBD_CDC_ACM_USER_EVT_TX_DONE

User event TX_DONE.

APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN

User event PORT_OPEN.

APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE

User event PORT_CLOSE.

Function Documentation

size_t app_usbd_cdc_acm_bytes_stored ( app_usbd_cdc_acm_t const * p_cdc_acm )

Returns the amount of data that was stored into internal buffer.

This function should be used on APP_USBD_CDC_ACM_USER_EVT_RX_DONE event to get information how many bytes are waiting in internal buffer.

Parameters
[in] p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
Returns
Amount of data waiting.
static app_usbd_cdc_acm_t const* app_usbd_cdc_acm_class_get ( app_usbd_class_inst_t const * p_inst )
inline static

Helper function to get cdc_acm from base class instance.

Parameters
[in] p_inst Base class instance.
Returns
CDC ACM class handle.
static app_usbd_class_inst_t const* app_usbd_cdc_acm_class_inst_get ( app_usbd_cdc_acm_t const * p_cdc_acm )
inline static

Helper function to get class instance from CDC ACM class.

Parameters
[in] p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
Returns
Base class instance.
static app_usbd_cdc_acm_req_t * app_usbd_cdc_acm_class_request_get ( app_usbd_cdc_acm_t const * p_cdc_acm )
inline static

Helper function to get cdc_acm specific request from cdc_acm class.

Parameters
[in] p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
Returns
CDC ACM class specific request.
ret_code_t app_usbd_cdc_acm_line_state_get ( app_usbd_cdc_acm_t const * p_cdc_acm ,
app_usbd_cdc_acm_line_state_t line_state ,
uint32_t * value
)

Control line value get.

Parameters
[in] p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
[in] line_state Line control value type.
[out] value Line control value.
Returns
Standard error code.
ret_code_t app_usbd_cdc_acm_read ( app_usbd_cdc_acm_t const * p_cdc_acm ,
void * p_buf ,
size_t length
)

Reads data from CDC ACM serial port.

This function uses internal buffer and double buffering for continuous transmission.

If there is enough data in internal buffer to fill user buffer, NRF_SUCCESS is returned and data is immediately available in the user buffer.

If not, up to two user buffers can be scheduled, function returns NRF_ERROR_IO_PENDING when first buffer is filled and APP_USBD_CDC_ACM_USER_EVT_RX_DONE event is generated.

See Also
app_usbd_cdc_acm_read_any
app_usbd_cdc_acm_rx_size
Parameters
[in] p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
[out] p_buf Output buffer.
[in] length Number of bytes to read.
Return values
NRF_SUCCESS Data is stored into user buffer.
NRF_ERROR_IO_PENDING Awaiting transmission, when data is stored into user buffer, APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised.
NRF_ERROR_BUSY There are already 2 buffers queued for transfers.
other Standard error code.
ret_code_t app_usbd_cdc_acm_read_any ( app_usbd_cdc_acm_t const * p_cdc_acm ,
void * p_buf ,
size_t length
)

Read any data from CDC ACM port up to given buffer size.

This function is very similar to the app_usbd_cdc_acm_read but it returns data as quick as any data is available, even if the given buffer was not totally full.

Note
This function cannot use double buffering.
To check the number of bytes really read use app_usbd_cdc_acm_rx_size function.
See Also
app_usbd_cdc_acm_read
app_usbd_cdc_acm_rx_size
Parameters
p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
[out] p_buf Output buffer.
[in] length Maximum number of bytes to read.
Return values
NRF_SUCCESS Data is stored into user buffer.
NRF_ERROR_IO_PENDING Awaiting transmission, when data is stored into user buffer, APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised.
NRF_ERROR_BUSY There is already buffer set for a transfer.
other Standard error code.
size_t app_usbd_cdc_acm_rx_size ( app_usbd_cdc_acm_t const * p_cdc_acm )

Returns the amount of data that was read.

This function should be used on APP_USBD_CDC_ACM_USER_EVT_RX_DONE event to get information how many bytes have been transfered into user buffer.

Parameters
[in] p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
Returns
Amount of data transfered.
ret_code_t app_usbd_cdc_acm_serial_state_notify ( app_usbd_cdc_acm_t const * p_cdc_acm ,
app_usbd_cdc_acm_serial_state_t serial_state ,
bool value
)

Serial state notification via IN interrupt endpoint.

Parameters
[in] p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
[in] serial_state Serial state notification type.
[in] value Serial state value.
Returns
Standard error code.
ret_code_t app_usbd_cdc_acm_write ( app_usbd_cdc_acm_t const * p_cdc_acm ,
const void * p_buf ,
size_t length
)

Writes data to CDC ACM serial port.

This is asynchronous call. User should wait for APP_USBD_CDC_ACM_USER_EVT_TX_DONE event to be sure that all data has been sent and input buffer could be accessed again.

Parameters
[in] p_cdc_acm CDC ACM class instance (defined by APP_USBD_CDC_ACM_GLOBAL_DEF ).
[in] p_buf Input buffer.
[in] length Input buffer length.
Returns
Standard error code.