cypress: Add support for watchdog timer update in boot image
Add watchdog timer to MCUBootApp plus BlinkyApp to implement additional way of boot/upgrade image operation confirmation.
Signed-off-by: Roman Okhrimenko <roman.okhrimenko@cypress.com>
diff --git a/boot/cypress/MCUBootApp/libs.mk b/boot/cypress/MCUBootApp/libs.mk
index 227cda6..3605bb3 100644
--- a/boot/cypress/MCUBootApp/libs.mk
+++ b/boot/cypress/MCUBootApp/libs.mk
@@ -33,6 +33,7 @@
# Collect source files for PDL
SOURCES_PDL := $(wildcard $(CUR_LIBS_PATH)/pdl/psoc6pdl/drivers/source/*.c)
+SOURCES_WATCHDOG := $(wildcard $(CUR_LIBS_PATH)/watchdog/*.c)
# PDL related include directories
INCLUDE_DIRS_PDL := $(CUR_LIBS_PATH)/pdl/psoc6pdl/drivers/include
@@ -42,12 +43,14 @@
# core-libs related include directories
INCLUDE_DIRS_CORE_LIB := $(CUR_LIBS_PATH)/core-lib/include
+INCLUDE_DIRS_WATCHDOG := $(CUR_LIBS_PATH)/watchdog
SOURCES_HAL += $(CUR_LIBS_PATH)/psoc6hal/COMPONENT_PSOC6HAL/source/cyhal_crypto_common.c
SOURCES_HAL += $(CUR_LIBS_PATH)/psoc6hal/COMPONENT_PSOC6HAL/source/cyhal_hwmgr.c
# Collected source files for libraries
SOURCES_LIBS := $(SOURCES_PDL)
+SOURCES_LIBS += $(SOURCES_WATCHDOG)
SOURCES_LIBS += $(SOURCES_PLATFORM)
SOURCES_LIBS += $(SOURCES_HAL)
@@ -61,6 +64,7 @@
INCLUDE_DIRS_LIBS := $(addprefix -I,$(INCLUDE_DIRS_PDL))
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_PLATFORM))
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_CORE_LIB))
+INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_WATCHDOG))
INCLUDE_DIRS_LIBS += $(addprefix -I,$(INCLUDE_DIRS_HAL))
################################################################################
diff --git a/boot/cypress/MCUBootApp/main.c b/boot/cypress/MCUBootApp/main.c
index 2211a28..6c28ba0 100644
--- a/boot/cypress/MCUBootApp/main.c
+++ b/boot/cypress/MCUBootApp/main.c
@@ -38,6 +38,11 @@
#include "bootutil/fault_injection_hardening.h"
+#include "watchdog.h"
+
+/* WDT time out for reset mode, in milliseconds. */
+#define WDT_TIME_OUT_MS 4000
+
/* Define pins for UART debug output */
#define CYBSP_UART_ENABLED 1U
#define CYBSP_UART_HW SCB5
@@ -121,6 +126,12 @@
if (fih_eq(fih_rc, FIH_SUCCESS))
{
BOOT_LOG_INF("User Application validated successfully");
+ /* initialize watchdog timer. it should be updated from user app
+ * to mark successful start up of this app. if the watchdog is not updated,
+ * reset will be initiated by watchdog timer and swap revert operation started
+ * to roll back to operable image.
+ */
+ cy_wdg_init(WDT_TIME_OUT_MS);
do_boot(&rsp);
boot_succeeded = true;
}