This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 644bfb6  tinyusb/dfu: Add boot_preboot for DFU in bootloader
644bfb6 is described below

commit 644bfb6d4330df93504731789a39ff0c42045b82
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Thu Nov 25 10:11:04 2021 +0100

    tinyusb/dfu: Add boot_preboot for DFU in bootloader
    
    When mcuboot have BOOT_PREBOOT set it executes boot_preboot() function.
    dfu package provides this function boot_preboot() that checks selected GPIO
    to see if DFU mode should be activated.
---
 hw/usb/tinyusb/dfu/src/dfu.c  | 20 ++++++++++++++++++++
 hw/usb/tinyusb/dfu/syscfg.yml | 17 ++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/hw/usb/tinyusb/dfu/src/dfu.c b/hw/usb/tinyusb/dfu/src/dfu.c
index bb37295..fd031cc 100644
--- a/hw/usb/tinyusb/dfu/src/dfu.c
+++ b/hw/usb/tinyusb/dfu/src/dfu.c
@@ -23,6 +23,8 @@
 
 #include <bsp/bsp.h>
 #include <img_mgmt/img_mgmt.h>
+#include <tinyusb/tinyusb.h>
+#include <hal/hal_gpio.h>
 
 /*
  * If DFU is activated from bootloader it writes to SLOT0.
@@ -165,3 +167,21 @@ tud_dfu_detach_cb(void)
 {
     /* TODO: implement detach if needed */
 }
+
+/**
+ * Function called by mcuboot before image verification/swap/and application 
execution.
+ * If GPIO pin is selected and in active state instead of performing normal 
startup
+ * TinyUSB with DFU interface is started allowing for application update.
+ */
+void
+boot_preboot(void)
+{
+#if MYNEWT_VAL(USBD_DFU_BOOT_PIN) >= 0
+    hal_gpio_init_in(MYNEWT_VAL(USBD_DFU_BOOT_PIN), 
MYNEWT_VAL(USBD_DFU_BOOT_PIN_PULL));
+    if (hal_gpio_read(MYNEWT_VAL(USBD_DFU_BOOT_PIN)) == 
MYNEWT_VAL(USBD_DFU_BOOT_PIN_VALUE)) {
+        hal_gpio_deinit(MYNEWT_VAL(USBD_DFU_BOOT_PIN));
+        tinyusb_start();
+    }
+    hal_gpio_deinit(MYNEWT_VAL(USBD_DFU_BOOT_PIN));
+#endif
+}
diff --git a/hw/usb/tinyusb/dfu/syscfg.yml b/hw/usb/tinyusb/dfu/syscfg.yml
index 9989735..5d8460a 100644
--- a/hw/usb/tinyusb/dfu/syscfg.yml
+++ b/hw/usb/tinyusb/dfu/syscfg.yml
@@ -68,6 +68,20 @@ syscfg.defs:
             shorter timeout in the DFU_DETACH request.
         value: 1000
 
+    USBD_DFU_BOOT_PIN:
+        description: >
+            GPIO pin to check during boot for DFU activation.
+        value: -1
+    USBD_DFU_BOOT_PIN_VALUE:
+        description: >
+            GPIO pin value required for DFU activation.
+        value: 0
+    USBD_DFU_BOOT_PIN_PULL:
+        description: >
+            Set to 1 if boot pin needs internal pull-up resistor.
+            Set to 2 if boto pin needs internal pull-down resistor.
+        value: 0
+
     USBD_DFU_LOG_MODULE:
         description: 'Numeric module ID to use for DFU log messages.'
         value: 43
@@ -81,5 +95,6 @@ syscfg.logs:
         level: MYNEWT_VAL(USBD_DFU_LOG_LVL)
 
 
-syscfg.vals.BOOTLOADER:
+syscfg.vals.BOOT_LOADER:
     USBD_DFU_SLOT_NAME: '"SLOT0"'
+    BOOT_PREBOOT: 1

Reply via email to