add button to force DFU bootloader
Change-Id: I163ab2de0fcbe13532c1992f6b78d49f4cda2d88
This commit is contained in:
parent
388dac3f87
commit
e49a3dbeba
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue