Skip to content

Commit d5f7d8b

Browse files
committed
add watchdog and move externs
1 parent 85f0dd8 commit d5f7d8b

12 files changed

Lines changed: 1343 additions & 39 deletions

File tree

.mxproject

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ endif()
2222
set(CMAKE_PROJECT_NAME MSB-FW-2)
2323

2424
# NER Include toolchain file
25-
include("cmake/gcc-arm-none-eabi.cmake")
2625

2726
# Enable compile command to ease indexing with e.g. clangd
2827
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

Core/Inc/main.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ extern "C" {
4141

4242
/* Exported constants --------------------------------------------------------*/
4343
/* USER CODE BEGIN EC */
44+
extern IWDG_HandleTypeDef hiwdg;
45+
extern I2C_HandleTypeDef hi2c1;
46+
extern SPI_HandleTypeDef hspi1;
47+
extern SPI_HandleTypeDef hspi2;
4448

4549
/* USER CODE END EC */
4650

Core/Inc/stm32h5xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
/*#define HAL_HASH_MODULE_ENABLED */
5858
/*#define HAL_HCD_MODULE_ENABLED */
5959
/*#define HAL_IRDA_MODULE_ENABLED */
60-
/*#define HAL_IWDG_MODULE_ENABLED */
60+
#define HAL_IWDG_MODULE_ENABLED
6161
#define HAL_I2C_MODULE_ENABLED
6262
/*#define HAL_I3C_MODULE_ENABLED */
6363
/*#define HAL_I2S_MODULE_ENABLED */

Core/Src/main.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
/* Includes ------------------------------------------------------------------*/
2020
#include "app_threadx.h"
2121
#include "main.h"
22-
#include "u_queues.h"
23-
#include "fdcan.h"
24-
#include "u_tx_debug.h"
2522

2623
/* Private includes ----------------------------------------------------------*/
2724
/* USER CODE BEGIN Includes */
@@ -62,6 +59,8 @@ FDCAN_HandleTypeDef hfdcan2;
6259
I2C_HandleTypeDef hi2c1;
6360
I2C_HandleTypeDef hi2c2;
6461

62+
IWDG_HandleTypeDef hiwdg;
63+
6564
UART_HandleTypeDef hlpuart1;
6665
UART_HandleTypeDef huart4;
6766

@@ -96,6 +95,7 @@ static void MX_ADC1_Init(void);
9695
static void MX_TIM3_Init(void);
9796
static void MX_TIM15_Init(void);
9897
static void MX_TIM1_Init(void);
98+
static void MX_IWDG_Init(void);
9999
/* USER CODE BEGIN PFP */
100100

101101
/* USER CODE END PFP */
@@ -195,6 +195,7 @@ int main(void)
195195
MX_TIM3_Init();
196196
MX_TIM15_Init();
197197
MX_TIM1_Init();
198+
MX_IWDG_Init();
198199
/* USER CODE BEGIN 2 */
199200

200201
/* USER CODE END 2 */
@@ -232,12 +233,13 @@ void SystemClock_Config(void)
232233
/** Initializes the RCC Oscillators according to the specified parameters
233234
* in the RCC_OscInitTypeDef structure.
234235
*/
235-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE
236-
|RCC_OSCILLATORTYPE_CSI;
236+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI
237+
|RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_CSI;
237238
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
238239
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
239240
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV2;
240241
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
242+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
241243
RCC_OscInitStruct.CSIState = RCC_CSI_ON;
242244
RCC_OscInitStruct.CSICalibrationValue = RCC_CSICALIBRATION_DEFAULT;
243245
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
@@ -754,6 +756,36 @@ static void MX_ICACHE_Init(void)
754756

755757
}
756758

759+
/**
760+
* @brief IWDG Initialization Function
761+
* @param None
762+
* @retval None
763+
*/
764+
static void MX_IWDG_Init(void)
765+
{
766+
767+
/* USER CODE BEGIN IWDG_Init 0 */
768+
769+
/* USER CODE END IWDG_Init 0 */
770+
771+
/* USER CODE BEGIN IWDG_Init 1 */
772+
773+
/* USER CODE END IWDG_Init 1 */
774+
hiwdg.Instance = IWDG;
775+
hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
776+
hiwdg.Init.Window = 4095;
777+
hiwdg.Init.Reload = 4095;
778+
hiwdg.Init.EWI = 0;
779+
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
780+
{
781+
Error_Handler();
782+
}
783+
/* USER CODE BEGIN IWDG_Init 2 */
784+
785+
/* USER CODE END IWDG_Init 2 */
786+
787+
}
788+
757789
/**
758790
* @brief LPUART1 Initialization Function
759791
* @param None

Core/Src/u_sensors.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#include "lsm6dsv_reg.h"
1616
#include "lis2mdl_reg.h"
1717

18-
extern I2C_HandleTypeDef hi2c1;
19-
extern SPI_HandleTypeDef hspi1;
20-
extern SPI_HandleTypeDef hspi2;
21-
2218
static sht30_t sht30;
2319
static stmdev_ctx_t imu;
2420
static stmdev_ctx_t lis2mdl_ctx;

Core/Src/u_threads.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ static thread_t _default_thread = {
2727
void default_thread(ULONG thread_input) {
2828

2929
while(1) {
30+
/* Kick watch dog */
31+
HAL_IWDG_Refresh(&hiwdg);
32+
3033
/* Sleep Thread for specified number of ticks. */
3134
tx_thread_sleep(_default_thread.sleep);
3235
}

0 commit comments

Comments
 (0)