diff --git a/left/build/uhk60-left_debug_jlink.launch b/left/build/uhk60-left_debug_jlink.launch
index 04ee5bf..1c47538 100644
--- a/left/build/uhk60-left_debug_jlink.launch
+++ b/left/build/uhk60-left_debug_jlink.launch
@@ -50,7 +50,7 @@
-
+
@@ -77,6 +77,6 @@
-
+
diff --git a/left/build/uhk60-left_release_jlink.launch b/left/build/uhk60-left_release_jlink.launch
index a7fb7d0..cebdb69 100644
--- a/left/build/uhk60-left_release_jlink.launch
+++ b/left/build/uhk60-left_release_jlink.launch
@@ -77,6 +77,6 @@
-
+
diff --git a/left/src/i2c_watchdog.c b/left/src/i2c_watchdog.c
index f60535d..79a5764 100644
--- a/left/src/i2c_watchdog.c
+++ b/left/src/i2c_watchdog.c
@@ -4,35 +4,46 @@
#include "test_led.h"
#include "init_peripherals.h"
-//static uint32_t prevWatchdogCounter = 0;
-uint32_t I2cWatchdog_RecoveryCounter;
-volatile uint32_t I2cWatchdog_WatchCounter;
+/* NOTE: Because of a bug in the ROM bootloader of the KL03Z, the watchdog timer is disabled and cannot be re-enabled.
+ * See https://community.nxp.com/thread/457893
+ * Therefore the hardware watchdog timer cannot be used without an extra way to enter bootloader or application mode.
+ */
+
+#define WATCH_ENABLE_WATCHDOG (1) /* additionally, un-comment InitI2cWatchdog() in init_peripherals.c */
+
+#if WATCH_ENABLE_WATCHDOG
+static uint32_t prevWatchdogCounter = 0;
+#endif
+static uint32_t I2cWatchdog_RecoveryCounter; /* counter for how many times we had to recover and restart */
void InitI2cWatchdog(void)
{
lptmr_config_t lptmrConfig;
LPTMR_GetDefaultConfig(&lptmrConfig);
LPTMR_Init(LPTMR0, &lptmrConfig);
- LPTMR_SetTimerPeriod(LPTMR0, USEC_TO_COUNT(LPTMR_USEC_COUNT, LPTMR_SOURCE_CLOCK));
+ LPTMR_SetTimerPeriod(LPTMR0, USEC_TO_COUNT(LPTMR_USEC_COUNT, LPTMR_SOURCE_CLOCK)); /* set LPTM for a 100 ms period */
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
EnableIRQ(LPTMR0_IRQn);
LPTMR_StartTimer(LPTMR0);
}
-/*
+
+#if WATCH_ENABLE_WATCHDOG
void I2C_WATCHDOG_LPTMR_HANDLER(void)
{
+ static volatile uint32_t I2cWatchdog_WatchCounter = 0; /* counter for timer */
TEST_LED_TOGGLE();
I2cWatchdog_WatchCounter++;
- if (I2C_Watchdog == prevWatchdogCounter) { // Restart I2C if there hasn't been any interrupt during 100 ms
-// NVIC_SystemReset();
- I2cWatchdog_RecoveryCounter++;
- I2C_SlaveDeinit(I2C_BUS_BASEADDR);
- InitI2c();
+ if (I2cWatchdog_WatchCounter>1) { /* do not check within the first 100 ms, as I2C might not be running yet */
+ if (I2C_Watchdog == prevWatchdogCounter) { // Restart I2C if there hasn't been any interrupt during 100 ms. I2C_Watchdog gets incremented for every I2C transaction
+ // NVIC_SystemReset();
+ I2cWatchdog_RecoveryCounter++;
+ I2C_SlaveDeinit(I2C_BUS_BASEADDR);
+ InitI2c();
+ }
}
-
- prevWatchdogCounter = I2C_Watchdog;
+ prevWatchdogCounter = I2C_Watchdog; /* remember previous counter */
LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
}
-*/
+#endif
diff --git a/left/src/init_peripherals.c b/left/src/init_peripherals.c
index 91172c0..267cdaf 100644
--- a/left/src/init_peripherals.c
+++ b/left/src/init_peripherals.c
@@ -85,7 +85,7 @@ void InitPeripherals(void)
InitLedDriver();
InitTestLed();
LedPwm_Init();
-// InitI2cWatchdog();
DebugOverSpi_Init();
InitI2c();
+ InitI2cWatchdog();
}
diff --git a/right/build/uhk60-right_debug_standalone_jlink.launch b/right/build/uhk60-right_debug_standalone_jlink.launch
index 4a685bc..be8d341 100644
--- a/right/build/uhk60-right_debug_standalone_jlink.launch
+++ b/right/build/uhk60-right_debug_standalone_jlink.launch
@@ -64,10 +64,10 @@
-
+
-
+
@@ -77,6 +77,6 @@
-
+