Add Autobox monitoring Watchdog

This commit is contained in:
n.jayaprakash 2024-07-04 23:27:14 +02:00
parent 36e57e5671
commit 20b613b661
8 changed files with 88 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,7 @@
#include "Current_Monitoring.h"
#define RX_STATUS_HEARTBEAT 0xC7
#define RX_STATUS_MSG_ID 0xC8 // new addresses will be given ( 0x C8 , 0xC9 usw)
#define TX_STATUS_MSG_ID 0xC9
#define CUR_CHANNELS_1_ID 0xCA

View File

@ -51,7 +51,7 @@
/*#define HAL_CRYP_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
#define HAL_IWDG_MODULE_ENABLED
/*#define HAL_LCD_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */

View File

@ -13,6 +13,9 @@ volatile uint8_t canmsg_received = 0;
extern PortExtenderGPIO EN_Ports;
extern CurrentMeasurements current_measurements_adc_val;
extern int inhibit_SDC;
extern IWDG_HandleTypeDef hiwdg;
void can_init(CAN_HandleTypeDef* hcan) {
ftcan_init(hcan);
ftcan_add_filter(0x00, 0x00); // No Filter
@ -107,4 +110,7 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t* data) {
rxstate.cooling_pump = data[5];
rxstate.checksum = data[6];
}
if (id == RX_STATUS_HEARTBEAT)
HAL_IWDG_Refresh(&hiwdg);
}

View File

@ -15,6 +15,8 @@ uint8_t timer2_running = 0;
TIM_HandleTypeDef* pwmtimer3;
TIM_HandleTypeDef* pwmtimer2;
extern int inhibit_SDC;
void ChannelControl_init(I2C_HandleTypeDef* hi2c, TIM_HandleTypeDef* timer3,
TIM_HandleTypeDef* timer2) {
@ -36,6 +38,8 @@ void ChannelControl_init(I2C_HandleTypeDef* hi2c, TIM_HandleTypeDef* timer3,
void ChannelControl_UpdateGPIOs(PortExtenderGPIO UpdatePorts) { // ctrl + left click auf portextender
EN_Ports = UpdatePorts;
UpdatePorts.porta.alwayson = 1; // Always on stays always on
if (inhibit_SDC)
UpdatePorts.porta.en8 = 0;
PCA9535_setGPIOPortOutput(PC9535_PORTA, UpdatePorts.porta.porta);
PCA9535_setGPIOPortOutput(PC9535_PORTB, UpdatePorts.portb.portb);
}

View File

@ -51,6 +51,8 @@ CAN_HandleTypeDef hcan;
I2C_HandleTypeDef hi2c1;
IWDG_HandleTypeDef hiwdg;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;
TIM_HandleTypeDef htim6;
@ -73,6 +75,7 @@ static void MX_TIM3_Init(void);
static void MX_I2C1_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_TIM6_Init(void);
static void MX_IWDG_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@ -84,6 +87,8 @@ uint16_t adc2_buffer[7]; // data type specific to 16 bit integer with no sign (
extern rx_status_frame rxstate;
extern volatile uint8_t canmsg_received;
int inhibit_SDC;
/* USER CODE END 0 */
/**
@ -95,6 +100,9 @@ int main(void)
/* USER CODE BEGIN 1 */
// Freeze WDG when debugging
__HAL_DBGMCU_FREEZE_IWDG();
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
@ -124,7 +132,9 @@ int main(void)
MX_I2C1_Init();
MX_USART1_UART_Init();
MX_TIM6_Init();
//MX_IWDG_Init();
/* USER CODE BEGIN 2 */
// REMINDER: Comment out the IWDG Init above!!!
HAL_GPIO_WritePin(STATUS_LED1_GPIO_Port , STATUS_LED1_Pin , GPIO_PIN_SET);
HAL_GPIO_WritePin(GSS_GPIO_GPIO_Port, GSS_GPIO_Pin, GPIO_PIN_SET);
@ -138,7 +148,19 @@ int main(void)
uint32_t lasttick = HAL_GetTick(); // gibt dir zuruck die milisekunden seit start. ( es fangt an und dann milisekunden + 1 usw....)
HAL_TIM_Base_Start(&htim2);
HAL_TIM_Base_Start(&htim3);
// ChannelControl_UpdatePWMs(20 , 0 , 50 ); ( testing code )
// Prevent closing of SDC (esp. after WDG reset)
inhibit_SDC = 1;
// Wait 1s to prevent bus error state while ABX is starting up
// Wait 5s for the discharge of the DC link (so AMS can't restart)
HAL_Delay(5000);
// SDC can now be closed
inhibit_SDC = 0;
// PDU will reset if it doesn't receive a heartbeat every 120ms
MX_IWDG_Init();
/* USER CODE END 2 */
/* Infinite loop */
@ -182,10 +204,11 @@ void SystemClock_Config(void)
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
@ -430,6 +453,35 @@ static void MX_I2C1_Init(void)
}
/**
* @brief IWDG Initialization Function
* @param None
* @retval None
*/
static void MX_IWDG_Init(void)
{
/* USER CODE BEGIN IWDG_Init 0 */
/* USER CODE END IWDG_Init 0 */
/* USER CODE BEGIN IWDG_Init 1 */
/* USER CODE END IWDG_Init 1 */
hiwdg.Instance = IWDG;
hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
hiwdg.Init.Window = 1000;
hiwdg.Init.Reload = 1000;
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN IWDG_Init 2 */
/* USER CODE END IWDG_Init 2 */
}
/**
* @brief TIM2 Initialization Function
* @param None

View File

@ -56,22 +56,27 @@ File.Version=6
GPIO.groupedBy=Group By Peripherals
I2C1.IPParameters=Timing
I2C1.Timing=0x00303D5B
IWDG.IPParameters=Prescaler,Window,Reload
IWDG.Prescaler=IWDG_PRESCALER_4
IWDG.Reload=1000
IWDG.Window=1000
KeepUserPlacement=false
Mcu.CPN=STM32F302RBT6
Mcu.Family=STM32F3
Mcu.IP0=ADC1
Mcu.IP1=ADC2
Mcu.IP10=TIM6
Mcu.IP11=USART1
Mcu.IP10=TIM3
Mcu.IP11=TIM6
Mcu.IP12=USART1
Mcu.IP2=CAN
Mcu.IP3=DMA
Mcu.IP4=I2C1
Mcu.IP5=NVIC
Mcu.IP6=RCC
Mcu.IP7=SYS
Mcu.IP8=TIM2
Mcu.IP9=TIM3
Mcu.IPNb=12
Mcu.IP5=IWDG
Mcu.IP6=NVIC
Mcu.IP7=RCC
Mcu.IP8=SYS
Mcu.IP9=TIM2
Mcu.IPNb=13
Mcu.Name=STM32F302R(B-C)Tx
Mcu.Package=LQFP64
Mcu.Pin0=PF0-OSC_IN
@ -105,15 +110,16 @@ Mcu.Pin33=PB3
Mcu.Pin34=PB4
Mcu.Pin35=PB7
Mcu.Pin36=PB9
Mcu.Pin37=VP_SYS_VS_Systick
Mcu.Pin38=VP_TIM6_VS_ClockSourceINT
Mcu.Pin37=VP_IWDG_VS_IWDG
Mcu.Pin38=VP_SYS_VS_Systick
Mcu.Pin39=VP_TIM6_VS_ClockSourceINT
Mcu.Pin4=PC2
Mcu.Pin5=PC3
Mcu.Pin6=PA0
Mcu.Pin7=PA1
Mcu.Pin8=PA2
Mcu.Pin9=PA3
Mcu.PinsNb=39
Mcu.PinsNb=40
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F302RBTx
@ -378,6 +384,8 @@ TIM6.Prescaler=400
TIM6.TIM_MasterOutputTrigger=TIM_TRGO_UPDATE
USART1.IPParameters=VirtualMode-Multiprocessor_communication
USART1.VirtualMode-Multiprocessor_communication=VM_ASYNC
VP_IWDG_VS_IWDG.Mode=IWDG_Activate
VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_TIM6_VS_ClockSourceINT.Mode=Enable_Timer

View File

@ -59,6 +59,7 @@ Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.c \
Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_gpio.c \
Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_i2c.c \
Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_i2c_ex.c \
Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_iwdg.c \
Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_pwr.c \
Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_pwr_ex.c \
Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_rcc.c \