Skip to content

Commit

Permalink
BOOT1 as 1 is now another option, aside of external A8 as LOW, to act…
Browse files Browse the repository at this point in the history
…ivate HID USB bootloader
  • Loading branch information
bootsector committed Apr 17, 2018
1 parent 22a1c05 commit ab2cc85
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ int main() {
bit_set(GPIOA->CRH, GPIO_CRH_CNF8_1);
bit_set(GPIOA->ODR, GPIO_ODR_ODR8);

// Turn GPIOB clock on
bit_set(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);

// Set B2 as Input Mode Floating
bit_clear(GPIOB->CRL, GPIO_CRL_MODE2);
bit_set(GPIOB->CRL, GPIO_CRL_CNF2_0);
bit_clear(GPIOB->CRL, GPIO_CRL_CNF2_1);

// Wait 1uS so the pull-up settles...
for(int i = 0; i < 72; i++) {
asm volatile ("nop\n");
}

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

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

// Turn GPIOB clock off
bit_clear(RCC->APB2ENR, RCC_APB2ENR_IOPBEN);

SCB->VTOR = USER_PROGRAM;

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

0 comments on commit ab2cc85

Please sign in to comment.