Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
usb_ser_hw.c File Reference

CDC USB device driver for STM32 architecture (STM32F1, STM32F4) More...

#include <stdlib.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h>
#include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/cdc.h>
#include <libopencm3/cm3/scb.h>
#include <libopencm3/stm32/desig.h>
#include "mcu_periph/usb_serial.h"
+ Include dependency graph for usb_ser_hw.c:

Go to the source code of this file.

Data Structures

struct  fifo_t
 

Macros

#define MAX_PACKET_SIZE   64
 
#define VCOM_FIFO_SIZE   128
 

Functions

void fifo_init (fifo_t *fifo, uint8_t *buf)
 
bool_t fifo_put (fifo_t *fifo, uint8_t c)
 
bool_t fifo_get (fifo_t *fifo, uint8_t *pc)
 
int fifo_avail (fifo_t *fifo)
 
int fifo_free (fifo_t *fifo)
 
static int cdcacm_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void(**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
 CDC device control request (from libopencm3 examples) More...
 
static void cdcacm_data_rx_cb (usbd_device *usbd_dev, uint8_t ep)
 RX callback for CDC device (from libopencm3 examples) More...
 
static void suspend_cb (void)
 
static void cdcacm_set_config (usbd_device *usbd_dev, uint16_t wValue)
 Set configuration and control callbacks for CDC device (from libopencm3 examples) More...
 
int VCOM_putchar (int c)
 Writes one character to VCOM port fifo. More...
 
int VCOM_getchar (void)
 Reads one character from VCOM port. More...
 
bool_t VCOM_check_free_space (uint8_t len)
 Checks if buffer free in VCOM buffer. More...
 
int VCOM_check_available (void)
 Checks if data available in VCOM buffer. More...
 
void VCOM_event (void)
 Poll usb (required by libopencm3). More...
 
void VCOM_send_message (void)
 Send data from fifo right now. More...
 
static int usb_serial_check_free_space (struct usb_serial_periph *p, uint8_t len)
 
static void usb_serial_transmit (struct usb_serial_periph *p, uint8_t byte)
 
static void usb_serial_send (struct usb_serial_periph *p)
 
static int usb_serial_char_available (struct usb_serial_periph *p)
 
static uint8_t usb_serial_getch (struct usb_serial_periph *p)
 
void VCOM_init (void)
 

Variables

static uint8_t txdata [VCOM_FIFO_SIZE]
 
static uint8_t rxdata [VCOM_FIFO_SIZE]
 
static fifo_t txfifo
 
static fifo_t rxfifo
 
usbd_device * my_usbd_dev
 
static const struct
usb_device_descriptor 
dev
 
static const struct
usb_endpoint_descriptor 
comm_endp []
 
static const struct
usb_endpoint_descriptor 
data_endp []
 
struct {
struct usb_cdc_header_descriptor header
 
struct
usb_cdc_call_management_descriptor 
call_mgmt
 
struct usb_cdc_acm_descriptor acm
 
struct usb_cdc_union_descriptor cdc_union
 
cdcacm_functional_descriptors
 
static const struct
usb_interface_descriptor 
comm_iface []
 
static const struct
usb_interface_descriptor 
data_iface []
 
static const struct usb_interface ifaces []
 
static const struct
usb_config_descriptor 
config
 
static char serial_no [25]
 
static const char * usb_strings []
 
uint8_t usbd_control_buffer [128]
 
static bool_t usb_connected
 
struct usb_serial_periph usb_serial
 

Detailed Description

CDC USB device driver for STM32 architecture (STM32F1, STM32F4)

Definition in file usb_ser_hw.c.


Data Structure Documentation

struct fifo_t

Definition at line 90 of file usb_ser_hw.c.

Data Fields
uint8_t * buf
int head
int tail

Macro Definition Documentation

#define MAX_PACKET_SIZE   64

Definition at line 44 of file usb_ser_hw.c.

Referenced by cdcacm_data_rx_cb(), cdcacm_set_config(), and VCOM_send_message().

#define VCOM_FIFO_SIZE   128

Definition at line 46 of file usb_ser_hw.c.

Referenced by fifo_avail(), fifo_free(), fifo_get(), and fifo_put().

Function Documentation

static int cdcacm_control_request ( usbd_device *  usbd_dev,
struct usb_setup_data *  req,
uint8_t **  buf,
uint16_t len,
void(**)(usbd_device *usbd_dev, struct usb_setup_data *req complete 
)
static

CDC device control request (from libopencm3 examples)

Definition at line 228 of file usb_ser_hw.c.

Referenced by cdcacm_set_config().

+ Here is the caller graph for this function:

static void cdcacm_data_rx_cb ( usbd_device *  usbd_dev,
uint8_t  ep 
)
static

RX callback for CDC device (from libopencm3 examples)

Definition at line 271 of file usb_ser_hw.c.

References fifo_put(), and MAX_PACKET_SIZE.

Referenced by cdcacm_set_config().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void cdcacm_set_config ( usbd_device *  usbd_dev,
uint16_t  wValue 
)
static

Set configuration and control callbacks for CDC device (from libopencm3 examples)

Definition at line 298 of file usb_ser_hw.c.

References cdcacm_control_request(), cdcacm_data_rx_cb(), MAX_PACKET_SIZE, suspend_cb(), and TRUE.

Referenced by VCOM_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int fifo_avail ( fifo_t fifo)

Definition at line 362 of file usb_ser_hw.c.

References fifo_t::head, fifo_t::tail, and VCOM_FIFO_SIZE.

int fifo_free ( fifo_t fifo)

Definition at line 368 of file usb_ser_hw.c.

References fifo_avail(), and VCOM_FIFO_SIZE.

+ Here is the call graph for this function:

bool_t fifo_get ( fifo_t fifo,
uint8_t pc 
)

Definition at line 344 of file usb_ser_hw.c.

References fifo_t::buf, FALSE, fifo_t::head, fifo_t::tail, TRUE, and VCOM_FIFO_SIZE.

void fifo_init ( fifo_t fifo,
uint8_t buf 
)

Definition at line 317 of file usb_ser_hw.c.

References fifo_t::buf, buf, fifo_t::head, and fifo_t::tail.

bool_t fifo_put ( fifo_t fifo,
uint8_t  c 
)

Definition at line 326 of file usb_ser_hw.c.

References fifo_t::buf, FALSE, fifo_t::head, fifo_t::tail, TRUE, and VCOM_FIFO_SIZE.

static void suspend_cb ( void  )
static

Definition at line 289 of file usb_ser_hw.c.

References FALSE.

Referenced by cdcacm_set_config().

+ Here is the caller graph for this function:

static int usb_serial_char_available ( struct usb_serial_periph p)
static

Definition at line 489 of file usb_ser_hw.c.

References VCOM_check_available().

Referenced by VCOM_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int usb_serial_check_free_space ( struct usb_serial_periph p,
uint8_t  len 
)
static

Definition at line 473 of file usb_ser_hw.c.

References VCOM_check_free_space().

Referenced by VCOM_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static uint8_t usb_serial_getch ( struct usb_serial_periph p)
static

Definition at line 494 of file usb_ser_hw.c.

References VCOM_getchar().

Referenced by VCOM_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void usb_serial_send ( struct usb_serial_periph p)
static

Definition at line 484 of file usb_ser_hw.c.

References VCOM_send_message().

Referenced by VCOM_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void usb_serial_transmit ( struct usb_serial_periph p,
uint8_t  byte 
)
static

Definition at line 479 of file usb_ser_hw.c.

References VCOM_putchar().

Referenced by VCOM_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int VCOM_check_available ( void  )

Checks if data available in VCOM buffer.

Returns
nonzero if char is available in the queue, zero otherwise

Definition at line 425 of file usb_ser_hw.c.

References fifo_avail().

+ Here is the call graph for this function:

bool_t VCOM_check_free_space ( uint8_t  len)

Checks if buffer free in VCOM buffer.

Returns
TRUE if len bytes are free

Definition at line 416 of file usb_ser_hw.c.

References FALSE, fifo_free(), and TRUE.

+ Here is the call graph for this function:

void VCOM_event ( void  )

Poll usb (required by libopencm3).

VCOM_event() should be called from main/module event function

Definition at line 434 of file usb_ser_hw.c.

References my_usbd_dev.

int VCOM_getchar ( void  )

Reads one character from VCOM port.

Returns
character read, or -1 if character could not be read

Definition at line 404 of file usb_ser_hw.c.

References BULK_OUT_EP, BulkOut(), BulkOut_is_blocked, disableIRQ(), enableIRQ(), EOF, fifo_free(), fifo_get(), and MAX_PACKET_SIZE.

+ Here is the call graph for this function:

int VCOM_putchar ( int  c)

Writes one character to VCOM port fifo.

Writes one character to VCOM port.

Since we don't really have an instant feeedback from USB driver if the character was written, we always return c if we are connected.

Parameters
[in]ccharacter to write
Returns
character to be written, -1 if not usb is not connected

Definition at line 383 of file usb_ser_hw.c.

References EOF, fifo_put(), VCOM_check_free_space(), and VCOM_send_message().

+ Here is the call graph for this function:

void VCOM_send_message ( void  )

Send data from fifo right now.

Only if usb is connected.

Definition at line 443 of file usb_ser_hw.c.

References fifo_get(), MAX_PACKET_SIZE, and my_usbd_dev.

+ Here is the call graph for this function:

Variable Documentation

const { ... } cdcacm_functional_descriptors
Initial value:
= {
.header = {
.bFunctionLength = sizeof(struct usb_cdc_header_descriptor),
.bDescriptorType = CS_INTERFACE,
.bDescriptorSubtype = USB_CDC_TYPE_HEADER,
.bcdCDC = 0x0110,
},
.call_mgmt = {
.bFunctionLength =
sizeof(struct usb_cdc_call_management_descriptor),
.bDescriptorType = CS_INTERFACE,
.bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT,
.bmCapabilities = 0,
.bDataInterface = 1,
},
.acm = {
.bFunctionLength = sizeof(struct usb_cdc_acm_descriptor),
.bDescriptorType = CS_INTERFACE,
.bDescriptorSubtype = USB_CDC_TYPE_ACM,
.bmCapabilities = 0,
},
.cdc_union = {
.bFunctionLength = sizeof(struct usb_cdc_union_descriptor),
.bDescriptorType = CS_INTERFACE,
.bDescriptorSubtype = USB_CDC_TYPE_UNION,
.bControlInterface = 0,
.bSubordinateInterface0 = 1,
}
}
#define CS_INTERFACE
Definition: usb_ser_hw.c:78
const struct usb_endpoint_descriptor comm_endp[]
static
Initial value:
= {{
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x83,
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
.wMaxPacketSize = 16,
.bInterval = 255,
}
}

Definition at line 91 of file usb_ser_hw.c.

const struct usb_interface_descriptor comm_iface[]
static
Initial value:
= {{
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = USB_CLASS_CDC,
.bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
.bInterfaceProtocol = USB_CDC_PROTOCOL_AT,
.iInterface = 0,
.endpoint = comm_endp,
.extralen = sizeof(cdcacm_functional_descriptors)
}
}
static const struct @10 cdcacm_functional_descriptors
static const struct usb_endpoint_descriptor comm_endp[]
Definition: usb_ser_hw.c:91

Definition at line 153 of file usb_ser_hw.c.

const struct usb_config_descriptor config
static
Initial value:
= {
.bLength = USB_DT_CONFIGURATION_SIZE,
.bDescriptorType = USB_DT_CONFIGURATION,
.wTotalLength = 0,
.bNumInterfaces = 2,
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = 0x80,
.bMaxPower = 0x32,
.interface = ifaces,
}
static const struct usb_interface ifaces[]
Definition: usb_ser_hw.c:186

Definition at line 195 of file usb_ser_hw.c.

const struct usb_endpoint_descriptor data_endp[]
static
Initial value:
= {{
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x01,
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = MAX_PACKET_SIZE,
.bInterval = 1,
}, {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x82,
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = MAX_PACKET_SIZE,
.bInterval = 1,
}
}
#define MAX_PACKET_SIZE
Definition: usb_ser_hw.c:44

Definition at line 101 of file usb_ser_hw.c.

const struct usb_interface_descriptor data_iface[]
static
Initial value:
= {{
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_CLASS_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
.iInterface = 0,
.endpoint = data_endp,
}
}
static const struct usb_endpoint_descriptor data_endp[]
Definition: usb_ser_hw.c:101

Definition at line 171 of file usb_ser_hw.c.

const struct usb_device_descriptor dev
static
Initial value:
= {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = USB_CLASS_CDC,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = MAX_PACKET_SIZE,
.idVendor = 0x1d50,
.idProduct = 0x603d,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
}
#define MAX_PACKET_SIZE
Definition: usb_ser_hw.c:44

Definition at line 69 of file usb_ser_hw.c.

Referenced by GpsEvent(), ins_event_check_and_handle(), parse_ins_msg(), v4l2_capture_thread(), v4l2_init(), and VCOM_init().

const struct usb_interface ifaces[]
static
Initial value:
= {{
.num_altsetting = 1,
.altsetting = comm_iface,
}, {
.num_altsetting = 1,
.altsetting = data_iface,
}
}
static const struct usb_interface_descriptor comm_iface[]
Definition: usb_ser_hw.c:153
static const struct usb_interface_descriptor data_iface[]
Definition: usb_ser_hw.c:171

Definition at line 186 of file usb_ser_hw.c.

usbd_device* my_usbd_dev

Definition at line 67 of file usb_ser_hw.c.

Referenced by VCOM_event(), VCOM_init(), and VCOM_send_message().

uint8_t rxdata[VCOM_FIFO_SIZE]
static

Definition at line 55 of file usb_ser_hw.c.

Referenced by VCOM_init().

fifo_t rxfifo
static

Definition at line 58 of file usb_ser_hw.c.

char serial_no[25]
static

Definition at line 208 of file usb_ser_hw.c.

uint8_t txdata[VCOM_FIFO_SIZE]
static

Definition at line 54 of file usb_ser_hw.c.

Referenced by VCOM_init().

fifo_t txfifo
static

Definition at line 57 of file usb_ser_hw.c.

bool_t usb_connected
static

Definition at line 286 of file usb_ser_hw.c.

struct usb_serial_periph usb_serial

Definition at line 470 of file usb_ser_hw.c.

const char* usb_strings[]
static
Initial value:
= {
"Paparazzi UAV",
"CDC Serial STM32",
}
static char serial_no[25]
Definition: usb_ser_hw.c:208

Definition at line 211 of file usb_ser_hw.c.

uint8_t usbd_control_buffer[128]

Definition at line 222 of file usb_ser_hw.c.