diff --git a/.vscode/settings.json b/.vscode/settings.json index a43d3e5..2260a0d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,13 @@ "capture.h": "c", "arm_math.h": "c", "abnormalmanage.h": "c", - "stm32g431xx.h": "c" + "stm32g431xx.h": "c", + "uart_dev.h": "c", + "hd_comm.h": "c", + "main.h": "c", + "hd_adc.h": "c", + "hd_tim.h": "c", + "checktime.h": "c", + "test.h": "c" } } \ No newline at end of file diff --git a/APP/application/Src/chargControl.c b/APP/application/Src/chargControl.c index 5c49ca4..703beaf 100644 --- a/APP/application/Src/chargControl.c +++ b/APP/application/Src/chargControl.c @@ -11,7 +11,7 @@ */ void chargControl(void) { - getCVData(); + // getCVData(); judgeYNBattery(); chargControlMode(); diff --git a/APP/businessLogic/Inc/bl_comm.h b/APP/businessLogic/Inc/bl_comm.h index c4ed462..ee25e82 100644 --- a/APP/businessLogic/Inc/bl_comm.h +++ b/APP/businessLogic/Inc/bl_comm.h @@ -3,10 +3,13 @@ #define BL_COMM_H_ #include "comm_types.h" +#include "uart_dev.h" void GW485_comm(void); void BAT485_comm(void); +void gw485_RxIt(void); +void bat485_RxIt(void); #endif \ No newline at end of file diff --git a/APP/businessLogic/Inc/parameter.h b/APP/businessLogic/Inc/parameter.h index 0e87bb4..db913bb 100644 --- a/APP/businessLogic/Inc/parameter.h +++ b/APP/businessLogic/Inc/parameter.h @@ -65,7 +65,7 @@ typedef struct _otherParameter{ float totalChargCapacity; /* 总充电电量(W*H) */ float SOC; /* 剩余电量 */ - uint16_t MPPT_Mode; /* 工作模式 */ + int MPPT_Mode; /* 工作模式 */ uint8_t versionInformation[13]; /* 软件版本信息 */ diff --git a/APP/businessLogic/Inc/test.h b/APP/businessLogic/Inc/test.h new file mode 100644 index 0000000..443642a --- /dev/null +++ b/APP/businessLogic/Inc/test.h @@ -0,0 +1,8 @@ +#ifndef BL_TEST_H_ +#define BL_TEST_H_ + + + +void test(void); + +#endif diff --git a/APP/businessLogic/Src/Init.c b/APP/businessLogic/Src/Init.c index 0d52924..79dabf9 100644 --- a/APP/businessLogic/Src/Init.c +++ b/APP/businessLogic/Src/Init.c @@ -7,6 +7,8 @@ #include "FM_GPIO.h" #include "FM_TIM.h" +extern int getMPPT_Mode(void); + void Init(void) { config_info_start(); diff --git a/APP/businessLogic/Src/bl_comm.c b/APP/businessLogic/Src/bl_comm.c index 373eaa9..7294850 100644 --- a/APP/businessLogic/Src/bl_comm.c +++ b/APP/businessLogic/Src/bl_comm.c @@ -16,4 +16,14 @@ void GW485_comm(void) void BAT485_comm(void) { +} + +void gw485_RxIt(void) +{ + +} + +void bat485_RxIt(void) +{ + } \ No newline at end of file diff --git a/APP/businessLogic/Src/test.c b/APP/businessLogic/Src/test.c new file mode 100644 index 0000000..94de3cd --- /dev/null +++ b/APP/businessLogic/Src/test.c @@ -0,0 +1,24 @@ + +#include "test.h" +#include "checkTime.h" +#include "uart_dev.h" +#include "HD_TIM.h" +#include "pDebug.h" + +void test(void) +{ + Init_debug_uart(); + HD_time_Init(); + HAL_TIM_Base_Start_IT(&htim15); + + while (1) { + checkTimeInit(); + HAL_Delay(1000); + debug("time:%f\r\n", getCheckTime()); + } +} + + + + + diff --git a/APP/functionalModule/Inc/FM_TIM.h b/APP/functionalModule/Inc/FM_TIM.h index b96b3c5..beaf1f4 100644 --- a/APP/functionalModule/Inc/FM_TIM.h +++ b/APP/functionalModule/Inc/FM_TIM.h @@ -11,5 +11,6 @@ void set_pwmPulse(uint32_t Pulse); extern void chargControl(void); extern void checkAbnormal(void); +extern void hw_inc_tick(void); #endif diff --git a/APP/functionalModule/Inc/capture.h b/APP/functionalModule/Inc/capture.h index a86addc..8b72b18 100644 --- a/APP/functionalModule/Inc/capture.h +++ b/APP/functionalModule/Inc/capture.h @@ -19,7 +19,7 @@ extern adcCapture PV_VOLT_IN_capture; extern adcCapture CHG_CURR_capture; void ADC_Capture_Init(void); -void proportionalInt(uint8_t mode); +void proportionalInt(int mode); float get_CHG_CURR(void); float get_PV_VOLT_OUT(void); diff --git a/APP/functionalModule/Inc/checkTime.h b/APP/functionalModule/Inc/checkTime.h new file mode 100644 index 0000000..af57826 --- /dev/null +++ b/APP/functionalModule/Inc/checkTime.h @@ -0,0 +1,16 @@ + +#ifndef FM_CHECK_TIME_H_ +#define FM_CHECK_TIME_H_ + +#include "HD_TIM.h" +#include "FM_TIM.h" + + + +void hw_inc_tick(void); +void checkTimeInit(void); +float getCheckTime(void); + + + +#endif diff --git a/APP/functionalModule/Inc/uart_dev.h b/APP/functionalModule/Inc/uart_dev.h new file mode 100644 index 0000000..254eef3 --- /dev/null +++ b/APP/functionalModule/Inc/uart_dev.h @@ -0,0 +1,52 @@ + +#ifndef FM_UART_DEV_H_ +#define FM_UART_DEV_H_ + +#include "main.h" +#include "HD_COMM.h" +#include "comm_types.h" + + +#define ASCII_CHAR_BACKSPACE 0x08 /* '\b' */ +#define ASCII_CHAR_CHARACTER_TABULATION 0x09 /* '\t' */ +#define ASCII_CHAR_LINE_FEED 0x0A /* '\n' */ +#define ASCII_CHAR_LINE_TABULATION 0x0B /* '\v' */ +#define ASCII_CHAR_FORM_FEED 0x0C /* '\f' */ +#define ASCII_CHAR_CARRIAGE_RETURN 0x0D /* '\r' */ + +typedef enum{ + DEBUG_UART_INDEX = 4, + BAT485_UART_INDEX = 3, + GW485_UART_INDEX = 2, +}uartIndex_e; + +/* UART 驱动数据结构,对应一个uart设备 */ +typedef struct _uart_device_info{ + uint8_t init; + uartIndex_e uart_index; + uint32_t uart_baudrate; + RingQueue uart_ring_queue; +}uart_device_info; + +typedef uint32_t device_handle; +extern device_handle g_gw485_uart2_handle; +extern device_handle g_bat485_uart3_handle; +extern device_handle g_debug_uart4_handle; + +extern uint8_t rx_gw485_buf[1]; +extern uint8_t rx_bat485_buf[1]; + +void uart_close(uartIndex_e uart_index); +void uart_sendstr(device_handle device, char *str); +void debug_printf(char *format, ...); +void Init_debug_uart(void); +void Init_BAT485_uart(void); +void Init_GW485_uart(void); + +void start_gw485Rx_It(void); +void start_bat485Rx_It(void); + +extern void gw485_RxIt(void); +extern void bat485_RxIt(void); + +#endif diff --git a/APP/functionalModule/Src/FM_TIM.c b/APP/functionalModule/Src/FM_TIM.c index dc51be4..c1e5989 100644 --- a/APP/functionalModule/Src/FM_TIM.c +++ b/APP/functionalModule/Src/FM_TIM.c @@ -3,6 +3,7 @@ #include "timeSliceOffset.h" #include "capture.h" + static int PWM_RESOLUTION; /** @@ -19,12 +20,24 @@ void tim_Init(void) HD_controlTim_Init(); HD_taskBaseTim_Init(); HD_checkAbnormalTim_Init(); + + HD_time_Init(); } +/** + * @brief 停止PWM信号输出 + * + * 本函数通过设置PWM脉冲宽度为0来停止PWM信号输出,然后调用HAL库函数进行PWM相关的硬件资源初始化。 + * 注意:这里使用了硬件抽象层(HAL)库提供的函数,特定于STM32微控制器。 + */ void pwm_Stop(void) { + // 设置PWM脉冲宽度为0, effectively停止PWM信号输出 set_pwmPulse(0); + // HAL_TIM_OC_MspDeInit(&htim3); + + // 调用HAL库函数进行PWM相关的硬件资源De初始化 HAL_TIM_PWM_MspDeInit(&htim3); } @@ -76,17 +89,21 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) } /* USER CODE BEGIN Callback 1 */ - if (htim->Instance == TIM7) { + else if (htim->Instance == TIM7) { chargControl(); } - if (htim->Instance == TIM16) { + else if (htim->Instance == TIM16) { TimeSliceOffset_Produce(); } - if (htim->Instance == TIM17) { + else if (htim->Instance == TIM17) { checkAbnormal(); } + else if (htim->Instance == TIM15) { + hw_inc_tick(); + } + /* USER CODE END Callback 1 */ } \ No newline at end of file diff --git a/APP/functionalModule/Src/capture.c b/APP/functionalModule/Src/capture.c index d1c0d15..ad2913e 100644 --- a/APP/functionalModule/Src/capture.c +++ b/APP/functionalModule/Src/capture.c @@ -159,7 +159,7 @@ void ADC_Capture_Init(void) * @param * @retval None */ -void proportionalInt(uint8_t mode) +void proportionalInt(int mode) { /* 仅充当电源盒 */ if (mode) { diff --git a/APP/functionalModule/Src/checkTime.c b/APP/functionalModule/Src/checkTime.c new file mode 100644 index 0000000..fe24e09 --- /dev/null +++ b/APP/functionalModule/Src/checkTime.c @@ -0,0 +1,59 @@ + +#include "checkTime.h" + + + +typedef struct _timeData { + /* 程序执行前的时间 */ + uint32_t time_ms1; + uint16_t time_tick1; + + /* 程序执行完的时间 */ + uint32_t time_ms2; + uint16_t time_tick2; + + + /* 程序执行所用的时间(ms) */ + float time_s; +}timeData; + +static timeData checkTimeData; + +volatile static uint32_t hw_sys_tick_ms = 0; //ms 自增计数变量 + +#define tim TIM15 +#define timLard 36000.0 + +/** + * hw_inc_tick函数 + * + * 本函数用于递增硬件系统的毫秒计时器hw_sys_tick_ms。 + * 每次调用此函数,hw_sys_tick_ms将增加1。 + * + * 注意:此函数没有输入参数和返回值。 + */ +void hw_inc_tick(void) +{ + ++hw_sys_tick_ms; +} + +void checkTimeInit(void) +{ + checkTimeData.time_ms1 = hw_sys_tick_ms; + checkTimeData.time_tick1 = tim->CNT; +} + + + +float getCheckTime(void) +{ + checkTimeData.time_ms2 = hw_sys_tick_ms; + checkTimeData.time_tick2 = tim->CNT; + + checkTimeData.time_s = checkTimeData.time_ms2 - checkTimeData.time_ms1 + + (checkTimeData.time_tick2 - checkTimeData.time_tick1) / timLard; + + return checkTimeData.time_s; +} + + diff --git a/APP/functionalModule/Src/uart_dev.c b/APP/functionalModule/Src/uart_dev.c new file mode 100644 index 0000000..f514ae3 --- /dev/null +++ b/APP/functionalModule/Src/uart_dev.c @@ -0,0 +1,229 @@ +#include "uart_dev.h" +#include +#include +#include + +device_handle g_gw485_uart2_handle; +device_handle g_bat485_uart3_handle; +device_handle g_debug_uart4_handle; + +static uint8_t Debug_in_buff[200]; +static uint8_t Gw485_in_buff[200]; +static uint8_t Bat485_in_buff[200]; + +uint8_t rx_gw485_buf[1]; +uint8_t rx_bat485_buf[1]; + +static uint8_t debug_out_buff[100]; + +/** + * @brief 串口信息初始化,串口号及波特率. + * @param uart_index 对应的硬件串口号 + * @param uart_baudrate 波特率 + */ +uart_device_info uart_devices[]={ + [0] = { + .init = 0, + .uart_index = GW485_UART_INDEX, + .uart_baudrate = 115200, + }, + [1] = { + .init = 0, + .uart_index = BAT485_UART_INDEX, + .uart_baudrate = 115200, + }, + [2] = { + .init = 0, + .uart_index = DEBUG_UART_INDEX, + .uart_baudrate = 115200, + }, +}; + +static device_handle uart_dev_init(uartIndex_e uart_index, uint8_t *buff, int buff_size); +static void uart_init(uartIndex_e uart_index, uint32_t baud); +static u_int8_t uart_putchar(device_handle device, char ch); + + +/** + * @brief 初始化串口设备. + * @param uart_index 初始化串口号 + * @param buff 串口循环buff地址 + * @param buff_size 串口循环buff对应大小 + * @retval 串口句柄 + */ +device_handle uart_dev_init(uartIndex_e uart_index, uint8_t *buff, int buff_size) +{ + int i = 0; + for (; i < ELEMENT_OF(uart_devices); i++) { + if (uart_devices[i].uart_index == uart_index) { + if (!uart_devices[i].init) { + InitRingQueue(&uart_devices[i].uart_ring_queue, buff, buff_size); + uart_init(uart_index, uart_devices[i].uart_baudrate); + + uart_devices[i].init = 1; + } + return (device_handle)(&uart_devices[i]); + } + } + return 0; +} + +/** + * @brief 串口硬件初始化. + * @param uart_index 串口号 + * @param baud 波特率 + * @retval None + */ +void uart_init(uartIndex_e uart_index, uint32_t baud) +{ + if (uart_index == GW485_UART_INDEX) { + HD_GW485_Init(baud); + } else if (uart_index == BAT485_UART_INDEX) { + HD_BAT485_Init(baud); + } else if (uart_index == DEBUG_UART_INDEX) { + HD_DEBUG_Uart_Init(baud); + } +} + +/** + * @brief 关闭串口 + * @param uart_index 串口号 + * @retval None + */ +void uart_close(uartIndex_e uart_index) +{ + if(uart_index == GW485_UART_INDEX){ + HAL_UART_MspDeInit(&huart2); + }else if(uart_index == BAT485_UART_INDEX){ + HAL_UART_MspDeInit(&huart3); + }else if(uart_index == DEBUG_UART_INDEX){ + HAL_UART_MspDeInit(&huart4); + } +} + +/** + * @brief 发送一个字节. + * @param uart_index 串口号 + * @param ch 待发送字符 + * @retval 1 成功 0失败 + */ +static u_int8_t uart_putchar(device_handle device, char ch) +{ + + int ret = HAL_ERROR; + + uart_device_info *device_info = (uart_device_info *)device; + if((!device) || (!device_info->init)) + return 0; + + if (device_info->uart_index == GW485_UART_INDEX) { + ret = HAL_UART_Transmit(&huart2, (uint8_t*)&ch, 1, 10); + } else if (device_info->uart_index == BAT485_UART_INDEX) { + ret = HAL_UART_Transmit(&huart3, (uint8_t*)&ch, 1, 10); + } else if (device_info->uart_index == DEBUG_UART_INDEX) { + ret = HAL_UART_Transmit(&huart4, (uint8_t*)&ch, 1, 10); + } + + if (ret == HAL_OK) { + return 1; + } else { + return 0; + } +} + +/** + * @brief 发送字符串. + * @param uart_index 串口号 + * @param str 待发送字符串地址 + * @retval None + */ +void uart_sendstr(device_handle device, char *str) +{ + while ((*str) != (char )0u) { + if (*str == ASCII_CHAR_LINE_FEED){ + uart_putchar(device, (ASCII_CHAR_CARRIAGE_RETURN)); + uart_putchar(device, ASCII_CHAR_LINE_FEED); + str++; + }else{ + uart_putchar(device, *str++); + } + } +} + +/** + * @brief 调试串口 . + * @param 可变参 + * @retval Null + */ +void debug_printf(char *format, ...) +{ + memset(debug_out_buff, 0, sizeof(debug_out_buff)); + va_list va_ptr; + va_start(va_ptr, format); + vsprintf((char*)debug_out_buff, (char const *)format, va_ptr); + va_end(va_ptr); + + uart_sendstr(g_debug_uart4_handle, (char*)debug_out_buff); +} + +/** + * @brief 初始化调试串口. + * @retval None + */ +void Init_debug_uart(void) +{ + g_debug_uart4_handle = uart_dev_init(DEBUG_UART_INDEX, Debug_in_buff, sizeof(Debug_in_buff)); +} + +/** + * @brief 初始化向下通信对电池pack串口. + * @retval None + */ +void Init_BAT485_uart(void) +{ + g_bat485_uart3_handle = uart_dev_init(BAT485_UART_INDEX, Bat485_in_buff, sizeof(Bat485_in_buff)); +} + +/** + * @brief 初始化向上对网关通信485串口. + * @retval None + */ +void Init_GW485_uart(void) +{ + g_gw485_uart2_handle = uart_dev_init(GW485_UART_INDEX, Gw485_in_buff, sizeof(Gw485_in_buff)); +} + +void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) +{ + if (huart->Instance == USART2) { + gw485_RxIt(); + } + else if (huart->Instance == USART3) { + bat485_RxIt(); + } +} + +/** + * @brief 开启向上对网关通信485串口的中断接收. + * @retval None + */ +void start_gw485Rx_It(void) +{ + HAL_UART_Receive_IT(&huart2, rx_gw485_buf, 1); +} + +/** + * @brief 开启向下通信对电池pack串口的中断接收. + * @retval None + */ +void start_bat485Rx_It(void) +{ + HAL_UART_Receive_IT(&huart3, rx_bat485_buf, 1); +} + + + + + + + diff --git a/APP/hardwareDriver/Inc/HD_COMM.h b/APP/hardwareDriver/Inc/HD_COMM.h new file mode 100644 index 0000000..0182bb4 --- /dev/null +++ b/APP/hardwareDriver/Inc/HD_COMM.h @@ -0,0 +1,15 @@ + +#ifndef CCB_HD_COMM_H_ +#define CCB_HD_COMM_H_ + +#include "main.h" +#include "usart.h" +#include "ring_queue.h" + + +void HD_COMM_Init(uint32_t GW485_BaudRate, uint32_t BAT485_BaudRate); +void HD_BAT485_Init(uint32_t BAT485_BaudRate); +void HD_GW485_Init(uint32_t GW485_BaudRate); +void HD_DEBUG_Uart_Init(uint32_t DEBUG_Uart_BaudRate); + +#endif \ No newline at end of file diff --git a/APP/hardwareDriver/Inc/HD_TIM.h b/APP/hardwareDriver/Inc/HD_TIM.h index aeeb962..0f15f5c 100644 --- a/APP/hardwareDriver/Inc/HD_TIM.h +++ b/APP/hardwareDriver/Inc/HD_TIM.h @@ -11,5 +11,6 @@ void HD_controlTim_Init(void); void HD_taskBaseTim_Init(void); void HD_checkAbnormalTim_Init(void); +void HD_time_Init(void); #endif \ No newline at end of file diff --git a/APP/hardwareDriver/Src/HD_COMM.c b/APP/hardwareDriver/Src/HD_COMM.c new file mode 100644 index 0000000..f70bd25 --- /dev/null +++ b/APP/hardwareDriver/Src/HD_COMM.c @@ -0,0 +1,162 @@ +#include "HD_COMM.h" + + + +void HD_BAT485_Init(uint32_t BAT485_BaudRate) +{ + /* BAT485初始化 */ + huart3.Instance = USART3; + huart3.Init.BaudRate = BAT485_BaudRate; + huart3.Init.WordLength = UART_WORDLENGTH_8B; + huart3.Init.StopBits = UART_STOPBITS_1; + huart3.Init.Parity = UART_PARITY_NONE; + huart3.Init.Mode = UART_MODE_TX_RX; + huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart3.Init.OverSampling = UART_OVERSAMPLING_16; + huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_RS485Ex_Init(&huart3, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK) + { + Error_Handler(); + } +} + +void HD_GW485_Init(uint32_t GW485_BaudRate) +{ + /* GW485初始化 */ + huart2.Instance = USART2; + huart2.Init.BaudRate = GW485_BaudRate; + 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; + huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK) + { + Error_Handler(); + } +} + +void HD_DEBUG_Uart_Init(uint32_t DEBUG_Uart_BaudRate) +{ + huart4.Instance = UART4; + huart4.Init.BaudRate = DEBUG_Uart_BaudRate; + huart4.Init.WordLength = UART_WORDLENGTH_8B; + huart4.Init.StopBits = UART_STOPBITS_1; + huart4.Init.Parity = UART_PARITY_NONE; + huart4.Init.Mode = UART_MODE_TX_RX; + huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart4.Init.OverSampling = UART_OVERSAMPLING_16; + huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&huart4) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK) + { + Error_Handler(); + } +} + + +void HD_COMM_Init(uint32_t GW485_BaudRate, uint32_t BAT485_BaudRate) +{ + MX_UART4_Init(); + + /* GW485初始化 */ + huart2.Instance = USART2; + huart2.Init.BaudRate = GW485_BaudRate; + 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; + huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK) + { + Error_Handler(); + } + + /* BAT485初始化 */ + huart3.Instance = USART3; + huart3.Init.BaudRate = BAT485_BaudRate; + huart3.Init.WordLength = UART_WORDLENGTH_8B; + huart3.Init.StopBits = UART_STOPBITS_1; + huart3.Init.Parity = UART_PARITY_NONE; + huart3.Init.Mode = UART_MODE_TX_RX; + huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart3.Init.OverSampling = UART_OVERSAMPLING_16; + huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_RS485Ex_Init(&huart3, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK) + { + Error_Handler(); + } +} \ No newline at end of file diff --git a/APP/hardwareDriver/Src/HD_TIM.c b/APP/hardwareDriver/Src/HD_TIM.c index 5459a20..b81fad7 100644 --- a/APP/hardwareDriver/Src/HD_TIM.c +++ b/APP/hardwareDriver/Src/HD_TIM.c @@ -39,3 +39,13 @@ void HD_checkAbnormalTim_Init(void) { MX_TIM17_Init(); } + +/** + * @brief 该定时器用来计时从而判断执行时间 + * @param None + * @retval None + */ +void HD_time_Init(void) +{ + MX_TIM15_Init(); +} diff --git a/Core/Inc/stm32g4xx_it.h b/Core/Inc/stm32g4xx_it.h index 64476a6..cf273fc 100644 --- a/Core/Inc/stm32g4xx_it.h +++ b/Core/Inc/stm32g4xx_it.h @@ -56,6 +56,7 @@ void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void DMA1_Channel1_IRQHandler(void); +void TIM1_BRK_TIM15_IRQHandler(void); void TIM1_UP_TIM16_IRQHandler(void); void TIM1_TRG_COM_TIM17_IRQHandler(void); void USART2_IRQHandler(void); diff --git a/Core/Inc/tim.h b/Core/Inc/tim.h index 48d1397..d3df754 100644 --- a/Core/Inc/tim.h +++ b/Core/Inc/tim.h @@ -38,6 +38,8 @@ extern TIM_HandleTypeDef htim6; extern TIM_HandleTypeDef htim7; +extern TIM_HandleTypeDef htim15; + extern TIM_HandleTypeDef htim16; extern TIM_HandleTypeDef htim17; @@ -49,6 +51,7 @@ extern TIM_HandleTypeDef htim17; void MX_TIM3_Init(void); void MX_TIM6_Init(void); void MX_TIM7_Init(void); +void MX_TIM15_Init(void); void MX_TIM16_Init(void); void MX_TIM17_Init(void); diff --git a/Core/Src/main.c b/Core/Src/main.c index d90e6c6..cd83a32 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -27,6 +27,9 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "test.h" + + /* USER CODE END Includes */ @@ -90,31 +93,37 @@ int main(void) /* USER CODE END SysInit */ /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - MX_ADC1_Init(); - MX_ADC2_Init(); - MX_SPI1_Init(); - MX_TIM3_Init(); - MX_TIM6_Init(); - MX_UART4_Init(); - MX_USART2_UART_Init(); - MX_USART3_UART_Init(); - MX_TIM7_Init(); - MX_TIM16_Init(); - MX_TIM17_Init(); +// MX_GPIO_Init(); +// MX_DMA_Init(); +// MX_ADC1_Init(); +// MX_ADC2_Init(); +// MX_SPI1_Init(); +// MX_TIM3_Init(); +// MX_TIM6_Init(); +// MX_UART4_Init(); +// MX_USART2_UART_Init(); +// MX_USART3_UART_Init(); +// MX_TIM7_Init(); +// MX_TIM16_Init(); +// MX_TIM17_Init(); +// MX_TIM15_Init(); /* USER CODE BEGIN 2 */ + test(); + + + + /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ - while (1) - { +// while (1) +// { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - } +// } /* USER CODE END 3 */ } diff --git a/Core/Src/stm32g4xx_it.c b/Core/Src/stm32g4xx_it.c index 28b0465..0493bcb 100644 --- a/Core/Src/stm32g4xx_it.c +++ b/Core/Src/stm32g4xx_it.c @@ -58,6 +58,7 @@ extern DMA_HandleTypeDef hdma_adc1; extern TIM_HandleTypeDef htim6; extern TIM_HandleTypeDef htim7; +extern TIM_HandleTypeDef htim15; extern TIM_HandleTypeDef htim16; extern TIM_HandleTypeDef htim17; extern UART_HandleTypeDef huart2; @@ -220,6 +221,20 @@ void DMA1_Channel1_IRQHandler(void) /* USER CODE END DMA1_Channel1_IRQn 1 */ } +/** + * @brief This function handles TIM1 break interrupt and TIM15 global interrupt. + */ +void TIM1_BRK_TIM15_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_BRK_TIM15_IRQn 0 */ + + /* USER CODE END TIM1_BRK_TIM15_IRQn 0 */ + HAL_TIM_IRQHandler(&htim15); + /* USER CODE BEGIN TIM1_BRK_TIM15_IRQn 1 */ + + /* USER CODE END TIM1_BRK_TIM15_IRQn 1 */ +} + /** * @brief This function handles TIM1 update interrupt and TIM16 global interrupt. */ diff --git a/Core/Src/system_stm32g4xx.c b/Core/Src/system_stm32g4xx.c index 922e57a..172f337 100644 --- a/Core/Src/system_stm32g4xx.c +++ b/Core/Src/system_stm32g4xx.c @@ -179,9 +179,9 @@ void SystemInit(void) { /* FPU settings ------------------------------------------------------------*/ - #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */ - #endif + #endif /* Configure the Vector Table location add offset address ------------------*/ #if defined(USER_VECT_TAB_ADDRESS) diff --git a/Core/Src/tim.c b/Core/Src/tim.c index 31848aa..b486d70 100644 --- a/Core/Src/tim.c +++ b/Core/Src/tim.c @@ -27,6 +27,7 @@ TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim6; TIM_HandleTypeDef htim7; +TIM_HandleTypeDef htim15; TIM_HandleTypeDef htim16; TIM_HandleTypeDef htim17; @@ -139,6 +140,47 @@ void MX_TIM7_Init(void) /* USER CODE END TIM7_Init 2 */ +} +/* TIM15 init function */ +void MX_TIM15_Init(void) +{ + + /* USER CODE BEGIN TIM15_Init 0 */ + + /* USER CODE END TIM15_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM15_Init 1 */ + + /* USER CODE END TIM15_Init 1 */ + htim15.Instance = TIM15; + htim15.Init.Prescaler = 1; + htim15.Init.CounterMode = TIM_COUNTERMODE_UP; + htim15.Init.Period = 35999; + htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim15.Init.RepetitionCounter = 0; + htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim15) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM15_Init 2 */ + + /* USER CODE END TIM15_Init 2 */ + } /* TIM16 init function */ void MX_TIM16_Init(void) @@ -244,6 +286,21 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) /* USER CODE END TIM7_MspInit 1 */ } + else if(tim_baseHandle->Instance==TIM15) + { + /* USER CODE BEGIN TIM15_MspInit 0 */ + + /* USER CODE END TIM15_MspInit 0 */ + /* TIM15 clock enable */ + __HAL_RCC_TIM15_CLK_ENABLE(); + + /* TIM15 interrupt Init */ + HAL_NVIC_SetPriority(TIM1_BRK_TIM15_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM1_BRK_TIM15_IRQn); + /* USER CODE BEGIN TIM15_MspInit 1 */ + + /* USER CODE END TIM15_MspInit 1 */ + } else if(tim_baseHandle->Instance==TIM16) { /* USER CODE BEGIN TIM16_MspInit 0 */ @@ -350,6 +407,20 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) /* USER CODE END TIM7_MspDeInit 1 */ } + else if(tim_baseHandle->Instance==TIM15) + { + /* USER CODE BEGIN TIM15_MspDeInit 0 */ + + /* USER CODE END TIM15_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM15_CLK_DISABLE(); + + /* TIM15 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM1_BRK_TIM15_IRQn); + /* USER CODE BEGIN TIM15_MspDeInit 1 */ + + /* USER CODE END TIM15_MspDeInit 1 */ + } else if(tim_baseHandle->Instance==TIM16) { /* USER CODE BEGIN TIM16_MspDeInit 0 */ diff --git a/EWARM/chargeController.ewp b/EWARM/chargeController.ewp index 2335743..e2e3c56 100644 --- a/EWARM/chargeController.ewp +++ b/EWARM/chargeController.ewp @@ -1,1316 +1,1333 @@ - 4 - - chargeController - - ARM - + 4 + + chargeController + + ARM + + 1 + + General + 3 + + 36 + 1 1 - - General - 3 - - 36 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ICCARM - 2 - - 38 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AARM - 2 - - 12 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OBJCOPY - 0 - - 1 - 1 - 1 - - - - - - - - - CUSTOM - 3 - - - - 0 - inputOutputBased - - - - ILINK - 0 - - 27 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IARCHIVE - 0 - - 0 - 1 - 1 - - - - - - - BUILDACTION - 2 - - - - Coder - 0 - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCARM + 2 + + 38 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 12 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 1 + + + + + + + + + CUSTOM + 3 + + + + 0 + inputOutputBased + + + + ILINK + 0 + + 27 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 1 + + + + + + + BUILDACTION + 2 + + + + Coder + 0 + + + + + APP - APP - - application - - $PROJ_DIR$\..\APP\application\Src\chargControl.c - - - $PROJ_DIR$\..\APP\application\Src\comm.c - - - $PROJ_DIR$\..\APP\application\Src\start.c - - - $PROJ_DIR$\..\APP\application\Src\task.c - - - - businessLogic - - $PROJ_DIR$\..\APP\businessLogic\Src\abnormalManage.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\bl_chargControl.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\bl_comm.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\inFlash.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\parameter.c - - - - functionalModule - - $PROJ_DIR$\..\APP\functionalModule\Src\capture.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\flash.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c - - - - hardwareDriver - - $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_ADC.c - - - $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c - - - $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c - - - $PROJ_DIR$\..\APP\hardwareDriver\Src\w25qxx.c - - + application + + $PROJ_DIR$\..\APP\application\Src\chargControl.c + + + $PROJ_DIR$\..\APP\application\Src\comm.c + + + $PROJ_DIR$\..\APP\application\Src\start.c + + + $PROJ_DIR$\..\APP\application\Src\task.c + - Application - - EWARM - - $PROJ_DIR$\startup_stm32g431xx.s - - - - User - - Core - - $PROJ_DIR$\..\Core\Src\adc.c - - - $PROJ_DIR$\..\Core\Src\dma.c - - - $PROJ_DIR$\..\Core\Src\gpio.c - - - $PROJ_DIR$\..\Core\Src\main.c - - - $PROJ_DIR$\..\Core\Src\spi.c - - - $PROJ_DIR$\..\Core\Src\stm32g4xx_hal_msp.c - - - $PROJ_DIR$\..\Core\Src\stm32g4xx_hal_timebase_tim.c - - - $PROJ_DIR$\..\Core\Src\stm32g4xx_it.c - - - $PROJ_DIR$\..\Core\Src\tim.c - - - $PROJ_DIR$\..\Core\Src\usart.c - - - + businessLogic + + $PROJ_DIR$\..\APP\businessLogic\Src\abnormalManage.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\bl_chargControl.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\bl_comm.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\inFlash.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\Init.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\parameter.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\test.c + - Drivers - - CMSIS - - $PROJ_DIR$\..\Core\Src\system_stm32g4xx.c - - - - STM32G4xx_HAL_Driver - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c - - + functionalModule + + $PROJ_DIR$\..\APP\functionalModule\Src\capture.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\checkTime.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\flash.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\uart_dev.c + - Middlewares - - Library - - DSP Library/DSP Library - - $PROJ_DIR$\..\Middlewares\ST\ARM\DSP\Lib\iar_cortexM4lf_math.a - - - + hardwareDriver + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_ADC.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_COMM.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\w25qxx.c + + + + + Application + + EWARM + + $PROJ_DIR$\startup_stm32g431xx.s + - tools + User + + Core - $PROJ_DIR$\..\tools\RingQueue\ring_queue.c + $PROJ_DIR$\..\Core\Src\main.c - $PROJ_DIR$\..\tools\TimeSliceOffset\timeSliceOffset.c + $PROJ_DIR$\..\Core\Src\gpio.c + + $PROJ_DIR$\..\Core\Src\adc.c + + + $PROJ_DIR$\..\Core\Src\dma.c + + + $PROJ_DIR$\..\Core\Src\spi.c + + + $PROJ_DIR$\..\Core\Src\tim.c + + + $PROJ_DIR$\..\Core\Src\usart.c + + + $PROJ_DIR$\..\Core\Src\stm32g4xx_it.c + + + $PROJ_DIR$\..\Core\Src\stm32g4xx_hal_msp.c + + + $PROJ_DIR$\..\Core\Src\stm32g4xx_hal_timebase_tim.c + + + + + Drivers + + CMSIS + + $PROJ_DIR$\..\Core\Src\system_stm32g4xx.c + + + + STM32G4xx_HAL_Driver + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c + + + + + tools + + $PROJ_DIR$\..\tools\RingQueue\ring_queue.c + + + $PROJ_DIR$\..\tools\TimeSliceOffset\timeSliceOffset.c + + + + Middlewares + + Library + + DSP Library/DSP Library + + $PROJ_DIR$/../Middlewares/ST/ARM/DSP/Lib/iar_cortexM4lf_math.a + + + + + diff --git a/EWARM/chargeController.ewt b/EWARM/chargeController.ewt index 80e55b6..328c086 100644 --- a/EWARM/chargeController.ewt +++ b/EWARM/chargeController.ewt @@ -1457,15 +1457,24 @@ $PROJ_DIR$\..\APP\businessLogic\Src\inFlash.c + + $PROJ_DIR$\..\APP\businessLogic\Src\Init.c + $PROJ_DIR$\..\APP\businessLogic\Src\parameter.c + + $PROJ_DIR$\..\APP\businessLogic\Src\test.c + functionalModule $PROJ_DIR$\..\APP\functionalModule\Src\capture.c + + $PROJ_DIR$\..\APP\functionalModule\Src\checkTime.c + $PROJ_DIR$\..\APP\functionalModule\Src\flash.c @@ -1475,12 +1484,18 @@ $PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c + + $PROJ_DIR$\..\APP\functionalModule\Src\uart_dev.c + hardwareDriver $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_ADC.c + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_COMM.c + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c diff --git a/chargeController.ioc b/chargeController.ioc index c8fccb2..00bb2a3 100644 --- a/chargeController.ioc +++ b/chargeController.ioc @@ -38,8 +38,8 @@ ADC2.NbrOfConversionFlag=1 ADC2.OffsetNumber-0\#ChannelRegularConversion=ADC_OFFSET_NONE ADC2.Rank-0\#ChannelRegularConversion=1 ADC2.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_6CYCLES_5 -CAD.formats= -CAD.pinconfig= +CAD.formats=[] +CAD.pinconfig=Dual CAD.provider= Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY Dma.ADC1.0.EventEnable=DISABLE @@ -67,11 +67,12 @@ Mcu.CPN=STM32G431RBT6 Mcu.Family=STM32G4 Mcu.IP0=ADC1 Mcu.IP1=ADC2 -Mcu.IP10=TIM16 -Mcu.IP11=TIM17 -Mcu.IP12=UART4 -Mcu.IP13=USART2 -Mcu.IP14=USART3 +Mcu.IP10=TIM15 +Mcu.IP11=TIM16 +Mcu.IP12=TIM17 +Mcu.IP13=UART4 +Mcu.IP14=USART2 +Mcu.IP15=USART3 Mcu.IP2=DMA Mcu.IP3=NVIC Mcu.IP4=RCC @@ -80,7 +81,7 @@ Mcu.IP6=SYS Mcu.IP7=TIM3 Mcu.IP8=TIM6 Mcu.IP9=TIM7 -Mcu.IPNb=15 +Mcu.IPNb=16 Mcu.Name=STM32G431R(6-8-B)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13 @@ -112,16 +113,17 @@ Mcu.Pin31=VP_SYS_VS_tim1 Mcu.Pin32=VP_SYS_VS_DBSignals Mcu.Pin33=VP_TIM6_VS_ClockSourceINT Mcu.Pin34=VP_TIM7_VS_ClockSourceINT -Mcu.Pin35=VP_TIM16_VS_ClockSourceINT -Mcu.Pin36=VP_TIM17_VS_ClockSourceINT -Mcu.Pin37=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0 +Mcu.Pin35=VP_TIM15_VS_ClockSourceINT +Mcu.Pin36=VP_TIM16_VS_ClockSourceINT +Mcu.Pin37=VP_TIM17_VS_ClockSourceINT +Mcu.Pin38=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0 Mcu.Pin4=PC2 Mcu.Pin5=PA0 Mcu.Pin6=PA1 Mcu.Pin7=PA2 Mcu.Pin8=PA3 Mcu.Pin9=PA4 -Mcu.PinsNb=38 +Mcu.PinsNb=39 Mcu.ThirdParty0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0 Mcu.ThirdPartyNb=1 Mcu.UserConstants= @@ -140,6 +142,7 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false +NVIC.TIM1_BRK_TIM15_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.TIM1_TRG_COM_TIM17_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.TIM1_UP_TIM16_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true NVIC.TIM6_DAC_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true @@ -304,7 +307,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_UART4_Init-UART4-false-HAL-true,10-MX_USART2_UART_Init-USART2-false-HAL-true,11-MX_USART3_UART_Init-USART3-false-HAL-true,12-MX_TIM7_Init-TIM7-false-HAL-true,13-MX_TIM16_Init-TIM16-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_UART4_Init-UART4-false-HAL-true,10-MX_USART2_UART_Init-USART2-false-HAL-true,11-MX_USART3_UART_Init-USART3-false-HAL-true,12-MX_TIM7_Init-TIM7-false-HAL-true,13-MX_TIM16_Init-TIM16-false-HAL-true,14-MX_TIM17_Init-TIM17-false-HAL-true,15-MX_TIM15_Init-TIM15-false-HAL-true RCC.ADC12Freq_Value=72000000 RCC.AHBFreq_Value=72000000 RCC.APB1Freq_Value=72000000 @@ -368,6 +371,9 @@ STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.DSPOoLibraryJjLibrary_Checked=true STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.IPParameters=LibraryCcDSPOoLibraryJjDSPOoLibrary STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.LibraryCcDSPOoLibraryJjDSPOoLibrary=true STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0_SwParameter=LibraryCcDSPOoLibraryJjDSPOoLibrary\:true; +TIM15.IPParameters=PeriodNoDither,Prescaler +TIM15.PeriodNoDither=7199 +TIM15.Prescaler=10 TIM16.IPParameters=Prescaler,PeriodNoDither TIM16.PeriodNoDither=999 TIM16.Prescaler=71 @@ -397,6 +403,8 @@ VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals VP_SYS_VS_tim1.Mode=TIM1 VP_SYS_VS_tim1.Signal=SYS_VS_tim1 +VP_TIM15_VS_ClockSourceINT.Mode=Internal +VP_TIM15_VS_ClockSourceINT.Signal=TIM15_VS_ClockSourceINT VP_TIM16_VS_ClockSourceINT.Mode=Enable_Timer VP_TIM16_VS_ClockSourceINT.Signal=TIM16_VS_ClockSourceINT VP_TIM17_VS_ClockSourceINT.Mode=Enable_Timer diff --git a/tools/pDebug.h b/tools/pDebug.h index 81897bb..cb6cf96 100644 --- a/tools/pDebug.h +++ b/tools/pDebug.h @@ -4,18 +4,18 @@ #include #include -// #include "uart_dev.h" +#include "uart_dev.h" // #include "pdebug.h" /* Comment out this define to include debug messages */ -#define NDEBUG +// #define NDEBUG #define log_info_enable 1 #define log_warn_enable 0 #define log_error_enable 0 /* Comment out this define to include log messages */ -#define NLOG +// #define NLOG #ifdef NDEBUG #define debug(M, ...) do {}while(0)