aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/stm32
diff options
context:
space:
mode:
authorUwe Bonnes2013-01-20 23:17:23 +0100
committerUwe Bonnes2013-01-21 11:02:44 +0100
commit8033fb2529c08ccae24aaa8853be76e97eb945da (patch)
tree9c8e45cc22013e69cc5b74446ac5d09d5b143c0b /src/platforms/stm32
parent749fb318e78b89584af000f4e2b41dce013a6fc3 (diff)
STLINK: Allow to force bootloader by starting with the RESET button pressed
Diffstat (limited to 'src/platforms/stm32')
-rw-r--r--src/platforms/stm32/usbdfu.c14
1 files changed, 13 insertions, 1 deletions
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)) {