diff options
-rw-r--r-- | atmel_start_pins.h | 5 | ||||
-rw-r--r-- | driver_init.c | 5 | ||||
-rw-r--r-- | usb_dfu_main.c | 4 |
3 files changed, 12 insertions, 2 deletions
diff --git a/atmel_start_pins.h b/atmel_start_pins.h index 23b8d33..86e1dfb 100644 --- a/atmel_start_pins.h +++ b/atmel_start_pins.h @@ -27,9 +27,12 @@ #define GPIO_PIN_FUNCTION_M 12 #define GPIO_PIN_FUNCTION_N 13 -/** LED pin to indicate system state (pull low to switch on */ +/** LED pin to indicate system state (pull low to switch on) */ #define LED_SYSTEM GPIO(GPIO_PORTC, 18) +/** User button to force DFu bootloader (connected to ground when pressed) */ +#define BUTTON_FORCE_DFU GPIO(GPIO_PORTB, 31) + /** USB D+/D- pins */ #define PA24 GPIO(GPIO_PORTA, 24) #define PA25 GPIO(GPIO_PORTA, 25) diff --git a/driver_init.c b/driver_init.c index 0b07cc1..a91b0eb 100644 --- a/driver_init.c +++ b/driver_init.c @@ -148,6 +148,11 @@ void system_init(void) gpio_set_pin_direction(LED_SYSTEM, GPIO_DIRECTION_OUT); gpio_set_pin_function(LED_SYSTEM, GPIO_PIN_FUNCTION_OFF); + // configure force DFU user button + gpio_set_pin_direction(BUTTON_FORCE_DFU, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(BUTTON_FORCE_DFU, GPIO_PULL_UP); + gpio_set_pin_function(BUTTON_FORCE_DFU, GPIO_PIN_FUNCTION_OFF); + USB_DEVICE_INSTANCE_init(); FLASH_0_init(); } diff --git a/usb_dfu_main.c b/usb_dfu_main.c index 91748a5..449b311 100644 --- a/usb_dfu_main.c +++ b/usb_dfu_main.c @@ -48,6 +48,8 @@ static bool check_bootloader(void) */ static bool check_force_dfu(void) { + gpio_set_pin_pull_mode(BUTTON_FORCE_DFU, GPIO_PULL_UP); // pull button high + return (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)); // signal is low when button is pressed } /** Check if the application is valid @@ -87,7 +89,7 @@ int main(void) delay_ms(500); } } - if (check_application()) { // application is valid + if (!check_force_dfu() && check_application()) { // application is valid start_application(); // start application } else { usb_dfu(); // start DFU bootloader |