diff --git a/Core/main.cc b/Core/main.cc index d9039e8..ed0a59d 100644 --- a/Core/main.cc +++ b/Core/main.cc @@ -7,19 +7,26 @@ #include "platform/stm32g0xx/Gpio.h" #include "platform/stm32g0xx/Uart.h" - -IWDG_HandleTypeDef hiwdg; +#include "platform/stm32g0xx/IndependentWatchdog.h" static void SystemClock_Config(void); -// static void MX_IWDG_Init(void); #define SYS_TICK_PRIO 0 +// NOTE! The independent watchdog is clocked by a separate clock. this one +// isn't controlled by JTAG. That's why the independent watchdog needs to +// be disabled during JTAG debug sessions. +#define JTAG_DEBUG + using namespace perinet::platform::stm32g0xx; Gpio green_led(Gpio::Port::PORT_A, 5, Gpio::Mode::MODE_OUTPUT_PP); Uart uart(Uart::UartDevice::UART_2, 115200); +#ifndef JTAG_DEBUG +IndependentWatchdog watchdog(4095, 4095); +#endif + int main(void) { unsigned int i = 1, j = 40; @@ -41,9 +48,12 @@ int main(void) SystemClock_Config(); - // MX_IWDG_Init(); - char tx_buf[80]; + +#ifndef JTAG_DEBUG + watchdog.enable(); +#endif + while (1) { if (j < 100) { j += 10; @@ -61,7 +71,10 @@ int main(void) uart.sync_send((const uint8_t *)tx_buf, strlen(tx_buf)); green_led.toggle(); HAL_Delay(j); - // HAL_IWDG_Refresh(&hiwdg); + +#ifndef JTAG_DEBUG + watchdog.trigger(); +#endif } } @@ -132,24 +145,6 @@ void SystemClock_Config(void) MODIFY_REG(RCC->CCIPR, RCC_CCIPR_USART2SEL, RCC_USART2CLKSOURCE_PCLK1); } -// static void MX_IWDG_Init(void) -// { -// hiwdg.Instance = IWDG; -// hiwdg.Init.Prescaler = IWDG_PRESCALER_4; -// hiwdg.Init.Window = 4095; -// hiwdg.Init.Reload = 4095; -// if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { -// Error_Handler(); -// } -// } - -void Error_Handler(void) -{ - __disable_irq(); - while (1) { - } -} - #ifdef USE_FULL_ASSERT void assert_failed(uint8_t *file, uint32_t line) { diff --git a/Makefile b/Makefile index 5f1003b..6042d24 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,8 @@ BUILD_DIR = _build CC_SOURCES = \ Core/main.cc \ platform/stm32g0xx/Gpio.cc \ -platform/stm32g0xx/Uart.cc +platform/stm32g0xx/Uart.cc \ +platform/stm32g0xx/IndependentWatchdog.cc C_SOURCES = \ platform/stm32g0xx/stm32g0xx_it.c \