Skip to content

Commit

Permalink
Only B2 (BOOT1) pin will be checked (HIGH) for activating the bootloa…
Browse files Browse the repository at this point in the history
…der.
  • Loading branch information
bootsector committed Apr 18, 2018
1 parent b65baf6 commit c62a957
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ hid-flash blank-config.bin MYFIRMWARE.BIN

Please check the cli directory for the hid-flash tool source code.

Bootloader will activate (i.e., enter USB HID mode) if A8 pin is driven LOW when
bootloader starts. Otherwise, it will just jump to the user program address.
Bootloader will activate (i.e., enter USB HID mode) if B2 (BOOT1) pin is driven HIGH
when bootloader starts. Otherwise, it will simply jump to the user program address.

Additionally, if you have a "Blue Pill" board, setting jumper BOOT1 to the 1
position (and leaving BOOT0 at the 0 position), the bootloader will kick in.
If you have a "Blue Pill" board, setting jumper BOOT1 to the 1 position (and leaving
BOOT0 at the 0 position), the bootloader will kick in.

Latest version of the GCC ARM toolchain is  recommended!
Latest version of the GCC ARM toolchain is recommended for building the bootloader.
34 changes: 11 additions & 23 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,31 @@ int main() {
uint32_t userProgramAddress = *(volatile uint32_t *)(USER_PROGRAM + 0x04);
funct_ptr userProgram = (funct_ptr) userProgramAddress;

// Turn GPIOA clock on
bit_set(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);

// Set A8 as Input Mode with Pull-ups
bit_clear(GPIOA->CRH, GPIO_CRH_MODE8);
bit_clear(GPIOA->CRH, GPIO_CRH_CNF8_0);
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
// Set B2 as Input Pull Down
bit_clear(GPIOB->CRL, GPIO_CRL_MODE2);
bit_set(GPIOB->CRL, GPIO_CRL_CNF2_0);
bit_clear(GPIOB->CRL, GPIO_CRL_CNF2_1);
bit_clear(GPIOB->CRL, GPIO_CRL_CNF2_0);
bit_set(GPIOB->CRL, GPIO_CRL_CNF2_1);
bit_clear(GPIOB->ODR, GPIO_ODR_ODR2);

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

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

for(;;);
}

// Set A8 to input floating
bit_clear(GPIOA->CRH, GPIO_CRH_MODE8);
bit_set(GPIOA->CRH, GPIO_CRH_CNF8_0);
bit_clear(GPIOA->CRH, GPIO_CRH_CNF8_1);
bit_clear(GPIOA->ODR, GPIO_ODR_ODR8);

// Turn GPIOA clock off
bit_clear(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);
// Set B2 to input floating
bit_clear(GPIOB->CRL, GPIO_CRL_MODE2);
bit_set(GPIOB->CRL, GPIO_CRL_CNF2_0);
bit_clear(GPIOB->CRL, GPIO_CRL_CNF2_1);

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

0 comments on commit c62a957

Please sign in to comment.