This commit is contained in:
v0stap
2026-04-05 11:31:20 +02:00
commit 78e6a1b8aa
254 changed files with 175905 additions and 0 deletions

16
DBW_V2/Core/Inc/adc.h Normal file
View File

@@ -0,0 +1,16 @@
/*
* adc.h
*
* Created on: Sep 6, 2017
* Author: dmitrijs
*/
#ifndef ADC_H_
#define ADC_H_
void Adc_Init(void);
unsigned short LPF(unsigned short lpf_c, unsigned short value,
unsigned short old_value);
unsigned short Adc_Read(unsigned char ch);
#endif /* ADC_H_ */

73
DBW_V2/Core/Inc/can.h Normal file
View File

@@ -0,0 +1,73 @@
/*
* CAN.h
*
* Created on: Dec 04, 2018
* Author: v0stap
*/
#ifndef _CAN_H_
#define _CAN_H_
#define CAN_ID_STD 0x00000000U
#define CAN_ID_EXT 0x00000004U
#define CAN_RTR_DATA 0x00000000U
#define CAN_RTR_REMOTE 0x00000002U
#define STD_FORMAT 0
#define EXTD_FORMAT 1
#define DATA_FRAME 0
#define REMOTE_FRAME 1
#define CAN_250KBS 0x031c000b
#define CAN_500KBS 0x031c0005
#define CAN_1000KBS 0x031c0002
typedef struct {
uint32_t id; // 29 bit identifier
uint8_t data[8]; // Data field
uint8_t lenght; // Length of data field in bytes
uint8_t format; // 0 - STANDART, 1- EXTENDED
uint8_t frame; // 0 - DATA FRAME, 1 - REMOTE FRAME
} can_msg_typedef;
typedef struct {
can_msg_typedef data[16];
uint8_t todo;
uint8_t corent;
uint8_t done;
} can_buffer_typedef;
typedef struct {
CAN_TypeDef *can_port;
uint8_t mode;
uint32_t speed;
uint8_t filter;
uint8_t rx_pin;
uint8_t tx_pin;
GPIO_TypeDef *port;
uint8_t tx_ready;
uint8_t rx_ready;
} can_config_typedef;
void CAN_Init(void);
void CAN_Setup(uint32_t speed);
void CAN_Start(void);
void CAN_Wait_Ready(void);
void CAN_Send_Msg(can_msg_typedef *msg);
void CAN_Recive_Msg(can_msg_typedef *msg);
void CAN_Write_Filter(uint32_t id, uint8_t format);
void CAN_Send_TX_Buffer(void);
void CAN_Add_TX_Buffer(can_msg_typedef *data);
void CAN_Add_RX_Buffer(void);
void CAN_Read_RX_Buffer(can_msg_typedef *data);
extern can_msg_typedef CAN_TX_Msg; // CAN message for transmit
extern can_msg_typedef CAN_RX_Msg; // CAN received message
extern uint8_t CAN_TX_Rdy; // CAN hardware ready to transmit a message
extern uint8_t CAN_RX_Rdy; // CAN hardware received a message
extern uint32_t CAN_Speed; // CAN Speed / CAN BTR register
extern can_buffer_typedef CAN_TX_Buffer;
extern can_buffer_typedef CAN_RX_Buffer;
#endif // _CAN_H_

260
DBW_V2/Core/Inc/dbw.h Normal file
View File

@@ -0,0 +1,260 @@
/*
* dbw.h
*
* Created on: May 5, 2021
* Author: Dmitrijs
*/
#ifndef SRC_DBW_H_
#define SRC_DBW_H_
#define CONFIG_AGREEMENT_F 0x01
#define CONFIG_SENSORS_CALIBRATED_F 0x02
#define CONFIG_TESTMODE_F 0x04
#define CONFIG_SAFETY_FEATURES_F 0x08
#define DBW_STATUS0_READY_F 0x1
#define DBW_STATUS0_AGREEMENT_F 0x2
#define DBW_STATUS0_SENSOR_CAL_F 0x4
#define DBW_STATUS0_FAULT_F 0x8
#define DBW_STATUS0_CAN_MSDBW_F 0x10
#define DBW_STATUS0_CAN_RX_BCST_F 0x20
#define DBW_STATUS0_PWM_IDLE_F 0x40
#define DBW_STATUS0_GPI1_F 0x80
#define DBW_STATUS0_GPI2_F 0x100
#define DBW_STATUS0_GPO1_F 0x200
#define DBW_STATUS0_GPO2_F 0x400
#define DBW_STATUS0_PPSTPS_CAL_F 0x800
#define DBW_STATUS0_UNPROTECTED_F 0x1000
#define DBW_STATUS0_CONF_ERROR_F 0x2000
#define DBW_STATUS0_SENSOR_FAULT_F 0x4000
#define DBW_STATUS1_SAFETY_F 0x01
#define PPS2_CALC_OPTION_LINEAR 0
#define PPS2_CALC_OPTION_POLYNOMAL 1
#define TPS2_CALC_OPTION_LINEAR 0
#define TPS2_CALC_OPTION_POLYNOMAL 1
#define PPS2TPS_OPTION_CURVE 0
#define PPS2TPS_OPTION_MS3_CAN 1
#define IDLE_OPTION_NO_IDLE_INPUT 0
#define IDLE_OPTION_PWM_INPUT1 1
#define IDLE_OPTION_PWM_INPUT2 2
#define IDLE_OPTION_MS_CAN 3
#define MOTOR_PID_OPTION_STATIC 0
#define MOTOR_PID_OPTION_STATIC_FWRW 1
#define MOTOR_PID_OPTION_TABLE 2
typedef struct
{
uint8_t pps_calc_option;
uint8_t tps_calc_option;
uint16_t pps1_min;
uint16_t pps1_max;
uint16_t pps2_min;
uint16_t pps2_mid;
uint16_t pps2_mid_pct;
uint16_t pps2_max;
uint16_t tps1_min;
uint16_t tps1_max;
uint16_t tps2_min;
uint16_t tps2_mid;
uint16_t tps2_mid_pct;
uint16_t tps2_max;
uint8_t pps2tps_option;
uint8_t idle_input_option;
// pps to tps target curve
int16_t pps_bins[16]; //[0.1%]
int16_t tps_bins[16]; //[0.1%]
// Idle pps modifier curve. when Idle input is used. it modifies tps target
int16_t idle_input_bins[8]; //input pwm duty [0.1%]
int16_t idle_tps_adder_bins[8]; //tps target adder [0.1%]
uint16_t motor_pwm_fq; // frequency in Hz
uint16_t motor_ctl_period; // ctl_teriod in [100uS]
uint16_t motor_pid_option; // PID static coefs, static coef, but different for forward and backward moving
// 3D table
// PID COEFICIENTS for forward and reward
int16_t motor_fw_p;
int16_t motor_fw_i;
int16_t motor_fw_d;
int16_t motor_rw_p;
int16_t motor_rw_i;
int16_t motor_rw_d;
int16_t motor_p_tps_bins[16];
int16_t motor_p_error_bins[16];
int16_t motor_p_table[16][16];
//PID limmits
int16_t i_limmit;
int16_t motor_dc_max;
int16_t motor_dc_min;
//DC offset curve
int16_t tps_dc_tps_bins[16]; // tps bins [0.1%]
int16_t tps_dc_offset_bins[16]; // motor pwm offset [0.01%PWM]
//Battery voltage correction curve
uint16_t vbat_bins[8]; // battery voltage ADC bins []
int16_t motor_pwm_corr_bins[8]; // motor pwm correction [0.1%]
uint16_t pwm_deadtime;
uint16_t can_dbw_id;
uint16_t can_idle_base_id;
uint16_t config_bits;
uint16_t pps1_margin;
uint16_t pps2_margin;
int16_t pps_delta_margin;
uint16_t tps1_margin;
uint16_t tps2_margin;
uint16_t tps_delta_margin;
int16_t tps_error_margin1;
uint16_t tps_error_time1;
int16_t tps_error_margin2;
uint16_t tps_error_time2;
uint16_t can_dbw_poll_perod;
//enable tuning over CAN;
uint8_t can_ms29bit_id;
uint8_t can_ms29bit_options;
//broadcast my data
uint8_t can_bcst_data_enable;
uint8_t can_bcst_data_period;
uint16_t can_bcst_canid;
}config_t;
typedef struct
{
uint32_t clock;
uint16_t status0;
uint16_t status1;
uint16_t status2;
uint16_t status3;
uint16_t pps1_adc;
uint16_t pps2_adc;
uint16_t tps1_adc;
uint16_t tps2_adc;
uint16_t motor_current_adc;
uint16_t vbat_adc;
int16_t pps1;
int16_t pps2;
int16_t tps1;
int16_t tps2;
int16_t pps;
int16_t tps;
int16_t tps_error;
int16_t motor_pwm;
uint16_t idle_dc;
int16_t pps_delta;
int16_t tps_delta;
int16_t tps_target;
uint16_t vss;
uint16_t rpm;
}var_t;
#define PWM_STATUS_DEFAULT 0
#define PWM_STATUS_IDLE 1
#define PWM_STATUS_STARTED 2
#define PWM_STATUS_ERROR 3
#define PWM_STATE_POSITIVE_INACTIVE 0
#define PWM_STATE_POSITIVE_ACTIVE 1
#define PWM_STATE_NEGATIVE_INACTIVE 2
#define PWM_STATE_NEGATIVE_ACTIVE 3
typedef struct
{
unsigned char status;
unsigned char state;
GPIO_TypeDef *pos_port;
unsigned short pos_pin;
GPIO_TypeDef *neg_port;
unsigned short neg_pin;
unsigned int period_ticks;
unsigned int duty_ticks;
signed int pwm;
signed int pwm_t;
signed int single_pulse;
}pwm_t;
extern volatile float pps1_gain, pps1_offset, pps2_gain, pps2_offset, tps1_gain, tps2_offset;
extern volatile uint16_t dbw_fast_process_timer, dbw_slow_process_timer;
void Apply_Sensor_Calibration(void);
int DBW_Process(void);
void DBW_Pwm_Init(void);
void DBW_Pwm_Set_Duty(signed int duty, pwm_t* ttl);
void TIM2_IRQHandler (void);
int intrp_1dstable(signed short x, unsigned char n, signed short * x_table, char sgn,signed short * z_table);
signed short intrp_1d_ss_table(signed short x, unsigned char n, signed short * x_table, char sgn, signed short * z_table);
unsigned int intrp_1d_uitable(unsigned int x, unsigned char nx, unsigned int * x_table, unsigned int * z_table);
void DBW_Init(void);
void DBW_Start(void);
void DBW_Stop(void);
void DBW_TPS_AutoCal(void);
void DBW_Read_sensors(void);
extern volatile pwm_t ttl1_pwm;
extern volatile unsigned short ctl_period;
extern volatile config_t config_ram;
extern volatile var_t var;
extern volatile config_t *config;
extern const config_t config_flash;
extern volatile int32_t vbat_corr, tps_slow_t, p_comp, i_comp, d_comp, tps_error_t, can_target, spring_preload, idle_adder;
extern volatile uint32_t ac_timer, ac_mode;
#endif /* SRC_DBW_H_ */

14
DBW_V2/Core/Inc/inputs.h Normal file
View File

@@ -0,0 +1,14 @@
/*
* inputs.h
*
* Created on: Mar 15, 2022
* Author: v0stap
*/
#ifndef SRC_INPUTS_H_
#define SRC_INPUTS_H_
void TIM3_Init(void); //iddle pwm input 1 PB4
void TIM14_Init(void); //rpm input 2 PB1
#endif /* SRC_INPUTS_H_ */

112
DBW_V2/Core/Inc/main.h Normal file
View File

@@ -0,0 +1,112 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "ts_comms.h"
#include "dbw.h"
#include "adc.h"
#include "can.h"
#include "safety.h"
#include "inputs.h"
#include "outputs.h"
#include "mazda_can.h"
/* 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 PPS1_Pin GPIO_PIN_0
#define PPS1_GPIO_Port GPIOA
#define PPS2_Pin GPIO_PIN_1
#define PPS2_GPIO_Port GPIOA
#define TPS1_Pin GPIO_PIN_2
#define TPS1_GPIO_Port GPIOA
#define TPS2_Pin GPIO_PIN_3
#define TPS2_GPIO_Port GPIOA
#define TTL_FB_Pin GPIO_PIN_4
#define TTL_FB_GPIO_Port GPIOA
#define VBAT_SENSE_Pin GPIO_PIN_5
#define VBAT_SENSE_GPIO_Port GPIOA
#define IN1_Pin GPIO_PIN_0
#define IN1_GPIO_Port GPIOB
#define IN2_Pin GPIO_PIN_1
#define IN2_GPIO_Port GPIOB
#define PWM1_Pin GPIO_PIN_10
#define PWM1_GPIO_Port GPIOB
#define PWM2_Pin GPIO_PIN_11
#define PWM2_GPIO_Port GPIOB
#define FAULT_Pin GPIO_PIN_12
#define FAULT_GPIO_Port GPIOB
#define D2_Pin GPIO_PIN_13
#define D2_GPIO_Port GPIOB
#define D1_Pin GPIO_PIN_14
#define D1_GPIO_Port GPIOB
#define STATUS_FLAG_Pin GPIO_PIN_15
#define STATUS_FLAG_GPIO_Port GPIOB
#define GPO1_Pin GPIO_PIN_5
#define GPO1_GPIO_Port GPIOB
#define GPO2_1_Pin GPIO_PIN_6
#define GPO2_1_GPIO_Port GPIOB
#define GPO2_2_Pin GPIO_PIN_7
#define GPO2_2_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,14 @@
/*
* mazda_can.h
*
* Created on: Mar 17, 2022
* Author: v0stap
*/
#ifndef INC_MAZDA_CAN_H_
#define INC_MAZDA_CAN_H_
void MAZDA_Send_Data(void);
void MAZDA_CAN_Read(void);
#endif /* INC_MAZDA_CAN_H_ */

14
DBW_V2/Core/Inc/outputs.h Normal file
View File

@@ -0,0 +1,14 @@
/*
* outputs.h
*
* Created on: Mar 16, 2022
* Author: v0stap
*/
#ifndef INC_OUTPUTS_H_
#define INC_OUTPUTS_H_
void TIM16_Init (void);
void TIM17_Init (void);
void VSS_Set(uint8_t vss);
#endif /* INC_OUTPUTS_H_ */

31
DBW_V2/Core/Inc/safety.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef SRC_SAFETY_H_
#define SRC_SAFETY_H_
#define STATUS3_NO_FAULT 0
#define STATUS3_PPS1_SS_GND 1
#define STATUS3_PPS1_SS_VREF 2
#define STATUS3_PPS2_SS_GND 3
#define STATUS3_PPS2_SS_VREF 4
#define STATUS3_PPS_DELTA 5
#define STATUS3_TPS1_SS_GND 6
#define STATUS3_TPS1_SS_VREF 7
#define STATUS3_TPS2_SS_GND 8
#define STATUS3_TPS2_SS_VREF 9
#define STATUS3_TPS_DELTA 10
#define STATUS3_TARGET1_FAULT 11
#define STATUS3_TARGET2_FAULT 12
void Flash_Write_Protect(void);
void Flash_Write_Unprotect(void);
void Watch_Dog_Update(void);
void Watch_Dog_Init(void);
void Check_Adc_Range(void);
void Check_Safety_Limits(void);
void Check_TPS_Target();
void Safety_TPS_Safety_Timer_Start(void);
void Safety_TPS_Safety_Timer(void);
extern volatile int dbw_target_tmr1, dbw_target_tmr2;
#endif

View File

@@ -0,0 +1,319 @@
/**
******************************************************************************
* @file stm32f0xx_hal_conf.h
* @brief HAL configuration file.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F0xx_HAL_CONF_H
#define __STM32F0xx_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_ADC_MODULE_ENABLED
/*#define HAL_CRYP_MODULE_ENABLED */
#define HAL_CAN_MODULE_ENABLED
/*#define HAL_CEC_MODULE_ENABLED */
/*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */
/*#define HAL_TSC_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_LCD_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_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_CORTEX_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_I2C_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 ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
/**
* @brief In the following line adjust the External High Speed oscillator (HSE) Startup
* Timeout value
*/
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< 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)8000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief In the following line adjust the Internal High Speed oscillator (HSI) Startup
* Timeout value
*/
#if !defined (HSI_STARTUP_TIMEOUT)
#define HSI_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSI start up */
#endif /* HSI_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator for ADC (HSI14) value.
*/
#if !defined (HSI14_VALUE)
#define HSI14_VALUE ((uint32_t)14000000) /*!< Value of the Internal High Speed oscillator for ADC in Hz.
The real value may vary depending on the variations
in voltage and temperature. */
#endif /* HSI14_VALUE */
/**
* @brief Internal High Speed oscillator for USB (HSI48) value.
*/
#if !defined (HSI48_VALUE)
#define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal High Speed oscillator for USB in Hz.
The real value may vary depending on the variations
in voltage and temperature. */
#endif /* HSI48_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE ((uint32_t)40000)
#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 (LSI) value.
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/* 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 ((uint32_t)3300) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority (lowest by default) */
/* Warning: Must be set to higher priority for HAL_Delay() */
/* and HAL_GetTick() usage under interrupt context */
#define USE_RTOS 0
#define PREFETCH_ENABLE 1
#define INSTRUCTION_CACHE_ENABLE 0
#define DATA_CACHE_ENABLE 0
#define USE_SPI_CRC 0U
#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_COMP_REGISTER_CALLBACKS 0U /* COMP register callback disabled */
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS 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_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
#define USE_HAL_TSC_REGISTER_CALLBACKS 0U /* TSC register callback disabled */
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD 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 */
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32f0xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32f0xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32f0xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32f0xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32f0xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32f0xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_CAN_MODULE_ENABLED
#include "stm32f0xx_hal_can.h"
#endif /* HAL_CAN_MODULE_ENABLED */
#ifdef HAL_CEC_MODULE_ENABLED
#include "stm32f0xx_hal_cec.h"
#endif /* HAL_CEC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32f0xx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32f0xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32f0xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32f0xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32f0xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32f0xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32f0xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32f0xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32f0xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32f0xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32f0xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32f0xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32f0xx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32f0xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32f0xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_TSC_MODULE_ENABLED
#include "stm32f0xx_hal_tsc.h"
#endif /* HAL_TSC_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32f0xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32f0xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32f0xx_hal_wwdg.h"
#endif /* HAL_WWDG_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 /* __STM32F0xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,65 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f0xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F0xx_IT_H
#define __STM32F0xx_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 SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32F0xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

108
DBW_V2/Core/Inc/ts_comms.h Normal file
View File

@@ -0,0 +1,108 @@
/*
* ts_comms.h
*
* Created on: 22 Oct 2020
* Author: Dmitrijs
*/
#ifndef TS_COMMS_H_
#define TS_COMMS_H_
#include <stdint.h>
typedef unsigned char crc_t;
#define TS_CAN_ID 0
#ifndef TS_CAN_ID
#error Set CAN ID !!! ts_comms.h
#endif
// Timeouts for comms: in mS
// Timeout for receive 2 bytes after <cmd>
#define RECEIVE_INDEX_TIMEOUT 10
//Timeout for receive 4 bytes of OFFSET and COUNT
#define RECEIVE_DATA_LOCATION_TIMEOUT 10
//Time out for receive block of data
#define RECEIVE_DATA_TIMEOUT 255
//Timeout for RESET sequence.
#define RECEIVE_RESET_TIMEOUT 1
#define RECEIVE_TABLE_TIMEOUT 255
//Define SCI MODES
#define IDLE 0
#define TRANSMISSION_IN_PROGRESS 1
#define RECEIVE_INDEX 1
#define RECEIVE_DATA_LOCATION 2
#define RECEIVE_DATA 3
#define RECEIVE_TABLE_DATA 4
#define RECEIVE_CANID 5
#define RECEIVE_RESET_CMD 10
//DEFINE ERROR CODES FOR TS COMMS
#define DATA_OVERRUN_ERROR 1
#define FRAME_ERROR 2
#define PARITY_ERROR 3
#define UNRECOGNIZED_1_LETTER_CMD 4
#define REQUEST_TO_TRANSMIT_WHILE_TRANSMITTING 5
#define RESET_SEQUENCE_FAILED 6
#define RESET_SEQUENCE_RECEIVED 7
#define MEMORY_ACCESS_VIOLATION 8
#define RX_TIMEOUT 9
#define NOICE_ERROR 10
#define SCI_FLAGS_CRC32 1
#define SCI_FLAGS_TX_VARIABLES 2
#define READ_DATA_FROM_ADC0 0
#define READ_DATA_FROM_ADC1 1
#define READ_DATA_FROM_CONFIG_ADC0 2
#define READ_DATA_FROM_CONFIG_ADC1 3
#define READ_DATA_FROM_Z0 4
#define READ_DATA_FROM_Z1 5
typedef struct {
unsigned char mode; //1
unsigned char cmd; //2
unsigned char CANid; //3
unsigned char table_index; //4
unsigned short offset; //5
unsigned short data_size; //7
unsigned short cnt; //9
unsigned short bytes_done; //11
unsigned char *address; //13
unsigned char current_table_index; //15
unsigned char error_cnt; //16
unsigned char error_code; //17
unsigned short timeout; //18
unsigned char pause_flag;
unsigned char dummy;
unsigned long crc32; //19
unsigned char can_bufer[256];
} comms_status;
void Rx_Char(unsigned char data); // pass RX byte stream here
void Poll_Tx(void); // function returns pointer to buffer and sets count
// of bytes to be transmitted
void TX_Done(void); // call this function when all data has been transmitted
void Comms_Init(void);
void Write_Config(void);
extern comms_status RX;
extern comms_status TX;
extern unsigned char SCI_flags;
extern const char Signature[20];
extern const char Revision[20];
extern char crc32_bufer[8];
void Comms_Reset(comms_status *CS);
void TX_Schedule(unsigned char *data, unsigned short count);
void Copy_Tx_Vars(void);
void CRC32(void);
crc_t calc_crc(crc_t message[], int nBytes);
uint32_t crc32(void *buf, uint32_t size);
uint32_t crc32inc(void *buf, uint32_t crc, uint32_t size);
void TS_Comms_RX_Timeout(void);
#endif /* TS_COMMS_H_ */