Manually committed changes from https://github.com/rogerclarkmelbourne/Arduino_STM32/pull/401, as that PR included changes to permissions on unrelated files in the tools

This commit is contained in:
Roger Clark 2018-01-21 15:34:24 +11:00
parent 184802c3ad
commit 9cd2f3a743
3 changed files with 17 additions and 2 deletions

View File

@ -120,6 +120,12 @@ static void usb_suspend(void) {
USBLIB->state = USB_SUSPENDED;
}
void usb_power_off(void) {
USB_BASE->CNTR = USB_CNTR_FRES;
USB_BASE->ISTR = 0;
USB_BASE->CNTR = USB_CNTR_FRES + USB_CNTR_PDWN;
}
static void usb_resume_init(void) {
uint16 cntr;
@ -268,6 +274,7 @@ static void handle_out0(void);
static void dispatch_ctr_lp() {
uint16 istr;
while (((istr = USB_BASE->ISTR) & USB_ISTR_CTR) != 0) {
/* TODO WTF, figure this out: RM0008 says CTR is read-only,
* but ST's firmware claims it's clear-only, and emphasizes
@ -288,6 +295,7 @@ static void dispatch_ctr_lp() {
}
}
/* FIXME Dataflow on endpoint 0 RX/TX status is based off of ST's
* code, and is ugly/confusing in its use of SaveRState/SaveTState.
* Fixing this requires filling in handle_in0(), handle_setup0(),

View File

@ -80,7 +80,6 @@ static uint8* usbGetConfigDescriptor(uint16 length);
static uint8* usbGetStringDescriptor(uint16 length);
static void usbSetConfiguration(void);
static void usbSetDeviceAddress(void);
/*
* Descriptors
*/
@ -392,6 +391,8 @@ void usb_cdcacm_enable(gpio_dev *disc_dev, uint8 disc_bit) {
}
/* Initialize the USB peripheral. */
/* One of the callbacks that will automatically happen from this will be to usbInit(),
which will power up the USB peripheral. */
usb_init_usblib(USBLIB, ep_int_in, ep_int_out);
}
@ -403,6 +404,9 @@ void usb_cdcacm_disable(gpio_dev *disc_dev, uint8 disc_bit) {
{
gpio_write_bit(disc_dev, disc_bit, 1);
}
/* Powerdown the USB peripheral. It gets powered up again with usbInit(), which
gets called when usb_cdcacm_enable() is called. */
usb_power_off();
}
void usb_cdcacm_putc(char ch) {
@ -644,7 +648,8 @@ static uint8* vcomGetSetLineCoding(uint16 length) {
static void usbInit(void) {
pInformation->Current_Configuration = 0;
USB_BASE->CNTR = USB_CNTR_FRES;
// Reset and power up the peripheral.
USB_BASE->CNTR = USB_CNTR_FRES;
USBLIB->irq_mask = 0;
USB_BASE->CNTR = USBLIB->irq_mask;

View File

@ -157,6 +157,8 @@ typedef struct usblib_dev {
extern usblib_dev *USBLIB;
void usb_power_off(void);
void usb_init_usblib(usblib_dev *dev,
void (**ep_int_in)(void),
void (**ep_int_out)(void));