Added watchdog

This commit is contained in:
mj
2022-01-02 14:32:44 +01:00
parent 5feb12310c
commit b21cefe412
5 changed files with 402 additions and 13 deletions

View File

@@ -29,6 +29,7 @@ extern "C" {
/* Includes ------------------------------------------------------------------*/
#include "stm32l0xx_ll_i2c.h"
#include "stm32l0xx_ll_iwdg.h"
#include "stm32l0xx_ll_crs.h"
#include "stm32l0xx_ll_rcc.h"
#include "stm32l0xx_ll_bus.h"

View File

@@ -125,6 +125,7 @@ static void MX_USART2_UART_Init(void);
static void MX_TIM21_Init(void);
static void MX_TIM2_Init(void);
static void MX_TIM22_Init(void);
static void MX_IWDG_Init(void);
/* USER CODE BEGIN PFP */
void USART2_TX_Buffer(uint8_t* buffer_tx, uint16_t buffer_tx_len);
void CO2_to_color(uint16_t co2, uint16_t co2_limit_yellow, uint16_t co2_limit_red);
@@ -186,6 +187,7 @@ int main(void)
MX_TIM21_Init();
MX_TIM2_Init();
MX_TIM22_Init();
MX_IWDG_Init();
/* USER CODE BEGIN 2 */
/* Turn on MAGENTA LED to signal startup state */
@@ -274,6 +276,8 @@ int main(void)
/* Enter the main loop */
while (1)
{
/* Watchdog is set to 28 s (37 kHz, prescaler 256, 4095 reload value) */
LL_IWDG_ReloadCounter(IWDG);
if (usart2_rx_done == 1)
{
/* Process the message */
@@ -406,6 +410,13 @@ void SystemClock_Config(void)
}
LL_RCC_HSI_SetCalibTrimming(16);
LL_RCC_LSI_Enable();
/* Wait till LSI is ready */
while(LL_RCC_LSI_IsReady() != 1)
{
}
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLL_MUL_3, LL_RCC_PLL_DIV_4);
LL_RCC_PLL_Enable();
@@ -495,6 +506,36 @@ static void MX_I2C1_Init(void)
}
/**
* @brief IWDG Initialization Function
* @param None
* @retval None
*/
static void MX_IWDG_Init(void)
{
/* USER CODE BEGIN IWDG_Init 0 */
/* USER CODE END IWDG_Init 0 */
/* USER CODE BEGIN IWDG_Init 1 */
/* USER CODE END IWDG_Init 1 */
LL_IWDG_Enable(IWDG);
LL_IWDG_EnableWriteAccess(IWDG);
LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_256);
LL_IWDG_SetReloadCounter(IWDG, 4095);
while (LL_IWDG_IsReady(IWDG) != 1)
{
}
LL_IWDG_ReloadCounter(IWDG);
/* USER CODE BEGIN IWDG_Init 2 */
/* USER CODE END IWDG_Init 2 */
}
/**
* @brief TIM2 Initialization Function
* @param None