USBCDC
USBCDC class hierarchy
The USBCDC class emulates a basic serial port over USB. You can use this serial port to send or receive data. If you want printf functionality, please see the USBSerial class.
USBCDC class reference
| Public Member Functions | |
| USBCDC (bool connect_blocking=true, uint16_t vendor_id=0x1f00, uint16_t product_id=0x2012, uint16_t product_release=0x0001) | |
| Basic constructor. More... | |
| USBCDC (USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release) | |
| Fully featured constructor. More... | |
| virtual | ~USBCDC () |
| Destroy this object. More... | |
| bool | ready () |
| Check if this class is ready. More... | |
| void | wait_ready () |
| Block until the terminal is connected. More... | |
| void | send_nb (uint8_t *buffer, uint32_t size, uint32_t *actual, bool now=true) |
| Send what there is room for. More... | |
| void | receive_nb (uint8_t *buffer, uint32_t size, uint32_t *actual) |
| Read from the receive buffer. More... | |
| void | init () |
| Initialize this instance. More... | |
| void | deinit () |
| Power down this instance. More... | |
| bool | configured () |
| Check if the device is configured. More... | |
| void | connect () |
| Connect a device This method can also be used to resume USB operation when USB power is detected after it was suspended via USBDevice::deinit. More... | |
| void | disconnect () |
| Disconnect a device. More... | |
| void | sof_enable () |
| Enable the start of frame interrupt. More... | |
| void | sof_disable () |
| Disable the start of frame interrupt. More... | |
| bool | endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback< void()> callback=nullptr) |
| Add an endpoint. More... | |
| template<typename T > | |
| bool | endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void(T::*callback)()) |
| Add an endpoint. More... | |
| void | endpoint_remove (usb_ep_t endpoint) |
| Remove an endpoint. More... | |
| void | endpoint_remove_all () |
| Remove all non-zero endpoints. More... | |
| void | endpoint_stall (usb_ep_t endpoint) |
| Stall an endpoint. More... | |
| void | endpoint_unstall (usb_ep_t endpoint) |
| Un-stall an endpoint. More... | |
| uint32_t | endpoint_max_packet_size (usb_ep_t endpoint) |
| Get the current maximum size for this endpoint. More... | |
| void | endpoint_abort (usb_ep_t endpoint) |
| Abort the current transfer on this endpoint. More... | |
| bool | read_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size) |
| start a read on the given endpoint More... | |
| uint32_t | read_finish (usb_ep_t endpoint) |
| Get the status of a read. More... | |
| bool | write_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size) |
| Write a data to the given endpoint. More... | |
| uint32_t | write_finish (usb_ep_t endpoint) |
| Get the status of a write. More... | |
| Protected Member Functions | |
| virtual void | callback_reset () |
| Called by USBDevice layer on bus reset. More... | |
| virtual void | callback_state_change (DeviceState new_state) |
| Called when USB changes state. More... | |
| virtual void | callback_request (const setup_packet_t *setup) |
| Called by USBDevice on Endpoint0 request. More... | |
| virtual void | callback_request_xfer_done (const setup_packet_t *setup, bool aborted) |
| Called by USBDevice on data stage completion. More... | |
| virtual void | callback_power (bool powered) |
| Called by USBDevice layer on power state change. More... | |
| virtual void | callback_sof (int frame_number) |
| Called by USBDevice layer on each new USB frame. More... | |
| void | complete_request (RequestResult result, uint8_t *data=NULL, uint32_t size=0) |
| Called to complete the setup stage of a callback request. More... | |
| void | complete_request_xfer_done (bool success) |
| Called to complete the data stage of a callback request. More... | |
| void | complete_set_configuration (bool success) |
| Called to complete a set configuration command. More... | |
| void | complete_set_interface (bool success) |
| Called to complete a set interface command. More... | |
| uint8_t * | find_descriptor (uint8_t descriptor_type, uint8_t index=0) |
| Find a descriptor type inside the configuration descriptor. More... | |
| const usb_ep_table_t * | endpoint_table () |
| Get the endpoint table of this device. More... | |
| virtual void | start_process () |
| Callback called to indicate the USB processing needs to be done. More... | |
| virtual void | lock () |
| Acquire exclusive access to this instance USBDevice. More... | |
| virtual void | unlock () |
| Release exclusive access to this instance USBDevice. More... | |
| virtual void | assert_locked () |
| Assert that the current thread of execution holds the lock. More... | |
USBCDC example
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
#include "USBCDC.h"
USBCDC cdc;
int main(void)
{
while (1) {
char msg[] = "Hello world\r\n";
cdc.send((uint8_t *)msg, strlen(msg));
ThisThread::sleep_for(1000);
}
}