Use independent watchdog driver

This commit is contained in:
Thomas Klaehn 2021-01-08 10:50:38 +01:00
parent 258c882c8c
commit 3c65600e31
2 changed files with 21 additions and 25 deletions

View File

@ -7,19 +7,26 @@
#include "platform/stm32g0xx/Gpio.h" #include "platform/stm32g0xx/Gpio.h"
#include "platform/stm32g0xx/Uart.h" #include "platform/stm32g0xx/Uart.h"
#include "platform/stm32g0xx/IndependentWatchdog.h"
IWDG_HandleTypeDef hiwdg;
static void SystemClock_Config(void); static void SystemClock_Config(void);
// static void MX_IWDG_Init(void);
#define SYS_TICK_PRIO 0 #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; using namespace perinet::platform::stm32g0xx;
Gpio green_led(Gpio::Port::PORT_A, 5, Gpio::Mode::MODE_OUTPUT_PP); Gpio green_led(Gpio::Port::PORT_A, 5, Gpio::Mode::MODE_OUTPUT_PP);
Uart uart(Uart::UartDevice::UART_2, 115200); Uart uart(Uart::UartDevice::UART_2, 115200);
#ifndef JTAG_DEBUG
IndependentWatchdog watchdog(4095, 4095);
#endif
int main(void) int main(void)
{ {
unsigned int i = 1, j = 40; unsigned int i = 1, j = 40;
@ -41,9 +48,12 @@ int main(void)
SystemClock_Config(); SystemClock_Config();
// MX_IWDG_Init();
char tx_buf[80]; char tx_buf[80];
#ifndef JTAG_DEBUG
watchdog.enable();
#endif
while (1) { while (1) {
if (j < 100) { if (j < 100) {
j += 10; j += 10;
@ -61,7 +71,10 @@ int main(void)
uart.sync_send((const uint8_t *)tx_buf, strlen(tx_buf)); uart.sync_send((const uint8_t *)tx_buf, strlen(tx_buf));
green_led.toggle(); green_led.toggle();
HAL_Delay(j); 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); 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 #ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line) void assert_failed(uint8_t *file, uint32_t line)
{ {

View File

@ -8,7 +8,8 @@ BUILD_DIR = _build
CC_SOURCES = \ CC_SOURCES = \
Core/main.cc \ Core/main.cc \
platform/stm32g0xx/Gpio.cc \ platform/stm32g0xx/Gpio.cc \
platform/stm32g0xx/Uart.cc platform/stm32g0xx/Uart.cc \
platform/stm32g0xx/IndependentWatchdog.cc
C_SOURCES = \ C_SOURCES = \
platform/stm32g0xx/stm32g0xx_it.c \ platform/stm32g0xx/stm32g0xx_it.c \