aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c')
-rw-r--r--examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c78
1 files changed, 41 insertions, 37 deletions
diff --git a/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c b/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c
index f9e2527..249b02e 100644
--- a/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c
+++ b/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c
@@ -24,25 +24,27 @@
#include <libopencm3/usb/cdc.h>
static const struct usb_device_descriptor dev = {
- .bLength = USB_DT_DEVICE_SIZE,
- .bDescriptorType = USB_DT_DEVICE,
- .bcdUSB = 0x0200,
- .bDeviceClass = USB_CLASS_CDC,
- .bDeviceSubClass = 0,
- .bDeviceProtocol = 0,
- .bMaxPacketSize0 = 64,
- .idVendor = 0x0483,
- .idProduct = 0x5740,
- .bcdDevice = 0x0200,
- .iManufacturer = 1,
- .iProduct = 2,
- .iSerialNumber = 3,
- .bNumConfigurations = 1,
+ .bLength = USB_DT_DEVICE_SIZE,
+ .bDescriptorType = USB_DT_DEVICE,
+ .bcdUSB = 0x0200,
+ .bDeviceClass = USB_CLASS_CDC,
+ .bDeviceSubClass = 0,
+ .bDeviceProtocol = 0,
+ .bMaxPacketSize0 = 64,
+ .idVendor = 0x0483,
+ .idProduct = 0x5740,
+ .bcdDevice = 0x0200,
+ .iManufacturer = 1,
+ .iProduct = 2,
+ .iSerialNumber = 3,
+ .bNumConfigurations = 1,
};
-/* This notification endpoint isn't implemented. According to CDC spec its
- * optional, but its absence causes a NULL pointer dereference in Linux cdc_acm
- * driver. */
+/*
+ * This notification endpoint isn't implemented. According to CDC spec its
+ * optional, but its absence causes a NULL pointer dereference in Linux
+ * cdc_acm driver.
+ */
static const struct usb_endpoint_descriptor comm_endp[] = {{
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
@@ -100,7 +102,7 @@ static const struct {
.bDescriptorSubtype = USB_CDC_TYPE_UNION,
.bControlInterface = 0,
.bSubordinateInterface0 = 1,
- }
+ },
};
static const struct usb_interface_descriptor comm_iface[] = {{
@@ -117,7 +119,7 @@ static const struct usb_interface_descriptor comm_iface[] = {{
.endpoint = comm_endp,
.extra = &cdcacm_functional_descriptors,
- .extralen = sizeof(cdcacm_functional_descriptors)
+ .extralen = sizeof(cdcacm_functional_descriptors),
}};
static const struct usb_interface_descriptor data_iface[] = {{
@@ -159,24 +161,26 @@ static const char *usb_strings[] = {
"x",
"Black Sphere Technologies",
"CDC-ACM Demo",
- "DEMO"
+ "DEMO",
};
-static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
+static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
u16 *len, void (**complete)(struct usb_setup_data *req))
{
(void)complete;
(void)buf;
- switch(req->bRequest) {
+ switch (req->bRequest) {
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
- /* This Linux cdc_acm driver requires this to be implemented
- * even though it's optional in the CDC spec, and we don't
- * advertise it in the ACM functional descriptor. */
+ /*
+ * This Linux cdc_acm driver requires this to be implemented
+ * even though it's optional in the CDC spec, and we don't
+ * advertise it in the ACM functional descriptor.
+ */
char buf[10];
- struct usb_cdc_notification *notif = (void*)buf;
+ struct usb_cdc_notification *notif = (void *)buf;
- /* We echo signals back to host as notification */
+ /* We echo signals back to host as notification. */
notif->bmRequestType = 0xA1;
notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE;
notif->wValue = 0;
@@ -184,13 +188,12 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
notif->wLength = 2;
buf[8] = req->wValue & 3;
buf[9] = 0;
- //usbd_ep_write_packet(0x83, buf, 10);
+ // usbd_ep_write_packet(0x83, buf, 10);
return 1;
}
- case USB_CDC_REQ_SET_LINE_CODING:
- if(*len < sizeof(struct usb_cdc_line_coding))
+ case USB_CDC_REQ_SET_LINE_CODING:
+ if (*len < sizeof(struct usb_cdc_line_coding))
return 0;
-
return 1;
}
return 0;
@@ -202,7 +205,8 @@ static void cdcacm_data_rx_cb(u8 ep)
char buf[64];
int len = usbd_ep_read_packet(0x01, buf, 64);
- if(len) {
+
+ if (len) {
usbd_ep_write_packet(0x82, buf, len);
buf[len] = 0;
}
@@ -217,7 +221,7 @@ static void cdcacm_set_config(u16 wValue)
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
usbd_register_control_callback(
- USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
+ USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
cdcacm_control_request);
}
@@ -226,13 +230,13 @@ int main(void)
{
int i;
- rcc_clock_setup_in_hsi_out_48mhz();
+ rcc_clock_setup_in_hsi_out_48mhz();
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
gpio_set(GPIOC, GPIO11);
- gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
- GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
+ gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
usbd_register_set_config_callback(cdcacm_set_config);
@@ -241,6 +245,6 @@ int main(void)
__asm__("nop");
gpio_clear(GPIOC, GPIO11);
- while (1)
+ while (1)
usbd_poll();
}