comparison Output/pjrcUSB/arm/usb_dev.c @ 385:d8f61e15aca1

Adding jump to bootloader key - Now enabled by default - Added protection around remote jumps
author Jacob Alexander <haata@kiibohd.com>
date Sun, 11 Oct 2015 22:07:11 -0700
parents 801e7628d977
children 23a1868b4ac2
comparison
equal deleted inserted replaced
384:82ce1988fefe 385:d8f61e15aca1
909 } 909 }
910 910
911 911
912 void usb_device_reload() 912 void usb_device_reload()
913 { 913 {
914 if ( flashModeEnabled_define == 0 )
915 {
916 print( NL );
917 warn_print("flashModeEnabled not set, cancelling firmware reload...");
918 info_msg("Set flashModeEnabled to 1 in your kll configuration.");
919 return;
920 }
921
922 // MCHCK 914 // MCHCK
923 #if defined(_mk20dx128vlf5_)
924
925 // MCHCK Kiibohd Variant
926 // Check to see if PTA3 (has a pull-up) is connected to GND (usually via jumper)
927 // Only allow reload if the jumper is present (security)
928 GPIOA_PDDR &= ~(1<<3); // Input
929 PORTA_PCR3 = PORT_PCR_PFE | PORT_PCR_MUX(1); // Internal pull-up
930
931 // Check for jumper
932 if ( GPIOA_PDIR & (1<<3) && flashModeEnabled_define != 0 )
933 {
934 print( NL );
935 warn_print("Security jumper not present, cancelling firmware reload...");
936 info_msg("Replace jumper on middle 2 pins, or manually press the firmware reload button.");
937 }
938 else
939 {
940 // Copies variable into the VBAT register, must be identical to the variable in the bootloader to jump to the bootloader flash mode
941 for ( int pos = 0; pos < sizeof(sys_reset_to_loader_magic); pos++ )
942 (&VBAT)[ pos ] = sys_reset_to_loader_magic[ pos ];
943 SOFTWARE_RESET();
944 }
945
946 // Kiibohd mk20dx256vlh7 915 // Kiibohd mk20dx256vlh7
947 #elif defined(_mk20dx256vlh7_) 916 #if defined(_mk20dx128vlf5_) || defined(_mk20dx256vlh7_)
948 // Copies variable into the VBAT register, must be identical to the variable in the bootloader to jump to the bootloader flash mode 917 // Copies variable into the VBAT register, must be identical to the variable in the bootloader to jump to the bootloader flash mode
949 for ( int pos = 0; pos < sizeof(sys_reset_to_loader_magic); pos++ ) 918 for ( int pos = 0; pos < sizeof(sys_reset_to_loader_magic); pos++ )
950 (&VBAT)[ pos ] = sys_reset_to_loader_magic[ pos ]; 919 (&VBAT)[ pos ] = sys_reset_to_loader_magic[ pos ];
951 SOFTWARE_RESET(); 920 SOFTWARE_RESET();
952 921