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 @@
439
445

View file

@ -39,10 +39,10 @@ static inline bool Bootloader_EntryCondition(void)
{
// Activate pull-up for test point
GPIOA->CRH = (0x44444444
& ~(0x0f << (PIN_TEST_POINT * 4 - 32)))
| (0x08<< (PIN_TEST_POINT * 4 - 32))
& ~(0x0f << (PIN_USB_PULLUP * 4 - 32)))
| (0x08<< (PIN_USB_PULLUP * 4 - 32))
;
GPIOA->BSRR = (1 << PIN_TEST_POINT);
GPIOA->BSRR = (1 << PIN_USB_PULLUP);
// The first word in the application frame is the stack end pointer
const uint32_t *application_start = (uint32_t*)FLASH_APPLICATION_BASE;
@ -61,7 +61,7 @@ static inline bool Bootloader_EntryCondition(void)
}
// Check if test point is held low externally
if(~GPIOA->IDR & (1 << PIN_TEST_POINT))
if(~GPIOA->IDR & (1 << PIN_USB_PULLUP))
{
return true;
}

View file

@ -1,6 +1,6 @@
#pragma once
// Port A
#define PIN_TEST_POINT 10 // PA10
#define PIN_USB_PULLUP 10 // PA10
#define PIN_USB_DM 11 // PA11 - USB_DM
#define PIN_USB_DP 12 // PA12 - USB_DP

View file

@ -18,11 +18,16 @@ void USB_Init(void)
// Note: This will reset the test point pin to an input without pullup
GPIOA->CRH = (0x44444444
& ~(0x0f << (PIN_USB_DM * 4 - 32))
& ~(0x0f << (PIN_USB_DP * 4 - 32)))
& ~(0x0f << (PIN_USB_DP * 4 - 32))
& ~(0x0f << (PIN_USB_PULLUP * 4 - 32)))
| (0x0b << (PIN_USB_DM * 4 - 32)) // AF mode, 50 MHz
| (0x0b << (PIN_USB_DP * 4 - 32)) // AF mode, 50 MHz
| (0x02 << (PIN_USB_PULLUP * 4 - 32)) // PP output, 2 MHz
;
// Enable pull-up
GPIOA->BSRR = (1 << PIN_USB_PULLUP);
Util_Delay(100000);
// Analog power up