Add CAN Filter and Watchdog functionality, theoretically complete
This commit is contained in:
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -51,7 +51,7 @@
 | 
				
			|||||||
/*#define HAL_CRYP_MODULE_ENABLED   */
 | 
					/*#define HAL_CRYP_MODULE_ENABLED   */
 | 
				
			||||||
/*#define HAL_DAC_MODULE_ENABLED   */
 | 
					/*#define HAL_DAC_MODULE_ENABLED   */
 | 
				
			||||||
/*#define HAL_I2S_MODULE_ENABLED   */
 | 
					/*#define HAL_I2S_MODULE_ENABLED   */
 | 
				
			||||||
/*#define HAL_IWDG_MODULE_ENABLED   */
 | 
					#define HAL_IWDG_MODULE_ENABLED
 | 
				
			||||||
/*#define HAL_LCD_MODULE_ENABLED   */
 | 
					/*#define HAL_LCD_MODULE_ENABLED   */
 | 
				
			||||||
/*#define HAL_LPTIM_MODULE_ENABLED   */
 | 
					/*#define HAL_LPTIM_MODULE_ENABLED   */
 | 
				
			||||||
/*#define HAL_RNG_MODULE_ENABLED   */
 | 
					/*#define HAL_RNG_MODULE_ENABLED   */
 | 
				
			||||||
 | 
				
			|||||||
@ -57,7 +57,7 @@ typedef enum {
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef union {
 | 
					typedef union {
 | 
				
			||||||
	uint8_t raw[1];
 | 
						uint8_t raw[8]; // Must be 8 bytes because HAL always writes 8 bytes
 | 
				
			||||||
	struct {
 | 
						struct {
 | 
				
			||||||
		// BITFIELDS ARE LSB FIRST!
 | 
							// BITFIELDS ARE LSB FIRST!
 | 
				
			||||||
		bool as_close_sdc : 1;
 | 
							bool as_close_sdc : 1;
 | 
				
			||||||
@ -118,6 +118,9 @@ typedef union {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#define AMI_GPIO_Port GPIOB
 | 
					#define AMI_GPIO_Port GPIOB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//#define WATCHDOG_UCC
 | 
				
			||||||
 | 
					#define WATCHDOG_STM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* USER CODE END PD */
 | 
					/* USER CODE END PD */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Private macro -------------------------------------------------------------*/
 | 
					/* Private macro -------------------------------------------------------------*/
 | 
				
			||||||
@ -128,6 +131,8 @@ typedef union {
 | 
				
			|||||||
/* Private variables ---------------------------------------------------------*/
 | 
					/* Private variables ---------------------------------------------------------*/
 | 
				
			||||||
CAN_HandleTypeDef hcan;
 | 
					CAN_HandleTypeDef hcan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					IWDG_HandleTypeDef hiwdg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* USER CODE BEGIN PV */
 | 
					/* USER CODE BEGIN PV */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Mission Maps:					NONE		ACCEL			SKIDPAD				TRACKDRIVE			EBSTEST				INSPECTION			AUTOX			MANUAL
 | 
					// Mission Maps:					NONE		ACCEL			SKIDPAD				TRACKDRIVE			EBSTEST				INSPECTION			AUTOX			MANUAL
 | 
				
			||||||
@ -136,12 +141,18 @@ const mission_t	mission2next[] 	= {M_MANUAL	, M_SKIDPAD		, M_AUTOX			, M_EBSTEST
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
mission_t mission = M_NONE;
 | 
					mission_t mission = M_NONE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef WATCHDOG_STM
 | 
				
			||||||
 | 
					bool pHeartbeat = false;
 | 
				
			||||||
 | 
					bool WD_OK = false;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* USER CODE END PV */
 | 
					/* USER CODE END PV */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Private function prototypes -----------------------------------------------*/
 | 
					/* Private function prototypes -----------------------------------------------*/
 | 
				
			||||||
void SystemClock_Config(void);
 | 
					void SystemClock_Config(void);
 | 
				
			||||||
static void MX_GPIO_Init(void);
 | 
					static void MX_GPIO_Init(void);
 | 
				
			||||||
static void MX_CAN_Init(void);
 | 
					static void MX_CAN_Init(void);
 | 
				
			||||||
 | 
					static void MX_IWDG_Init(void);
 | 
				
			||||||
/* USER CODE BEGIN PFP */
 | 
					/* USER CODE BEGIN PFP */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* USER CODE END PFP */
 | 
					/* USER CODE END PFP */
 | 
				
			||||||
@ -184,20 +195,23 @@ int main(void)
 | 
				
			|||||||
  /* Initialize all configured peripherals */
 | 
					  /* Initialize all configured peripherals */
 | 
				
			||||||
  MX_GPIO_Init();
 | 
					  MX_GPIO_Init();
 | 
				
			||||||
  MX_CAN_Init();
 | 
					  MX_CAN_Init();
 | 
				
			||||||
 | 
					  MX_IWDG_Init();
 | 
				
			||||||
  /* USER CODE BEGIN 2 */
 | 
					  /* USER CODE BEGIN 2 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Ensure we start with SDC disabled
 | 
				
			||||||
 | 
					  HAL_GPIO_WritePin(Watchdog_GPIO_Port, Watchdog_Pin, GPIO_PIN_RESET);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (HAL_CAN_Start(&hcan) != HAL_OK)
 | 
					  if (HAL_CAN_Start(&hcan) != HAL_OK)
 | 
				
			||||||
  	Error_Handler();
 | 
					  	Error_Handler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // TODO: Use Filter
 | 
					 | 
				
			||||||
  CAN_FilterTypeDef canfilterconfig;
 | 
					  CAN_FilterTypeDef canfilterconfig;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
 | 
					  canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
 | 
				
			||||||
  canfilterconfig.FilterBank = 0;
 | 
					  canfilterconfig.FilterBank = 0;
 | 
				
			||||||
  canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
 | 
					  canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
 | 
				
			||||||
  canfilterconfig.FilterIdHigh = 0;
 | 
					  canfilterconfig.FilterIdHigh = 0 << (16 - 11);
 | 
				
			||||||
  canfilterconfig.FilterIdLow = 0;
 | 
					  canfilterconfig.FilterIdLow = 0;
 | 
				
			||||||
  canfilterconfig.FilterMaskIdHigh = 0;
 | 
					  canfilterconfig.FilterMaskIdHigh = 0x7FF << (16 - 11);
 | 
				
			||||||
  canfilterconfig.FilterMaskIdLow = 0;
 | 
					  canfilterconfig.FilterMaskIdLow = 0;
 | 
				
			||||||
  canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
 | 
					  canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
 | 
				
			||||||
  canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
 | 
					  canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
 | 
				
			||||||
@ -230,13 +244,16 @@ int main(void)
 | 
				
			|||||||
  bool pAMC = false;
 | 
					  bool pAMC = false;
 | 
				
			||||||
  mission_t new_mission = mission; // By default, don't change mission
 | 
					  mission_t new_mission = mission; // By default, don't change mission
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Important to prevent bus error state while ABX is starting up
 | 
				
			||||||
  HAL_Delay(1000);
 | 
					  HAL_Delay(1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  while (true) {
 | 
					  while (true) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool TS_activate_MUXed	= HAL_GPIO_ReadPin(TS_activate_MUXed_GPIO_Port, TS_activate_MUXed_Pin)	== GPIO_PIN_RESET;
 | 
						bool TS_activate_MUXed	= HAL_GPIO_ReadPin(TS_activate_MUXed_GPIO_Port, TS_activate_MUXed_Pin)	== GPIO_PIN_RESET;
 | 
				
			||||||
	bool ASMS				= HAL_GPIO_ReadPin(ASMS_GPIO_Port, ASMS_Pin)							== GPIO_PIN_RESET;
 | 
						bool ASMS				= HAL_GPIO_ReadPin(ASMS_GPIO_Port, ASMS_Pin)							== GPIO_PIN_RESET;
 | 
				
			||||||
	//bool WD_OK				= HAL_GPIO_ReadPin(WD_OK_GPIO_Port, WD_OK_Pin)							== GPIO_PIN_RESET;
 | 
					#ifdef WATCHDOG_UCC
 | 
				
			||||||
 | 
						bool WD_OK				= HAL_GPIO_ReadPin(WD_OK_GPIO_Port, WD_OK_Pin)							== GPIO_PIN_RESET;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
	bool SDC_is_ready		= HAL_GPIO_ReadPin(SDC_is_ready_GPIO_Port, SDC_is_ready_Pin)			== GPIO_PIN_SET;
 | 
						bool SDC_is_ready		= HAL_GPIO_ReadPin(SDC_is_ready_GPIO_Port, SDC_is_ready_Pin)			== GPIO_PIN_SET;
 | 
				
			||||||
	bool SDC_in_3V3			= HAL_GPIO_ReadPin(SDC_in_3V3_GPIO_Port, SDC_in_3V3_Pin)				== GPIO_PIN_SET;
 | 
						bool SDC_in_3V3			= HAL_GPIO_ReadPin(SDC_in_3V3_GPIO_Port, SDC_in_3V3_Pin)				== GPIO_PIN_SET;
 | 
				
			||||||
	bool LV_SENSE_1			= HAL_GPIO_ReadPin(LV_SENSE_1_GPIO_Port, LV_SENSE_1_Pin)				== GPIO_PIN_SET;
 | 
						bool LV_SENSE_1			= HAL_GPIO_ReadPin(LV_SENSE_1_GPIO_Port, LV_SENSE_1_Pin)				== GPIO_PIN_SET;
 | 
				
			||||||
@ -258,9 +275,6 @@ int main(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO: Depends on STM watchdog
 | 
					 | 
				
			||||||
	bool WD_OK = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	txData = (tx_data_t) {
 | 
						txData = (tx_data_t) {
 | 
				
			||||||
		.signals = {
 | 
							.signals = {
 | 
				
			||||||
			.asms_state = ASMS,
 | 
								.asms_state = ASMS,
 | 
				
			||||||
@ -304,9 +318,10 @@ void SystemClock_Config(void)
 | 
				
			|||||||
  /** Initializes the RCC Oscillators according to the specified parameters
 | 
					  /** Initializes the RCC Oscillators according to the specified parameters
 | 
				
			||||||
  * in the RCC_OscInitTypeDef structure.
 | 
					  * in the RCC_OscInitTypeDef structure.
 | 
				
			||||||
  */
 | 
					  */
 | 
				
			||||||
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 | 
					  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
 | 
				
			||||||
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 | 
					  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 | 
				
			||||||
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 | 
					  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 | 
				
			||||||
 | 
					  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
 | 
				
			||||||
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
 | 
					  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
 | 
				
			||||||
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 | 
					  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
@ -365,6 +380,35 @@ static void MX_CAN_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 */
 | 
				
			||||||
 | 
					  hiwdg.Instance = IWDG;
 | 
				
			||||||
 | 
					  hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
 | 
				
			||||||
 | 
					  hiwdg.Init.Window = 1000;
 | 
				
			||||||
 | 
					  hiwdg.Init.Reload = 1000;
 | 
				
			||||||
 | 
					  if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    Error_Handler();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  /* USER CODE BEGIN IWDG_Init 2 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* USER CODE END IWDG_Init 2 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
  * @brief GPIO Initialization Function
 | 
					  * @brief GPIO Initialization Function
 | 
				
			||||||
  * @param None
 | 
					  * @param None
 | 
				
			||||||
@ -425,32 +469,33 @@ static void MX_GPIO_Init(void)
 | 
				
			|||||||
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
 | 
					void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  CAN_RxHeaderTypeDef   rxHeader;
 | 
					  CAN_RxHeaderTypeDef   rxHeader;
 | 
				
			||||||
  // TODO: Remove buffer once filter is implemented?
 | 
					 | 
				
			||||||
  uint8_t				rxBuffer[8];
 | 
					 | 
				
			||||||
  rx_data_t				rxData;
 | 
					  rx_data_t				rxData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Read frame from HW into buffer
 | 
					  // Read frame from HW into buffer
 | 
				
			||||||
  if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rxHeader, rxBuffer) != HAL_OK)
 | 
					  if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rxHeader, rxData.raw) != HAL_OK)
 | 
				
			||||||
    Error_Handler();
 | 
					    Error_Handler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Discard if it's not for us
 | 
					  // Discard if it's not for us (shouldn't happen thanks to filter, but just to be sure)
 | 
				
			||||||
  if (rxHeader.StdId != CAN_ID_RX)
 | 
					  if (rxHeader.StdId != CAN_ID_RX)
 | 
				
			||||||
	  return;
 | 
						  return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // copy to bitfield
 | 
					 | 
				
			||||||
  rxData.raw[0] = rxBuffer[0];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  HAL_GPIO_WritePin(ASB_Error_GPIO_Port, ASB_Error_Pin, rxData.signals.asb_error);
 | 
					  HAL_GPIO_WritePin(ASB_Error_GPIO_Port, ASB_Error_Pin, rxData.signals.asb_error);
 | 
				
			||||||
  HAL_GPIO_WritePin(AS_close_SDC_GPIO_Port, AS_close_SDC_Pin, rxData.signals.as_close_sdc);
 | 
					  HAL_GPIO_WritePin(AS_close_SDC_GPIO_Port, AS_close_SDC_Pin, rxData.signals.as_close_sdc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /*
 | 
					#ifdef WATCHDOG_STM
 | 
				
			||||||
   * TODO: Heartbeat -> Watchdog via STM Watchdog
 | 
					 | 
				
			||||||
   * Also alternative implementation for UCC? With ifdefs?
 | 
					 | 
				
			||||||
   * rxData.signals.heartbeat
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // TODO: TEMP!
 | 
					  if (rxData.signals.heartbeat != pHeartbeat) {
 | 
				
			||||||
  HAL_GPIO_WritePin(Watchdog_GPIO_Port, Watchdog_Pin, true);
 | 
						  HAL_IWDG_Refresh(&hiwdg);
 | 
				
			||||||
 | 
						  WD_OK = true;
 | 
				
			||||||
 | 
					  	  HAL_GPIO_WritePin(Watchdog_GPIO_Port, Watchdog_Pin, GPIO_PIN_SET);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  pHeartbeat = rxData.signals.heartbeat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef WATCHDOG_UCC
 | 
				
			||||||
 | 
					  HAL_GPIO_WritePin(Watchdog_GPIO_Port, Watchdog_Pin, rxData.signals.heartbeat);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Reset old mission LED
 | 
					  // Reset old mission LED
 | 
				
			||||||
  setMissionLED(mission, GPIO_PIN_RESET);
 | 
					  setMissionLED(mission, GPIO_PIN_RESET);
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,240 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					  ******************************************************************************
 | 
				
			||||||
 | 
					  * @file    stm32f3xx_hal_iwdg.h
 | 
				
			||||||
 | 
					  * @author  MCD Application Team
 | 
				
			||||||
 | 
					  * @brief   Header file of IWDG HAL module.
 | 
				
			||||||
 | 
					  ******************************************************************************
 | 
				
			||||||
 | 
					  * @attention
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					  * <h2><center>© Copyright (c) 2016 STMicroelectronics.
 | 
				
			||||||
 | 
					  * All rights reserved.</center></h2>
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					  * This software component is licensed by ST under BSD 3-Clause license,
 | 
				
			||||||
 | 
					  * the "License"; You may not use this file except in compliance with the
 | 
				
			||||||
 | 
					  * License. You may obtain a copy of the License at:
 | 
				
			||||||
 | 
					  *                        opensource.org/licenses/BSD-3-Clause
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					  ******************************************************************************
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Define to prevent recursive inclusion -------------------------------------*/
 | 
				
			||||||
 | 
					#ifndef STM32F3xx_HAL_IWDG_H
 | 
				
			||||||
 | 
					#define STM32F3xx_HAL_IWDG_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Includes ------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#include "stm32f3xx_hal_def.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @addtogroup STM32F3xx_HAL_Driver
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @defgroup IWDG IWDG
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Exported types ------------------------------------------------------------*/
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Exported_Types IWDG Exported Types
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  IWDG Init structure definition
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					typedef struct
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  uint32_t Prescaler;  /*!< Select the prescaler of the IWDG.
 | 
				
			||||||
 | 
					                            This parameter can be a value of @ref IWDG_Prescaler */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  uint32_t Reload;     /*!< Specifies the IWDG down-counter reload value.
 | 
				
			||||||
 | 
					                            This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  uint32_t Window;     /*!< Specifies the window value to be compared to the down-counter.
 | 
				
			||||||
 | 
					                            This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} IWDG_InitTypeDef;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  IWDG Handle Structure definition
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					typedef struct
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  IWDG_TypeDef                 *Instance;  /*!< Register base address    */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  IWDG_InitTypeDef             Init;       /*!< IWDG required parameters */
 | 
				
			||||||
 | 
					} IWDG_HandleTypeDef;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Exported constants --------------------------------------------------------*/
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Exported_Constants IWDG Exported Constants
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Prescaler IWDG Prescaler
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define IWDG_PRESCALER_4                0x00000000u                                     /*!< IWDG prescaler set to 4   */
 | 
				
			||||||
 | 
					#define IWDG_PRESCALER_8                IWDG_PR_PR_0                                    /*!< IWDG prescaler set to 8   */
 | 
				
			||||||
 | 
					#define IWDG_PRESCALER_16               IWDG_PR_PR_1                                    /*!< IWDG prescaler set to 16  */
 | 
				
			||||||
 | 
					#define IWDG_PRESCALER_32               (IWDG_PR_PR_1 | IWDG_PR_PR_0)                   /*!< IWDG prescaler set to 32  */
 | 
				
			||||||
 | 
					#define IWDG_PRESCALER_64               IWDG_PR_PR_2                                    /*!< IWDG prescaler set to 64  */
 | 
				
			||||||
 | 
					#define IWDG_PRESCALER_128              (IWDG_PR_PR_2 | IWDG_PR_PR_0)                   /*!< IWDG prescaler set to 128 */
 | 
				
			||||||
 | 
					#define IWDG_PRESCALER_256              (IWDG_PR_PR_2 | IWDG_PR_PR_1)                   /*!< IWDG prescaler set to 256 */
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Window_option IWDG Window option
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define IWDG_WINDOW_DISABLE             IWDG_WINR_WIN
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Exported macros -----------------------------------------------------------*/
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Exported_Macros IWDG Exported Macros
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Enable the IWDG peripheral.
 | 
				
			||||||
 | 
					  * @param  __HANDLE__  IWDG handle
 | 
				
			||||||
 | 
					  * @retval None
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define __HAL_IWDG_START(__HANDLE__)                WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Reload IWDG counter with value defined in the reload register
 | 
				
			||||||
 | 
					  *         (write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers disabled).
 | 
				
			||||||
 | 
					  * @param  __HANDLE__  IWDG handle
 | 
				
			||||||
 | 
					  * @retval None
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__)       WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Exported functions --------------------------------------------------------*/
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Exported_Functions  IWDG Exported Functions
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Exported_Functions_Group1 Initialization and Start functions
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					/* Initialization/Start functions  ********************************************/
 | 
				
			||||||
 | 
					HAL_StatusTypeDef     HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					/* I/O operation functions ****************************************************/
 | 
				
			||||||
 | 
					HAL_StatusTypeDef     HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Private constants ---------------------------------------------------------*/
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Private_Constants IWDG Private Constants
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  IWDG Key Register BitMask
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define IWDG_KEY_RELOAD                 0x0000AAAAu  /*!< IWDG Reload Counter Enable   */
 | 
				
			||||||
 | 
					#define IWDG_KEY_ENABLE                 0x0000CCCCu  /*!< IWDG Peripheral Enable       */
 | 
				
			||||||
 | 
					#define IWDG_KEY_WRITE_ACCESS_ENABLE    0x00005555u  /*!< IWDG KR Write Access Enable  */
 | 
				
			||||||
 | 
					#define IWDG_KEY_WRITE_ACCESS_DISABLE   0x00000000u  /*!< IWDG KR Write Access Disable */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Private macros ------------------------------------------------------------*/
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Private_Macros IWDG Private Macros
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
 | 
				
			||||||
 | 
					  * @param  __HANDLE__  IWDG handle
 | 
				
			||||||
 | 
					  * @retval None
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__)  WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Disable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
 | 
				
			||||||
 | 
					  * @param  __HANDLE__  IWDG handle
 | 
				
			||||||
 | 
					  * @retval None
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Check IWDG prescaler value.
 | 
				
			||||||
 | 
					  * @param  __PRESCALER__  IWDG prescaler value
 | 
				
			||||||
 | 
					  * @retval None
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define IS_IWDG_PRESCALER(__PRESCALER__)      (((__PRESCALER__) == IWDG_PRESCALER_4)  || \
 | 
				
			||||||
 | 
					                                               ((__PRESCALER__) == IWDG_PRESCALER_8)  || \
 | 
				
			||||||
 | 
					                                               ((__PRESCALER__) == IWDG_PRESCALER_16) || \
 | 
				
			||||||
 | 
					                                               ((__PRESCALER__) == IWDG_PRESCALER_32) || \
 | 
				
			||||||
 | 
					                                               ((__PRESCALER__) == IWDG_PRESCALER_64) || \
 | 
				
			||||||
 | 
					                                               ((__PRESCALER__) == IWDG_PRESCALER_128)|| \
 | 
				
			||||||
 | 
					                                               ((__PRESCALER__) == IWDG_PRESCALER_256))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Check IWDG reload value.
 | 
				
			||||||
 | 
					  * @param  __RELOAD__  IWDG reload value
 | 
				
			||||||
 | 
					  * @retval None
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define IS_IWDG_RELOAD(__RELOAD__)            ((__RELOAD__) <= IWDG_RLR_RL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Check IWDG window value.
 | 
				
			||||||
 | 
					  * @param  __WINDOW__  IWDG window value
 | 
				
			||||||
 | 
					  * @retval None
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#define IS_IWDG_WINDOW(__WINDOW__)            ((__WINDOW__) <= IWDG_WINR_WIN)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* STM32F3xx_HAL_IWDG_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
				
			||||||
@ -0,0 +1,285 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					  ******************************************************************************
 | 
				
			||||||
 | 
					  * @file    stm32f3xx_hal_iwdg.c
 | 
				
			||||||
 | 
					  * @author  MCD Application Team
 | 
				
			||||||
 | 
					  * @brief   IWDG HAL module driver.
 | 
				
			||||||
 | 
					  *          This file provides firmware functions to manage the following
 | 
				
			||||||
 | 
					  *          functionalities of the Independent Watchdog (IWDG) peripheral:
 | 
				
			||||||
 | 
					  *           + Initialization and Start functions
 | 
				
			||||||
 | 
					  *           + IO operation functions
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					  @verbatim
 | 
				
			||||||
 | 
					  ==============================================================================
 | 
				
			||||||
 | 
					                    ##### IWDG Generic features #####
 | 
				
			||||||
 | 
					  ==============================================================================
 | 
				
			||||||
 | 
					  [..]
 | 
				
			||||||
 | 
					    (+) The IWDG can be started by either software or hardware (configurable
 | 
				
			||||||
 | 
					        through option byte).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (+) The IWDG is clocked by the Low-Speed Internal clock (LSI) and thus stays
 | 
				
			||||||
 | 
					        active even if the main clock fails.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (+) Once the IWDG is started, the LSI is forced ON and both cannot be
 | 
				
			||||||
 | 
					        disabled. The counter starts counting down from the reset value (0xFFF).
 | 
				
			||||||
 | 
					        When it reaches the end of count value (0x000) a reset signal is
 | 
				
			||||||
 | 
					        generated (IWDG reset).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register,
 | 
				
			||||||
 | 
					        the IWDG_RLR value is reloaded into the counter and the watchdog reset
 | 
				
			||||||
 | 
					        is prevented.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (+) The IWDG is implemented in the VDD voltage domain that is still functional
 | 
				
			||||||
 | 
					        in STOP and STANDBY mode (IWDG reset can wake up the CPU from STANDBY).
 | 
				
			||||||
 | 
					        IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
 | 
				
			||||||
 | 
					        reset occurs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (+) Debug mode: When the microcontroller enters debug mode (core halted),
 | 
				
			||||||
 | 
					        the IWDG counter either continues to work normally or stops, depending
 | 
				
			||||||
 | 
					        on DBG_IWDG_STOP configuration bit in DBG module, accessible through
 | 
				
			||||||
 | 
					        __HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [..] Min-max timeout value @40KHz (LSI): ~100us / ~26.2s
 | 
				
			||||||
 | 
					         The IWDG timeout may vary due to LSI clock frequency dispersion.
 | 
				
			||||||
 | 
					         STM32F3xx devices provide the capability to measure the LSI clock
 | 
				
			||||||
 | 
					         frequency (LSI clock is internally connected to TIM16 CH1 input capture).
 | 
				
			||||||
 | 
					         The measured value can be used to have an IWDG timeout with an
 | 
				
			||||||
 | 
					         acceptable accuracy.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [..] Default timeout value (necessary for IWDG_SR status register update):
 | 
				
			||||||
 | 
					         Constant LSI_VALUE is defined based on the nominal LSI clock frequency.
 | 
				
			||||||
 | 
					         This frequency being subject to variations as mentioned above, the
 | 
				
			||||||
 | 
					         default timeout value (defined through constant HAL_IWDG_DEFAULT_TIMEOUT
 | 
				
			||||||
 | 
					         below) may become too short or too long.
 | 
				
			||||||
 | 
					         In such cases, this default timeout value can be tuned by redefining
 | 
				
			||||||
 | 
					         the constant LSI_VALUE at user-application level (based, for instance,
 | 
				
			||||||
 | 
					         on the measured LSI clock frequency as explained above).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                     ##### How to use this driver #####
 | 
				
			||||||
 | 
					  ==============================================================================
 | 
				
			||||||
 | 
					  [..]
 | 
				
			||||||
 | 
					    (#) Use IWDG using HAL_IWDG_Init() function to :
 | 
				
			||||||
 | 
					      (++) Enable instance by writing Start keyword in IWDG_KEY register. LSI
 | 
				
			||||||
 | 
					           clock is forced ON and IWDG counter starts counting down.
 | 
				
			||||||
 | 
					      (++) Enable write access to configuration registers:
 | 
				
			||||||
 | 
					          IWDG_PR, IWDG_RLR and IWDG_WINR.
 | 
				
			||||||
 | 
					      (++) Configure the IWDG prescaler and counter reload value. This reload
 | 
				
			||||||
 | 
					           value will be loaded in the IWDG counter each time the watchdog is
 | 
				
			||||||
 | 
					           reloaded, then the IWDG will start counting down from this value.
 | 
				
			||||||
 | 
					      (++) Depending on window parameter:
 | 
				
			||||||
 | 
					        (+++) If Window Init parameter is same as Window register value,
 | 
				
			||||||
 | 
					             nothing more is done but reload counter value in order to exit
 | 
				
			||||||
 | 
					             function with exact time base.
 | 
				
			||||||
 | 
					        (+++) Else modify Window register. This will automatically reload
 | 
				
			||||||
 | 
					             watchdog counter.
 | 
				
			||||||
 | 
					      (++) Wait for status flags to be reset.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (#) Then the application program must refresh the IWDG counter at regular
 | 
				
			||||||
 | 
					        intervals during normal operation to prevent an MCU reset, using
 | 
				
			||||||
 | 
					        HAL_IWDG_Refresh() function.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     *** IWDG HAL driver macros list ***
 | 
				
			||||||
 | 
					     ====================================
 | 
				
			||||||
 | 
					     [..]
 | 
				
			||||||
 | 
					       Below the list of most used macros in IWDG HAL driver:
 | 
				
			||||||
 | 
					      (+) __HAL_IWDG_START: Enable the IWDG peripheral
 | 
				
			||||||
 | 
					      (+) __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in
 | 
				
			||||||
 | 
					          the reload register
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @endverbatim
 | 
				
			||||||
 | 
					  ******************************************************************************
 | 
				
			||||||
 | 
					  * @attention
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					  * <h2><center>© Copyright (c) 2016 STMicroelectronics.
 | 
				
			||||||
 | 
					  * All rights reserved.</center></h2>
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					  * This software component is licensed by ST under BSD 3-Clause license,
 | 
				
			||||||
 | 
					  * the "License"; You may not use this file except in compliance with the
 | 
				
			||||||
 | 
					  * License. You may obtain a copy of the License at:
 | 
				
			||||||
 | 
					  *                        opensource.org/licenses/BSD-3-Clause
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					  ******************************************************************************
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Includes ------------------------------------------------------------------*/
 | 
				
			||||||
 | 
					#include "stm32f3xx_hal.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @addtogroup STM32F3xx_HAL_Driver
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAL_IWDG_MODULE_ENABLED
 | 
				
			||||||
 | 
					/** @addtogroup IWDG
 | 
				
			||||||
 | 
					  * @brief IWDG HAL module driver.
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Private typedef -----------------------------------------------------------*/
 | 
				
			||||||
 | 
					/* Private define ------------------------------------------------------------*/
 | 
				
			||||||
 | 
					/** @defgroup IWDG_Private_Defines IWDG Private Defines
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					/* Status register needs up to 5 LSI clock periods divided by the clock
 | 
				
			||||||
 | 
					   prescaler to be updated. The number of LSI clock periods is upper-rounded to
 | 
				
			||||||
 | 
					   6 for the timeout value calculation.
 | 
				
			||||||
 | 
					   The timeout value is calculated using the highest prescaler (256) and
 | 
				
			||||||
 | 
					   the LSI_VALUE constant. The value of this constant can be changed by the user
 | 
				
			||||||
 | 
					   to take into account possible LSI clock period variations.
 | 
				
			||||||
 | 
					   The timeout value is multiplied by 1000 to be converted in milliseconds.
 | 
				
			||||||
 | 
					   LSI startup time is also considered here by adding LSI_STARTUP_TIMEOUT
 | 
				
			||||||
 | 
					   converted in milliseconds. */
 | 
				
			||||||
 | 
					#define HAL_IWDG_DEFAULT_TIMEOUT        (((6UL * 256UL * 1000UL) / LSI_VALUE) + ((LSI_STARTUP_TIME / 1000UL) + 1UL))
 | 
				
			||||||
 | 
					#define IWDG_KERNEL_UPDATE_FLAGS        (IWDG_SR_WVU | IWDG_SR_RVU | IWDG_SR_PVU)
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Private macro -------------------------------------------------------------*/
 | 
				
			||||||
 | 
					/* Private variables ---------------------------------------------------------*/
 | 
				
			||||||
 | 
					/* Private function prototypes -----------------------------------------------*/
 | 
				
			||||||
 | 
					/* Exported functions --------------------------------------------------------*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @addtogroup IWDG_Exported_Functions
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @addtogroup IWDG_Exported_Functions_Group1
 | 
				
			||||||
 | 
					  *  @brief    Initialization and Start functions.
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					@verbatim
 | 
				
			||||||
 | 
					 ===============================================================================
 | 
				
			||||||
 | 
					          ##### Initialization and Start functions #####
 | 
				
			||||||
 | 
					 ===============================================================================
 | 
				
			||||||
 | 
					 [..]  This section provides functions allowing to:
 | 
				
			||||||
 | 
					      (+) Initialize the IWDG according to the specified parameters in the
 | 
				
			||||||
 | 
					          IWDG_InitTypeDef of associated handle.
 | 
				
			||||||
 | 
					      (+) Manage Window option.
 | 
				
			||||||
 | 
					      (+) Once initialization is performed in HAL_IWDG_Init function, Watchdog
 | 
				
			||||||
 | 
					          is reloaded in order to exit function with correct time base.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@endverbatim
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Initialize the IWDG according to the specified parameters in the
 | 
				
			||||||
 | 
					  *         IWDG_InitTypeDef and start watchdog. Before exiting function,
 | 
				
			||||||
 | 
					  *         watchdog is refreshed in order to have correct time base.
 | 
				
			||||||
 | 
					  * @param  hiwdg  pointer to a IWDG_HandleTypeDef structure that contains
 | 
				
			||||||
 | 
					  *                the configuration information for the specified IWDG module.
 | 
				
			||||||
 | 
					  * @retval HAL status
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  uint32_t tickstart;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Check the IWDG handle allocation */
 | 
				
			||||||
 | 
					  if (hiwdg == NULL)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    return HAL_ERROR;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Check the parameters */
 | 
				
			||||||
 | 
					  assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
 | 
				
			||||||
 | 
					  assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
 | 
				
			||||||
 | 
					  assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
 | 
				
			||||||
 | 
					  assert_param(IS_IWDG_WINDOW(hiwdg->Init.Window));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Enable IWDG. LSI is turned on automatically */
 | 
				
			||||||
 | 
					  __HAL_IWDG_START(hiwdg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers by writing
 | 
				
			||||||
 | 
					  0x5555 in KR */
 | 
				
			||||||
 | 
					  IWDG_ENABLE_WRITE_ACCESS(hiwdg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Write to IWDG registers the Prescaler & Reload values to work with */
 | 
				
			||||||
 | 
					  hiwdg->Instance->PR = hiwdg->Init.Prescaler;
 | 
				
			||||||
 | 
					  hiwdg->Instance->RLR = hiwdg->Init.Reload;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Check pending flag, if previous update not done, return timeout */
 | 
				
			||||||
 | 
					  tickstart = HAL_GetTick();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Wait for register to be updated */
 | 
				
			||||||
 | 
					  while ((hiwdg->Instance->SR & IWDG_KERNEL_UPDATE_FLAGS) != 0x00u)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      if ((hiwdg->Instance->SR & IWDG_KERNEL_UPDATE_FLAGS) != 0x00u)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        return HAL_TIMEOUT;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* If window parameter is different than current value, modify window
 | 
				
			||||||
 | 
					  register */
 | 
				
			||||||
 | 
					  if (hiwdg->Instance->WINR != hiwdg->Init.Window)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    /* Write to IWDG WINR the IWDG_Window value to compare with. In any case,
 | 
				
			||||||
 | 
					    even if window feature is disabled, Watchdog will be reloaded by writing
 | 
				
			||||||
 | 
					    windows register */
 | 
				
			||||||
 | 
					    hiwdg->Instance->WINR = hiwdg->Init.Window;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    /* Reload IWDG counter with value defined in the reload register */
 | 
				
			||||||
 | 
					    __HAL_IWDG_RELOAD_COUNTER(hiwdg);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Return function status */
 | 
				
			||||||
 | 
					  return HAL_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @addtogroup IWDG_Exported_Functions_Group2
 | 
				
			||||||
 | 
					  *  @brief   IO operation functions
 | 
				
			||||||
 | 
					  *
 | 
				
			||||||
 | 
					@verbatim
 | 
				
			||||||
 | 
					 ===============================================================================
 | 
				
			||||||
 | 
					                      ##### IO operation functions #####
 | 
				
			||||||
 | 
					 ===============================================================================
 | 
				
			||||||
 | 
					 [..]  This section provides functions allowing to:
 | 
				
			||||||
 | 
					      (+) Refresh the IWDG.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@endverbatim
 | 
				
			||||||
 | 
					  * @{
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @brief  Refresh the IWDG.
 | 
				
			||||||
 | 
					  * @param  hiwdg  pointer to a IWDG_HandleTypeDef structure that contains
 | 
				
			||||||
 | 
					  *                the configuration information for the specified IWDG module.
 | 
				
			||||||
 | 
					  * @retval HAL status
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  /* Reload IWDG counter with value defined in the reload register */
 | 
				
			||||||
 | 
					  __HAL_IWDG_RELOAD_COUNTER(hiwdg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Return function status */
 | 
				
			||||||
 | 
					  return HAL_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* HAL_IWDG_MODULE_ENABLED */
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  * @}
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 | 
				
			||||||
@ -12,14 +12,18 @@ CAN.Prescaler=1
 | 
				
			|||||||
CAN.SJW=CAN_SJW_1TQ
 | 
					CAN.SJW=CAN_SJW_1TQ
 | 
				
			||||||
File.Version=6
 | 
					File.Version=6
 | 
				
			||||||
GPIO.groupedBy=Group By Peripherals
 | 
					GPIO.groupedBy=Group By Peripherals
 | 
				
			||||||
 | 
					IWDG.IPParameters=Window,Reload
 | 
				
			||||||
 | 
					IWDG.Reload=1000
 | 
				
			||||||
 | 
					IWDG.Window=1000
 | 
				
			||||||
KeepUserPlacement=false
 | 
					KeepUserPlacement=false
 | 
				
			||||||
Mcu.CPN=STM32F302C8T6
 | 
					Mcu.CPN=STM32F302C8T6
 | 
				
			||||||
Mcu.Family=STM32F3
 | 
					Mcu.Family=STM32F3
 | 
				
			||||||
Mcu.IP0=CAN
 | 
					Mcu.IP0=CAN
 | 
				
			||||||
Mcu.IP1=NVIC
 | 
					Mcu.IP1=IWDG
 | 
				
			||||||
Mcu.IP2=RCC
 | 
					Mcu.IP2=NVIC
 | 
				
			||||||
Mcu.IP3=SYS
 | 
					Mcu.IP3=RCC
 | 
				
			||||||
Mcu.IPNb=4
 | 
					Mcu.IP4=SYS
 | 
				
			||||||
 | 
					Mcu.IPNb=5
 | 
				
			||||||
Mcu.Name=STM32F302C(6-8)Tx
 | 
					Mcu.Name=STM32F302C(6-8)Tx
 | 
				
			||||||
Mcu.Package=LQFP48
 | 
					Mcu.Package=LQFP48
 | 
				
			||||||
Mcu.Pin0=PA0
 | 
					Mcu.Pin0=PA0
 | 
				
			||||||
@ -41,7 +45,8 @@ Mcu.Pin22=PB6
 | 
				
			|||||||
Mcu.Pin23=PB7
 | 
					Mcu.Pin23=PB7
 | 
				
			||||||
Mcu.Pin24=PB8
 | 
					Mcu.Pin24=PB8
 | 
				
			||||||
Mcu.Pin25=PB9
 | 
					Mcu.Pin25=PB9
 | 
				
			||||||
Mcu.Pin26=VP_SYS_VS_Systick
 | 
					Mcu.Pin26=VP_IWDG_VS_IWDG
 | 
				
			||||||
 | 
					Mcu.Pin27=VP_SYS_VS_Systick
 | 
				
			||||||
Mcu.Pin3=PA3
 | 
					Mcu.Pin3=PA3
 | 
				
			||||||
Mcu.Pin4=PA4
 | 
					Mcu.Pin4=PA4
 | 
				
			||||||
Mcu.Pin5=PA5
 | 
					Mcu.Pin5=PA5
 | 
				
			||||||
@ -49,7 +54,7 @@ Mcu.Pin6=PA6
 | 
				
			|||||||
Mcu.Pin7=PA7
 | 
					Mcu.Pin7=PA7
 | 
				
			||||||
Mcu.Pin8=PB0
 | 
					Mcu.Pin8=PB0
 | 
				
			||||||
Mcu.Pin9=PB1
 | 
					Mcu.Pin9=PB1
 | 
				
			||||||
Mcu.PinsNb=27
 | 
					Mcu.PinsNb=28
 | 
				
			||||||
Mcu.ThirdPartyNb=0
 | 
					Mcu.ThirdPartyNb=0
 | 
				
			||||||
Mcu.UserConstants=
 | 
					Mcu.UserConstants=
 | 
				
			||||||
Mcu.UserName=STM32F302C8Tx
 | 
					Mcu.UserName=STM32F302C8Tx
 | 
				
			||||||
@ -259,10 +264,11 @@ ProjectManager.StackSize=0x400
 | 
				
			|||||||
ProjectManager.TargetToolchain=STM32CubeIDE
 | 
					ProjectManager.TargetToolchain=STM32CubeIDE
 | 
				
			||||||
ProjectManager.ToolChainLocation=
 | 
					ProjectManager.ToolChainLocation=
 | 
				
			||||||
ProjectManager.UnderRoot=true
 | 
					ProjectManager.UnderRoot=true
 | 
				
			||||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_CAN_Init-CAN-false-HAL-true
 | 
					ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_CAN_Init-CAN-false-HAL-true,4-MX_WWDG_Init-WWDG-false-HAL-true
 | 
				
			||||||
RCC.ADC12outputFreq_Value=16000000
 | 
					RCC.ADC12outputFreq_Value=16000000
 | 
				
			||||||
RCC.AHBFreq_Value=8000000
 | 
					RCC.AHBFreq_Value=8000000
 | 
				
			||||||
RCC.APB1Freq_Value=8000000
 | 
					RCC.APB1Freq_Value=8000000
 | 
				
			||||||
 | 
					RCC.APB1TimFreq_Value=8000000
 | 
				
			||||||
RCC.APB2Freq_Value=8000000
 | 
					RCC.APB2Freq_Value=8000000
 | 
				
			||||||
RCC.CortexFreq_Value=8000000
 | 
					RCC.CortexFreq_Value=8000000
 | 
				
			||||||
RCC.FamilyName=M
 | 
					RCC.FamilyName=M
 | 
				
			||||||
@ -273,7 +279,7 @@ RCC.HSI_VALUE=8000000
 | 
				
			|||||||
RCC.I2C1Freq_Value=8000000
 | 
					RCC.I2C1Freq_Value=8000000
 | 
				
			||||||
RCC.I2C2Freq_Value=8000000
 | 
					RCC.I2C2Freq_Value=8000000
 | 
				
			||||||
RCC.I2C3Freq_Value=8000000
 | 
					RCC.I2C3Freq_Value=8000000
 | 
				
			||||||
RCC.IPParameters=ADC12outputFreq_Value,AHBFreq_Value,APB1Freq_Value,APB2Freq_Value,CortexFreq_Value,FamilyName,HSEPLLFreq_Value,HSE_VALUE,HSIPLLFreq_Value,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,LSE_VALUE,LSI_VALUE,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,TIM2Freq_Value,USART1Freq_Value,USBFreq_Value,VCOOutput2Freq_Value
 | 
					RCC.IPParameters=ADC12outputFreq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,CortexFreq_Value,FamilyName,HSEPLLFreq_Value,HSE_VALUE,HSIPLLFreq_Value,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,LSE_VALUE,LSI_VALUE,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,TIM2Freq_Value,USART1Freq_Value,USBFreq_Value,VCOOutput2Freq_Value
 | 
				
			||||||
RCC.LSE_VALUE=32768
 | 
					RCC.LSE_VALUE=32768
 | 
				
			||||||
RCC.LSI_VALUE=40000
 | 
					RCC.LSI_VALUE=40000
 | 
				
			||||||
RCC.PLLCLKFreq_Value=16000000
 | 
					RCC.PLLCLKFreq_Value=16000000
 | 
				
			||||||
@ -286,6 +292,8 @@ RCC.TIM2Freq_Value=8000000
 | 
				
			|||||||
RCC.USART1Freq_Value=8000000
 | 
					RCC.USART1Freq_Value=8000000
 | 
				
			||||||
RCC.USBFreq_Value=16000000
 | 
					RCC.USBFreq_Value=16000000
 | 
				
			||||||
RCC.VCOOutput2Freq_Value=4000000
 | 
					RCC.VCOOutput2Freq_Value=4000000
 | 
				
			||||||
 | 
					VP_IWDG_VS_IWDG.Mode=IWDG_Activate
 | 
				
			||||||
 | 
					VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG
 | 
				
			||||||
VP_SYS_VS_Systick.Mode=SysTick
 | 
					VP_SYS_VS_Systick.Mode=SysTick
 | 
				
			||||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
 | 
					VP_SYS_VS_Systick.Signal=SYS_VS_Systick
 | 
				
			||||||
board=custom
 | 
					board=custom
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user