From 8033fb2529c08ccae24aaa8853be76e97eb945da Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 20 Jan 2013 23:17:23 +0100 Subject: [PATCH] STLINK: Allow to force bootloader by starting with the RESET button pressed --- src/platforms/stm32/usbdfu.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/platforms/stm32/usbdfu.c b/src/platforms/stm32/usbdfu.c index fb8f34f..55318ec 100644 --- a/src/platforms/stm32/usbdfu.c +++ b/src/platforms/stm32/usbdfu.c @@ -55,6 +55,18 @@ u8 usbd_control_buffer[1024]; #if defined(DISCOVERY_STLINK) u32 led2_state = 0; +int stlink_test_nrst(void) { +/* Test if NRST is pulled down*/ + int i; + uint16_t nrst; + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); + gpio_set_mode(GPIOB, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, GPIO0); + gpio_set(GPIOB, GPIO0); + for (i=0; i< 100000; i++) + nrst = gpio_get(GPIOB, GPIO0); + return (nrst)?1:0; +} #endif static u32 max_address; @@ -366,7 +378,7 @@ int main(void) { #if defined (DISCOVERY_STLINK) rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); - if(!gpio_get(GPIOC, GPIO13)) { + if(!gpio_get(GPIOC, GPIO13) && stlink_test_nrst()) { #elif defined (STM32_CAN) rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); if(!gpio_get(GPIOA, GPIO0)) {