diff --git a/Core/Inc/adc.h b/Core/Inc/adc.h index 145bcad..4580b14 100644 --- a/Core/Inc/adc.h +++ b/Core/Inc/adc.h @@ -1,148 +1,148 @@ -/* USER CODE BEGIN Header */ -/** - * @file adc.h - * @prefix ADC - * @author Simone Ruffini [simone.ruffini.work@gmail.com | simone.ruffini@squadracorse.com] - * @date Thu Jun 1 07:14:33 PM CEST 2023 - * - * @brief This file contains all the function prototypes for the adc.c file - * - * @license Licensed under "THE BEER-WARE LICENSE", Revision 69 (see LICENSE) - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __ADC_H__ -#define __ADC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ -#include - -/* USER CODE END Includes */ - -extern ADC_HandleTypeDef hadc1; - -/* USER CODE BEGIN Private defines */ - -enum ADC_Channel { - ADC_Channel0 = 0, - ADC_Channel1 , - ADC_Channel2 , - ADC_Channel3 , - ADC_Channel4 , - ADC_Channel5 , - ADC_Channel6 , - ADC_Channel7 , - ADC_Channel8 , - ADC_Channel9 , - ADC_Channel10 , - ADC_Channel11 , - ADC_Channel12 , - ADC_Channel13 , - ADC_Channel14 , - ADC_Channel15 , - ADC_Channel16 , - ADC_Channel17 , - ADC_Channel18 , - ADC_Channel_NUM -}; - -/* USER CODE END Private defines */ - -void MX_ADC1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -#define ADC_ADC1_VREF_V (3.3f) /*!< ADC1 voltage reference in millivolt float*/ - -/** -* TODO: Calculate correct alpha value using nyquist *4 filtering at the sampling speed -* RC = 100ms => FREQcut_off = 10Hz -* alpha = sampling_period / (RC + sampling_period) -* = 1ms/(100ms+1ms) = 1/101 = 0.00999 ~ 1*10E-2 -*/ -#define ADC_ADC1_IIR_ALPHA \ - (0.1) /*!< ADC1 Infinite Impulse Response filter (1 order) alpha value (smooth factor) - @NOTE if the sampling changes update this value */ - -/** - * @brief Get the resolution of the ADC in bits given the ADC Handle pointer - * @param HADC_INSTANCE_PTR ADC Handle pointer of type @ref ADC_HandleTypeDef* - * @return Resolution in bits for the ADC used if it exists otherwise 0 - */ -#define ADC_GET_RESOLUTION_BITS(HADC_INSTANCE_PTR) \ - (ADC_GET_RESOLUTION(HADC_INSTANCE_PTR) == ADC_RESOLUTION_12B ? 12U \ - : ADC_GET_RESOLUTION(HADC_INSTANCE_PTR) == ADC_RESOLUTION_10B ? (10U) \ - : ADC_GET_RESOLUTION(HADC_INSTANCE_PTR) == ADC_RESOLUTION_8B ? (8U) \ - : ADC_GET_RESOLUTION(HADC_INSTANCE_PTR) == ADC_RESOLUTION_6B ? (6U) \ - : (0U)) - -/** - * @brief return the raw value read by the ADC1 on given channel - * @param channel @ref enum ADC_Channel - * @return converted raw value of channel - * -1 in case wrong channel given - */ -int16_t ADC_ADC1_getChannelRaw(enum ADC_Channel channel); - - -/** - * @brief return the raw filtered value read by the ADC1 on given channel - * @param channel @ref enum ADC_Channel - * @return converted raw filtered value of channel - * -1 in case wrong channel given - */ -int16_t ADC_ADC1_getChannelRawFiltered(enum ADC_Channel channel); - -/** - * @brief Convert ADC raw value to volts given the adc voltage reference in - * volts and its resolution - * @param ADC_RAW_VALUE The sampled value from the ADC - * @param ADC_RESOLUTION_BITS The resolution of the adc in bits (e.g: 12U) - * @param ADC_VREF_mV The ADC reference voltage in millivolts - * @return Analog rappresentation in volts (float) of ADC_RAW_VALUE - */ -#define ADC_CONV_RAW_TO_V(ADC_RAW_VALUE, ADC_RESOLUTION_BITS, ADC_VREF_V) \ - ((float)(ADC_VREF_V) / ((1U) << (ADC_RESOLUTION_BITS)) * ADC_RAW_VALUE) - -// TODO: remove old stuff -///** -// * @brief Get the Filtered Raw Value of an ADC channel given the ADC peripheral -// * @param hadc Pointer to the ADC peripheral @ref ADC_HandleTypeDef -// * @param adc_channel Channel Number of the given value in the ADC @see main.h -// * @return - adc filtered raw value of the channel in uin32_t form must apply later ranging and covnersions -// * - -1U in case of error -// */ -//uint32_t ADC_Get_Filtered_Raw(ADC_HandleTypeDef *hadc, uint8_t adc_channel); -// -///** -// * @brief Get the Filtered Real Value of an ADC channel given the ADC peripheral -// * @param hadc Pointer to the ADC peripheral @ref ADC_HandleTypeDef -// * @param adc_channel Channel Number of the given value in the ADC @see main.h -// * @return - adc filtered real/phisycal value of the channel -// * - DBL_MAX in case of error -// */ -//double ADC_Get_Filtered_Real(ADC_HandleTypeDef *hadc, uint8_t adc_channel); -// -///** -// * @brief Transform an ADC raw value into it's real form given the ADC_channel and ADC peripheral it was sampled from -// * @param hadc Pointer to the ADC peripheral @ref ADC_HandleTypeDef -// * @param adc_channel Channel Number of the given value in the ADC @see main.h -// * @param adc_raw Raw adc value sampled by the adc -// * @return Real value of the sampled value. The meaning of this value depends on the measured channel -// */ -//double ADC_RawToReal(ADC_HandleTypeDef *hadc, uint8_t adc_channel, uint32_t raw_adc_value); -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ADC_H__ */ - +/* USER CODE BEGIN Header */ +/** + * @file adc.h + * @prefix ADC + * @author Simone Ruffini [simone.ruffini.work@gmail.com | simone.ruffini@squadracorse.com] + * @date Thu Jun 1 07:14:33 PM CEST 2023 + * + * @brief This file contains all the function prototypes for the adc.c file + * + * @license Licensed under "THE BEER-WARE LICENSE", Revision 69 (see LICENSE) + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __ADC_H__ +#define __ADC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ +#include + +/* USER CODE END Includes */ + +extern ADC_HandleTypeDef hadc1; + +/* USER CODE BEGIN Private defines */ + +enum ADC_Channel { + ADC_Channel0 = 0, + ADC_Channel1 , + ADC_Channel2 , + ADC_Channel3 , + ADC_Channel4 , + ADC_Channel5 , + ADC_Channel6 , + ADC_Channel7 , + ADC_Channel8 , + ADC_Channel9 , + ADC_Channel10 , + ADC_Channel11 , + ADC_Channel12 , + ADC_Channel13 , + ADC_Channel14 , + ADC_Channel15 , + ADC_Channel16 , + ADC_Channel17 , + ADC_Channel18 , + ADC_Channel_NUM +}; + +/* USER CODE END Private defines */ + +void MX_ADC1_Init(void); + +/* USER CODE BEGIN Prototypes */ + +#define ADC_ADC1_VREF_V (3.3f) /*!< ADC1 voltage reference in millivolt float*/ + +/** +* TODO: Calculate correct alpha value using nyquist *4 filtering at the sampling speed +* RC = 100ms => FREQcut_off = 10Hz +* alpha = sampling_period / (RC + sampling_period) +* = 1ms/(100ms+1ms) = 1/101 = 0.00999 ~ 1*10E-2 +*/ +#define ADC_ADC1_IIR_ALPHA \ + (0.1) /*!< ADC1 Infinite Impulse Response filter (1 order) alpha value (smooth factor) + @NOTE if the sampling changes update this value */ + +/** + * @brief Get the resolution of the ADC in bits given the ADC Handle pointer + * @param HADC_INSTANCE_PTR ADC Handle pointer of type @ref ADC_HandleTypeDef* + * @return Resolution in bits for the ADC used if it exists otherwise 0 + */ +#define ADC_GET_RESOLUTION_BITS(HADC_INSTANCE_PTR) \ + (ADC_GET_RESOLUTION(HADC_INSTANCE_PTR) == ADC_RESOLUTION_12B ? 12U \ + : ADC_GET_RESOLUTION(HADC_INSTANCE_PTR) == ADC_RESOLUTION_10B ? (10U) \ + : ADC_GET_RESOLUTION(HADC_INSTANCE_PTR) == ADC_RESOLUTION_8B ? (8U) \ + : ADC_GET_RESOLUTION(HADC_INSTANCE_PTR) == ADC_RESOLUTION_6B ? (6U) \ + : (0U)) + +/** + * @brief return the raw value read by the ADC1 on given channel + * @param channel @ref enum ADC_Channel + * @return converted raw value of channel + * -1 in case wrong channel given + */ +int16_t ADC_ADC1_getChannelRaw(enum ADC_Channel channel); + + +/** + * @brief return the raw filtered value read by the ADC1 on given channel + * @param channel @ref enum ADC_Channel + * @return converted raw filtered value of channel + * -1 in case wrong channel given + */ +int16_t ADC_ADC1_getChannelRawFiltered(enum ADC_Channel channel); + +/** + * @brief Convert ADC raw value to volts given the adc voltage reference in + * volts and its resolution + * @param ADC_RAW_VALUE The sampled value from the ADC + * @param ADC_RESOLUTION_BITS The resolution of the adc in bits (e.g: 12U) + * @param ADC_VREF_mV The ADC reference voltage in millivolts + * @return Analog rappresentation in volts (float) of ADC_RAW_VALUE + */ +#define ADC_CONV_RAW_TO_V(ADC_RAW_VALUE, ADC_RESOLUTION_BITS, ADC_VREF_V) \ + ((float)(ADC_VREF_V) / ((1U) << (ADC_RESOLUTION_BITS)) * ADC_RAW_VALUE) + +// TODO: remove old stuff +///** +// * @brief Get the Filtered Raw Value of an ADC channel given the ADC peripheral +// * @param hadc Pointer to the ADC peripheral @ref ADC_HandleTypeDef +// * @param adc_channel Channel Number of the given value in the ADC @see main.h +// * @return - adc filtered raw value of the channel in uin32_t form must apply later ranging and covnersions +// * - -1U in case of error +// */ +//uint32_t ADC_Get_Filtered_Raw(ADC_HandleTypeDef *hadc, uint8_t adc_channel); +// +///** +// * @brief Get the Filtered Real Value of an ADC channel given the ADC peripheral +// * @param hadc Pointer to the ADC peripheral @ref ADC_HandleTypeDef +// * @param adc_channel Channel Number of the given value in the ADC @see main.h +// * @return - adc filtered real/phisycal value of the channel +// * - DBL_MAX in case of error +// */ +//double ADC_Get_Filtered_Real(ADC_HandleTypeDef *hadc, uint8_t adc_channel); +// +///** +// * @brief Transform an ADC raw value into it's real form given the ADC_channel and ADC peripheral it was sampled from +// * @param hadc Pointer to the ADC peripheral @ref ADC_HandleTypeDef +// * @param adc_channel Channel Number of the given value in the ADC @see main.h +// * @param adc_raw Raw adc value sampled by the adc +// * @return Real value of the sampled value. The meaning of this value depends on the measured channel +// */ +//double ADC_RawToReal(ADC_HandleTypeDef *hadc, uint8_t adc_channel, uint32_t raw_adc_value); +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __ADC_H__ */ + diff --git a/Core/Inc/can.h b/Core/Inc/can.h index aaf99be..83fc885 100644 --- a/Core/Inc/can.h +++ b/Core/Inc/can.h @@ -1,56 +1,56 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file can.h - * @brief This file contains all the function prototypes for - * the can.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __CAN_H__ -#define __CAN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ -/* USER CODE END Includes */ - -extern CAN_HandleTypeDef hcan1; - -/* USER CODE BEGIN Private defines */ -/* USER CODE END Private defines */ - -void MX_CAN1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -extern CAN_TxHeaderTypeDef CAN_CAN1_tx_header; -extern volatile uint8_t CAN_err; - - -HAL_StatusTypeDef CAN_send(CAN_HandleTypeDef *hcan, uint8_t *buffer, CAN_TxHeaderTypeDef *header); - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CAN_H__ */ - +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file can.h + * @brief This file contains all the function prototypes for + * the can.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __CAN_H__ +#define __CAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ +/* USER CODE END Includes */ + +extern CAN_HandleTypeDef hcan1; + +/* USER CODE BEGIN Private defines */ +/* USER CODE END Private defines */ + +void MX_CAN1_Init(void); + +/* USER CODE BEGIN Prototypes */ + +extern CAN_TxHeaderTypeDef CAN_CAN1_tx_header; +extern volatile uint8_t CAN_err; + + +HAL_StatusTypeDef CAN_send(CAN_HandleTypeDef *hcan, uint8_t *buffer, CAN_TxHeaderTypeDef *header); + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __CAN_H__ */ + diff --git a/Core/Inc/conf.h b/Core/Inc/conf.h index 4fa8b61..c98ae14 100644 --- a/Core/Inc/conf.h +++ b/Core/Inc/conf.h @@ -24,7 +24,7 @@ /* ---------- Exported constants --------------------------------------------*/ #define VERSION_MAJOR 3 #define VERSION_MINOR 0 -#define VERSION_PATCH 1 +#define VERSION_PATCH 2 #define DEBUG_SERIAL #define DEBUG_AIN diff --git a/Core/Inc/dma.h b/Core/Inc/dma.h index 959a5b0..9b1e623 100644 --- a/Core/Inc/dma.h +++ b/Core/Inc/dma.h @@ -1,52 +1,52 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.h - * @brief This file contains all the function prototypes for - * the dma.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __DMA_H__ -#define __DMA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* DMA memory to memory transfer handles -------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_DMA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __DMA_H__ */ - +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file dma.h + * @brief This file contains all the function prototypes for + * the dma.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __DMA_H__ +#define __DMA_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* DMA memory to memory transfer handles -------------------------------------*/ + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_DMA_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __DMA_H__ */ + diff --git a/Core/Inc/gpio.h b/Core/Inc/gpio.h index 21473d8..c0cd1c5 100644 --- a/Core/Inc/gpio.h +++ b/Core/Inc/gpio.h @@ -1,79 +1,79 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ -#include - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ -#define GPIO_IntEventCnt_t uint8_t -#define GPIO_IntEventCnt_MAX_VAL (UINT8_MAX) -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -enum GPIO_IntEventsEnum { - SD_FB_SD_FNL_IN_TO_SD_DLY_CAPS, - AMS_ERR, - IMD_ERR, - FB_ANY_IMPL_ERR_LTCH, - FB_DCBUS_OVER_60V_IMPL_ERR, - // keep the below enum - GPIO_INT_EVENTS_ENUM_NUM -}; - -extern GPIO_IntEventCnt_t GPIO_rise_edge_events[GPIO_INT_EVENTS_ENUM_NUM]; -extern GPIO_IntEventCnt_t GPIO_fall_edge_events[GPIO_INT_EVENTS_ENUM_NUM]; - -void GPIO_IntRiseEdgeCnt_OverrunErr_callback(void); -void GPIO_IntFallEdgeCnt_OverrunErr_callback(void); - -void GPIO_IntEventRoutine(); - -/** -* @brief Get a decimal representation of the state of a GPIO -* @param __GPIO_BASE_NAME__ The base name of a GPIO i.e. the one found in main.h but without _Pin or _GPIO_Port -* @retval decimal representation of the GPIO: 0U if OFF, MAX_UINT if ON -*/ -#define GPIO_READ_PIN_DEC(__GPIO_BASE_NAME__) \ - (HAL_GPIO_ReadPin(__GPIO_BASE_NAME__##_GPIO_Port, __GPIO_BASE_NAME__##_Pin) == GPIO_PIN_SET ? (-1U) : (0U)) - -#define GPIO_READ_PIN(__GPIO_BASE_NAME__) HAL_GPIO_ReadPin(__GPIO_BASE_NAME__##_GPIO_Port, __GPIO_BASE_NAME__##_Pin) - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ - +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.h + * @brief This file contains all the function prototypes for + * the gpio.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __GPIO_H__ +#define __GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ +#include + +/* USER CODE END Includes */ + +/* USER CODE BEGIN Private defines */ +#define GPIO_IntEventCnt_t uint8_t +#define GPIO_IntEventCnt_MAX_VAL (UINT8_MAX) +/* USER CODE END Private defines */ + +void MX_GPIO_Init(void); + +/* USER CODE BEGIN Prototypes */ + +enum GPIO_IntEventsEnum { + SD_FB_SD_FNL_IN_TO_SD_DLY_CAPS, + AMS_ERR, + IMD_ERR, + FB_ANY_IMPL_ERR_LTCH, + FB_DCBUS_OVER_60V_IMPL_ERR, + // keep the below enum + GPIO_INT_EVENTS_ENUM_NUM +}; + +extern GPIO_IntEventCnt_t GPIO_rise_edge_events[GPIO_INT_EVENTS_ENUM_NUM]; +extern GPIO_IntEventCnt_t GPIO_fall_edge_events[GPIO_INT_EVENTS_ENUM_NUM]; + +void GPIO_IntRiseEdgeCnt_OverrunErr_callback(void); +void GPIO_IntFallEdgeCnt_OverrunErr_callback(void); + +void GPIO_IntEventRoutine(); + +/** +* @brief Get a decimal representation of the state of a GPIO +* @param __GPIO_BASE_NAME__ The base name of a GPIO i.e. the one found in main.h but without _Pin or _GPIO_Port +* @retval decimal representation of the GPIO: 0U if OFF, MAX_UINT if ON +*/ +#define GPIO_READ_PIN_DEC(__GPIO_BASE_NAME__) \ + (HAL_GPIO_ReadPin(__GPIO_BASE_NAME__##_GPIO_Port, __GPIO_BASE_NAME__##_Pin) == GPIO_PIN_SET ? (-1U) : (0U)) + +#define GPIO_READ_PIN(__GPIO_BASE_NAME__) HAL_GPIO_ReadPin(__GPIO_BASE_NAME__##_GPIO_Port, __GPIO_BASE_NAME__##_Pin) + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif +#endif /*__ GPIO_H__ */ + diff --git a/Core/Inc/iwdg.h b/Core/Inc/iwdg.h index ecf58c0..71f17ef 100644 --- a/Core/Inc/iwdg.h +++ b/Core/Inc/iwdg.h @@ -1,52 +1,52 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file iwdg.h - * @brief This file contains all the function prototypes for - * the iwdg.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __IWDG_H__ -#define __IWDG_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern IWDG_HandleTypeDef hiwdg; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_IWDG_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __IWDG_H__ */ - +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file iwdg.h + * @brief This file contains all the function prototypes for + * the iwdg.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __IWDG_H__ +#define __IWDG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern IWDG_HandleTypeDef hiwdg; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_IWDG_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __IWDG_H__ */ + diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 58c0e6d..adbedbb 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -1,125 +1,125 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.h - * @brief : Header for main.c file. - * This file contains the common defines of the application. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MAIN_H -#define __MAIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Exported types ------------------------------------------------------------*/ -/* USER CODE BEGIN ET */ - -/* USER CODE END ET */ - -/* Exported constants --------------------------------------------------------*/ -/* USER CODE BEGIN EC */ - -/* USER CODE END EC */ - -/* Exported macro ------------------------------------------------------------*/ -/* USER CODE BEGIN EM */ - -/* USER CODE END EM */ - -/* Exported functions prototypes ---------------------------------------------*/ -void Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define IMD_ERR_LATCH_GPIO_IN_Pin GPIO_PIN_0 -#define IMD_ERR_LATCH_GPIO_IN_GPIO_Port GPIOC -#define SDC_POST_AMS_IMD_RLY_GPIO_IN_Pin GPIO_PIN_1 -#define SDC_POST_AMS_IMD_RLY_GPIO_IN_GPIO_Port GPIOC -#define SDC_TSAC_INIT_IN_ADC_IN_Pin GPIO_PIN_3 -#define SDC_TSAC_INIT_IN_ADC_IN_GPIO_Port GPIOC -#define SDC_TSAC_FINAL_IN_ADC_IN_Pin GPIO_PIN_0 -#define SDC_TSAC_FINAL_IN_ADC_IN_GPIO_Port GPIOA -#define T_VCP_TX_USART_TX_Pin GPIO_PIN_2 -#define T_VCP_TX_USART_TX_GPIO_Port GPIOA -#define T_VCP_RX_USART_RX_Pin GPIO_PIN_3 -#define T_VCP_RX_USART_RX_GPIO_Port GPIOA -#define AMS_ERR_LATCH_GPIO_IN_Pin GPIO_PIN_4 -#define AMS_ERR_LATCH_GPIO_IN_GPIO_Port GPIOA -#define AIR_POS__INT_STATE_CLOSED_GPIO_IN_Pin GPIO_PIN_5 -#define AIR_POS__INT_STATE_CLOSED_GPIO_IN_GPIO_Port GPIOA -#define AIR_NEG__INT_STATE_CLOSED_GPIO_IN_Pin GPIO_PIN_6 -#define AIR_NEG__INT_STATE_CLOSED_GPIO_IN_GPIO_Port GPIOA -#define DCBUS_PRECH__INT_STATE_CLOSED_GPIO_IN_Pin GPIO_PIN_7 -#define DCBUS_PRECH__INT_STATE_CLOSED_GPIO_IN_GPIO_Port GPIOA -#define ERR_LED_GPIO_OUT_Pin GPIO_PIN_4 -#define ERR_LED_GPIO_OUT_GPIO_Port GPIOC -#define WARN_LED_GPIO_OUT_Pin GPIO_PIN_5 -#define WARN_LED_GPIO_OUT_GPIO_Port GPIOC -#define STAT1_LED_GPIO_OUT_Pin GPIO_PIN_0 -#define STAT1_LED_GPIO_OUT_GPIO_Port GPIOB -#define STAT2_LED_GPIO_OUT_Pin GPIO_PIN_1 -#define STAT2_LED_GPIO_OUT_GPIO_Port GPIOB -#define nSTG_AIR_NEG_GPIO_IN_Pin GPIO_PIN_2 -#define nSTG_AIR_NEG_GPIO_IN_GPIO_Port GPIOB -#define nSTG_AIR_POS_GPIO_IN_Pin GPIO_PIN_10 -#define nSTG_AIR_POS_GPIO_IN_GPIO_Port GPIOB -#define DCBUS_PRECH__MECH_STATE_OPEN_GPIO_IN_Pin GPIO_PIN_12 -#define DCBUS_PRECH__MECH_STATE_OPEN_GPIO_IN_GPIO_Port GPIOB -#define TSAL_GREEN_GPIO_IN_Pin GPIO_PIN_14 -#define TSAL_GREEN_GPIO_IN_GPIO_Port GPIOB -#define ANY_IMPL_ERR_LATCH_GPIO_IN_Pin GPIO_PIN_15 -#define ANY_IMPL_ERR_LATCH_GPIO_IN_GPIO_Port GPIOB -#define DCBUS_IMPL_GPIO_IN_Pin GPIO_PIN_7 -#define DCBUS_IMPL_GPIO_IN_GPIO_Port GPIOC -#define STAT3_LED_GPIO_OUT_Pin GPIO_PIN_8 -#define STAT3_LED_GPIO_OUT_GPIO_Port GPIOC -#define DCBUS_RELAYS_IMPL_GPIO_IN_Pin GPIO_PIN_8 -#define DCBUS_RELAYS_IMPL_GPIO_IN_GPIO_Port GPIOA -#define AIR_NEG__MECH_STATE_OPEN_3V3_Pin GPIO_PIN_9 -#define AIR_NEG__MECH_STATE_OPEN_3V3_GPIO_Port GPIOA -#define AIR_POS__MECH_STATE_OPEN_GPIO_IN_Pin GPIO_PIN_10 -#define AIR_POS__MECH_STATE_OPEN_GPIO_IN_GPIO_Port GPIOA -#define DCBUS_OVER_60V_GPIO_IN_Pin GPIO_PIN_11 -#define DCBUS_OVER_60V_GPIO_IN_GPIO_Port GPIOA -#define SDC_PRECH_CMD__INT_STATE_OPEN_GPIO_IN_Pin GPIO_PIN_11 -#define SDC_PRECH_CMD__INT_STATE_OPEN_GPIO_IN_GPIO_Port GPIOC -#define SN65HVD23x_R_CAN_RX_Pin GPIO_PIN_8 -#define SN65HVD23x_R_CAN_RX_GPIO_Port GPIOB -#define SN65HVD23x_D_CAN_TX_Pin GPIO_PIN_9 -#define SN65HVD23x_D_CAN_TX_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_hal.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Exported types ------------------------------------------------------------*/ +/* USER CODE BEGIN ET */ + +/* USER CODE END ET */ + +/* Exported constants --------------------------------------------------------*/ +/* USER CODE BEGIN EC */ + +/* USER CODE END EC */ + +/* Exported macro ------------------------------------------------------------*/ +/* USER CODE BEGIN EM */ + +/* USER CODE END EM */ + +/* Exported functions prototypes ---------------------------------------------*/ +void Error_Handler(void); + +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +/* Private defines -----------------------------------------------------------*/ +#define IMD_ERR_LATCH_GPIO_IN_Pin GPIO_PIN_0 +#define IMD_ERR_LATCH_GPIO_IN_GPIO_Port GPIOC +#define SDC_POST_AMS_IMD_RLY_GPIO_IN_Pin GPIO_PIN_1 +#define SDC_POST_AMS_IMD_RLY_GPIO_IN_GPIO_Port GPIOC +#define SDC_TSAC_INIT_IN_ADC_IN_Pin GPIO_PIN_3 +#define SDC_TSAC_INIT_IN_ADC_IN_GPIO_Port GPIOC +#define SDC_TSAC_FINAL_IN_ADC_IN_Pin GPIO_PIN_0 +#define SDC_TSAC_FINAL_IN_ADC_IN_GPIO_Port GPIOA +#define T_VCP_TX_USART_TX_Pin GPIO_PIN_2 +#define T_VCP_TX_USART_TX_GPIO_Port GPIOA +#define T_VCP_RX_USART_RX_Pin GPIO_PIN_3 +#define T_VCP_RX_USART_RX_GPIO_Port GPIOA +#define AMS_ERR_LATCH_GPIO_IN_Pin GPIO_PIN_4 +#define AMS_ERR_LATCH_GPIO_IN_GPIO_Port GPIOA +#define AIR_POS__INT_STATE_CLOSED_GPIO_IN_Pin GPIO_PIN_5 +#define AIR_POS__INT_STATE_CLOSED_GPIO_IN_GPIO_Port GPIOA +#define AIR_NEG__INT_STATE_CLOSED_GPIO_IN_Pin GPIO_PIN_6 +#define AIR_NEG__INT_STATE_CLOSED_GPIO_IN_GPIO_Port GPIOA +#define DCBUS_PRECH__INT_STATE_CLOSED_GPIO_IN_Pin GPIO_PIN_7 +#define DCBUS_PRECH__INT_STATE_CLOSED_GPIO_IN_GPIO_Port GPIOA +#define ERR_LED_GPIO_OUT_Pin GPIO_PIN_4 +#define ERR_LED_GPIO_OUT_GPIO_Port GPIOC +#define WARN_LED_GPIO_OUT_Pin GPIO_PIN_5 +#define WARN_LED_GPIO_OUT_GPIO_Port GPIOC +#define STAT1_LED_GPIO_OUT_Pin GPIO_PIN_0 +#define STAT1_LED_GPIO_OUT_GPIO_Port GPIOB +#define STAT2_LED_GPIO_OUT_Pin GPIO_PIN_1 +#define STAT2_LED_GPIO_OUT_GPIO_Port GPIOB +#define nSTG_AIR_NEG_GPIO_IN_Pin GPIO_PIN_2 +#define nSTG_AIR_NEG_GPIO_IN_GPIO_Port GPIOB +#define nSTG_AIR_POS_GPIO_IN_Pin GPIO_PIN_10 +#define nSTG_AIR_POS_GPIO_IN_GPIO_Port GPIOB +#define DCBUS_PRECH__MECH_STATE_OPEN_GPIO_IN_Pin GPIO_PIN_12 +#define DCBUS_PRECH__MECH_STATE_OPEN_GPIO_IN_GPIO_Port GPIOB +#define TSAL_GREEN_GPIO_IN_Pin GPIO_PIN_14 +#define TSAL_GREEN_GPIO_IN_GPIO_Port GPIOB +#define ANY_IMPL_ERR_LATCH_GPIO_IN_Pin GPIO_PIN_15 +#define ANY_IMPL_ERR_LATCH_GPIO_IN_GPIO_Port GPIOB +#define DCBUS_IMPL_GPIO_IN_Pin GPIO_PIN_7 +#define DCBUS_IMPL_GPIO_IN_GPIO_Port GPIOC +#define STAT3_LED_GPIO_OUT_Pin GPIO_PIN_8 +#define STAT3_LED_GPIO_OUT_GPIO_Port GPIOC +#define DCBUS_RELAYS_IMPL_GPIO_IN_Pin GPIO_PIN_8 +#define DCBUS_RELAYS_IMPL_GPIO_IN_GPIO_Port GPIOA +#define AIR_NEG__MECH_STATE_OPEN_3V3_Pin GPIO_PIN_9 +#define AIR_NEG__MECH_STATE_OPEN_3V3_GPIO_Port GPIOA +#define AIR_POS__MECH_STATE_OPEN_GPIO_IN_Pin GPIO_PIN_10 +#define AIR_POS__MECH_STATE_OPEN_GPIO_IN_GPIO_Port GPIOA +#define DCBUS_OVER_60V_GPIO_IN_Pin GPIO_PIN_11 +#define DCBUS_OVER_60V_GPIO_IN_GPIO_Port GPIOA +#define SDC_PRECH_CMD__INT_STATE_OPEN_GPIO_IN_Pin GPIO_PIN_11 +#define SDC_PRECH_CMD__INT_STATE_OPEN_GPIO_IN_GPIO_Port GPIOC +#define SN65HVD23x_R_CAN_RX_Pin GPIO_PIN_8 +#define SN65HVD23x_R_CAN_RX_GPIO_Port GPIOB +#define SN65HVD23x_D_CAN_TX_Pin GPIO_PIN_9 +#define SN65HVD23x_D_CAN_TX_GPIO_Port GPIOB + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Core/Inc/stm32f4xx_hal_conf.h b/Core/Inc/stm32f4xx_hal_conf.h index f719bb9..c22097d 100644 --- a/Core/Inc/stm32f4xx_hal_conf.h +++ b/Core/Inc/stm32f4xx_hal_conf.h @@ -1,495 +1,495 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f4xx_hal_conf_template.h - * @author MCD Application Team - * @brief HAL configuration template file. - * This file should be copied to the application folder and renamed - * to stm32f4xx_hal_conf.h. - ****************************************************************************** - * @attention - * - * Copyright (c) 2017 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4xx_HAL_CONF_H -#define __STM32F4xx_HAL_CONF_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ - -/* ########################## Module Selection ############################## */ -/** - * @brief This is the list of modules to be used in the HAL driver - */ -#define HAL_MODULE_ENABLED - - /* #define HAL_CRYP_MODULE_ENABLED */ -#define HAL_ADC_MODULE_ENABLED -#define HAL_CAN_MODULE_ENABLED -/* #define HAL_CRC_MODULE_ENABLED */ -/* #define HAL_CAN_LEGACY_MODULE_ENABLED */ -/* #define HAL_DAC_MODULE_ENABLED */ -/* #define HAL_DCMI_MODULE_ENABLED */ -/* #define HAL_DMA2D_MODULE_ENABLED */ -/* #define HAL_ETH_MODULE_ENABLED */ -/* #define HAL_ETH_LEGACY_MODULE_ENABLED */ -/* #define HAL_NAND_MODULE_ENABLED */ -/* #define HAL_NOR_MODULE_ENABLED */ -/* #define HAL_PCCARD_MODULE_ENABLED */ -/* #define HAL_SRAM_MODULE_ENABLED */ -/* #define HAL_SDRAM_MODULE_ENABLED */ -/* #define HAL_HASH_MODULE_ENABLED */ -/* #define HAL_I2C_MODULE_ENABLED */ -/* #define HAL_I2S_MODULE_ENABLED */ -#define HAL_IWDG_MODULE_ENABLED -/* #define HAL_LTDC_MODULE_ENABLED */ -/* #define HAL_RNG_MODULE_ENABLED */ -/* #define HAL_RTC_MODULE_ENABLED */ -/* #define HAL_SAI_MODULE_ENABLED */ -/* #define HAL_SD_MODULE_ENABLED */ -/* #define HAL_MMC_MODULE_ENABLED */ -/* #define HAL_SPI_MODULE_ENABLED */ -#define HAL_TIM_MODULE_ENABLED -#define HAL_UART_MODULE_ENABLED -/* #define HAL_USART_MODULE_ENABLED */ -/* #define HAL_IRDA_MODULE_ENABLED */ -/* #define HAL_SMARTCARD_MODULE_ENABLED */ -/* #define HAL_SMBUS_MODULE_ENABLED */ -/* #define HAL_WWDG_MODULE_ENABLED */ -/* #define HAL_PCD_MODULE_ENABLED */ -/* #define HAL_HCD_MODULE_ENABLED */ -/* #define HAL_DSI_MODULE_ENABLED */ -/* #define HAL_QSPI_MODULE_ENABLED */ -/* #define HAL_QSPI_MODULE_ENABLED */ -/* #define HAL_CEC_MODULE_ENABLED */ -/* #define HAL_FMPI2C_MODULE_ENABLED */ -/* #define HAL_FMPSMBUS_MODULE_ENABLED */ -/* #define HAL_SPDIFRX_MODULE_ENABLED */ -/* #define HAL_DFSDM_MODULE_ENABLED */ -/* #define HAL_LPTIM_MODULE_ENABLED */ -#define HAL_GPIO_MODULE_ENABLED -#define HAL_EXTI_MODULE_ENABLED -#define HAL_DMA_MODULE_ENABLED -#define HAL_RCC_MODULE_ENABLED -#define HAL_FLASH_MODULE_ENABLED -#define HAL_PWR_MODULE_ENABLED -#define HAL_CORTEX_MODULE_ENABLED - -/* ########################## HSE/HSI Values adaptation ##################### */ -/** - * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. - * This value is used by the RCC HAL module to compute the system frequency - * (when HSE is used as system clock source, directly or through the PLL). - */ -#if !defined (HSE_VALUE) - #define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ - -/** - * @brief Internal High Speed oscillator (HSI) value. - * This value is used by the RCC HAL module to compute the system frequency - * (when HSI is used as system clock source, directly or through the PLL). - */ -#if !defined (HSI_VALUE) - #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) - #define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz - The real value may vary depending on the variations - in voltage and temperature.*/ -/** - * @brief External Low Speed oscillator (LSE) value. - */ -#if !defined (LSE_VALUE) - #define LSE_VALUE 32768U /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined (LSE_STARTUP_TIMEOUT) - #define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S peripheral - * This value is used by the I2S HAL module to compute the I2S clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) - #define EXTERNAL_CLOCK_VALUE 12288000U /*!< Value of the External audio frequency in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ - -/* Tip: To avoid modifying this file each time you need to use different HSE, - === you can define the HSE value in your toolchain compiler preprocessor. */ - -/* ########################### System Configuration ######################### */ -/** - * @brief This is the HAL system configuration section - */ -#define VDD_VALUE 3300U /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 1U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */ -#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */ -#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */ -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */ -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */ -#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */ -#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */ -#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */ -#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */ -#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */ -#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */ -#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */ -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */ -#define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U /* FMPI2C register callback disabled */ -#define USE_HAL_FMPSMBUS_REGISTER_CALLBACKS 0U /* FMPSMBUS register callback disabled */ -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */ -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */ -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */ -#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */ -#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */ -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */ -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */ -#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */ -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */ -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */ -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */ -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */ -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */ -#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */ -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */ -#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */ -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */ -#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */ -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */ -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ -#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */ -#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */ -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## Ethernet peripheral configuration ##################### */ - -/* Section 1 : Ethernet peripheral configuration */ - -/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ -#define MAC_ADDR0 2U -#define MAC_ADDR1 0U -#define MAC_ADDR2 0U -#define MAC_ADDR3 0U -#define MAC_ADDR4 0U -#define MAC_ADDR5 0U - -/* Definition of the Ethernet driver buffers size and count */ -#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ -#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ -#define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ -#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ - -/* Section 2: PHY configuration section */ - -/* DP83848_PHY_ADDRESS Address*/ -#define DP83848_PHY_ADDRESS -/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ -#define PHY_RESET_DELAY 0x000000FFU -/* PHY Configuration delay */ -#define PHY_CONFIG_DELAY 0x00000FFFU - -#define PHY_READ_TO 0x0000FFFFU -#define PHY_WRITE_TO 0x0000FFFFU - -/* Section 3: Common PHY Registers */ - -#define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */ -#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */ - -#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ -#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ -#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ -#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ -#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ -#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ -#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ -#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ -#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ -#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ - -#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ -#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ -#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ - -/* Section 4: Extended PHY Registers */ -#define PHY_SR ((uint16_t)) /*!< PHY status register Offset */ - -#define PHY_SPEED_STATUS ((uint16_t)) /*!< PHY Speed mask */ -#define PHY_DUPLEX_STATUS ((uint16_t)) /*!< PHY Duplex mask */ - -/* ################## SPI peripheral configuration ########################## */ - -/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver -* Activated: CRC code is present inside driver -* Deactivated: CRC code cleaned from driver -*/ - -#define USE_SPI_CRC 0U - -/* Includes ------------------------------------------------------------------*/ -/** - * @brief Include module's header file - */ - -#ifdef HAL_RCC_MODULE_ENABLED - #include "stm32f4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED - #include "stm32f4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED - #include "stm32f4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED - #include "stm32f4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED - #include "stm32f4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED - #include "stm32f4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_CAN_MODULE_ENABLED - #include "stm32f4xx_hal_can.h" -#endif /* HAL_CAN_MODULE_ENABLED */ - -#ifdef HAL_CAN_LEGACY_MODULE_ENABLED - #include "stm32f4xx_hal_can_legacy.h" -#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED - #include "stm32f4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED - #include "stm32f4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DMA2D_MODULE_ENABLED - #include "stm32f4xx_hal_dma2d.h" -#endif /* HAL_DMA2D_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED - #include "stm32f4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_DCMI_MODULE_ENABLED - #include "stm32f4xx_hal_dcmi.h" -#endif /* HAL_DCMI_MODULE_ENABLED */ - -#ifdef HAL_ETH_MODULE_ENABLED - #include "stm32f4xx_hal_eth.h" -#endif /* HAL_ETH_MODULE_ENABLED */ - -#ifdef HAL_ETH_LEGACY_MODULE_ENABLED - #include "stm32f4xx_hal_eth_legacy.h" -#endif /* HAL_ETH_LEGACY_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED - #include "stm32f4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED - #include "stm32f4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED - #include "stm32f4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED - #include "stm32f4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_PCCARD_MODULE_ENABLED - #include "stm32f4xx_hal_pccard.h" -#endif /* HAL_PCCARD_MODULE_ENABLED */ - -#ifdef HAL_SDRAM_MODULE_ENABLED - #include "stm32f4xx_hal_sdram.h" -#endif /* HAL_SDRAM_MODULE_ENABLED */ - -#ifdef HAL_HASH_MODULE_ENABLED - #include "stm32f4xx_hal_hash.h" -#endif /* HAL_HASH_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED - #include "stm32f4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED - #include "stm32f4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED - #include "stm32f4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED - #include "stm32f4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_LTDC_MODULE_ENABLED - #include "stm32f4xx_hal_ltdc.h" -#endif /* HAL_LTDC_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED - #include "stm32f4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED - #include "stm32f4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED - #include "stm32f4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED - #include "stm32f4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SD_MODULE_ENABLED - #include "stm32f4xx_hal_sd.h" -#endif /* HAL_SD_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED - #include "stm32f4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED - #include "stm32f4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED - #include "stm32f4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED - #include "stm32f4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED - #include "stm32f4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED - #include "stm32f4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED - #include "stm32f4xx_hal_wwdg.h" -#endif /* HAL_WWDG_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED - #include "stm32f4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_HCD_MODULE_ENABLED - #include "stm32f4xx_hal_hcd.h" -#endif /* HAL_HCD_MODULE_ENABLED */ - -#ifdef HAL_DSI_MODULE_ENABLED - #include "stm32f4xx_hal_dsi.h" -#endif /* HAL_DSI_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED - #include "stm32f4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_CEC_MODULE_ENABLED - #include "stm32f4xx_hal_cec.h" -#endif /* HAL_CEC_MODULE_ENABLED */ - -#ifdef HAL_FMPI2C_MODULE_ENABLED - #include "stm32f4xx_hal_fmpi2c.h" -#endif /* HAL_FMPI2C_MODULE_ENABLED */ - -#ifdef HAL_FMPSMBUS_MODULE_ENABLED - #include "stm32f4xx_hal_fmpsmbus.h" -#endif /* HAL_FMPSMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPDIFRX_MODULE_ENABLED - #include "stm32f4xx_hal_spdifrx.h" -#endif /* HAL_SPDIFRX_MODULE_ENABLED */ - -#ifdef HAL_DFSDM_MODULE_ENABLED - #include "stm32f4xx_hal_dfsdm.h" -#endif /* HAL_DFSDM_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED - #include "stm32f4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_MMC_MODULE_ENABLED - #include "stm32f4xx_hal_mmc.h" -#endif /* HAL_MMC_MODULE_ENABLED */ - -/* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT -/** - * @brief The assert_param macro is used for function's parameters check. - * @param expr If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ - #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ - void assert_failed(uint8_t* file, uint32_t line); -#else - #define assert_param(expr) ((void)0U) -#endif /* USE_FULL_ASSERT */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F4xx_HAL_CONF_H */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_hal_conf_template.h + * @author MCD Application Team + * @brief HAL configuration template file. + * This file should be copied to the application folder and renamed + * to stm32f4xx_hal_conf.h. + ****************************************************************************** + * @attention + * + * Copyright (c) 2017 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F4xx_HAL_CONF_H +#define __STM32F4xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED + + /* #define HAL_CRYP_MODULE_ENABLED */ +#define HAL_ADC_MODULE_ENABLED +#define HAL_CAN_MODULE_ENABLED +/* #define HAL_CRC_MODULE_ENABLED */ +/* #define HAL_CAN_LEGACY_MODULE_ENABLED */ +/* #define HAL_DAC_MODULE_ENABLED */ +/* #define HAL_DCMI_MODULE_ENABLED */ +/* #define HAL_DMA2D_MODULE_ENABLED */ +/* #define HAL_ETH_MODULE_ENABLED */ +/* #define HAL_ETH_LEGACY_MODULE_ENABLED */ +/* #define HAL_NAND_MODULE_ENABLED */ +/* #define HAL_NOR_MODULE_ENABLED */ +/* #define HAL_PCCARD_MODULE_ENABLED */ +/* #define HAL_SRAM_MODULE_ENABLED */ +/* #define HAL_SDRAM_MODULE_ENABLED */ +/* #define HAL_HASH_MODULE_ENABLED */ +/* #define HAL_I2C_MODULE_ENABLED */ +/* #define HAL_I2S_MODULE_ENABLED */ +#define HAL_IWDG_MODULE_ENABLED +/* #define HAL_LTDC_MODULE_ENABLED */ +/* #define HAL_RNG_MODULE_ENABLED */ +/* #define HAL_RTC_MODULE_ENABLED */ +/* #define HAL_SAI_MODULE_ENABLED */ +/* #define HAL_SD_MODULE_ENABLED */ +/* #define HAL_MMC_MODULE_ENABLED */ +/* #define HAL_SPI_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED +#define HAL_UART_MODULE_ENABLED +/* #define HAL_USART_MODULE_ENABLED */ +/* #define HAL_IRDA_MODULE_ENABLED */ +/* #define HAL_SMARTCARD_MODULE_ENABLED */ +/* #define HAL_SMBUS_MODULE_ENABLED */ +/* #define HAL_WWDG_MODULE_ENABLED */ +/* #define HAL_PCD_MODULE_ENABLED */ +/* #define HAL_HCD_MODULE_ENABLED */ +/* #define HAL_DSI_MODULE_ENABLED */ +/* #define HAL_QSPI_MODULE_ENABLED */ +/* #define HAL_QSPI_MODULE_ENABLED */ +/* #define HAL_CEC_MODULE_ENABLED */ +/* #define HAL_FMPI2C_MODULE_ENABLED */ +/* #define HAL_FMPSMBUS_MODULE_ENABLED */ +/* #define HAL_SPDIFRX_MODULE_ENABLED */ +/* #define HAL_DFSDM_MODULE_ENABLED */ +/* #define HAL_LPTIM_MODULE_ENABLED */ +#define HAL_GPIO_MODULE_ENABLED +#define HAL_EXTI_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_PWR_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED + +/* ########################## HSE/HSI Values adaptation ##################### */ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) + #define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) + #define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz + The real value may vary depending on the variations + in voltage and temperature.*/ +/** + * @brief External Low Speed oscillator (LSE) value. + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE 32768U /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ + +/** + * @brief External clock source for I2S peripheral + * This value is used by the I2S HAL module to compute the I2S clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) + #define EXTERNAL_CLOCK_VALUE 12288000U /*!< Value of the External audio frequency in Hz*/ +#endif /* EXTERNAL_CLOCK_VALUE */ + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE 3300U /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U + +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */ +#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */ +#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */ +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */ +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */ +#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */ +#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */ +#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */ +#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */ +#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */ +#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */ +#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */ +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */ +#define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U /* FMPI2C register callback disabled */ +#define USE_HAL_FMPSMBUS_REGISTER_CALLBACKS 0U /* FMPSMBUS register callback disabled */ +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */ +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */ +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */ +#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */ +#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */ +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */ +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */ +#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */ +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */ +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */ +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */ +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */ +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */ +#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */ +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */ +#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */ +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */ +#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */ +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */ +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ +#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */ +#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */ +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/* #define USE_FULL_ASSERT 1U */ + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2U +#define MAC_ADDR1 0U +#define MAC_ADDR2 0U +#define MAC_ADDR3 0U +#define MAC_ADDR4 0U +#define MAC_ADDR5 0U + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848_PHY_ADDRESS Address*/ +#define DP83848_PHY_ADDRESS +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY 0x000000FFU +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY 0x00000FFFU + +#define PHY_READ_TO 0x0000FFFFU +#define PHY_WRITE_TO 0x0000FFFFU + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ +#define PHY_SR ((uint16_t)) /*!< PHY status register Offset */ + +#define PHY_SPEED_STATUS ((uint16_t)) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)) /*!< PHY Duplex mask */ + +/* ################## SPI peripheral configuration ########################## */ + +/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver +* Activated: CRC code is present inside driver +* Deactivated: CRC code cleaned from driver +*/ + +#define USE_SPI_CRC 0U + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f4xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f4xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_EXTI_MODULE_ENABLED + #include "stm32f4xx_hal_exti.h" +#endif /* HAL_EXTI_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f4xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f4xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f4xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f4xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CAN_LEGACY_MODULE_ENABLED + #include "stm32f4xx_hal_can_legacy.h" +#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f4xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED + #include "stm32f4xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DMA2D_MODULE_ENABLED + #include "stm32f4xx_hal_dma2d.h" +#endif /* HAL_DMA2D_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f4xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_DCMI_MODULE_ENABLED + #include "stm32f4xx_hal_dcmi.h" +#endif /* HAL_DCMI_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f4xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_ETH_LEGACY_MODULE_ENABLED + #include "stm32f4xx_hal_eth_legacy.h" +#endif /* HAL_ETH_LEGACY_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f4xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f4xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f4xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f4xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_PCCARD_MODULE_ENABLED + #include "stm32f4xx_hal_pccard.h" +#endif /* HAL_PCCARD_MODULE_ENABLED */ + +#ifdef HAL_SDRAM_MODULE_ENABLED + #include "stm32f4xx_hal_sdram.h" +#endif /* HAL_SDRAM_MODULE_ENABLED */ + +#ifdef HAL_HASH_MODULE_ENABLED + #include "stm32f4xx_hal_hash.h" +#endif /* HAL_HASH_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f4xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_SMBUS_MODULE_ENABLED + #include "stm32f4xx_hal_smbus.h" +#endif /* HAL_SMBUS_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f4xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f4xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_LTDC_MODULE_ENABLED + #include "stm32f4xx_hal_ltdc.h" +#endif /* HAL_LTDC_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f4xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED + #include "stm32f4xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f4xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SAI_MODULE_ENABLED + #include "stm32f4xx_hal_sai.h" +#endif /* HAL_SAI_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f4xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f4xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f4xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f4xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f4xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f4xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f4xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f4xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f4xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f4xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + +#ifdef HAL_DSI_MODULE_ENABLED + #include "stm32f4xx_hal_dsi.h" +#endif /* HAL_DSI_MODULE_ENABLED */ + +#ifdef HAL_QSPI_MODULE_ENABLED + #include "stm32f4xx_hal_qspi.h" +#endif /* HAL_QSPI_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f4xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_FMPI2C_MODULE_ENABLED + #include "stm32f4xx_hal_fmpi2c.h" +#endif /* HAL_FMPI2C_MODULE_ENABLED */ + +#ifdef HAL_FMPSMBUS_MODULE_ENABLED + #include "stm32f4xx_hal_fmpsmbus.h" +#endif /* HAL_FMPSMBUS_MODULE_ENABLED */ + +#ifdef HAL_SPDIFRX_MODULE_ENABLED + #include "stm32f4xx_hal_spdifrx.h" +#endif /* HAL_SPDIFRX_MODULE_ENABLED */ + +#ifdef HAL_DFSDM_MODULE_ENABLED + #include "stm32f4xx_hal_dfsdm.h" +#endif /* HAL_DFSDM_MODULE_ENABLED */ + +#ifdef HAL_LPTIM_MODULE_ENABLED + #include "stm32f4xx_hal_lptim.h" +#endif /* HAL_LPTIM_MODULE_ENABLED */ + +#ifdef HAL_MMC_MODULE_ENABLED + #include "stm32f4xx_hal_mmc.h" +#endif /* HAL_MMC_MODULE_ENABLED */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F4xx_HAL_CONF_H */ diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index 537c0aa..97b5948 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -1,71 +1,71 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4xx_IT_H -#define __STM32F4xx_IT_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Exported types ------------------------------------------------------------*/ -/* USER CODE BEGIN ET */ - -/* USER CODE END ET */ - -/* Exported constants --------------------------------------------------------*/ -/* USER CODE BEGIN EC */ - -/* USER CODE END EC */ - -/* Exported macro ------------------------------------------------------------*/ -/* USER CODE BEGIN EM */ - -/* USER CODE END EM */ - -/* Exported functions prototypes ---------------------------------------------*/ -void NMI_Handler(void); -void HardFault_Handler(void); -void MemManage_Handler(void); -void BusFault_Handler(void); -void UsageFault_Handler(void); -void SVC_Handler(void); -void DebugMon_Handler(void); -void PendSV_Handler(void); -void SysTick_Handler(void); -void ADC_IRQHandler(void); -void CAN1_RX0_IRQHandler(void); -void CAN1_SCE_IRQHandler(void); -void TIM2_IRQHandler(void); -void DMA2_Stream0_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F4xx_IT_H */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F4xx_IT_H +#define __STM32F4xx_IT_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Exported types ------------------------------------------------------------*/ +/* USER CODE BEGIN ET */ + +/* USER CODE END ET */ + +/* Exported constants --------------------------------------------------------*/ +/* USER CODE BEGIN EC */ + +/* USER CODE END EC */ + +/* Exported macro ------------------------------------------------------------*/ +/* USER CODE BEGIN EM */ + +/* USER CODE END EM */ + +/* Exported functions prototypes ---------------------------------------------*/ +void NMI_Handler(void); +void HardFault_Handler(void); +void MemManage_Handler(void); +void BusFault_Handler(void); +void UsageFault_Handler(void); +void SVC_Handler(void); +void DebugMon_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +void ADC_IRQHandler(void); +void CAN1_RX0_IRQHandler(void); +void CAN1_SCE_IRQHandler(void); +void TIM2_IRQHandler(void); +void DMA2_Stream0_IRQHandler(void); +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F4xx_IT_H */ diff --git a/Core/Inc/tim.h b/Core/Inc/tim.h index 56b08d3..774960a 100644 --- a/Core/Inc/tim.h +++ b/Core/Inc/tim.h @@ -1,52 +1,52 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.h - * @brief This file contains all the function prototypes for - * the tim.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __TIM_H__ -#define __TIM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern TIM_HandleTypeDef htim2; - -/* USER CODE BEGIN Private defines */ -#define TIM_DMA1_HandleTypeDef htim2 -/* USER CODE END Private defines */ - -void MX_TIM2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIM_H__ */ - +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.h + * @brief This file contains all the function prototypes for + * the tim.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __TIM_H__ +#define __TIM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern TIM_HandleTypeDef htim2; + +/* USER CODE BEGIN Private defines */ +#define TIM_DMA1_HandleTypeDef htim2 +/* USER CODE END Private defines */ + +void MX_TIM2_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIM_H__ */ + diff --git a/Core/Inc/usart.h b/Core/Inc/usart.h index 2982d49..57ab14e 100644 --- a/Core/Inc/usart.h +++ b/Core/Inc/usart.h @@ -1,52 +1,52 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USART_H__ -#define __USART_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern UART_HandleTypeDef huart2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_USART2_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USART_H__ */ - +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USART_H__ +#define __USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern UART_HandleTypeDef huart2; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_USART2_UART_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USART_H__ */ + diff --git a/Core/Src/adc.c b/Core/Src/adc.c index d22a0cf..9691b23 100644 --- a/Core/Src/adc.c +++ b/Core/Src/adc.c @@ -1,350 +1,350 @@ -/* USER CODE BEGIN Header */ -/** - * @file adc.c - * @prefix ADC - * @author Simone Ruffini [simone.ruffini.work@gmail.com | simone.ruffini@squadracorse.com] - * @date Thu Jun 1 07:14:33 PM CEST 2023 - * - * @brief This file provides code for the configuration - * of the ADC instances. - * - * @license Licensed under "THE BEER-WARE LICENSE", Revision 69 (see LICENSE) - * @notes ADC1 CONFIGURATION: - * - hadc1.Init.ExternalTrigConv: who triggers the conversion - * - ADC_EXTERNALTRIGCONV_T2_TRGO => TIM2 triggers the conversion when - * TRGO fires (check TIM2 for details) - * - ADCCLK: PCLCK2/hadc1.Init.ClockPrescaler - * - PCLCK2 why? because ADC1/2/3 peripherals are on the APB2 bus (check stm32f446xx.h file) - * - hadc1.Init.ScanConvMode: if ENABLES means multiple channels/ranks will be sampled once triggered - * - hadc1.Init.NbrOfConversion: number of channels/ranks that will be sampled - * - hadc1.Init.ContinuousConvMode = DISABLED, why? because timer triggers the conversion - * - hadc1.Init.DiscontinuousConvMode = DISABLED, why? all channels need to be converted in sequence without halts - * - hadc1.Init.DMAContinuousRequests = ENABLED, why? DMA requests can continue to be generated after the conversion sequence ends (otherwise the DMA is disabled and must be re-enabled) - * - NOTE: this should be disabled if the timer is not in continuos mode or there is no retriggering via a timer (DMA remains active) - * - NOTE: this value is effective only if a DMA request is configured - * - hdma_adc1.Init.Mode = DMA_CIRCULAR; -> DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached. - * - hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; -> increase the memory address after each transfer - * - hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV; EndOfConversion event flag will be activated at the end of conversion of the sequence of channels/ranks instead of a single conversion (NOTE: interrupts must be enabled) - * - NOTE: IF DMA is enabled then setting EOCSelection as that will enable overrun detection feature - - hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD - - Peripheral data allignemtn for the DMA is halfword because the ADC Data Register (ADC.Instance.DR) is 16 bit wide. - This means that the trasnfer to memory will be necessary a halfword too! - - hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD - Therefore since the DMA is set with memory autoincrease and circular mode (see above) this means that - the autoincrease will be by HALWORDS. - @NOTE Therefore when HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length) is called: - - sizeof(pData[0]) == hdma_adc1.Init.MemDataAlignment - otherwise, if greater (uint32_t pData[N]), the DMA will save data in the vector each 16 bits: - a pData item will hold two values -> pData[0] = {[adc_conv1],[adc_conv0]}; - * @note ADC TIMINGS: - * - CHANNEL/RANK TOTAL SAMPLING CYCLES = sConfig.SamplingTime + hadc1.Init.Resolution(#ofbits) + 2 or 3 cycles (depending on resolution) - * - CHANNEL/RANK TOTAL SAMPLING TIME = (CHANNEL/RANK TOTAL SAMPLING CYCLES)/ADCCLK - * - SAMPLING FREQUENCY = the one of the timer - * - * @see https://wiki.st.com/stm32mcu/wiki/Getting_started_with_ADC - * @see https://deepbluembedded.com/stm32-adc-tutorial-complete-guide-with-examples/ - */ - -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "adc.h" - -/* USER CODE BEGIN 0 */ -#include "main.h" - -#include -#include -#include - -// TODO: remove old -double __adc1_dma_data_filtered[2] = {0}; - -uint16_t __adc1_dma_data[2] = {0}; -uint16_t __adc1_filtered_data[2] = {0}; -/** - * @brief Array that maps ADC1 channels to ranks - * @note ranks start from 1 - * @note non initialized channels are set to 0 an invalid rank - */ -static const uint8_t ADC_ADC1_Channel_to_Rank_map[ADC_Channel_NUM]={ - [ADC_Channel13]=1, - [ADC_Channel0]=2 -}; - -/* USER CODE END 0 */ - -ADC_HandleTypeDef hadc1; -DMA_HandleTypeDef hdma_adc1; - -/* ADC1 init function */ -void MX_ADC1_Init(void) -{ - - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - ADC_ChannelConfTypeDef sConfig = {0}; - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - - /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) - */ - hadc1.Instance = ADC1; - hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV6; - hadc1.Init.Resolution = ADC_RESOLUTION_12B; - hadc1.Init.ScanConvMode = ENABLE; - hadc1.Init.ContinuousConvMode = DISABLE; - hadc1.Init.DiscontinuousConvMode = DISABLE; - hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; - hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO; - hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc1.Init.NbrOfConversion = 2; - hadc1.Init.DMAContinuousRequests = ENABLE; - hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV; - if (HAL_ADC_Init(&hadc1) != HAL_OK) - { - Error_Handler(); - } - - /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. - */ - sConfig.Channel = ADC_CHANNEL_13; - sConfig.Rank = 1; - sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; - if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) - { - Error_Handler(); - } - - /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. - */ - sConfig.Channel = ADC_CHANNEL_0; - sConfig.Rank = 2; - if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN ADC1_Init 2 */ - - // Start ADC IN DMA MODE - HAL_TIM_Base_Start(&TIM_DMA1_HandleTypeDef); - HAL_ADC_Start_DMA(&hadc1, (uint32_t *)__adc1_dma_data, hadc1.Init.NbrOfConversion); - - /* USER CODE END ADC1_Init 2 */ - -} - -void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(adcHandle->Instance==ADC1) - { - /* USER CODE BEGIN ADC1_MspInit 0 */ - - /* USER CODE END ADC1_MspInit 0 */ - /* ADC1 clock enable */ - __HAL_RCC_ADC1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**ADC1 GPIO Configuration - PC3 ------> ADC1_IN13 - PA0-WKUP ------> ADC1_IN0 - */ - GPIO_InitStruct.Pin = SDC_TSAC_INIT_IN_ADC_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(SDC_TSAC_INIT_IN_ADC_IN_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = SDC_TSAC_FINAL_IN_ADC_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(SDC_TSAC_FINAL_IN_ADC_IN_GPIO_Port, &GPIO_InitStruct); - - /* ADC1 DMA Init */ - /* ADC1 Init */ - hdma_adc1.Instance = DMA2_Stream0; - hdma_adc1.Init.Channel = DMA_CHANNEL_0; - hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; - hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; - hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; - hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; - hdma_adc1.Init.Mode = DMA_CIRCULAR; - hdma_adc1.Init.Priority = DMA_PRIORITY_LOW; - hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; - if (HAL_DMA_Init(&hdma_adc1) != HAL_OK) - { - Error_Handler(); - } - - __HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc1); - - /* ADC1 interrupt Init */ - HAL_NVIC_SetPriority(ADC_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(ADC_IRQn); - /* USER CODE BEGIN ADC1_MspInit 1 */ - - /* USER CODE END ADC1_MspInit 1 */ - } -} - -void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) -{ - - if(adcHandle->Instance==ADC1) - { - /* USER CODE BEGIN ADC1_MspDeInit 0 */ - - /* USER CODE END ADC1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_ADC1_CLK_DISABLE(); - - /**ADC1 GPIO Configuration - PC3 ------> ADC1_IN13 - PA0-WKUP ------> ADC1_IN0 - */ - HAL_GPIO_DeInit(SDC_TSAC_INIT_IN_ADC_IN_GPIO_Port, SDC_TSAC_INIT_IN_ADC_IN_Pin); - - HAL_GPIO_DeInit(SDC_TSAC_FINAL_IN_ADC_IN_GPIO_Port, SDC_TSAC_FINAL_IN_ADC_IN_Pin); - - /* ADC1 DMA DeInit */ - HAL_DMA_DeInit(adcHandle->DMA_Handle); - - /* ADC1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(ADC_IRQn); - /* USER CODE BEGIN ADC1_MspDeInit 1 */ - - /* USER CODE END ADC1_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ -int16_t ADC_ADC1_getChannelRaw(enum ADC_Channel channel){ - if (!(channel < ADC_Channel_NUM)) return -1; - int8_t rankNumber = ADC_ADC1_Channel_to_Rank_map[channel]; - return rankNumber > 0 ? __adc1_dma_data[rankNumber-1] : -1; -} - -int16_t ADC_ADC1_getChannelRawFiltered(enum ADC_Channel channel) { - if (!(channel < ADC_Channel_NUM)) return -1; - int8_t rankNumber = ADC_ADC1_Channel_to_Rank_map[channel]; - return rankNumber > 0 ? __adc1_filtered_data[rankNumber-1] : -1; -}; -/** - * @brief Implements a first-order IIR single pole low pass filter - * @long Y[n] = alpha * X[n] + (1-alpha)Y[n-1] - * Y[n] = new filtered sample - * Y[n-1] = previous filtered samples (history) - * X[n] = current sample - * @param alpha smoohting factor - * @param X_n currently sampled value - * @param Y_n_min1 previous sample already filtered (history) - * @return truncated filtered sample (Y[n]) - * @see https://en.wikipedia.org/wiki/Low-pass_filter#math_Q - * @see https://www.youtube.com/watch?v=QRMe02kzVkA - */ -static double _ADC_IIR_first_order(double alpha, double X_n, double Y_n_min1) { - // Y[n] = alpha * X[n] + (1-alpha)Y[n-1] - // = Y[n-1] + alpha * (X[n]-Y[n-1]) - return (uint32_t)(Y_n_min1 + alpha * (X_n - Y_n_min1)); -} - -/** - * @brief Regular conversion complete callback in non blocking mode - * @param hadc pointer to a ADC_HandleTypeDef structure that contains - * the configuration information for the specified ADC. - * @retval None - */ -void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) { - if(hadc == &hadc1){ - for (int i = 0; i < hadc1.Init.NbrOfConversion; ++i) { - __adc1_filtered_data[i] = _ADC_IIR_first_order(ADC_ADC1_IIR_ALPHA,(double)__adc1_dma_data[i],(double) __adc1_filtered_data[i]); - } - } -} - -///// OLD TODO: delete - -///** -// * @brief Transform RAW adc values to a real and physical counterpart -// * @details real_output[phisycal_unit] = offset[phisycal_value] + adc_raw_value[steps] * LSB_weight[Volts/steps] * gain[phisycal_unit/Volts] -// * @param adc_raw_data ADC raw data -// * @param adc_res_bit ADC resolution, number of bits -// * @param adc_FSR_mv ADC full-scale input range (in milli Volts) proportional to the reference voltage (usually 3300mV or else VDDA voltage on uC) -// * @param adc_sig_res_bit ADC significant/usable resolution bits, i.e. a 12 bit reading could have only the first 8 bit significant -// * @note adc_sig_res_bit <= adc_res_bit and both greater then 0 -// * @param offset Offest of the real measure the raw data is representing, has the same physical unit of the output -// * @param gain Multiplier coefficent that maps 1mV change to a physical change, e.g. 0.005 degC/mV means 1mV change is 0.005 degrees celsius change -// * @return real_output from the formula above -// */ -//static double _ADC_RawToReal(uint32_t adc_raw_data, -// uint8_t adc_res_bit, -// double adc_FSR_mv, -// uint8_t adc_sig_res_bit, -// double offset, -// double gain) { -// assert_param(adc_sig_res_bit > 0); -// assert_param(adc_res_bit > 0); -// assert_param(adc_sig_res_bit <= adc_res_bit); -// // If the adc resolution is 12 bit (adc_res_bit = 12) but the usable -// // and significant bits of the adc are the first 8 (adc_sig_res_bit = 8) -// // We mask the adc_raw_data with 0x1111_1111_0000 -// uint32_t raw_data_significant_bits_mask = ~((1U << (adc_res_bit - adc_sig_res_bit)) - 1U); -// uint32_t adc_raw_data_significant = adc_raw_data & raw_data_significant_bits_mask; -// double LSb_weight = adc_FSR_mv / (1U << adc_res_bit); // Least Significan Bit weight -// return offset + (adc_raw_data_significant * LSb_weight * gain); -//} -// -//uint32_t ADC_Get_Filtered_Raw(ADC_HandleTypeDef *hadc, uint8_t adc_channel) { -// if (hadc->Instance == SD_FB_ADC_Handle.Instance) { -// switch (adc_channel) { -// case SD_FB_SD_DLY_CAPS_TO_SD_FIN_OUT_AIRS_ADC1_IN_ADC_CHNL: -// return __adc1_dma_data_filtered[0]; -// break; -// case SD_FB_SD_PRCH_RLY_TO_SD_MID_OUT_ADC1_IN_ADC_CHNL: -// return __adc1_dma_data_filtered[1]; -// break; -// default: -// // Should not be here -// return -1U; -// break; -// } -// } else -// return -1U; // Should not be here -//} - -//double ADC_Get_Filtered_Real(ADC_HandleTypeDef *hadc, uint8_t adc_channel) { -// uint32_t raw = ADC_Get_Filtered_Raw(hadc, adc_channel); -// if (raw != (-1U)) -// return ADC_RawToReal(hadc, adc_channel, raw); -// else -// return DBL_MAX; -//} -// -//double ADC_RawToReal(ADC_HandleTypeDef *hadc, uint8_t adc_channel, uint32_t raw_adc_value) { -// assert_param(IS_ADC_CHANNEL(adc_channel)); -// if (hadc->Instance == SD_FB_ADC_Handle.Instance) { -// switch (adc_channel) { -// case SD_FB_SD_DLY_CAPS_TO_SD_FIN_OUT_AIRS_ADC1_IN_ADC_CHNL: -// case SD_FB_SD_PRCH_RLY_TO_SD_MID_OUT_ADC1_IN_ADC_CHNL: -// return _ADC_RawToReal(raw_adc_value, -// ADC_RESOLUTION_TO_NUMB_BITS(hadc->Init.Resolution), -// ADC_VDDA_mV, -// ADC_RESOLUTION_TO_NUMB_BITS(hadc->Init.Resolution), -// SD_FB_ADC_OFFSET, -// SD_FB_ADC_GAIN); -// break; -// default: -// // Should not be here -// return 0; -// break; -// } -// } else -// return 0; // Should not be here -//} -/* USER CODE END 1 */ +/* USER CODE BEGIN Header */ +/** + * @file adc.c + * @prefix ADC + * @author Simone Ruffini [simone.ruffini.work@gmail.com | simone.ruffini@squadracorse.com] + * @date Thu Jun 1 07:14:33 PM CEST 2023 + * + * @brief This file provides code for the configuration + * of the ADC instances. + * + * @license Licensed under "THE BEER-WARE LICENSE", Revision 69 (see LICENSE) + * @notes ADC1 CONFIGURATION: + * - hadc1.Init.ExternalTrigConv: who triggers the conversion + * - ADC_EXTERNALTRIGCONV_T2_TRGO => TIM2 triggers the conversion when + * TRGO fires (check TIM2 for details) + * - ADCCLK: PCLCK2/hadc1.Init.ClockPrescaler + * - PCLCK2 why? because ADC1/2/3 peripherals are on the APB2 bus (check stm32f446xx.h file) + * - hadc1.Init.ScanConvMode: if ENABLES means multiple channels/ranks will be sampled once triggered + * - hadc1.Init.NbrOfConversion: number of channels/ranks that will be sampled + * - hadc1.Init.ContinuousConvMode = DISABLED, why? because timer triggers the conversion + * - hadc1.Init.DiscontinuousConvMode = DISABLED, why? all channels need to be converted in sequence without halts + * - hadc1.Init.DMAContinuousRequests = ENABLED, why? DMA requests can continue to be generated after the conversion sequence ends (otherwise the DMA is disabled and must be re-enabled) + * - NOTE: this should be disabled if the timer is not in continuos mode or there is no retriggering via a timer (DMA remains active) + * - NOTE: this value is effective only if a DMA request is configured + * - hdma_adc1.Init.Mode = DMA_CIRCULAR; -> DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached. + * - hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; -> increase the memory address after each transfer + * - hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV; EndOfConversion event flag will be activated at the end of conversion of the sequence of channels/ranks instead of a single conversion (NOTE: interrupts must be enabled) + * - NOTE: IF DMA is enabled then setting EOCSelection as that will enable overrun detection feature + - hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD + - Peripheral data allignemtn for the DMA is halfword because the ADC Data Register (ADC.Instance.DR) is 16 bit wide. + This means that the trasnfer to memory will be necessary a halfword too! + - hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD + Therefore since the DMA is set with memory autoincrease and circular mode (see above) this means that + the autoincrease will be by HALWORDS. + @NOTE Therefore when HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length) is called: + - sizeof(pData[0]) == hdma_adc1.Init.MemDataAlignment + otherwise, if greater (uint32_t pData[N]), the DMA will save data in the vector each 16 bits: + a pData item will hold two values -> pData[0] = {[adc_conv1],[adc_conv0]}; + * @note ADC TIMINGS: + * - CHANNEL/RANK TOTAL SAMPLING CYCLES = sConfig.SamplingTime + hadc1.Init.Resolution(#ofbits) + 2 or 3 cycles (depending on resolution) + * - CHANNEL/RANK TOTAL SAMPLING TIME = (CHANNEL/RANK TOTAL SAMPLING CYCLES)/ADCCLK + * - SAMPLING FREQUENCY = the one of the timer + * + * @see https://wiki.st.com/stm32mcu/wiki/Getting_started_with_ADC + * @see https://deepbluembedded.com/stm32-adc-tutorial-complete-guide-with-examples/ + */ + +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "adc.h" + +/* USER CODE BEGIN 0 */ +#include "main.h" + +#include +#include +#include + +// TODO: remove old +double __adc1_dma_data_filtered[2] = {0}; + +uint16_t __adc1_dma_data[2] = {0}; +uint16_t __adc1_filtered_data[2] = {0}; +/** + * @brief Array that maps ADC1 channels to ranks + * @note ranks start from 1 + * @note non initialized channels are set to 0 an invalid rank + */ +static const uint8_t ADC_ADC1_Channel_to_Rank_map[ADC_Channel_NUM]={ + [ADC_Channel13]=1, + [ADC_Channel0]=2 +}; + +/* USER CODE END 0 */ + +ADC_HandleTypeDef hadc1; +DMA_HandleTypeDef hdma_adc1; + +/* ADC1 init function */ +void MX_ADC1_Init(void) +{ + + /* USER CODE BEGIN ADC1_Init 0 */ + + /* USER CODE END ADC1_Init 0 */ + + ADC_ChannelConfTypeDef sConfig = {0}; + + /* USER CODE BEGIN ADC1_Init 1 */ + + /* USER CODE END ADC1_Init 1 */ + + /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) + */ + hadc1.Instance = ADC1; + hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV6; + hadc1.Init.Resolution = ADC_RESOLUTION_12B; + hadc1.Init.ScanConvMode = ENABLE; + hadc1.Init.ContinuousConvMode = DISABLE; + hadc1.Init.DiscontinuousConvMode = DISABLE; + hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; + hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO; + hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc1.Init.NbrOfConversion = 2; + hadc1.Init.DMAContinuousRequests = ENABLE; + hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV; + if (HAL_ADC_Init(&hadc1) != HAL_OK) + { + Error_Handler(); + } + + /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. + */ + sConfig.Channel = ADC_CHANNEL_13; + sConfig.Rank = 1; + sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. + */ + sConfig.Channel = ADC_CHANNEL_0; + sConfig.Rank = 2; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN ADC1_Init 2 */ + + // Start ADC IN DMA MODE + HAL_TIM_Base_Start(&TIM_DMA1_HandleTypeDef); + HAL_ADC_Start_DMA(&hadc1, (uint32_t *)__adc1_dma_data, hadc1.Init.NbrOfConversion); + + /* USER CODE END ADC1_Init 2 */ + +} + +void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(adcHandle->Instance==ADC1) + { + /* USER CODE BEGIN ADC1_MspInit 0 */ + + /* USER CODE END ADC1_MspInit 0 */ + /* ADC1 clock enable */ + __HAL_RCC_ADC1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**ADC1 GPIO Configuration + PC3 ------> ADC1_IN13 + PA0-WKUP ------> ADC1_IN0 + */ + GPIO_InitStruct.Pin = SDC_TSAC_INIT_IN_ADC_IN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(SDC_TSAC_INIT_IN_ADC_IN_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = SDC_TSAC_FINAL_IN_ADC_IN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(SDC_TSAC_FINAL_IN_ADC_IN_GPIO_Port, &GPIO_InitStruct); + + /* ADC1 DMA Init */ + /* ADC1 Init */ + hdma_adc1.Instance = DMA2_Stream0; + hdma_adc1.Init.Channel = DMA_CHANNEL_0; + hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; + hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; + hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; + hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; + hdma_adc1.Init.Mode = DMA_CIRCULAR; + hdma_adc1.Init.Priority = DMA_PRIORITY_LOW; + hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + if (HAL_DMA_Init(&hdma_adc1) != HAL_OK) + { + Error_Handler(); + } + + __HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc1); + + /* ADC1 interrupt Init */ + HAL_NVIC_SetPriority(ADC_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(ADC_IRQn); + /* USER CODE BEGIN ADC1_MspInit 1 */ + + /* USER CODE END ADC1_MspInit 1 */ + } +} + +void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) +{ + + if(adcHandle->Instance==ADC1) + { + /* USER CODE BEGIN ADC1_MspDeInit 0 */ + + /* USER CODE END ADC1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_ADC1_CLK_DISABLE(); + + /**ADC1 GPIO Configuration + PC3 ------> ADC1_IN13 + PA0-WKUP ------> ADC1_IN0 + */ + HAL_GPIO_DeInit(SDC_TSAC_INIT_IN_ADC_IN_GPIO_Port, SDC_TSAC_INIT_IN_ADC_IN_Pin); + + HAL_GPIO_DeInit(SDC_TSAC_FINAL_IN_ADC_IN_GPIO_Port, SDC_TSAC_FINAL_IN_ADC_IN_Pin); + + /* ADC1 DMA DeInit */ + HAL_DMA_DeInit(adcHandle->DMA_Handle); + + /* ADC1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(ADC_IRQn); + /* USER CODE BEGIN ADC1_MspDeInit 1 */ + + /* USER CODE END ADC1_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ +int16_t ADC_ADC1_getChannelRaw(enum ADC_Channel channel){ + if (!(channel < ADC_Channel_NUM)) return -1; + int8_t rankNumber = ADC_ADC1_Channel_to_Rank_map[channel]; + return rankNumber > 0 ? __adc1_dma_data[rankNumber-1] : -1; +} + +int16_t ADC_ADC1_getChannelRawFiltered(enum ADC_Channel channel) { + if (!(channel < ADC_Channel_NUM)) return -1; + int8_t rankNumber = ADC_ADC1_Channel_to_Rank_map[channel]; + return rankNumber > 0 ? __adc1_filtered_data[rankNumber-1] : -1; +}; +/** + * @brief Implements a first-order IIR single pole low pass filter + * @long Y[n] = alpha * X[n] + (1-alpha)Y[n-1] + * Y[n] = new filtered sample + * Y[n-1] = previous filtered samples (history) + * X[n] = current sample + * @param alpha smoohting factor + * @param X_n currently sampled value + * @param Y_n_min1 previous sample already filtered (history) + * @return truncated filtered sample (Y[n]) + * @see https://en.wikipedia.org/wiki/Low-pass_filter#math_Q + * @see https://www.youtube.com/watch?v=QRMe02kzVkA + */ +static double _ADC_IIR_first_order(double alpha, double X_n, double Y_n_min1) { + // Y[n] = alpha * X[n] + (1-alpha)Y[n-1] + // = Y[n-1] + alpha * (X[n]-Y[n-1]) + return (uint32_t)(Y_n_min1 + alpha * (X_n - Y_n_min1)); +} + +/** + * @brief Regular conversion complete callback in non blocking mode + * @param hadc pointer to a ADC_HandleTypeDef structure that contains + * the configuration information for the specified ADC. + * @retval None + */ +void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) { + if(hadc == &hadc1){ + for (int i = 0; i < hadc1.Init.NbrOfConversion; ++i) { + __adc1_filtered_data[i] = _ADC_IIR_first_order(ADC_ADC1_IIR_ALPHA,(double)__adc1_dma_data[i],(double) __adc1_filtered_data[i]); + } + } +} + +///// OLD TODO: delete + +///** +// * @brief Transform RAW adc values to a real and physical counterpart +// * @details real_output[phisycal_unit] = offset[phisycal_value] + adc_raw_value[steps] * LSB_weight[Volts/steps] * gain[phisycal_unit/Volts] +// * @param adc_raw_data ADC raw data +// * @param adc_res_bit ADC resolution, number of bits +// * @param adc_FSR_mv ADC full-scale input range (in milli Volts) proportional to the reference voltage (usually 3300mV or else VDDA voltage on uC) +// * @param adc_sig_res_bit ADC significant/usable resolution bits, i.e. a 12 bit reading could have only the first 8 bit significant +// * @note adc_sig_res_bit <= adc_res_bit and both greater then 0 +// * @param offset Offest of the real measure the raw data is representing, has the same physical unit of the output +// * @param gain Multiplier coefficent that maps 1mV change to a physical change, e.g. 0.005 degC/mV means 1mV change is 0.005 degrees celsius change +// * @return real_output from the formula above +// */ +//static double _ADC_RawToReal(uint32_t adc_raw_data, +// uint8_t adc_res_bit, +// double adc_FSR_mv, +// uint8_t adc_sig_res_bit, +// double offset, +// double gain) { +// assert_param(adc_sig_res_bit > 0); +// assert_param(adc_res_bit > 0); +// assert_param(adc_sig_res_bit <= adc_res_bit); +// // If the adc resolution is 12 bit (adc_res_bit = 12) but the usable +// // and significant bits of the adc are the first 8 (adc_sig_res_bit = 8) +// // We mask the adc_raw_data with 0x1111_1111_0000 +// uint32_t raw_data_significant_bits_mask = ~((1U << (adc_res_bit - adc_sig_res_bit)) - 1U); +// uint32_t adc_raw_data_significant = adc_raw_data & raw_data_significant_bits_mask; +// double LSb_weight = adc_FSR_mv / (1U << adc_res_bit); // Least Significan Bit weight +// return offset + (adc_raw_data_significant * LSb_weight * gain); +//} +// +//uint32_t ADC_Get_Filtered_Raw(ADC_HandleTypeDef *hadc, uint8_t adc_channel) { +// if (hadc->Instance == SD_FB_ADC_Handle.Instance) { +// switch (adc_channel) { +// case SD_FB_SD_DLY_CAPS_TO_SD_FIN_OUT_AIRS_ADC1_IN_ADC_CHNL: +// return __adc1_dma_data_filtered[0]; +// break; +// case SD_FB_SD_PRCH_RLY_TO_SD_MID_OUT_ADC1_IN_ADC_CHNL: +// return __adc1_dma_data_filtered[1]; +// break; +// default: +// // Should not be here +// return -1U; +// break; +// } +// } else +// return -1U; // Should not be here +//} + +//double ADC_Get_Filtered_Real(ADC_HandleTypeDef *hadc, uint8_t adc_channel) { +// uint32_t raw = ADC_Get_Filtered_Raw(hadc, adc_channel); +// if (raw != (-1U)) +// return ADC_RawToReal(hadc, adc_channel, raw); +// else +// return DBL_MAX; +//} +// +//double ADC_RawToReal(ADC_HandleTypeDef *hadc, uint8_t adc_channel, uint32_t raw_adc_value) { +// assert_param(IS_ADC_CHANNEL(adc_channel)); +// if (hadc->Instance == SD_FB_ADC_Handle.Instance) { +// switch (adc_channel) { +// case SD_FB_SD_DLY_CAPS_TO_SD_FIN_OUT_AIRS_ADC1_IN_ADC_CHNL: +// case SD_FB_SD_PRCH_RLY_TO_SD_MID_OUT_ADC1_IN_ADC_CHNL: +// return _ADC_RawToReal(raw_adc_value, +// ADC_RESOLUTION_TO_NUMB_BITS(hadc->Init.Resolution), +// ADC_VDDA_mV, +// ADC_RESOLUTION_TO_NUMB_BITS(hadc->Init.Resolution), +// SD_FB_ADC_OFFSET, +// SD_FB_ADC_GAIN); +// break; +// default: +// // Should not be here +// return 0; +// break; +// } +// } else +// return 0; // Should not be here +//} +/* USER CODE END 1 */ diff --git a/Core/Src/bsp.c b/Core/Src/bsp.c index ed8a8f0..54139cc 100644 --- a/Core/Src/bsp.c +++ b/Core/Src/bsp.c @@ -340,7 +340,7 @@ void MCB_send_msg(uint32_t id) { CAN_CAN1_tx_header.DLC = mcb_tlb_bat_sd_csensing_status_pack(buffer, &msg.tlb_bat_sdc_sensing_status, 8); break; - case MCB_TLB_BATTERY_HELO: + case MCB_TLB_BAT_HELLO_FRAME_ID: msg.tlb_bat_hello.fw_major_version = mcb_tlb_bat_hello_fw_major_version_encode(VERSION_MAJOR); msg.tlb_bat_hello.fw_minor_version = mcb_tlb_bat_hello_fw_minor_version_encode(VERSION_MINOR); diff --git a/Core/Src/can.c b/Core/Src/can.c index b0322ba..12d83d3 100644 --- a/Core/Src/can.c +++ b/Core/Src/can.c @@ -1,346 +1,344 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file can.c - * @brief This file provides code for the configuration - * of the CAN instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "can.h" - -/* USER CODE BEGIN 0 */ -#include "bsp.h" -#include "gpio.h" -#include "main.h" -#include "mcb.h" -#include "usart.h" - -#include -#include -#include - -CAN_TxHeaderTypeDef CAN_CAN1_tx_header = {.ExtId = 0, .IDE=CAN_ID_STD, .RTR=CAN_RTR_DATA}; -volatile uint8_t CAN_err = 0; - -/* USER CODE END 0 */ - -CAN_HandleTypeDef hcan1; - -/* CAN1 init function */ -void MX_CAN1_Init(void) -{ - - /* USER CODE BEGIN CAN1_Init 0 */ - - /* USER CODE END CAN1_Init 0 */ - - /* USER CODE BEGIN CAN1_Init 1 */ - - /* USER CODE END CAN1_Init 1 */ - hcan1.Instance = CAN1; - hcan1.Init.Prescaler = 3; - hcan1.Init.Mode = CAN_MODE_NORMAL; - hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ; - hcan1.Init.TimeSeg1 = CAN_BS1_12TQ; - hcan1.Init.TimeSeg2 = CAN_BS2_2TQ; - hcan1.Init.TimeTriggeredMode = DISABLE; - hcan1.Init.AutoBusOff = ENABLE; - hcan1.Init.AutoWakeUp = DISABLE; - hcan1.Init.AutoRetransmission = DISABLE; - hcan1.Init.ReceiveFifoLocked = DISABLE; - hcan1.Init.TransmitFifoPriority = DISABLE; - if (HAL_CAN_Init(&hcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN CAN1_Init 2 */ - - CAN_FilterTypeDef filter; - -#define MCB_DIAGTOOL_xcpTX (0x286U) // Accepts XCP message for flashing via can - - filter.FilterScale = CAN_FILTERSCALE_16BIT; - filter.FilterMode = CAN_FILTERMODE_IDLIST; - /* HAL considers IdLow and IdHigh not as just the ID of the can message but - as the combination of: - STDID + RTR + IDE + 3 most significant bits of EXTID (not used in 16 bit mode) - Hence if you care only to filter by id shift by 5 - */ - filter.FilterIdLow = MCB_DIAGTOOL_xcpTX << 5U; // Filter for this ID (shift by 5 see filtering registers on RM) - filter.FilterIdHigh = MCB_DIAGTOOL_xcpTX << 5; // repeat the filter to not leave it empty - // - filter.FilterFIFOAssignment = CAN_FILTER_FIFO0; - filter.FilterBank = 0; - filter.FilterActivation = ENABLE; - filter.SlaveStartFilterBank = 14; - - HAL_CAN_ConfigFilter(&hcan1, &filter); - - HAL_CAN_ActivateNotification(&hcan1, - CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_ERROR_WARNING | CAN_IT_ERROR_PASSIVE | - CAN_IT_BUSOFF | CAN_IT_LAST_ERROR_CODE | CAN_IT_ERROR); - HAL_CAN_Start(&hcan1); - - /* USER CODE END CAN1_Init 2 */ - -} - -void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(canHandle->Instance==CAN1) - { - /* USER CODE BEGIN CAN1_MspInit 0 */ - - /* USER CODE END CAN1_MspInit 0 */ - /* CAN1 clock enable */ - __HAL_RCC_CAN1_CLK_ENABLE(); - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**CAN1 GPIO Configuration - PB8 ------> CAN1_RX - PB9 ------> CAN1_TX - */ - GPIO_InitStruct.Pin = SN65HVD23x_R_CAN_RX_Pin|SN65HVD23x_D_CAN_TX_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_CAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* CAN1 interrupt Init */ - HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn); - HAL_NVIC_SetPriority(CAN1_SCE_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(CAN1_SCE_IRQn); - /* USER CODE BEGIN CAN1_MspInit 1 */ - - /* USER CODE END CAN1_MspInit 1 */ - } -} - -void HAL_CAN_MspDeInit(CAN_HandleTypeDef* canHandle) -{ - - if(canHandle->Instance==CAN1) - { - /* USER CODE BEGIN CAN1_MspDeInit 0 */ - - /* USER CODE END CAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_CAN1_CLK_DISABLE(); - - /**CAN1 GPIO Configuration - PB8 ------> CAN1_RX - PB9 ------> CAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, SN65HVD23x_R_CAN_RX_Pin|SN65HVD23x_D_CAN_TX_Pin); - - /* CAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn); - HAL_NVIC_DisableIRQ(CAN1_SCE_IRQn); - /* USER CODE BEGIN CAN1_MspDeInit 1 */ - - /* USER CODE END CAN1_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) { - CAN_RxHeaderTypeDef rx_header; - uint8_t buffer[8] = {0}; - if(hcan == &MCB_Handle){ - if(HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_header, buffer) == HAL_OK) { - // Reset when preparing for flash via CAN bus - if(rx_header.StdId == MCB_DIAGTOOL_xcpTX && buffer[0] == 0xff && buffer[1] == 0x00) { - NVIC_SystemReset(); - } - } - } -} - -/** - * @brief Print the error message in the serial console and activate - * the CAN error LED - * */ -static void CAN_error_handler(CAN_HandleTypeDef *hcan) { - return; -#define print_log(x, y) ((void)0U) - - uint32_t err_code = HAL_CAN_GetError(hcan); - - if ((err_code & HAL_CAN_ERROR_EWG) == HAL_CAN_ERROR_EWG) - print_log("Protocol error warning", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_EPV) == HAL_CAN_ERROR_EPV) - print_log("Error passive", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_BOF) == HAL_CAN_ERROR_BOF) - print_log("Bus-off error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_STF) == HAL_CAN_ERROR_STF) - print_log("Stuff error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_FOR) == HAL_CAN_ERROR_FOR) - print_log("Form error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_ACK) == HAL_CAN_ERROR_ACK) - print_log("ACK error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_BR) == HAL_CAN_ERROR_BR) - print_log("Bit Recessive error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_BD) == HAL_CAN_ERROR_BD) - print_log("Bit Dominant error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_CRC) == HAL_CAN_ERROR_CRC) - print_log("CRC error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_RX_FOV0) == HAL_CAN_ERROR_RX_FOV0) - print_log("FIFO 0 overrun error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_RX_FOV1) == HAL_CAN_ERROR_RX_FOV1) - print_log("FIFO 1 overrun error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_TX_ALST0) == HAL_CAN_ERROR_TX_ALST0) - print_log("TX 0 arbitration lost error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_TX_TERR0) == HAL_CAN_ERROR_TX_TERR0) - print_log("TX 0 transmit error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_TX_ALST1) == HAL_CAN_ERROR_TX_ALST1) - print_log("TX 1 arbitration lost error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_TX_TERR1) == HAL_CAN_ERROR_TX_TERR1) - print_log("TX 1 transmit error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_TX_ALST2) == HAL_CAN_ERROR_TX_ALST2) - print_log("TX 2 arbitration lost error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_TX_TERR2) == HAL_CAN_ERROR_TX_TERR2) - print_log("TX 2 transmit error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_TIMEOUT) == HAL_CAN_ERROR_TIMEOUT) - print_log("Timeout error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_NOT_INITIALIZED) == HAL_CAN_ERROR_NOT_INITIALIZED) - print_log("CAN bus not initialized", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_NOT_READY) == HAL_CAN_ERROR_NOT_READY) - print_log("CAN bus not ready", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_NOT_STARTED) == HAL_CAN_ERROR_NOT_STARTED) - print_log("CAN bus not started", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_PARAM) == HAL_CAN_ERROR_PARAM) - print_log("Parameter error", NO_HEADER); - if ((err_code & HAL_CAN_ERROR_INTERNAL) == HAL_CAN_ERROR_INTERNAL) - print_log("Internal error", NO_HEADER); - - char buf[50]; - - uint16_t rec_val = (uint16_t)((hcan->Instance->ESR && CAN_ESR_REC_Msk) >> CAN_ESR_REC_Pos); - if (rec_val > 0) { - sprintf(buf, "REC (Receive Error Counter) %d", rec_val); - print_log(buf, NO_HEADER); - } - - uint16_t tec_val = (uint16_t)((hcan->Instance->ESR && CAN_ESR_TEC_Msk) >> CAN_ESR_TEC_Pos); - if (tec_val > 0) { - sprintf(buf, "TEC (Transmit Error Counter) %d", tec_val); - print_log(buf, NO_HEADER); - } - print_log("ERROR\r\n", NO_HEADER); -} - - -void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan) { - if(hcan == &MCB_Handle){ - CAN_error_handler(hcan); - } -} - -static HAL_StatusTypeDef CAN_wait(CAN_HandleTypeDef *hcan, uint8_t timeout) { - uint32_t tick = HAL_GetTick(); - while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) { - if(HAL_GetTick() - tick > timeout) return HAL_TIMEOUT; - } - return HAL_OK; -} - -HAL_StatusTypeDef CAN_send(CAN_HandleTypeDef *hcan, uint8_t *buffer, CAN_TxHeaderTypeDef *header) { - if(CAN_wait(hcan, 1) != HAL_OK) return HAL_TIMEOUT; - uint32_t mailbox; - - volatile HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(hcan, header, buffer, &mailbox); - - return status; -} - -//void _CAN_SendInstantMessagesRoutine(void) { -// // check instant ERROR messages -// -// uint8_t send_shut_status_message = 0; -// uint8_t send_tsal_status_message = 0; -// -// if (GPIO_fall_edge_events[SD_FB_SD_FNL_IN_TO_SD_DLY_CAPS] != 0) { -// send_shut_status_message = 1; -// DB_data.sd_fnl_in_to_sd_dly_caps = 1U; -// } -// -// if (GPIO_rise_edge_events[AMS_ERR] != 0) { -// send_tsal_status_message = 1; -// DB_data.ams_err = 1U; -// } -// if (GPIO_rise_edge_events[IMD_ERR] != 0) { -// send_tsal_status_message = 1; -// DB_data.imd_err = 1U; -// } -// if (GPIO_rise_edge_events[FB_ANY_IMPL_ERR_LTCH] != 0) { -// send_tsal_status_message = 1; -// DB_data.any_impl_err_ltch = 1U; -// } -// if (GPIO_rise_edge_events[FB_DCBUS_OVER_60V_IMPL_ERR] != 0) { -// send_tsal_status_message = 1; -// DB_data.dcbus_over_60v_impl_err = 1U; -// } -// // if an error toggled -// // - if the error was not already active -// // -- send message -// // - else (the error was already active) -// // -- do nothing -// // else (the error is not active) -// // -- do nothing -// // AMS Error -// if (send_shut_status_message) { -// // re-sample -// CAN_SendMsg(&MCB_Handle, MCB_TLB_BATTERY_SHUT_STATUS_FRAME_ID); -// } -// if (send_tsal_status_message) { -// // re-sample -// CAN_SendMsg(&MCB_Handle, MCB_TLB_BATTERY_TSAL_STATUS_FRAME_ID); -// } -//} - -//void CAN_SendMessagesRoutine(void) { -// static volatile uint32_t cnt100ms = 0U; -// static volatile uint32_t cnt1000ms = 0U; -// -// // Instant Messages -// // _CAN_SendInstantMessagesRoutine(); //TODO -// -// // 100 ms messages -// if (HAL_GetTick() >= cnt100ms) { -// cnt100ms = HAL_GetTick() + 100U; -// CAN_Send100msMessages(); -// } -// -// // 1s messages -// if (HAL_GetTick() >= cnt1000ms) { -// cnt1000ms = HAL_GetTick() + 1000U; -// CAN_Send1secMessages(); -// } -//} - -//void CAN_Send100msMessages(void) { -// CAN_SendMsg(&MCB_Handle, MCB_TLB_BATTERY_TSAL_STATUS_FRAME_ID); -// CAN_SendMsg(&MCB_Handle, MCB_TLB_BATTERY_SHUT_STATUS_FRAME_ID); -//} -// -//void CAN_Send1secMessages(void) { -// __NOP(); -//}; -/* USER CODE END 1 */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file can.c + * @brief This file provides code for the configuration + * of the CAN instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "can.h" + +/* USER CODE BEGIN 0 */ +#include "bsp.h" +#include "gpio.h" +#include "main.h" +#include "mcb.h" +#include "usart.h" + +#include +#include +#include + +CAN_TxHeaderTypeDef CAN_CAN1_tx_header = {.ExtId = 0, .IDE=CAN_ID_STD, .RTR=CAN_RTR_DATA}; +volatile uint8_t CAN_err = 0; + +/* USER CODE END 0 */ + +CAN_HandleTypeDef hcan1; + +/* CAN1 init function */ +void MX_CAN1_Init(void) +{ + + /* USER CODE BEGIN CAN1_Init 0 */ + + /* USER CODE END CAN1_Init 0 */ + + /* USER CODE BEGIN CAN1_Init 1 */ + + /* USER CODE END CAN1_Init 1 */ + hcan1.Instance = CAN1; + hcan1.Init.Prescaler = 3; + hcan1.Init.Mode = CAN_MODE_NORMAL; + hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ; + hcan1.Init.TimeSeg1 = CAN_BS1_12TQ; + hcan1.Init.TimeSeg2 = CAN_BS2_2TQ; + hcan1.Init.TimeTriggeredMode = DISABLE; + hcan1.Init.AutoBusOff = ENABLE; + hcan1.Init.AutoWakeUp = DISABLE; + hcan1.Init.AutoRetransmission = ENABLE; + hcan1.Init.ReceiveFifoLocked = DISABLE; + hcan1.Init.TransmitFifoPriority = DISABLE; + if (HAL_CAN_Init(&hcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN CAN1_Init 2 */ + + CAN_FilterTypeDef filter; + + + filter.FilterScale = CAN_FILTERSCALE_16BIT; + filter.FilterMode = CAN_FILTERMODE_IDLIST; + /* HAL considers IdLow and IdHigh not as just the ID of the can message but + as the combination of: + STDID + RTR + IDE + 3 most significant bits of EXTID (not used in 16 bit mode) + Hence if you care only to filter by id shift by 5 + */ + filter.FilterIdLow = MCB_DIAG_TOOL_XCP_TX_TLB_BAT_FRAME_ID << 5U; // Filter for this ID (shift by 5 see filtering registers on RM) + filter.FilterIdHigh = MCB_DIAG_TOOL_XCP_TX_TLB_BAT_FRAME_ID << 5U; // repeat the filter to not leave it empty + filter.FilterFIFOAssignment = CAN_FILTER_FIFO0; + filter.FilterBank = 0; + filter.FilterActivation = ENABLE; + filter.SlaveStartFilterBank = 14; + + HAL_CAN_ConfigFilter(&hcan1, &filter); + + HAL_CAN_ActivateNotification(&hcan1, + CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_ERROR_WARNING | CAN_IT_ERROR_PASSIVE | + CAN_IT_BUSOFF | CAN_IT_LAST_ERROR_CODE | CAN_IT_ERROR); + HAL_CAN_Start(&hcan1); + + /* USER CODE END CAN1_Init 2 */ + +} + +void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(canHandle->Instance==CAN1) + { + /* USER CODE BEGIN CAN1_MspInit 0 */ + + /* USER CODE END CAN1_MspInit 0 */ + /* CAN1 clock enable */ + __HAL_RCC_CAN1_CLK_ENABLE(); + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**CAN1 GPIO Configuration + PB8 ------> CAN1_RX + PB9 ------> CAN1_TX + */ + GPIO_InitStruct.Pin = SN65HVD23x_R_CAN_RX_Pin|SN65HVD23x_D_CAN_TX_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF9_CAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* CAN1 interrupt Init */ + HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn); + HAL_NVIC_SetPriority(CAN1_SCE_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(CAN1_SCE_IRQn); + /* USER CODE BEGIN CAN1_MspInit 1 */ + + /* USER CODE END CAN1_MspInit 1 */ + } +} + +void HAL_CAN_MspDeInit(CAN_HandleTypeDef* canHandle) +{ + + if(canHandle->Instance==CAN1) + { + /* USER CODE BEGIN CAN1_MspDeInit 0 */ + + /* USER CODE END CAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_CAN1_CLK_DISABLE(); + + /**CAN1 GPIO Configuration + PB8 ------> CAN1_RX + PB9 ------> CAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, SN65HVD23x_R_CAN_RX_Pin|SN65HVD23x_D_CAN_TX_Pin); + + /* CAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn); + HAL_NVIC_DisableIRQ(CAN1_SCE_IRQn); + /* USER CODE BEGIN CAN1_MspDeInit 1 */ + + /* USER CODE END CAN1_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) { + CAN_RxHeaderTypeDef rx_header; + uint8_t buffer[8] = {0}; + if(hcan == &MCB_Handle){ + if(HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_header, buffer) == HAL_OK) { + // Reset when preparing for flash via CAN bus + if(rx_header.StdId == MCB_DIAG_TOOL_XCP_TX_TLB_BAT_FRAME_ID && buffer[0] == 0xff && buffer[1] == 0x00) { + NVIC_SystemReset(); + } + } + } +} + +/** + * @brief Print the error message in the serial console and activate + * the CAN error LED + * */ +static void CAN_error_handler(CAN_HandleTypeDef *hcan) { + return; +#define print_log(x, y) ((void)0U) + + uint32_t err_code = HAL_CAN_GetError(hcan); + + if ((err_code & HAL_CAN_ERROR_EWG) == HAL_CAN_ERROR_EWG) + print_log("Protocol error warning", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_EPV) == HAL_CAN_ERROR_EPV) + print_log("Error passive", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_BOF) == HAL_CAN_ERROR_BOF) + print_log("Bus-off error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_STF) == HAL_CAN_ERROR_STF) + print_log("Stuff error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_FOR) == HAL_CAN_ERROR_FOR) + print_log("Form error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_ACK) == HAL_CAN_ERROR_ACK) + print_log("ACK error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_BR) == HAL_CAN_ERROR_BR) + print_log("Bit Recessive error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_BD) == HAL_CAN_ERROR_BD) + print_log("Bit Dominant error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_CRC) == HAL_CAN_ERROR_CRC) + print_log("CRC error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_RX_FOV0) == HAL_CAN_ERROR_RX_FOV0) + print_log("FIFO 0 overrun error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_RX_FOV1) == HAL_CAN_ERROR_RX_FOV1) + print_log("FIFO 1 overrun error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_TX_ALST0) == HAL_CAN_ERROR_TX_ALST0) + print_log("TX 0 arbitration lost error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_TX_TERR0) == HAL_CAN_ERROR_TX_TERR0) + print_log("TX 0 transmit error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_TX_ALST1) == HAL_CAN_ERROR_TX_ALST1) + print_log("TX 1 arbitration lost error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_TX_TERR1) == HAL_CAN_ERROR_TX_TERR1) + print_log("TX 1 transmit error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_TX_ALST2) == HAL_CAN_ERROR_TX_ALST2) + print_log("TX 2 arbitration lost error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_TX_TERR2) == HAL_CAN_ERROR_TX_TERR2) + print_log("TX 2 transmit error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_TIMEOUT) == HAL_CAN_ERROR_TIMEOUT) + print_log("Timeout error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_NOT_INITIALIZED) == HAL_CAN_ERROR_NOT_INITIALIZED) + print_log("CAN bus not initialized", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_NOT_READY) == HAL_CAN_ERROR_NOT_READY) + print_log("CAN bus not ready", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_NOT_STARTED) == HAL_CAN_ERROR_NOT_STARTED) + print_log("CAN bus not started", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_PARAM) == HAL_CAN_ERROR_PARAM) + print_log("Parameter error", NO_HEADER); + if ((err_code & HAL_CAN_ERROR_INTERNAL) == HAL_CAN_ERROR_INTERNAL) + print_log("Internal error", NO_HEADER); + + char buf[50]; + + uint16_t rec_val = (uint16_t)((hcan->Instance->ESR && CAN_ESR_REC_Msk) >> CAN_ESR_REC_Pos); + if (rec_val > 0) { + sprintf(buf, "REC (Receive Error Counter) %d", rec_val); + print_log(buf, NO_HEADER); + } + + uint16_t tec_val = (uint16_t)((hcan->Instance->ESR && CAN_ESR_TEC_Msk) >> CAN_ESR_TEC_Pos); + if (tec_val > 0) { + sprintf(buf, "TEC (Transmit Error Counter) %d", tec_val); + print_log(buf, NO_HEADER); + } + print_log("ERROR\r\n", NO_HEADER); +} + + +void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan) { + if(hcan == &MCB_Handle){ + CAN_error_handler(hcan); + } +} + +static HAL_StatusTypeDef CAN_wait(CAN_HandleTypeDef *hcan, uint8_t timeout) { + uint32_t tick = HAL_GetTick(); + while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) { + if(HAL_GetTick() - tick > timeout) return HAL_TIMEOUT; + } + return HAL_OK; +} + +HAL_StatusTypeDef CAN_send(CAN_HandleTypeDef *hcan, uint8_t *buffer, CAN_TxHeaderTypeDef *header) { + if(CAN_wait(hcan, 1) != HAL_OK) return HAL_TIMEOUT; + uint32_t mailbox; + + volatile HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(hcan, header, buffer, &mailbox); + + return status; +} + +//void _CAN_SendInstantMessagesRoutine(void) { +// // check instant ERROR messages +// +// uint8_t send_shut_status_message = 0; +// uint8_t send_tsal_status_message = 0; +// +// if (GPIO_fall_edge_events[SD_FB_SD_FNL_IN_TO_SD_DLY_CAPS] != 0) { +// send_shut_status_message = 1; +// DB_data.sd_fnl_in_to_sd_dly_caps = 1U; +// } +// +// if (GPIO_rise_edge_events[AMS_ERR] != 0) { +// send_tsal_status_message = 1; +// DB_data.ams_err = 1U; +// } +// if (GPIO_rise_edge_events[IMD_ERR] != 0) { +// send_tsal_status_message = 1; +// DB_data.imd_err = 1U; +// } +// if (GPIO_rise_edge_events[FB_ANY_IMPL_ERR_LTCH] != 0) { +// send_tsal_status_message = 1; +// DB_data.any_impl_err_ltch = 1U; +// } +// if (GPIO_rise_edge_events[FB_DCBUS_OVER_60V_IMPL_ERR] != 0) { +// send_tsal_status_message = 1; +// DB_data.dcbus_over_60v_impl_err = 1U; +// } +// // if an error toggled +// // - if the error was not already active +// // -- send message +// // - else (the error was already active) +// // -- do nothing +// // else (the error is not active) +// // -- do nothing +// // AMS Error +// if (send_shut_status_message) { +// // re-sample +// CAN_SendMsg(&MCB_Handle, MCB_TLB_BATTERY_SHUT_STATUS_FRAME_ID); +// } +// if (send_tsal_status_message) { +// // re-sample +// CAN_SendMsg(&MCB_Handle, MCB_TLB_BATTERY_TSAL_STATUS_FRAME_ID); +// } +//} + +//void CAN_SendMessagesRoutine(void) { +// static volatile uint32_t cnt100ms = 0U; +// static volatile uint32_t cnt1000ms = 0U; +// +// // Instant Messages +// // _CAN_SendInstantMessagesRoutine(); //TODO +// +// // 100 ms messages +// if (HAL_GetTick() >= cnt100ms) { +// cnt100ms = HAL_GetTick() + 100U; +// CAN_Send100msMessages(); +// } +// +// // 1s messages +// if (HAL_GetTick() >= cnt1000ms) { +// cnt1000ms = HAL_GetTick() + 1000U; +// CAN_Send1secMessages(); +// } +//} + +//void CAN_Send100msMessages(void) { +// CAN_SendMsg(&MCB_Handle, MCB_TLB_BATTERY_TSAL_STATUS_FRAME_ID); +// CAN_SendMsg(&MCB_Handle, MCB_TLB_BATTERY_SHUT_STATUS_FRAME_ID); +//} +// +//void CAN_Send1secMessages(void) { +// __NOP(); +//}; +/* USER CODE END 1 */ diff --git a/Core/Src/dma.c b/Core/Src/dma.c index e807baa..d67333c 100644 --- a/Core/Src/dma.c +++ b/Core/Src/dma.c @@ -1,55 +1,55 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.c - * @brief This file provides code for the configuration - * of all the requested memory to memory DMA transfers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "dma.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure DMA */ -/*----------------------------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Enable DMA controller clock - */ -void MX_DMA_Init(void) -{ - - /* DMA controller clock enable */ - __HAL_RCC_DMA2_CLK_ENABLE(); - - /* DMA interrupt init */ - /* DMA2_Stream0_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn); - -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ - +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file dma.c + * @brief This file provides code for the configuration + * of all the requested memory to memory DMA transfers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "dma.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/*----------------------------------------------------------------------------*/ +/* Configure DMA */ +/*----------------------------------------------------------------------------*/ + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/** + * Enable DMA controller clock + */ +void MX_DMA_Init(void) +{ + + /* DMA controller clock enable */ + __HAL_RCC_DMA2_CLK_ENABLE(); + + /* DMA interrupt init */ + /* DMA2_Stream0_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn); + +} + +/* USER CODE BEGIN 2 */ + +/* USER CODE END 2 */ + diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index c221504..8cde8a2 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -1,99 +1,99 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI -*/ -void MX_GPIO_Init(void) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, ERR_LED_GPIO_OUT_Pin|WARN_LED_GPIO_OUT_Pin|STAT3_LED_GPIO_OUT_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, STAT1_LED_GPIO_OUT_Pin|STAT2_LED_GPIO_OUT_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pins : PCPin PCPin PCPin PCPin */ - GPIO_InitStruct.Pin = IMD_ERR_LATCH_GPIO_IN_Pin|SDC_POST_AMS_IMD_RLY_GPIO_IN_Pin|DCBUS_IMPL_GPIO_IN_Pin|SDC_PRECH_CMD__INT_STATE_OPEN_GPIO_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pins : PAPin PAPin PAPin PAPin - PAPin PAPin PAPin PAPin */ - GPIO_InitStruct.Pin = AMS_ERR_LATCH_GPIO_IN_Pin|AIR_POS__INT_STATE_CLOSED_GPIO_IN_Pin|AIR_NEG__INT_STATE_CLOSED_GPIO_IN_Pin|DCBUS_PRECH__INT_STATE_CLOSED_GPIO_IN_Pin - |DCBUS_RELAYS_IMPL_GPIO_IN_Pin|AIR_NEG__MECH_STATE_OPEN_3V3_Pin|AIR_POS__MECH_STATE_OPEN_GPIO_IN_Pin|DCBUS_OVER_60V_GPIO_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /*Configure GPIO pins : PCPin PCPin PCPin */ - GPIO_InitStruct.Pin = ERR_LED_GPIO_OUT_Pin|WARN_LED_GPIO_OUT_Pin|STAT3_LED_GPIO_OUT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pins : PBPin PBPin */ - GPIO_InitStruct.Pin = STAT1_LED_GPIO_OUT_Pin|STAT2_LED_GPIO_OUT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pins : PBPin PBPin PBPin PBPin - PBPin */ - GPIO_InitStruct.Pin = nSTG_AIR_NEG_GPIO_IN_Pin|nSTG_AIR_POS_GPIO_IN_Pin|DCBUS_PRECH__MECH_STATE_OPEN_GPIO_IN_Pin|TSAL_GREEN_GPIO_IN_Pin - |ANY_IMPL_ERR_LATCH_GPIO_IN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.c + * @brief This file provides code for the configuration + * of all used GPIO pins. + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "gpio.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/*----------------------------------------------------------------------------*/ +/* Configure GPIO */ +/*----------------------------------------------------------------------------*/ +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/** Configure pins as + * Analog + * Input + * Output + * EVENT_OUT + * EXTI +*/ +void MX_GPIO_Init(void) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOH_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOC, ERR_LED_GPIO_OUT_Pin|WARN_LED_GPIO_OUT_Pin|STAT3_LED_GPIO_OUT_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, STAT1_LED_GPIO_OUT_Pin|STAT2_LED_GPIO_OUT_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pins : PCPin PCPin PCPin PCPin */ + GPIO_InitStruct.Pin = IMD_ERR_LATCH_GPIO_IN_Pin|SDC_POST_AMS_IMD_RLY_GPIO_IN_Pin|DCBUS_IMPL_GPIO_IN_Pin|SDC_PRECH_CMD__INT_STATE_OPEN_GPIO_IN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pins : PAPin PAPin PAPin PAPin + PAPin PAPin PAPin PAPin */ + GPIO_InitStruct.Pin = AMS_ERR_LATCH_GPIO_IN_Pin|AIR_POS__INT_STATE_CLOSED_GPIO_IN_Pin|AIR_NEG__INT_STATE_CLOSED_GPIO_IN_Pin|DCBUS_PRECH__INT_STATE_CLOSED_GPIO_IN_Pin + |DCBUS_RELAYS_IMPL_GPIO_IN_Pin|AIR_NEG__MECH_STATE_OPEN_3V3_Pin|AIR_POS__MECH_STATE_OPEN_GPIO_IN_Pin|DCBUS_OVER_60V_GPIO_IN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /*Configure GPIO pins : PCPin PCPin PCPin */ + GPIO_InitStruct.Pin = ERR_LED_GPIO_OUT_Pin|WARN_LED_GPIO_OUT_Pin|STAT3_LED_GPIO_OUT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pins : PBPin PBPin */ + GPIO_InitStruct.Pin = STAT1_LED_GPIO_OUT_Pin|STAT2_LED_GPIO_OUT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /*Configure GPIO pins : PBPin PBPin PBPin PBPin + PBPin */ + GPIO_InitStruct.Pin = nSTG_AIR_NEG_GPIO_IN_Pin|nSTG_AIR_POS_GPIO_IN_Pin|DCBUS_PRECH__MECH_STATE_OPEN_GPIO_IN_Pin|TSAL_GREEN_GPIO_IN_Pin + |ANY_IMPL_ERR_LATCH_GPIO_IN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + +} + +/* USER CODE BEGIN 2 */ + +/* USER CODE END 2 */ diff --git a/Core/Src/iwdg.c b/Core/Src/iwdg.c index 802eaef..7a3bcbe 100644 --- a/Core/Src/iwdg.c +++ b/Core/Src/iwdg.c @@ -1,55 +1,55 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file iwdg.c - * @brief This file provides code for the configuration - * of the IWDG instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "iwdg.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -IWDG_HandleTypeDef hiwdg; - -/* IWDG init function */ -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.Reload = 4096-1; - if (HAL_IWDG_Init(&hiwdg) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN IWDG_Init 2 */ - - /* USER CODE END IWDG_Init 2 */ - -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file iwdg.c + * @brief This file provides code for the configuration + * of the IWDG instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "iwdg.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +IWDG_HandleTypeDef hiwdg; + +/* IWDG init function */ +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.Reload = 4096-1; + if (HAL_IWDG_Init(&hiwdg) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN IWDG_Init 2 */ + + /* USER CODE END IWDG_Init 2 */ + +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Core/Src/main.c b/Core/Src/main.c index 69f1546..53452bc 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -1,231 +1,232 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "adc.h" -#include "can.h" -#include "dma.h" -#include "iwdg.h" -#include "tim.h" -#include "usart.h" -#include "gpio.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -#include "bsp.h" - -#include -#include - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - MX_TIM2_Init(); - MX_ADC1_Init(); - MX_CAN1_Init(); - MX_USART2_UART_Init(); - MX_IWDG_Init(); - /* USER CODE BEGIN 2 */ - MCB_send_msg(MCB_TLB_BATTERY_HELO); - /* USER CODE END 2 */ - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - char log_buf[400] = {0}; // init logging buffer - volatile uint32_t cnt_10ms = HAL_GetTick() + 10U; - volatile uint32_t cnt_100ms = HAL_GetTick() + 100U; - volatile uint32_t cnt_500ms = HAL_GetTick() + 500U; - volatile uint32_t cnt_1s = HAL_GetTick() + 1000U; - while (1) { - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ - - if (HAL_GetTick() >= cnt_10ms) { - cnt_10ms = HAL_GetTick() + 10U; - } - - if (HAL_GetTick() >= cnt_100ms) { - } - - STAT_LED_Routine(); - SDC_SENS_Routine(); - SDC_ANAL_SENS_Routine(); - SIG_SENS_Routine(); - HVRLYS_SENS_Routine(); - - // needs updated data so leave routine as last - MCB_SendMessagesRoutine(); - - HAL_IWDG_Refresh(&hiwdg); // refresh watchdog ~500ms timeout - - } // end while(1) - /* USER CODE END 3 */ -} - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - - /** Configure the main internal regulator output voltage - */ - __HAL_RCC_PWR_CLK_ENABLE(); - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.LSIState = RCC_LSI_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 4; - RCC_OscInitStruct.PLL.PLLN = 180; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = 2; - RCC_OscInitStruct.PLL.PLLR = 2; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } - - /** Activate the Over-Drive mode - */ - if (HAL_PWREx_EnableOverDrive() != HAL_OK) - { - Error_Handler(); - } - - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) - { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ - __disable_irq(); - while (1) { - } - /* USER CODE END Error_Handler_Debug */ -} - -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - * es: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "adc.h" +#include "can.h" +#include "dma.h" +#include "iwdg.h" +#include "tim.h" +#include "usart.h" +#include "gpio.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +#include "bsp.h" +#include "mcb.h" + +#include +#include + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN PTD */ + +/* USER CODE END PTD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ + +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +void SystemClock_Config(void); +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/** + * @brief The application entry point. + * @retval int + */ +int main(void) +{ + + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_DMA_Init(); + MX_TIM2_Init(); + MX_ADC1_Init(); + MX_CAN1_Init(); + MX_USART2_UART_Init(); + MX_IWDG_Init(); + /* USER CODE BEGIN 2 */ + MCB_send_msg(MCB_TLB_BAT_HELLO_FRAME_ID); + /* USER CODE END 2 */ + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + char log_buf[400] = {0}; // init logging buffer + volatile uint32_t cnt_10ms = HAL_GetTick() + 10U; + volatile uint32_t cnt_100ms = HAL_GetTick() + 100U; + volatile uint32_t cnt_500ms = HAL_GetTick() + 500U; + volatile uint32_t cnt_1s = HAL_GetTick() + 1000U; + while (1) { + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + + if (HAL_GetTick() >= cnt_10ms) { + cnt_10ms = HAL_GetTick() + 10U; + } + + if (HAL_GetTick() >= cnt_100ms) { + } + + STAT_LED_Routine(); + SDC_SENS_Routine(); + SDC_ANAL_SENS_Routine(); + SIG_SENS_Routine(); + HVRLYS_SENS_Routine(); + + // needs updated data so leave routine as last + MCB_SendMessagesRoutine(); + + HAL_IWDG_Refresh(&hiwdg); // refresh watchdog ~500ms timeout + + } // end while(1) + /* USER CODE END 3 */ +} + +/** + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure the main internal regulator output voltage + */ + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.LSIState = RCC_LSI_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 4; + RCC_OscInitStruct.PLL.PLLN = 180; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 2; + RCC_OscInitStruct.PLL.PLLR = 2; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + /** Activate the Over-Drive mode + */ + if (HAL_PWREx_EnableOverDrive() != HAL_OK) + { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) + { + Error_Handler(); + } +} + +/* USER CODE BEGIN 4 */ + +/* USER CODE END 4 */ + +/** + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) +{ + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while (1) { + } + /* USER CODE END Error_Handler_Debug */ +} + +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) +{ + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line number, + * es: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + /* USER CODE END 6 */ +} +#endif /* USE_FULL_ASSERT */ diff --git a/Core/Src/stm32f4xx_hal_msp.c b/Core/Src/stm32f4xx_hal_msp.c index e4c0192..a4ef761 100644 --- a/Core/Src/stm32f4xx_hal_msp.c +++ b/Core/Src/stm32f4xx_hal_msp.c @@ -1,83 +1,83 @@ - -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN TD */ - -/* USER CODE END TD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN Define */ - -/* USER CODE END Define */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN Macro */ - -/* USER CODE END Macro */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* External functions --------------------------------------------------------*/ -/* USER CODE BEGIN ExternalFunctions */ - -/* USER CODE END ExternalFunctions */ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ -/** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) -{ - - /* USER CODE BEGIN MspInit 0 */ - - /* USER CODE END MspInit 0 */ - - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); - - /* System interrupt init*/ - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ + +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN Define */ + +/* USER CODE END Define */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN Macro */ + +/* USER CODE END Macro */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* External functions --------------------------------------------------------*/ +/* USER CODE BEGIN ExternalFunctions */ + +/* USER CODE END ExternalFunctions */ + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ +/** + * Initializes the Global MSP. + */ +void HAL_MspInit(void) +{ + + /* USER CODE BEGIN MspInit 0 */ + + /* USER CODE END MspInit 0 */ + + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); + + /* System interrupt init*/ + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index c5ee7ab..c83b10b 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -1,275 +1,275 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "stm32f4xx_it.h" -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN TD */ - -/* USER CODE END TD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* External variables --------------------------------------------------------*/ -extern DMA_HandleTypeDef hdma_adc1; -extern ADC_HandleTypeDef hadc1; -extern CAN_HandleTypeDef hcan1; -extern TIM_HandleTypeDef htim2; -/* USER CODE BEGIN EV */ - -/* USER CODE END EV */ - -/******************************************************************************/ -/* Cortex-M4 Processor Interruption and Exception Handlers */ -/******************************************************************************/ -/** - * @brief This function handles Non maskable interrupt. - */ -void NMI_Handler(void) -{ - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - while (1) { - } - /* USER CODE END NonMaskableInt_IRQn 1 */ -} - -/** - * @brief This function handles Hard fault interrupt. - */ -void HardFault_Handler(void) -{ - /* USER CODE BEGIN HardFault_IRQn 0 */ - - /* USER CODE END HardFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_HardFault_IRQn 0 */ - /* USER CODE END W1_HardFault_IRQn 0 */ - } -} - -/** - * @brief This function handles Memory management fault. - */ -void MemManage_Handler(void) -{ - /* USER CODE BEGIN MemoryManagement_IRQn 0 */ - - /* USER CODE END MemoryManagement_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ - /* USER CODE END W1_MemoryManagement_IRQn 0 */ - } -} - -/** - * @brief This function handles Pre-fetch fault, memory access fault. - */ -void BusFault_Handler(void) -{ - /* USER CODE BEGIN BusFault_IRQn 0 */ - - /* USER CODE END BusFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_BusFault_IRQn 0 */ - /* USER CODE END W1_BusFault_IRQn 0 */ - } -} - -/** - * @brief This function handles Undefined instruction or illegal state. - */ -void UsageFault_Handler(void) -{ - /* USER CODE BEGIN UsageFault_IRQn 0 */ - - /* USER CODE END UsageFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ - /* USER CODE END W1_UsageFault_IRQn 0 */ - } -} - -/** - * @brief This function handles System service call via SWI instruction. - */ -void SVC_Handler(void) -{ - /* USER CODE BEGIN SVCall_IRQn 0 */ - - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ - - /* USER CODE END SVCall_IRQn 1 */ -} - -/** - * @brief This function handles Debug monitor. - */ -void DebugMon_Handler(void) -{ - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - - /* USER CODE END DebugMonitor_IRQn 1 */ -} - -/** - * @brief This function handles Pendable request for system service. - */ -void PendSV_Handler(void) -{ - /* USER CODE BEGIN PendSV_IRQn 0 */ - - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ - - /* USER CODE END PendSV_IRQn 1 */ -} - -/** - * @brief This function handles System tick timer. - */ -void SysTick_Handler(void) -{ - /* USER CODE BEGIN SysTick_IRQn 0 */ - - /* USER CODE END SysTick_IRQn 0 */ - HAL_IncTick(); - /* USER CODE BEGIN SysTick_IRQn 1 */ - - /* USER CODE END SysTick_IRQn 1 */ -} - -/******************************************************************************/ -/* STM32F4xx Peripheral Interrupt Handlers */ -/* Add here the Interrupt Handlers for the used peripherals. */ -/* For the available peripheral interrupt handler names, */ -/* please refer to the startup file (startup_stm32f4xx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles ADC1, ADC2 and ADC3 interrupts. - */ -void ADC_IRQHandler(void) -{ - /* USER CODE BEGIN ADC_IRQn 0 */ - - /* USER CODE END ADC_IRQn 0 */ - HAL_ADC_IRQHandler(&hadc1); - /* USER CODE BEGIN ADC_IRQn 1 */ - - /* USER CODE END ADC_IRQn 1 */ -} - -/** - * @brief This function handles CAN1 RX0 interrupt. - */ -void CAN1_RX0_IRQHandler(void) -{ - /* USER CODE BEGIN CAN1_RX0_IRQn 0 */ - - /* USER CODE END CAN1_RX0_IRQn 0 */ - HAL_CAN_IRQHandler(&hcan1); - /* USER CODE BEGIN CAN1_RX0_IRQn 1 */ - - /* USER CODE END CAN1_RX0_IRQn 1 */ -} - -/** - * @brief This function handles CAN1 SCE interrupt. - */ -void CAN1_SCE_IRQHandler(void) -{ - /* USER CODE BEGIN CAN1_SCE_IRQn 0 */ - - /* USER CODE END CAN1_SCE_IRQn 0 */ - HAL_CAN_IRQHandler(&hcan1); - /* USER CODE BEGIN CAN1_SCE_IRQn 1 */ - - /* USER CODE END CAN1_SCE_IRQn 1 */ -} - -/** - * @brief This function handles TIM2 global interrupt. - */ -void TIM2_IRQHandler(void) -{ - /* USER CODE BEGIN TIM2_IRQn 0 */ - - /* USER CODE END TIM2_IRQn 0 */ - HAL_TIM_IRQHandler(&htim2); - /* USER CODE BEGIN TIM2_IRQn 1 */ - - /* USER CODE END TIM2_IRQn 1 */ -} - -/** - * @brief This function handles DMA2 stream0 global interrupt. - */ -void DMA2_Stream0_IRQHandler(void) -{ - /* USER CODE BEGIN DMA2_Stream0_IRQn 0 */ - - /* USER CODE END DMA2_Stream0_IRQn 0 */ - HAL_DMA_IRQHandler(&hdma_adc1); - /* USER CODE BEGIN DMA2_Stream0_IRQn 1 */ - - /* USER CODE END DMA2_Stream0_IRQn 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "stm32f4xx_it.h" +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* External variables --------------------------------------------------------*/ +extern DMA_HandleTypeDef hdma_adc1; +extern ADC_HandleTypeDef hadc1; +extern CAN_HandleTypeDef hcan1; +extern TIM_HandleTypeDef htim2; +/* USER CODE BEGIN EV */ + +/* USER CODE END EV */ + +/******************************************************************************/ +/* Cortex-M4 Processor Interruption and Exception Handlers */ +/******************************************************************************/ +/** + * @brief This function handles Non maskable interrupt. + */ +void NMI_Handler(void) +{ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + while (1) { + } + /* USER CODE END NonMaskableInt_IRQn 1 */ +} + +/** + * @brief This function handles Hard fault interrupt. + */ +void HardFault_Handler(void) +{ + /* USER CODE BEGIN HardFault_IRQn 0 */ + + /* USER CODE END HardFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_HardFault_IRQn 0 */ + /* USER CODE END W1_HardFault_IRQn 0 */ + } +} + +/** + * @brief This function handles Memory management fault. + */ +void MemManage_Handler(void) +{ + /* USER CODE BEGIN MemoryManagement_IRQn 0 */ + + /* USER CODE END MemoryManagement_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ + /* USER CODE END W1_MemoryManagement_IRQn 0 */ + } +} + +/** + * @brief This function handles Pre-fetch fault, memory access fault. + */ +void BusFault_Handler(void) +{ + /* USER CODE BEGIN BusFault_IRQn 0 */ + + /* USER CODE END BusFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_BusFault_IRQn 0 */ + /* USER CODE END W1_BusFault_IRQn 0 */ + } +} + +/** + * @brief This function handles Undefined instruction or illegal state. + */ +void UsageFault_Handler(void) +{ + /* USER CODE BEGIN UsageFault_IRQn 0 */ + + /* USER CODE END UsageFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ + /* USER CODE END W1_UsageFault_IRQn 0 */ + } +} + +/** + * @brief This function handles System service call via SWI instruction. + */ +void SVC_Handler(void) +{ + /* USER CODE BEGIN SVCall_IRQn 0 */ + + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ + + /* USER CODE END SVCall_IRQn 1 */ +} + +/** + * @brief This function handles Debug monitor. + */ +void DebugMon_Handler(void) +{ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + + /* USER CODE END DebugMonitor_IRQn 1 */ +} + +/** + * @brief This function handles Pendable request for system service. + */ +void PendSV_Handler(void) +{ + /* USER CODE BEGIN PendSV_IRQn 0 */ + + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ + + /* USER CODE END PendSV_IRQn 1 */ +} + +/** + * @brief This function handles System tick timer. + */ +void SysTick_Handler(void) +{ + /* USER CODE BEGIN SysTick_IRQn 0 */ + + /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ + + /* USER CODE END SysTick_IRQn 1 */ +} + +/******************************************************************************/ +/* STM32F4xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32f4xx.s). */ +/******************************************************************************/ + +/** + * @brief This function handles ADC1, ADC2 and ADC3 interrupts. + */ +void ADC_IRQHandler(void) +{ + /* USER CODE BEGIN ADC_IRQn 0 */ + + /* USER CODE END ADC_IRQn 0 */ + HAL_ADC_IRQHandler(&hadc1); + /* USER CODE BEGIN ADC_IRQn 1 */ + + /* USER CODE END ADC_IRQn 1 */ +} + +/** + * @brief This function handles CAN1 RX0 interrupt. + */ +void CAN1_RX0_IRQHandler(void) +{ + /* USER CODE BEGIN CAN1_RX0_IRQn 0 */ + + /* USER CODE END CAN1_RX0_IRQn 0 */ + HAL_CAN_IRQHandler(&hcan1); + /* USER CODE BEGIN CAN1_RX0_IRQn 1 */ + + /* USER CODE END CAN1_RX0_IRQn 1 */ +} + +/** + * @brief This function handles CAN1 SCE interrupt. + */ +void CAN1_SCE_IRQHandler(void) +{ + /* USER CODE BEGIN CAN1_SCE_IRQn 0 */ + + /* USER CODE END CAN1_SCE_IRQn 0 */ + HAL_CAN_IRQHandler(&hcan1); + /* USER CODE BEGIN CAN1_SCE_IRQn 1 */ + + /* USER CODE END CAN1_SCE_IRQn 1 */ +} + +/** + * @brief This function handles TIM2 global interrupt. + */ +void TIM2_IRQHandler(void) +{ + /* USER CODE BEGIN TIM2_IRQn 0 */ + + /* USER CODE END TIM2_IRQn 0 */ + HAL_TIM_IRQHandler(&htim2); + /* USER CODE BEGIN TIM2_IRQn 1 */ + + /* USER CODE END TIM2_IRQn 1 */ +} + +/** + * @brief This function handles DMA2 stream0 global interrupt. + */ +void DMA2_Stream0_IRQHandler(void) +{ + /* USER CODE BEGIN DMA2_Stream0_IRQn 0 */ + + /* USER CODE END DMA2_Stream0_IRQn 0 */ + HAL_DMA_IRQHandler(&hdma_adc1); + /* USER CODE BEGIN DMA2_Stream0_IRQn 1 */ + + /* USER CODE END DMA2_Stream0_IRQn 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Core/Src/tim.c b/Core/Src/tim.c index 54c507f..39280fb 100644 --- a/Core/Src/tim.c +++ b/Core/Src/tim.c @@ -1,117 +1,117 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.c - * @brief This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "tim.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -TIM_HandleTypeDef htim2; - -/* TIM2 init function */ -void MX_TIM2_Init(void) -{ - - /* USER CODE BEGIN TIM2_Init 0 */ - - /* USER CODE END TIM2_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM2_Init 1 */ - - /* USER CODE END TIM2_Init 1 */ - htim2.Instance = TIM2; - htim2.Init.Prescaler = 10-1; - htim2.Init.CounterMode = TIM_COUNTERMODE_UP; - htim2.Init.Period = 9000-1; - htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; - if (HAL_TIM_Base_Init(&htim2) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM2_Init 2 */ - - /* USER CODE END TIM2_Init 2 */ - -} - -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) -{ - - if(tim_baseHandle->Instance==TIM2) - { - /* USER CODE BEGIN TIM2_MspInit 0 */ - - /* USER CODE END TIM2_MspInit 0 */ - /* TIM2 clock enable */ - __HAL_RCC_TIM2_CLK_ENABLE(); - - /* TIM2 interrupt Init */ - HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM2_IRQn); - /* USER CODE BEGIN TIM2_MspInit 1 */ - - /* USER CODE END TIM2_MspInit 1 */ - } -} - -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) -{ - - if(tim_baseHandle->Instance==TIM2) - { - /* USER CODE BEGIN TIM2_MspDeInit 0 */ - - /* USER CODE END TIM2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM2_CLK_DISABLE(); - - /* TIM2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM2_IRQn); - /* USER CODE BEGIN TIM2_MspDeInit 1 */ - - /* USER CODE END TIM2_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { - //if (htim == &TIM_DMA1_HandleTypeDef) { - // Debug if TIM is elapsing - // static uint32_t counter_adc_conversions = 0; - // ++counter_adc_conversions; - //} -} -/* USER CODE END 1 */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.c + * @brief This file provides code for the configuration + * of the TIM instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "tim.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +TIM_HandleTypeDef htim2; + +/* TIM2 init function */ +void MX_TIM2_Init(void) +{ + + /* USER CODE BEGIN TIM2_Init 0 */ + + /* USER CODE END TIM2_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM2_Init 1 */ + + /* USER CODE END TIM2_Init 1 */ + htim2.Instance = TIM2; + htim2.Init.Prescaler = 10-1; + htim2.Init.CounterMode = TIM_COUNTERMODE_UP; + htim2.Init.Period = 9000-1; + htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; + if (HAL_TIM_Base_Init(&htim2) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM2_Init 2 */ + + /* USER CODE END TIM2_Init 2 */ + +} + +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM2) + { + /* USER CODE BEGIN TIM2_MspInit 0 */ + + /* USER CODE END TIM2_MspInit 0 */ + /* TIM2 clock enable */ + __HAL_RCC_TIM2_CLK_ENABLE(); + + /* TIM2 interrupt Init */ + HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM2_IRQn); + /* USER CODE BEGIN TIM2_MspInit 1 */ + + /* USER CODE END TIM2_MspInit 1 */ + } +} + +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM2) + { + /* USER CODE BEGIN TIM2_MspDeInit 0 */ + + /* USER CODE END TIM2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM2_CLK_DISABLE(); + + /* TIM2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM2_IRQn); + /* USER CODE BEGIN TIM2_MspDeInit 1 */ + + /* USER CODE END TIM2_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { + //if (htim == &TIM_DMA1_HandleTypeDef) { + // Debug if TIM is elapsing + // static uint32_t counter_adc_conversions = 0; + // ++counter_adc_conversions; + //} +} +/* USER CODE END 1 */ diff --git a/Core/Src/usart.c b/Core/Src/usart.c index 65680e2..c831bd3 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -1,114 +1,114 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "usart.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -UART_HandleTypeDef huart2; - -/* USART2 init function */ - -void MX_USART2_UART_Init(void) -{ - - /* USER CODE BEGIN USART2_Init 0 */ - - /* USER CODE END USART2_Init 0 */ - - /* USER CODE BEGIN USART2_Init 1 */ - - /* USER CODE END USART2_Init 1 */ - huart2.Instance = USART2; - huart2.Init.BaudRate = 115200; - huart2.Init.WordLength = UART_WORDLENGTH_8B; - huart2.Init.StopBits = UART_STOPBITS_1; - huart2.Init.Parity = UART_PARITY_NONE; - huart2.Init.Mode = UART_MODE_TX_RX; - huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart2.Init.OverSampling = UART_OVERSAMPLING_16; - if (HAL_UART_Init(&huart2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USART2_Init 2 */ - - /* USER CODE END USART2_Init 2 */ - -} - -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==USART2) - { - /* USER CODE BEGIN USART2_MspInit 0 */ - - /* USER CODE END USART2_MspInit 0 */ - /* USART2 clock enable */ - __HAL_RCC_USART2_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX - */ - GPIO_InitStruct.Pin = T_VCP_TX_USART_TX_Pin|T_VCP_RX_USART_RX_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF7_USART2; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN USART2_MspInit 1 */ - - /* USER CODE END USART2_MspInit 1 */ - } -} - -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) -{ - - if(uartHandle->Instance==USART2) - { - /* USER CODE BEGIN USART2_MspDeInit 0 */ - - /* USER CODE END USART2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USART2_CLK_DISABLE(); - - /**USART2 GPIO Configuration - PA2 ------> USART2_TX - PA3 ------> USART2_RX - */ - HAL_GPIO_DeInit(GPIOA, T_VCP_TX_USART_TX_Pin|T_VCP_RX_USART_RX_Pin); - - /* USER CODE BEGIN USART2_MspDeInit 1 */ - - /* USER CODE END USART2_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "usart.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +UART_HandleTypeDef huart2; + +/* USART2 init function */ + +void MX_USART2_UART_Init(void) +{ + + /* USER CODE BEGIN USART2_Init 0 */ + + /* USER CODE END USART2_Init 0 */ + + /* USER CODE BEGIN USART2_Init 1 */ + + /* USER CODE END USART2_Init 1 */ + huart2.Instance = USART2; + huart2.Init.BaudRate = 115200; + huart2.Init.WordLength = UART_WORDLENGTH_8B; + huart2.Init.StopBits = UART_STOPBITS_1; + huart2.Init.Parity = UART_PARITY_NONE; + huart2.Init.Mode = UART_MODE_TX_RX; + huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart2.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USART2_Init 2 */ + + /* USER CODE END USART2_Init 2 */ + +} + +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==USART2) + { + /* USER CODE BEGIN USART2_MspInit 0 */ + + /* USER CODE END USART2_MspInit 0 */ + /* USART2 clock enable */ + __HAL_RCC_USART2_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USART2 GPIO Configuration + PA2 ------> USART2_TX + PA3 ------> USART2_RX + */ + GPIO_InitStruct.Pin = T_VCP_TX_USART_TX_Pin|T_VCP_RX_USART_RX_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF7_USART2; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN USART2_MspInit 1 */ + + /* USER CODE END USART2_MspInit 1 */ + } +} + +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +{ + + if(uartHandle->Instance==USART2) + { + /* USER CODE BEGIN USART2_MspDeInit 0 */ + + /* USER CODE END USART2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART2_CLK_DISABLE(); + + /**USART2 GPIO Configuration + PA2 ------> USART2_TX + PA3 ------> USART2_RX + */ + HAL_GPIO_DeInit(GPIOA, T_VCP_TX_USART_TX_Pin|T_VCP_RX_USART_RX_Pin); + + /* USER CODE BEGIN USART2_MspDeInit 1 */ + + /* USER CODE END USART2_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/openblt_f446re/Makefile b/openblt_f446re/Makefile index 19c6d82..577eda5 100644 --- a/openblt_f446re/Makefile +++ b/openblt_f446re/Makefile @@ -1,252 +1,255 @@ -########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Sun Jun 25 21:11:43 CEST 2023] -########################################################################################################################## - -# ------------------------------------------------ -# Generic Makefile (based on gcc) -# -# ChangeLog : -# 2017-02-10 - Several enhancements + project update mode -# 2015-07-22 - first version -# ------------------------------------------------ - -###################################### -# target -###################################### -TARGET = openblt_f446re - - -###################################### -# building variables -###################################### -# debug build? -DEBUG = 1 -# optimization -OPT = -Og - - -####################################### -# paths -####################################### -# Build path -BUILD_DIR = build -# Release path -RELEASE_DIR = release - -###################################### -# source -###################################### -# C sources -C_SOURCES = \ -Core/Src/main.c \ -Core/Src/stm32f4xx_it.c \ -Core/Src/stm32f4xx_hal_msp.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \ -Core/Src/system_stm32f4xx.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c \ -Core/Src/BLT/asserts.c \ -Core/Src/BLT/backdoor.c \ -Core/Src/BLT/boot.c \ -Core/Src/BLT/can.c \ -Core/Src/BLT/com.c \ -Core/Src/BLT/cop.c \ -Core/Src/BLT/cpu.c \ -Core/Src/BLT/cpu_comp.c \ -Core/Src/BLT/file.c \ -Core/Src/BLT/flash.c \ -Core/Src/BLT/hooks.c \ -Core/Src/BLT/led.c \ -Core/Src/BLT/net.c \ -Core/Src/BLT/nvm.c \ -Core/Src/BLT/rs232.c \ -Core/Src/BLT/timer.c \ -Core/Src/BLT/usb.c \ -Core/Src/BLT/xcp.c - -# ASM sources -ASM_SOURCES = \ -startup_stm32f446xx.s - - -####################################### -# binaries -####################################### -PREFIX = arm-none-eabi- -# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) -# either it can be added to the PATH environment variable. -ifdef GCC_PATH -CC = $(GCC_PATH)/$(PREFIX)gcc -AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp -CP = $(GCC_PATH)/$(PREFIX)objcopy -SZ = $(GCC_PATH)/$(PREFIX)size -else -CC = $(PREFIX)gcc -AS = $(PREFIX)gcc -x assembler-with-cpp -CP = $(PREFIX)objcopy -SZ = $(PREFIX)size -endif -HEX = $(CP) -O ihex -BIN = $(CP) -O binary -S - -####################################### -# CFLAGS -####################################### -# cpu -CPU = -mcpu=cortex-m4 - -# fpu -FPU = -mfpu=fpv4-sp-d16 - -# float-abi -FLOAT-ABI = -mfloat-abi=hard - -# mcu -MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) - -# macros for gcc -# AS defines -AS_DEFS = - -# C defines -C_DEFS = \ --DUSE_HAL_DRIVER \ --DSTM32F446xx \ --DUSE_FULL_LL_DRIVER - - -# AS includes -AS_INCLUDES = - -# C includes -C_INCLUDES = \ --ICore/Inc \ --IDrivers/STM32F4xx_HAL_Driver/Inc \ --IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \ --IDrivers/CMSIS/Device/ST/STM32F4xx/Include \ --IDrivers/CMSIS/Include \ --ICore/Inc/BLT - - -# compile gcc flags -ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) - -CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) - -ifeq ($(DEBUG), 1) -CFLAGS += -g -gdwarf-2 -ggdb -endif - -# Add additional flags -CFLAGS += -Wall -fdata-sections -ffunction-sections -ASFLAGS += -Wall -fdata-sections -ffunction-sections - -# Generate dependency information -CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" - - -####################################### -# LDFLAGS -####################################### -# link script -LDSCRIPT = STM32F446RETx_FLASH.ld - -# libraries -LIBS = -lc -lm -lnosys -LIBDIR = \ - - -# Additional LD Flags from config file -ADDITIONALLDFLAGS = -specs=nano.specs -u_printf_float - -LDFLAGS = $(MCU) $(ADDITIONALLDFLAGS) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections - -# default action: build all -all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin - - -####################################### -# build the application -####################################### -# list of C objects -OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) -vpath %.c $(sort $(dir $(C_SOURCES))) -# list of ASM program objects -OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) -vpath %.s $(sort $(dir $(ASM_SOURCES))) - -$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) - $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ - -$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) - $(AS) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - $(SZ) $@ - -$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) - $(HEX) $< $@ - -$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) - $(BIN) $< $@ - -$(BUILD_DIR): - mkdir $@ - -####################################### -# clean up -####################################### -clean: - -rm -fR $(BUILD_DIR) $(RELEASE_DIR) - -###################################### -# custom makefile rules -####################################### - -####################################### -# release -####################################### -release: $(BUILD_DIR)/$(TARGET).elf - mkdir -p $(RELEASE_DIR) && cp $^ $(RELEASE_DIR) - -# The openocd bin path can be either defined in make command via OPENOCD_PATH variable (> make OPENOCD_PATH=xxx) -# either it can be added to the PATH environment variable. -ifdef OPENOCD_PATH -OPENOCD = "$(OPENOCD_PATH)/openocd" -else -OPENOCD = "openocd" -endif - -####################################### -# flash -####################################### -flash: openocd.cfg $(BUILD_DIR)/$(TARGET).elf - $(OPENOCD) -f ./openocd.cfg -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit" - -####################################### -# erase -####################################### -erase: openocd.cfg $(BUILD_DIR)/$(TARGET).elf - $(OPENOCD) -f ./openocd.cfg -c "init; reset halt; stm32f4x mass_erase 0; exit" - -####################################### -# dependencies -####################################### --include $(wildcard $(BUILD_DIR)/*.d) - -# *** EOF *** +########################################################################################################################## +# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Sun Jun 25 21:11:43 CEST 2023] +########################################################################################################################## + +# ------------------------------------------------ +# Generic Makefile (based on gcc) +# +# ChangeLog : +# 2017-02-10 - Several enhancements + project update mode +# 2015-07-22 - first version +# ------------------------------------------------ + +###################################### +# target +###################################### +TARGET = openblt_f446re + + +###################################### +# building variables +###################################### +# debug build? +DEBUG = 1 +# optimization +OPT = -Og + + +####################################### +# paths +####################################### +# Build path +BUILD_DIR = build +# Release path +RELEASE_DIR = release + +###################################### +# source +###################################### +# C sources +C_SOURCES = \ +Core/Src/BLT/asserts.c \ +Core/Src/BLT/backdoor.c \ +Core/Src/BLT/boot.c \ +Core/Src/BLT/can.c \ +Core/Src/BLT/com.c \ +Core/Src/BLT/cop.c \ +Core/Src/BLT/cpu.c \ +Core/Src/BLT/cpu_comp.c \ +Core/Src/BLT/file.c \ +Core/Src/BLT/flash.c \ +Core/Src/BLT/hooks.c \ +Core/Src/BLT/led.c \ +Core/Src/BLT/net.c \ +Core/Src/BLT/nvm.c \ +Core/Src/BLT/rs232.c \ +Core/Src/BLT/timer.c \ +Core/Src/BLT/usb.c \ +Core/Src/BLT/xcp.c \ +Core/Src/main.c \ +Core/Src/stm32f4xx_hal_msp.c \ +Core/Src/stm32f4xx_it.c \ +Core/Src/system_stm32f4xx.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c + +# ASM sources +ASM_SOURCES = \ +startup_stm32f446xx.s + + + +####################################### +# binaries +####################################### +PREFIX = arm-none-eabi- +# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) +# either it can be added to the PATH environment variable. +ifdef GCC_PATH +CC = $(GCC_PATH)/$(PREFIX)gcc +AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp +CP = $(GCC_PATH)/$(PREFIX)objcopy +SZ = $(GCC_PATH)/$(PREFIX)size +else +CC = $(PREFIX)gcc +AS = $(PREFIX)gcc -x assembler-with-cpp +CP = $(PREFIX)objcopy +SZ = $(PREFIX)size +endif +HEX = $(CP) -O ihex +BIN = $(CP) -O binary -S + +####################################### +# CFLAGS +####################################### +# cpu +CPU = -mcpu=cortex-m4 + +# fpu +FPU = -mfpu=fpv4-sp-d16 + +# float-abi +FLOAT-ABI = -mfloat-abi=hard + +# mcu +MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) + +# macros for gcc +# AS defines +AS_DEFS = + +# C defines +C_DEFS = \ +-DSTM32F446xx \ +-DUSE_HAL_DRIVER\ +-DUSE_FULL_LL_DRIVER + + +# AS includes +AS_INCLUDES = \ + +# C includes +C_INCLUDES = \ +-ICore/Inc \ +-ICore/Inc/BLT \ +-IDrivers/CMSIS/Device/ST/STM32F4xx/Include \ +-IDrivers/CMSIS/Include \ +-IDrivers/STM32F4xx_HAL_Driver/Inc \ +-IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy + + + +# compile gcc flags +ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) + +CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) + +ifeq ($(DEBUG), 1) +CFLAGS += -g -gdwarf -ggdb +endif + +# Add additional flags +CFLAGS += -Wall -fdata-sections -ffunction-sections +ASFLAGS += -Wall -fdata-sections -ffunction-sections + +# Generate dependency information +CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" + + +####################################### +# LDFLAGS +####################################### +# link script +LDSCRIPT = STM32F446RETx_FLASH.ld + +# libraries +LIBS = -lc -lm -lnosys +LIBDIR = \ + + +# Additional LD Flags from config file +ADDITIONALLDFLAGS = -specs=nano.specs + +LDFLAGS = $(MCU) $(ADDITIONALLDFLAGS) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections + +# default action: build all +all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin + + +####################################### +# build the application +####################################### +# list of C objects +OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) +vpath %.c $(sort $(dir $(C_SOURCES))) + +# list of ASM program objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) +vpath %.s $(sort $(dir $(ASM_SOURCES))) + +$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) + $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ + +$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) + $(AS) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + $(SZ) $@ + +$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(HEX) $< $@ + +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(BIN) $< $@ + +$(BUILD_DIR): + mkdir $@ + +####################################### +# clean up +####################################### +clean: + -rm -fR $(BUILD_DIR) $(RELEASE_DIR) + +###################################### +# custom makefile rules +####################################### + +####################################### +# release +####################################### +release: $(BUILD_DIR)/$(TARGET).elf + mkdir -p $(RELEASE_DIR) && cp $^ $(RELEASE_DIR) + +# The openocd bin path can be either defined in make command via OPENOCD_PATH variable (> make OPENOCD_PATH=xxx) +# either it can be added to the PATH environment variable. +ifdef OPENOCD_PATH +OPENOCD = "$(OPENOCD_PATH)/openocd" +else +OPENOCD = "openocd" +endif + +####################################### +# flash +####################################### +flash: openocd.cfg $(BUILD_DIR)/$(TARGET).elf + $(OPENOCD) -f ./openocd.cfg -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit" + +####################################### +# erase +####################################### +erase: openocd.cfg $(BUILD_DIR)/$(TARGET).elf + $(OPENOCD) -f ./openocd.cfg -c "init; reset halt; stm32f4x mass_erase 0; exit" + +####################################### +# dependencies +####################################### +-include $(wildcard $(BUILD_DIR)/*.d) + +# *** EOF *** diff --git a/tlb_battery.ioc b/tlb_battery.ioc index c4a18e0..20848ee 100644 --- a/tlb_battery.ioc +++ b/tlb_battery.ioc @@ -25,7 +25,8 @@ CAN1.BS2=CAN_BS2_2TQ CAN1.CalculateBaudRate=1000000 CAN1.CalculateTimeBit=1000 CAN1.CalculateTimeQuantum=66.66666666666666 -CAN1.IPParameters=CalculateTimeQuantum,CalculateTimeBit,CalculateBaudRate,Prescaler,BS1,BS2,ABOM +CAN1.IPParameters=CalculateTimeQuantum,CalculateTimeBit,CalculateBaudRate,Prescaler,BS1,BS2,ABOM,NART +CAN1.NART=ENABLE CAN1.Prescaler=3 Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY Dma.ADC1.0.FIFOMode=DMA_FIFOMODE_DISABLE