aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2019-01-16 18:14:41 +0100
committerKévin Redon <kredon@sysmocom.de>2019-01-16 18:41:23 +0100
commite49a3dbebad53e8088f8eab39e5d413f5f2c9615 (patch)
treee4b1fe387e5c99e5ca1fa514272d4063c25c5449
parent388dac3f877e7e6f6ce9db541567a9bc05f3a15e (diff)
add button to force DFU bootloader
-rw-r--r--atmel_start_pins.h5
-rw-r--r--driver_init.c5
-rw-r--r--usb_dfu_main.c4
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