Update to current libopencm3 usb api.
This commit is contained in:
parent
a84052915f
commit
ad9c76e97f
|
@ -1 +1 @@
|
|||
Subproject commit 4e4496f70d00fe24b2c5d594d6500f537eeb6478
|
||||
Subproject commit 20bfcaeb1c773012f1c41e004915b72f6abba352
|
|
@ -27,12 +27,12 @@
|
|||
*/
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/exti.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/cdc.h>
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -42,11 +42,14 @@
|
|||
|
||||
#define DFU_IF_NO 4
|
||||
|
||||
usbd_device * usbdev;
|
||||
|
||||
static char *get_dev_unique_id(char *serial_no);
|
||||
|
||||
static int configured;
|
||||
static int cdcacm_gdb_dtr = 1;
|
||||
|
||||
|
||||
static const struct usb_device_descriptor dev = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
|
@ -381,7 +384,6 @@ static const struct usb_config_descriptor config = {
|
|||
char serial_no[9];
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
"x",
|
||||
"Black Sphere Technologies",
|
||||
"Black Magic Probe",
|
||||
serial_no,
|
||||
|
@ -391,8 +393,9 @@ static const char *usb_strings[] = {
|
|||
"Black Magic Trace Capture",
|
||||
};
|
||||
|
||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req)
|
||||
{
|
||||
(void)dev;
|
||||
(void)req;
|
||||
|
||||
/* Disconnect USB cable */
|
||||
|
@ -407,9 +410,11 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
|||
scb_reset_core();
|
||||
}
|
||||
|
||||
static int cdcacm_control_request(struct usb_setup_data *req, uint8_t **buf,
|
||||
uint16_t *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int cdcacm_control_request(usbd_device *dev,
|
||||
struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
|
||||
void (**complete)(usbd_device *dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)dev;
|
||||
(void)complete;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
|
@ -467,29 +472,34 @@ int cdcacm_get_dtr(void)
|
|||
return cdcacm_gdb_dtr;
|
||||
}
|
||||
|
||||
static void cdcacm_set_config(u16 wValue)
|
||||
static void cdcacm_set_config(usbd_device *dev, u16 wValue)
|
||||
{
|
||||
configured = wValue;
|
||||
|
||||
/* GDB interface */
|
||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, NULL);
|
||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, NULL);
|
||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK,
|
||||
CDCACM_PACKET_SIZE, NULL);
|
||||
usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK,
|
||||
CDCACM_PACKET_SIZE, NULL);
|
||||
usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
|
||||
/* Serial interface */
|
||||
usbd_ep_setup(0x03, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, usbuart_usb_out_cb);
|
||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, usbuart_usb_in_cb);
|
||||
usbd_ep_setup(0x84, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
usbd_ep_setup(dev, 0x03, USB_ENDPOINT_ATTR_BULK,
|
||||
CDCACM_PACKET_SIZE, usbuart_usb_out_cb);
|
||||
usbd_ep_setup(dev, 0x83, USB_ENDPOINT_ATTR_BULK,
|
||||
CDCACM_PACKET_SIZE, usbuart_usb_in_cb);
|
||||
usbd_ep_setup(dev, 0x84, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
|
||||
/* Trace interface */
|
||||
usbd_ep_setup(0x85, USB_ENDPOINT_ATTR_BULK, 64, trace_buf_drain);
|
||||
usbd_ep_setup(dev, 0x85, USB_ENDPOINT_ATTR_BULK,
|
||||
64, trace_buf_drain);
|
||||
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
usbd_register_control_callback(dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
cdcacm_control_request);
|
||||
|
||||
/* Notify the host that DCD is asserted.
|
||||
/* Notify the host that DCD is asserted.
|
||||
* Allows the use of /dev/tty* devices on *BSD/MacOS
|
||||
*/
|
||||
char buf[10];
|
||||
|
@ -502,9 +512,9 @@ static void cdcacm_set_config(u16 wValue)
|
|||
notif->wLength = 2;
|
||||
buf[8] = 3; /* DCD | DSR */
|
||||
buf[9] = 0;
|
||||
usbd_ep_write_packet(0x82, buf, 10);
|
||||
usbd_ep_write_packet(dev, 0x82, buf, 10);
|
||||
notif->wIndex = 2;
|
||||
usbd_ep_write_packet(0x84, buf, 10);
|
||||
usbd_ep_write_packet(dev, 0x84, buf, 10);
|
||||
}
|
||||
|
||||
/* We need a special large control buffer for this device: */
|
||||
|
@ -516,9 +526,10 @@ void cdcacm_init(void)
|
|||
|
||||
get_dev_unique_id(serial_no);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_register_set_config_callback(cdcacm_set_config);
|
||||
usbdev = usbd_init(&stm32f103_usb_driver,
|
||||
&dev, &config, usb_strings, 7);
|
||||
usbd_set_control_buffer_size(usbdev, sizeof(usbd_control_buffer));
|
||||
usbd_register_set_config_callback(usbdev, cdcacm_set_config);
|
||||
|
||||
nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, IRQ_PRI_USB);
|
||||
nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ);
|
||||
|
@ -528,7 +539,7 @@ void cdcacm_init(void)
|
|||
gpio_set(USB_VBUS_PORT, USB_VBUS_PIN);
|
||||
gpio_set(USB_PU_PORT, USB_PU_PIN);
|
||||
|
||||
gpio_set_mode(USB_VBUS_PORT, GPIO_MODE_INPUT,
|
||||
gpio_set_mode(USB_VBUS_PORT, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_PULL_UPDOWN, USB_VBUS_PIN);
|
||||
|
||||
/* Configure EXTI for USB VBUS monitor */
|
||||
|
@ -541,7 +552,7 @@ void cdcacm_init(void)
|
|||
|
||||
void usb_lp_can_rx0_isr(void)
|
||||
{
|
||||
usbd_poll();
|
||||
usbd_poll(usbdev);
|
||||
}
|
||||
|
||||
void exti15_10_isr(void)
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
*/
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/stm32/f1/adc.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#define __PLATFORM_H
|
||||
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <alloca.h>
|
||||
|
@ -35,6 +36,7 @@
|
|||
#define CDCACM_PACKET_SIZE 64
|
||||
#define PLATFORM_HAS_TRACESWO
|
||||
|
||||
extern usbd_device *usbdev;
|
||||
#define CDCACM_GDB_ENDPOINT 1
|
||||
#define CDCACM_UART_ENDPOINT 3
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
*/
|
||||
#include "general.h"
|
||||
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
|
||||
|
@ -84,10 +84,10 @@ static uint8_t trace_usb_buf_size;
|
|||
|
||||
void trace_buf_push(uint8_t *buf, int len)
|
||||
{
|
||||
if (usbd_ep_write_packet(0x85, buf, len) != len) {
|
||||
if (usbd_ep_write_packet(usbdev, 0x85, buf, len) != len) {
|
||||
if (trace_usb_buf_size + len > 64) {
|
||||
/* Stall if upstream to too slow. */
|
||||
usbd_ep_stall_set(0x85, 1);
|
||||
usbd_ep_stall_set(usbdev, 0x85, 1);
|
||||
trace_usb_buf_size = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -96,12 +96,12 @@ void trace_buf_push(uint8_t *buf, int len)
|
|||
}
|
||||
}
|
||||
|
||||
void trace_buf_drain(uint8_t ep)
|
||||
void trace_buf_drain(usbd_device *dev, uint8_t ep)
|
||||
{
|
||||
if (!trace_usb_buf_size)
|
||||
if (!trace_usb_buf_size)
|
||||
return;
|
||||
|
||||
usbd_ep_write_packet(ep, trace_usb_buf, trace_usb_buf_size);
|
||||
usbd_ep_write_packet(dev, ep, trace_usb_buf, trace_usb_buf_size);
|
||||
trace_usb_buf_size = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
#ifndef __TRACESWO_H
|
||||
#define __TRACESWO_H
|
||||
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
|
||||
void traceswo_init(void);
|
||||
void trace_buf_drain(uint8_t ep);
|
||||
void trace_buf_drain(usbd_device *dev, uint8_t ep);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
|||
|
||||
#define FLASH_OBP_RDP_KEY 0x5aa5
|
||||
|
||||
usbd_device *usbdev;
|
||||
/* We need a special large control buffer for this device: */
|
||||
u8 usbd_control_buffer[1024];
|
||||
|
||||
|
@ -116,7 +117,6 @@ const struct usb_config_descriptor config = {
|
|||
static char serial_no[9];
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
"x",
|
||||
"Black Sphere Technologies",
|
||||
"Black Magic Probe (Upgrade)",
|
||||
serial_no,
|
||||
|
@ -142,7 +142,8 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
|||
}
|
||||
}
|
||||
|
||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
static void
|
||||
usbdfu_getstatus_complete(usbd_device *dev, struct usb_setup_data *req)
|
||||
{
|
||||
int i;
|
||||
(void)req;
|
||||
|
@ -154,7 +155,7 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
|||
if(prog.blocknum == 0) {
|
||||
if ((*(u32*)(prog.buf+1) < 0x8002000) ||
|
||||
(*(u32*)(prog.buf+1) >= 0x8020000)) {
|
||||
usbd_ep_stall_set(0, 1);
|
||||
usbd_ep_stall_set(dev, 0, 1);
|
||||
return;
|
||||
}
|
||||
switch(prog.buf[0]) {
|
||||
|
@ -188,9 +189,11 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
|||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int usbdfu_control_request(usbd_device *dev,
|
||||
struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(usbd_device *dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)dev;
|
||||
|
||||
if((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request */
|
||||
|
@ -287,22 +290,23 @@ int main(void)
|
|||
|
||||
get_dev_unique_id(serial_no);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(
|
||||
usbdev = usbd_init(&stm32f103_usb_driver,
|
||||
&dev, &config, usb_strings, 4);
|
||||
usbd_set_control_buffer_size(usbdev, sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(usbdev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
|
||||
gpio_set(GPIOA, GPIO8);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
while (1)
|
||||
usbd_poll(usbdev);
|
||||
}
|
||||
|
||||
static char *get_dev_unique_id(char *s)
|
||||
static char *get_dev_unique_id(char *s)
|
||||
{
|
||||
volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8;
|
||||
uint32_t unique_id = *unique_id_p +
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/scs.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/cdc.h>
|
||||
|
@ -86,12 +86,13 @@ void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
|
|||
}
|
||||
}
|
||||
|
||||
void usbuart_usb_out_cb(uint8_t ep)
|
||||
void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
||||
{
|
||||
(void)ep;
|
||||
|
||||
char buf[CDCACM_PACKET_SIZE];
|
||||
int len = usbd_ep_read_packet(CDCACM_UART_ENDPOINT, buf, CDCACM_PACKET_SIZE);
|
||||
int len = usbd_ep_read_packet(dev, CDCACM_UART_ENDPOINT,
|
||||
buf, CDCACM_PACKET_SIZE);
|
||||
|
||||
/* Don't bother if uart is disabled.
|
||||
* This will be the case on mini while we're being debugged.
|
||||
|
@ -108,14 +109,14 @@ void usbuart_usb_out_cb(uint8_t ep)
|
|||
static uint8_t uart_usb_buf[CDCACM_PACKET_SIZE];
|
||||
static uint8_t uart_usb_buf_size;
|
||||
|
||||
void usbuart_usb_in_cb(uint8_t ep)
|
||||
void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep)
|
||||
{
|
||||
if (!uart_usb_buf_size) {
|
||||
gpio_clear(LED_PORT, LED_UART);
|
||||
return;
|
||||
}
|
||||
|
||||
usbd_ep_write_packet(ep, uart_usb_buf, uart_usb_buf_size);
|
||||
usbd_ep_write_packet(dev, ep, uart_usb_buf, uart_usb_buf_size);
|
||||
uart_usb_buf_size = 0;
|
||||
}
|
||||
|
||||
|
@ -126,9 +127,9 @@ void usart1_isr(void)
|
|||
gpio_set(LED_PORT, LED_UART);
|
||||
|
||||
/* Try to send now */
|
||||
if (usbd_ep_write_packet(CDCACM_UART_ENDPOINT, &c, 1) == 1)
|
||||
if (usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, &c, 1) == 1)
|
||||
return;
|
||||
|
||||
|
||||
/* We failed, so queue for later */
|
||||
if (uart_usb_buf_size == CDCACM_PACKET_SIZE) {
|
||||
/* Drop if the buffer's full: we have no flow control */
|
||||
|
|
|
@ -20,14 +20,15 @@
|
|||
#ifndef __USBUART_H
|
||||
#define __USBUART_H
|
||||
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/cdc.h>
|
||||
#include "general.h"
|
||||
|
||||
void usbuart_init(void);
|
||||
|
||||
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding);
|
||||
void usbuart_usb_out_cb(uint8_t ep);
|
||||
void usbuart_usb_in_cb(uint8_t ep);
|
||||
void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep);
|
||||
void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -43,7 +43,8 @@ void gdb_if_putchar(unsigned char c, int flush)
|
|||
count_in = 0;
|
||||
return;
|
||||
}
|
||||
while(usbd_ep_write_packet(CDCACM_GDB_ENDPOINT, buffer_in, count_in) <= 0);
|
||||
while(usbd_ep_write_packet(usbdev, CDCACM_GDB_ENDPOINT,
|
||||
buffer_in, count_in) <= 0);
|
||||
count_in = 0;
|
||||
}
|
||||
}
|
||||
|
@ -56,8 +57,8 @@ unsigned char gdb_if_getchar(void)
|
|||
return 0x04;
|
||||
|
||||
while(cdcacm_get_config() != 1);
|
||||
count_out = usbd_ep_read_packet(CDCACM_GDB_ENDPOINT, buffer_out,
|
||||
CDCACM_PACKET_SIZE);
|
||||
count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT,
|
||||
buffer_out, CDCACM_PACKET_SIZE);
|
||||
out_ptr = 0;
|
||||
}
|
||||
|
||||
|
@ -73,12 +74,12 @@ unsigned char gdb_if_getchar_to(int timeout)
|
|||
if(!cdcacm_get_dtr())
|
||||
return 0x04;
|
||||
|
||||
count_out = usbd_ep_read_packet(CDCACM_GDB_ENDPOINT, buffer_out,
|
||||
CDCACM_PACKET_SIZE);
|
||||
count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT,
|
||||
buffer_out, CDCACM_PACKET_SIZE);
|
||||
out_ptr = 0;
|
||||
} while(timeout_counter && !(out_ptr < count_out));
|
||||
|
||||
if(out_ptr < count_out)
|
||||
if(out_ptr < count_out)
|
||||
return gdb_if_getchar();
|
||||
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue