Skip to content

Commit ab2cc85

Browse files
committed
BOOT1 as 1 is now another option, aside of external A8 as LOW, to activate HID USB bootloader
1 parent 22a1c05 commit ab2cc85

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

main.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@ int main() {
4040
bit_set(GPIOA->CRH, GPIO_CRH_CNF8_1);
4141
bit_set(GPIOA->ODR, GPIO_ODR_ODR8);
4242

43+
// Turn GPIOB clock on
44+
bit_set(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);
45+
46+
// Set B2 as Input Mode Floating
47+
bit_clear(GPIOB->CRL, GPIO_CRL_MODE2);
48+
bit_set(GPIOB->CRL, GPIO_CRL_CNF2_0);
49+
bit_clear(GPIOB->CRL, GPIO_CRL_CNF2_1);
50+
4351
// Wait 1uS so the pull-up settles...
4452
for(int i = 0; i < 72; i++) {
4553
asm volatile ("nop\n");
4654
}
4755

48-
// If A8 is LOW, enter HID bootloader...
49-
if(!(GPIOA->IDR & GPIO_IDR_IDR8)) {
56+
// If A8 is LOW or B2 is HIGH enter HID bootloader...
57+
if((!(GPIOA->IDR & GPIO_IDR_IDR8)) || (GPIOB->IDR & GPIO_IDR_IDR2)) {
5058
USB_Init(HIDUSB_EPHandler, HIDUSB_Reset);
5159

5260
for(;;);
@@ -61,6 +69,9 @@ int main() {
6169
// Turn GPIOA clock off
6270
bit_clear(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);
6371

72+
// Turn GPIOB clock off
73+
bit_clear(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);
74+
6475
SCB->VTOR = USER_PROGRAM;
6576

6677
asm volatile("msr msp, %0"::"g"(*(volatile u32 *) USER_PROGRAM));

0 commit comments

Comments
 (0)