diff --git a/stm32f103t8u6-bootloader/build_number.txt b/stm32f103t8u6-bootloader/build_number.txt index 99dea3b..e5a135a 100644 --- a/stm32f103t8u6-bootloader/build_number.txt +++ b/stm32f103t8u6-bootloader/build_number.txt @@ -1 +1 @@ -439 +445 diff --git a/stm32f103t8u6-bootloader/src/main.c b/stm32f103t8u6-bootloader/src/main.c index 2e503ee..5d2c1f7 100644 --- a/stm32f103t8u6-bootloader/src/main.c +++ b/stm32f103t8u6-bootloader/src/main.c @@ -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; } diff --git a/stm32f103t8u6-bootloader/src/pinning.h b/stm32f103t8u6-bootloader/src/pinning.h index b7208aa..47db3ae 100644 --- a/stm32f103t8u6-bootloader/src/pinning.h +++ b/stm32f103t8u6-bootloader/src/pinning.h @@ -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 diff --git a/stm32f103t8u6-bootloader/src/usb.c b/stm32f103t8u6-bootloader/src/usb.c index 9041418..ee067aa 100644 --- a/stm32f103t8u6-bootloader/src/usb.c +++ b/stm32f103t8u6-bootloader/src/usb.c @@ -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 diff --git a/stm32f103t8u6/build_number.txt b/stm32f103t8u6/build_number.txt index f59a90f..ec9163d 100644 --- a/stm32f103t8u6/build_number.txt +++ b/stm32f103t8u6/build_number.txt @@ -1 +1 @@ -337 +352 diff --git a/stm32f103t8u6/src/pinning.h b/stm32f103t8u6/src/pinning.h index 7358ad7..ed08ca3 100644 --- a/stm32f103t8u6/src/pinning.h +++ b/stm32f103t8u6/src/pinning.h @@ -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 diff --git a/stm32f103t8u6/src/usb.c b/stm32f103t8u6/src/usb.c index 4691417..e1184f8 100644 --- a/stm32f103t8u6/src/usb.c +++ b/stm32f103t8u6/src/usb.c @@ -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