USB Component  Version 6.17.0
MDK Middleware for USB Device and Host Communication

User API reference of the Communication Device Class (Abstract Control Model). More...

Functions

void USBH_CDC_ACM_Initialize (uint8_t instance)
 Callback function called when Communication Device Class device was enumerated and is ready. More...
 
void USBH_CDC_ACM_Uninitialize (uint8_t instance)
 Callback function called when Communication Device Class device was disconnected. More...
 
uint8_t USBH_CDC_ACM_GetDevice (uint8_t instance)
 Get Device instance of Communication Device Class device. More...
 
usbStatus USBH_CDC_ACM_GetStatus (uint8_t instance)
 Get status of Communication Device Class device. More...
 
usbStatus USBH_CDC_ACM_Send (uint8_t instance, const uint8_t *data, uint32_t num)
 Send data to Communication Device Class device. More...
 
uint32_t USBH_CDC_ACM_GetTxCount (uint8_t instance)
 Get result of send data to Communication Device Class device. More...
 
usbStatus USBH_CDC_ACM_AbortSend (uint8_t instance)
 Abort data sending to Communication Device Class device. More...
 
usbStatus USBH_CDC_ACM_Receive (uint8_t instance, uint8_t *data, uint32_t num)
 Receive data from Communication Device Class device. More...
 
uint32_t USBH_CDC_ACM_GetRxCount (uint8_t instance)
 Get result of receive data from Communication Device Class device. More...
 
usbStatus USBH_CDC_ACM_AbortReceive (uint8_t instance)
 Abort data reception from Communication Device Class device. More...
 
usbStatus USBH_CDC_ACM_SetLineCoding (uint8_t instance, const CDC_LINE_CODING *line_coding)
 Change communication settings of Communication Device Class device. More...
 
usbStatus USBH_CDC_ACM_GetLineCoding (uint8_t instance, CDC_LINE_CODING *line_coding)
 Retrieve communication settings of Communication Device Class device. More...
 
usbStatus USBH_CDC_ACM_SetControlLineState (uint8_t instance, uint16_t state)
 Set control line states of Communication Device Class device. More...
 
void USBH_CDC_ACM_Notify (uint8_t instance, uint16_t status)
 Callback function called when Communication Device Class device modem line or error status changes. More...
 
usbStatus USBH_CDC_ACM_SendBreak (uint8_t instance, uint16_t duration)
 Send break on Communication Device Class device. More...
 

Description

User API reference of the Communication Device Class (Abstract Control Model).

Function Documentation

◆ USBH_CDC_ACM_Initialize()

void USBH_CDC_ACM_Initialize ( uint8_t  instance)

Callback function called when Communication Device Class device was enumerated and is ready.

Parameters
[in]instanceinstance of CDC Device.
Returns
none.

The function USBH_CDC_ACM_Initialize is called when a CDC device was connected and successfully enumerated and is ready for communication.

The argument instance specifies the CDC device instance.

◆ USBH_CDC_ACM_Uninitialize()

void USBH_CDC_ACM_Uninitialize ( uint8_t  instance)

Callback function called when Communication Device Class device was disconnected.

Parameters
[in]instanceinstance of CDC Device.
Returns
none.

The function USBH_CDC_ACM_Unitialize is called when a CDC device was disconnected form the USB Bus.

The argument instance specifies the CDC device instance.

◆ USBH_CDC_ACM_GetDevice()

uint8_t USBH_CDC_ACM_GetDevice ( uint8_t  instance)

Get Device instance of Communication Device Class device.

Parameters
[in]instanceinstance of CDC Device.
Returns
instance of Device or non-existing Device instance :
  • value <= 127 : instance of Device
  • value 255 : non-existing Device instance

The function USBH_CDC_ACM_GetDevice is used to retrieve device instance that is used to handle CDC device instance.

The argument instance specifies the CDC device instance.

◆ USBH_CDC_ACM_GetStatus()

usbStatus USBH_CDC_ACM_GetStatus ( uint8_t  instance)

Get status of Communication Device Class device.

Parameters
[in]instanceinstance of CDC Device.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_CDC_ACM_GetStatus returns the status of a CDC device attached to the USB Host.

The argument instance specifies the instance of the CDC device to be queried.

Code Example

void USBH_Thread (void const *arg) {
static bool con = false;
USBH_Initialize (0); /* Initialize USB Host 0 */
while (1) {
if ((USBH_CDC_ACM_GetStatus(0) == usbOK) ^ con) {
if (!con) {
con = true;
osDelay(1000);
//do something
osThreadCreate (osThread(USBH_Serial_RecevieThread), NULL);
} else {
con = false;
//do something else
}
} else {
osDelay(1000);
}
}
}

◆ USBH_CDC_ACM_Send()

usbStatus USBH_CDC_ACM_Send ( uint8_t  instance,
const uint8_t *  data,
uint32_t  num 
)

Send data to Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
[in]databuffer containing data bytes to send.
[in]numnumber of bytes to send.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_CDC_ACM_Send transmits data to an attached CDC device.

The argument instance specifies the instance of the targeted CDC device.

The argument data is a pointer to the buffer containing the data that is to be sent. It is recommended that buffer is 4-byte aligned as some drivers might not support 1-byte alignment if DMA is used.

The argument num specifies the number of bytes to be sent.

Code Example

void USART_CDC_Send_Thread (void const *arg) {
USART_CDC_t *ptr_usart_cdc;
uint8_t instance;
usbStatus status;
instance = *(uint8_t *)arg;
ptr_usart_cdc = &usart_cdc[instance];
// Send Data on Bulk Out Pipe in thread
status = USBH_CDC_ACM_Send (instance, ptr_usart_cdc->send_data, ptr_usart_cdc->send_num);
ptr_usart_cdc->send_busy = false;
if (status == usbOK) ARM_USARTx_Sent(instance);
}

◆ USBH_CDC_ACM_GetTxCount()

uint32_t USBH_CDC_ACM_GetTxCount ( uint8_t  instance)

Get result of send data to Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
Returns
number of successfully sent data bytes.

The function USBH_CDC_ACM_GetTxCount returns the number of data bytes sent to an attached CDC device.

The argument instance specifies the instance of the targeted CDC device.

Code Example

static uint32_t ARM_USARTx_GetTxCount (uint8_t instance) {
if (CheckInstance (instance) == false) return 0;
return (USBH_CDC_ACM_GetTxCount(instance));
}

◆ USBH_CDC_ACM_AbortSend()

usbStatus USBH_CDC_ACM_AbortSend ( uint8_t  instance)

Abort data sending to Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_CDC_ACM_AbortSend aborts the data sending to an attached CDC device.

The argument instance specifies the instance of the targeted CDC device.

◆ USBH_CDC_ACM_Receive()

usbStatus USBH_CDC_ACM_Receive ( uint8_t  instance,
uint8_t *  data,
uint32_t  num 
)

Receive data from Communication Device Class device.

Parameters
[in]instanceindex of CDC instance
[out]databuffer that receives data.
[in]nummaximum number of bytes to receive.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_CDC_ACM_Receive receives data from an attached CDC device.

The argument instance specifies the instance of the CDC device that is sending the data.

The argument data is a pointer to the buffer storing the incoming data. It is recommended that buffer is 4-byte aligned as some drivers might not support 1-byte alignment if DMA is used.

The argument num specifies the maximum number of data bytes to be received (must be multiple of CDC device Bulk In endpoint maximum packet size).

Code Example

void USART_CDC_Receive_Thread (void const *arg) {
USART_CDC_t *ptr_usart_cdc;
uint8_t instance;
usbStatus status;
instance = *(uint8_t *)arg;
ptr_usart_cdc = &usart_cdc[instance];
// Receive Data on Bulk In Pipe in thread
do {
status = USBH_CDC_ACM_Receive (instance, ptr_usart_cdc->receive_data, ptr_usart_cdc->receive_num);
} while (status == usbTimeout);
ptr_usart_cdc->receive_busy = false;
if (status == usbOK) ARM_USARTx_Received(instance);
}

◆ USBH_CDC_ACM_GetRxCount()

uint32_t USBH_CDC_ACM_GetRxCount ( uint8_t  instance)

Get result of receive data from Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
Returns
number of successfully received data bytes.

The function USBH_CDC_ACM_GetRxCount returns the number of received data bytes from an attached CDC device.

The argument instance specifies the instance of the sending CDC device.

Code Example

static uint32_t ARM_USARTx_GetRxCount (uint8_t instance) {
if (CheckInstance (instance) == false) return 0;
return (USBH_CDC_ACM_GetRxCount(instance));
}

◆ USBH_CDC_ACM_AbortReceive()

usbStatus USBH_CDC_ACM_AbortReceive ( uint8_t  instance)

Abort data reception from Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_CDC_ACM_AbortReceive aborts the data reception from an attached CDC device.

The argument instance specifies the instance of the CDC device that is sending the data.

◆ USBH_CDC_ACM_SetLineCoding()

usbStatus USBH_CDC_ACM_SetLineCoding ( uint8_t  instance,
const CDC_LINE_CODING line_coding 
)

Change communication settings of Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
[in]line_codingpointer to CDC_LINE_CODING structure.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_CDC_ACM_SetLineCoding changes the communication parameters of the attached CDC device.

The argument instance specifies the instance of the targeted CDC device.

The argument line_coding is a pointer to the CDC_LINE_CODING structure containing the communication parameters that are to be used.

Code Example

static int32_t ARM_USARTx_Control (uint8_t instance, uint32_t control, uint32_t arg) {
USART_CDC_t *ptr_usart_cdc;
CDC_LINE_CODING line_coding;
if (CheckInstance (instance) == false) return ARM_DRIVER_ERROR;
ptr_usart_cdc = &usart_cdc[instance];
line_coding = ptr_usart_cdc->line_coding;
:
line_coding.dwDTERate = arg; // USART Baudrate
if (USBH_CDC_ACM_SetLineCoding (instance, (const CDC_LINE_CODING *)(&line_coding))) return ARM_DRIVER_ERROR;
ptr_usart_cdc->line_coding = line_coding;
return ARM_DRIVER_OK;
}

◆ USBH_CDC_ACM_GetLineCoding()

usbStatus USBH_CDC_ACM_GetLineCoding ( uint8_t  instance,
CDC_LINE_CODING line_coding 
)

Retrieve communication settings of Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
[out]line_codingpointer to CDC_LINE_CODING structure.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_CDC_ACM_GetLineCoding retrieves the communication parameters of the attached CDC device.

The argument instance specifies the instance of the targeted CDC device.

The argument line_coding is a pointer to the CDC_LINE_CODING to store the communication parameters.

◆ USBH_CDC_ACM_SetControlLineState()

usbStatus USBH_CDC_ACM_SetControlLineState ( uint8_t  instance,
uint16_t  state 
)

Set control line states of Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
[in]statecontrol line settings bitmap :
  • bit 0 : DTR state
  • bit 1 : RTS state
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_CDC_ACM_SetControlLineState sets the states of the control lines of the attached CDC device.

The argument instance specifies the instance of the targeted CDC device.

The argument state sets the control line parameters.

Code Example

static int32_t ARM_USARTx_SetModemControl (uint8_t instance, ARM_USART_MODEM_CONTROL control) {
USART_CDC_t *ptr_usart_cdc;
uint16_t ctrl_lines;
if (CheckInstance (instance) == false) return ARM_DRIVER_ERROR;
ptr_usart_cdc = &usart_cdc[instance];
ctrl_lines = ptr_usart_cdc->ctrl_lines;
if (ptr_usart_cdc->flow_control_rts) {// If flow control on RTS line enabled
if (control == ARM_USART_RTS_CLEAR) // Deactivate RTS
ctrl_lines &= ~(1 << 1);
if (control == ARM_USART_RTS_SET) // Activate RTS
ctrl_lines |= (1 << 1);
}
if (control == ARM_USART_DTR_CLEAR) // Deactivate DTR
ctrl_lines &= ~(1 << 0);
if (control == ARM_USART_DTR_SET) // Activate DTR
ctrl_lines |= (1 << 0);
if (USBH_CDC_ACM_SetControlLineState (instance, ctrl_lines) != usbOK) return ARM_DRIVER_ERROR;
ptr_usart_cdc->ctrl_lines = ctrl_lines;
return ARM_DRIVER_OK;
}

◆ USBH_CDC_ACM_Notify()

void USBH_CDC_ACM_Notify ( uint8_t  instance,
uint16_t  status 
)

Callback function called when Communication Device Class device modem line or error status changes.

Parameters
[in]instanceindex of CDC instance.
[in]statuserror status and line states :
  • bit 6 : bOverRun
  • bit 5 : bParity
  • bit 4 : bFraming
  • bit 3 : bRingSignal
  • bit 2 : bBreak
  • bit 1 : bTxCarrier (DSR line state)
  • bit 0 : bRxCarrier (DCD line state)
Returns
none.

The callback function USBH_CDC_ACM_Notify is called when an attached CDC device signals modem line or error status changes.

The argument instance specifies the instance of the calling CDC device.

The argument status shows the modem line or error status.

Code Example

void USBH_CDC_ACM_Notify (uint8_t instance, uint16_t status) {
usart_cdc[instance].status = status;
}

◆ USBH_CDC_ACM_SendBreak()

usbStatus USBH_CDC_ACM_SendBreak ( uint8_t  instance,
uint16_t  duration 
)

Send break on Communication Device Class device.

Parameters
[in]instanceindex of CDC instance.
[in]durationduration of break (in milliseconds) :
  • value 65535 : indefinite
  • value 0 : immediate
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The USBH_CDC_ACM_SendBreak function sends a break to the attached CDC device.

The argument instance specifies the instance of the targeted CDC device.

The argument duration specifies the duration of the break in milliseconds.

Code Example

static int32_t ARM_USARTx_Control (uint8_t instance, uint32_t control, uint32_t arg) {
USART_CDC_t *ptr_usart_cdc;
CDC_LINE_CODING line_coding;
if (CheckInstance (instance) == false) return ARM_DRIVER_ERROR;
ptr_usart_cdc = &usart_cdc[instance];
line_coding = ptr_usart_cdc->line_coding;
switch (control & ARM_USART_CONTROL_Msk) {
:
case ARM_USART_CONTROL_BREAK: // Control break
if (arg) { // Break enabled
if (USBH_CDC_ACM_SendBreak (instance, 0xFFFF) != usbOK) return ARM_DRIVER_ERROR;
} else { // Break disable
if (USBH_CDC_ACM_SendBreak (instance, 0) != usbOK) return ARM_DRIVER_ERROR;
}
return ARM_DRIVER_OK;