X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Output%2FpjrcUSB%2Farm%2Fusb_dev.c;h=3b2d3a98e7dca758089932bc2bf19ba471ee9ed5;hb=d6345c307fa4c64deb3f293fe91760f05c928120;hp=aab87f2f5b2e91ef4ead39d23cbb588674ecddb1;hpb=c1f8a2c545063168a2f6c2f375df8266cb0f1f01;p=kiibohd-controller.git diff --git a/Output/pjrcUSB/arm/usb_dev.c b/Output/pjrcUSB/arm/usb_dev.c index aab87f2..3b2d3a9 100644 --- a/Output/pjrcUSB/arm/usb_dev.c +++ b/Output/pjrcUSB/arm/usb_dev.c @@ -684,11 +684,28 @@ void usb_device_reload() { // MCHCK #if defined(_mk20dx128vlf5_) - // This line must be exactly the same in the bootloader - const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; - for ( int pos = 0; pos < sizeof(sys_reset_to_loader_magic); pos++ )(&VBAT)[pos] = sys_reset_to_loader_magic[ pos ]; - SOFTWARE_RESET(); + // MCHCK Kiibohd Variant + // Check to see if PTA3 (has a pull-up) is connected to GND (usually via jumper) + // Only allow reload if the jumper is present (security) + GPIOA_PDDR &= ~(1<<3); // Input + PORTA_PCR3 = PORT_PCR_PFE | PORT_PCR_MUX(1); // Internal pull-up + + // Check for jumper + if ( GPIOA_PDIR & (1<<3) ) + { + print( NL ); + warn_print("Security jumper not present, cancelling firmware reload..."); + info_msg("Replace jumper on middle 2 pins, or manually press the firmware reload button."); + } + else + { + // This line must be exactly the same in the bootloader + const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; + for ( int pos = 0; pos < sizeof(sys_reset_to_loader_magic); pos++ )(&VBAT)[pos] = sys_reset_to_loader_magic[ pos ]; + SOFTWARE_RESET(); + } + // Teensy 3.0 and 3.1 #else asm volatile("bkpt");