native: hw rev 5 has the usb vbus sense pin on PA15.

We had to move the pin to free up the SPI SCLK pin.
This commit is contained in:
Piotr Esden-Tempski 2021-06-24 14:59:54 -07:00
parent 9ffa923bc1
commit 655014ac9c
2 changed files with 38 additions and 8 deletions

View File

@ -343,7 +343,18 @@ void platform_request_boot(void)
void exti15_10_isr(void)
{
if (gpio_get(USB_VBUS_PORT, USB_VBUS_PIN)) {
uint32_t usb_vbus_port;
uint16_t usb_vbus_pin;
if (platform_hwversion() < 5) {
usb_vbus_port = USB_VBUS_PORT;
usb_vbus_pin = USB_VBUS_PIN;
} else {
usb_vbus_port = USB_VBUS5_PORT;
usb_vbus_pin = USB_VBUS5_PIN;
}
if (gpio_get(usb_vbus_port, usb_vbus_pin)) {
/* Drive pull-up high if VBUS connected */
gpio_set_mode(USB_PU_PORT, GPIO_MODE_OUTPUT_10_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, USB_PU_PIN);
@ -353,24 +364,35 @@ void exti15_10_isr(void)
GPIO_CNF_INPUT_FLOAT, USB_PU_PIN);
}
exti_reset_request(USB_VBUS_PIN);
exti_reset_request(usb_vbus_pin);
}
static void setup_vbus_irq(void)
{
uint32_t usb_vbus_port;
uint16_t usb_vbus_pin;
if (platform_hwversion() < 5) {
usb_vbus_port = USB_VBUS_PORT;
usb_vbus_pin = USB_VBUS_PIN;
} else {
usb_vbus_port = USB_VBUS5_PORT;
usb_vbus_pin = USB_VBUS5_PIN;
}
nvic_set_priority(USB_VBUS_IRQ, IRQ_PRI_USB_VBUS);
nvic_enable_irq(USB_VBUS_IRQ);
gpio_set(USB_VBUS_PORT, USB_VBUS_PIN);
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_CNF_INPUT_PULL_UPDOWN, USB_VBUS_PIN);
gpio_set_mode(usb_vbus_port, GPIO_MODE_INPUT,
GPIO_CNF_INPUT_PULL_UPDOWN, usb_vbus_pin);
/* Configure EXTI for USB VBUS monitor */
exti_select_source(USB_VBUS_PIN, USB_VBUS_PORT);
exti_set_trigger(USB_VBUS_PIN, EXTI_TRIGGER_BOTH);
exti_enable_request(USB_VBUS_PIN);
exti_select_source(usb_vbus_pin, usb_vbus_port);
exti_set_trigger(usb_vbus_pin, EXTI_TRIGGER_BOTH);
exti_enable_request(usb_vbus_pin);
exti15_10_isr();
}

View File

@ -61,6 +61,8 @@ int usbuart_debug_write(const char *buf, size_t len);
* USB cable pull-up: PA8
* USB VBUS detect: PB13 -- New on mini design.
* Enable pull up for compatibility.
* Hardware 4 and older. (we needed the pin for SPI on 5)
* PA15 -- Hardware 5 and newer.
* Force DFU mode button: PB12
*/
@ -96,10 +98,16 @@ int usbuart_debug_write(const char *buf, size_t len);
#define USB_PU_PORT GPIOA
#define USB_PU_PIN GPIO8
// For HW Rev 4 and older
#define USB_VBUS_PORT GPIOB
#define USB_VBUS_PIN GPIO13
// IRQ stays the same for all hw revisions.
#define USB_VBUS_IRQ NVIC_EXTI15_10_IRQ
// For HW Rev 5 and newer
#define USB_VBUS5_PORT GPIOA
#define USB_VBUS5_PIN GPIO15
#define LED_PORT GPIOB
#define LED_PORT_UART GPIOB
#define LED_0 GPIO2