Add pin for USB pull-up

This allows forcing re-enumeration, which is necessary for switching to
bootloader mode from the application firmware
This commit is contained in:
fruchti 2023-06-17 16:22:51 +02:00
parent 4095de4e8b
commit c9eb526d46
7 changed files with 32 additions and 12 deletions

View file

@ -1 +1 @@
337
352

View file

@ -6,6 +6,7 @@
#define PIN_LED_ORANGE 7 // PA7 - Status LED 2
#define PIN_OUTPUT_X 8 // PA8 - TIM1_CH1
#define PIN_OUTPUT_Y 9 // PA9 - TIM1_CH2
#define PIN_USB_PULLUP 10 // PA10 - 1.5 kΩ to D-
#define PIN_USB_DM 11 // PA11 - USB_DM
#define PIN_USB_DP 12 // PA12 - USB_DP

View file

@ -9,6 +9,7 @@
MODULE_OWNS_PERIPHERAL(USB);
MODULE_OWNS_PIN(GPIOA, PIN_USB_DM);
MODULE_OWNS_PIN(GPIOA, PIN_USB_DP);
MODULE_OWNS_PIN(GPIOA, PIN_USB_PULLUP);
USB_PacketHandler_t USB_EP0OutPacketHandler;
@ -23,10 +24,23 @@ void USB_Init(void)
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
RCC->APB1ENR |= RCC_APB1ENR_USBEN;
GPIOA->CRH &= ~(GPIO_CRH_CNF11 | GPIO_CRH_MODE11
| GPIO_CRH_CNF12 | GPIO_CRH_MODE12);
GPIOA->CRH |= GPIO_CRH_MODE11 | GPIO_CRH_MODE12;
GPIOA->ODR &= ~(GPIO_CRH_MODE11 | GPIO_CRH_MODE12);
GPIOA->BRR = (1 << PIN_USB_DM) | (1 << PIN_USB_DP) | (1 << PIN_USB_PULLUP);
GPIOA->CRH = (GPIOA->CRH
& ~(0xf << (4 * PIN_USB_DM - 32))
& ~(0xf << (4 * PIN_USB_DP - 32))
& ~(0xf << (4 * PIN_USB_PULLUP - 32)))
| (0x3 << (4 * PIN_USB_DM - 32)) // PP output, 50 MHz
| (0x3 << (4 * PIN_USB_DP - 32)) // PP output, 50 MHz
| (0x3 << (4 * PIN_USB_PULLUP - 32)) // PP output, 2 MHz
;
// Enable D- pull-up
GPIOA->BSRR = (1 << PIN_USB_PULLUP);
// GPIOA->CRH &= ~(GPIO_CRH_CNF11 | GPIO_CRH_MODE11
// | GPIO_CRH_CNF12 | GPIO_CRH_MODE12);
// GPIOA->CRH |= GPIO_CRH_MODE11 | GPIO_CRH_MODE12;
// GPIOA->ODR &= ~(GPIO_CRH_MODE11 | GPIO_CRH_MODE12);
USB_Delay(100000);
// Enable reset and correct transfer interrupts