From 7940acccf4c6205c8cdbe265cfd3a0bad28deb68 Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Fri, 7 Feb 2020 17:36:19 +0100 Subject: [PATCH] Zephyr: STM bootloader activation added --- .../arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts | 5 ++++- boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts | 4 ++++ src/hardware.cpp | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts index 615dbbf..17fb1bb 100755 --- a/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts +++ b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts @@ -48,8 +48,11 @@ gpios = <&gpioc 14 GPIO_DIR_IN>; label = "Solar voltage measurement enable"; }; + boot0-en { + gpios = <&gpiob 12 GPIO_DIR_IN>; + label = "BOOT0 pin trigger"; + }; }; - aliases { uart-dbg = &usart1; uext-uart = &usart2; diff --git a/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts b/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts index b27b781..ccca5e3 100644 --- a/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts +++ b/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts @@ -44,6 +44,10 @@ gpios = <&gpiob 5 GPIO_DIR_IN>; label = "USB charging port disable"; }; + boot0-en { + gpios = <&gpiob 12 GPIO_DIR_IN>; + label = "BOOT0 pin trigger"; + }; }; aliases { diff --git a/src/hardware.cpp b/src/hardware.cpp index e232450..792473e 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -220,10 +220,23 @@ void reset_device() #elif defined(__ZEPHYR__) #include +#include void start_stm32_bootloader() { - // TODO +#ifdef DT_SWITCH_BOOT0_EN_GPIOS_CONTROLLER + // pin is connected to BOOT0 via resistor and capacitor + struct device *dev = device_get_binding(DT_SWITCH_BOOT0_EN_GPIOS_CONTROLLER); + gpio_pin_configure(dev, DT_SWITCH_BOOT0_EN_GPIOS_PIN, GPIO_DIR_OUT); + gpio_pin_write(dev, DT_SWITCH_BOOT0_EN_GPIOS_PIN, 1); + + k_sleep(100); // wait for capacitor at BOOT0 pin to charge up + reset_device(); +#elif defined (STM32F0) + // place magic code at end of RAM and initiate reset + *((uint32_t *)(MAGIC_CODE_ADDR)) = 0xDEADBEEF; + reset_device(); +#endif } void reset_device()