You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2022/02/03 21:12:41 UTC

[mynewt-core] branch master updated: dfu: Add auto confirm with timeout

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 03a58a4  dfu: Add auto confirm with timeout
03a58a4 is described below

commit 03a58a49341880e56e8ccf9f4b03ce2421b63a3e
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Tue Nov 30 15:21:19 2021 +0100

    dfu: Add auto confirm with timeout
    
    To prevent bricking device image is confirm in software
    after bootloader swap.
    Decision when to confirm new software is left to the application.
    
    This allows to add simple timer that will confirm new image
    after it was executing for some time (60 s default).
    
    Then user does not need to write own decision-making way if
    simply running new image is enough.
    
    Two syscfg values are added:
    - USBD_DFU_AUTO_CONFIRM
    - USBD_DFU_AUTO_CONFIRM_TIME
---
 hw/usb/tinyusb/dfu/pkg.yml    |  3 +++
 hw/usb/tinyusb/dfu/src/dfu.c  | 16 ++++++++++++++++
 hw/usb/tinyusb/dfu/syscfg.yml | 12 ++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/hw/usb/tinyusb/dfu/pkg.yml b/hw/usb/tinyusb/dfu/pkg.yml
index 4c61670..ba7c3ad 100644
--- a/hw/usb/tinyusb/dfu/pkg.yml
+++ b/hw/usb/tinyusb/dfu/pkg.yml
@@ -32,3 +32,6 @@ pkg.deps:
     - "@tinyusb/tinyusb"
     - "@apache-mynewt-core/mgmt/imgmgr"
     - "@mcuboot/boot/bootutil"
+
+pkg.init.USBD_DFU_AUTO_CONFIRM:
+    dfu_init: 'MYNEWT_VAL(USBD_DFU_SYSINIT_STAGE)'
diff --git a/hw/usb/tinyusb/dfu/src/dfu.c b/hw/usb/tinyusb/dfu/src/dfu.c
index fd031cc..2376d0e 100644
--- a/hw/usb/tinyusb/dfu/src/dfu.c
+++ b/hw/usb/tinyusb/dfu/src/dfu.c
@@ -40,6 +40,7 @@
 #if MYNEWT_VAL(USBD_DFU_RESET_AFTER_DOWNLOAD)
 
 struct os_callout delayed_reset_callout;
+struct os_callout auto_confirm_callout;
 
 void
 delayed_reset_cb(struct os_event *event)
@@ -185,3 +186,18 @@ boot_preboot(void)
     hal_gpio_deinit(MYNEWT_VAL(USBD_DFU_BOOT_PIN));
 #endif
 }
+
+void
+auto_confirm_cb(struct os_event *event)
+{
+    img_mgmt_state_confirm();
+}
+
+void
+dfu_init(void)
+{
+    os_callout_init(&auto_confirm_callout, os_eventq_dflt_get(),
+                    auto_confirm_cb, NULL);
+
+    os_callout_reset(&auto_confirm_callout, OS_TICKS_PER_SEC * MYNEWT_VAL(USBD_DFU_AUTO_CONFIRM_TIME));
+}
diff --git a/hw/usb/tinyusb/dfu/syscfg.yml b/hw/usb/tinyusb/dfu/syscfg.yml
index 5d8460a..62d7e4b 100644
--- a/hw/usb/tinyusb/dfu/syscfg.yml
+++ b/hw/usb/tinyusb/dfu/syscfg.yml
@@ -44,6 +44,14 @@ syscfg.defs:
         description: >
             Mark image as confirmed after download.
         value: 0
+    USBD_DFU_AUTO_CONFIRM:
+        description: >
+            Confirm image if it runs without crash for some time.
+        value: 0
+    USBD_DFU_AUTO_CONFIRM_TIME:
+        description: >
+            Time in seconds needed for automatic image confirmation.
+        value: 60
     USBD_DFU_BLOCK_WRITE_TIME:
         description: >
             Time in milliseconds needed for writing block to the device.
@@ -82,6 +90,10 @@ syscfg.defs:
             Set to 2 if boto pin needs internal pull-down resistor.
         value: 0
 
+    USBD_DFU_SYSINIT_STAGE:
+        description: >
+            Sysinit stage for DFU functionality.
+        value: 1000
     USBD_DFU_LOG_MODULE:
         description: 'Numeric module ID to use for DFU log messages.'
         value: 43