特性:实现电机控制与霍尔传感器功能
新增电机板级支持包:基于 AT8236-MS 驱动芯片,实现了对 4 个直流电机的 PWM 控制。 实现霍尔传感器功能:用于速度测量和脉冲计数。 更新 GPIO 初始化:为霍尔传感器添加了外部中断(EXTI)配置。 修改系统时钟配置:改用高速外部时钟(HSE)并调整了锁相环(PLL)设置。 更改定时器配置:将时基生成从 TIM8 改为 TIM4。 增强 FreeRTOS 任务:实现从霍尔传感器周期性读取并更新速度数据。 更新项目配置:以反映外设使用情况和优先级的变更。
This commit is contained in:
@@ -53,6 +53,8 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Core/Bsp/easylogger/port/elog_port.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Core/Bsp/checksum.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Core/Bsp/protocol.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Core/Bsp/bsp_motor.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Core/Bsp/bsp_hall.c
|
||||
)
|
||||
|
||||
# Add include paths
|
||||
@@ -77,3 +79,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
# Add user defined libraries
|
||||
)
|
||||
|
||||
# Enable float support for printf
|
||||
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
-u _printf_float
|
||||
)
|
||||
99
Core/Bsp/README.md
Normal file
99
Core/Bsp/README.md
Normal file
@@ -0,0 +1,99 @@
|
||||
# BSP Motor 驱动说明 (AT8236-MS)
|
||||
|
||||
该驱动模块用于通过 STM32 的硬件 PWM 功能控制 4 路直流电机,适配 **AT8236-MS** 驱动芯片。
|
||||
|
||||
## 硬件连接
|
||||
|
||||
| 电机 ID | 信号定义 | STM32 引脚 | 定时器通道 |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| **MOTOR_1** | M1_W / M1_S | PE9 / PE11 | TIM1_CH1 / TIM1_CH2 |
|
||||
| **MOTOR_2** | M2_W / M2_S | PE13 / PE14 | TIM1_CH3 / TIM1_CH4 |
|
||||
| **MOTOR_3** | M3_W / M3_S | PA15 / PB3 | TIM2_CH1 / TIM2_CH2 |
|
||||
| **MOTOR_4** | M4_W / M4_S | PA2 / PA3 | TIM2_CH3 / TIM2_CH4 |
|
||||
|
||||
## 霍尔传感器 (由于是一根线,仅限频率测速)
|
||||
|
||||
| 传感器 ID | STM32 引脚 | 模式 | 功能 |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| **HALL_1 (M1)** | PD9 (M_I_1) | GPIO_EXTI | 脉冲计数 / 测速 |
|
||||
| **HALL_2 (M2)** | PD8 (M_I_2) | GPIO_EXTI | 脉冲计数 / 测速 |
|
||||
| **HALL_3 (M3)** | PB15 (M_I_3) | GPIO_EXTI | 脉冲计数 / 测速 |
|
||||
| **HALL_4 (M4)** | PB14 (M_I_4) | GPIO_EXTI | 脉冲计数 / 测速 |
|
||||
|
||||
## 使用方式
|
||||
|
||||
### 1. 硬件初始化 (main.c)
|
||||
在 `main.c` 的循环前调用电机和霍尔的初始化函数:
|
||||
```c
|
||||
/* USER CODE BEGIN 2 */
|
||||
motor_init();
|
||||
hall_init();
|
||||
/* USER CODE END 2 */
|
||||
```
|
||||
|
||||
### 2. 中断绑定 (stm32f1xx_it.c)
|
||||
在外部中断回调函数中加入脉冲统计:
|
||||
```c
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
hall_pulse_callback(GPIO_Pin);
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 控制电机
|
||||
调用 `motor_set_speed` 函数控制电机转动:
|
||||
```c
|
||||
// 电机1正转,中等速度
|
||||
motor_set_speed(MOTOR_1, 2000);
|
||||
|
||||
// 电机2反转,全速
|
||||
motor_set_speed(MOTOR_2, -3599);
|
||||
```
|
||||
|
||||
### 4. 获取测量结果
|
||||
在 FreeRTOS 任务或主循环中读取脉冲数或计算转速:
|
||||
```c
|
||||
uint32_t count = hall_get_count(MOTOR_1);
|
||||
printf("Motor 1 Pulses: %ld\r\n", count);
|
||||
```
|
||||
|
||||
## 预期结果
|
||||
|
||||
1. **电机控制**:
|
||||
- 给予正数速度时,对应电机的 W 引脚输出 PWM,S 引脚为低,电机正向旋转。
|
||||
- 给予负数速度时,S 引脚输出 PWM,W 引脚为低,电机反向旋转。
|
||||
- 速度数值越大,电机转速越高,最大有效值为 3599。
|
||||
|
||||
2. **霍尔测量**:
|
||||
- 电机每旋转一圈,对应的 `pulse_count` 会根据编码器磁极对数增加。
|
||||
- 通过观察 `hall_get_count` 的数值增长,可以确认传感器信号捕获正常。
|
||||
|
||||
## 驱动逻辑 (AT8236-MS)
|
||||
|
||||
驱动器通过两路电平差控制方向:
|
||||
- **正转**: W引脚输出 PWM,S引脚输出低电平(0%)。
|
||||
- **反转**: W引脚输出低电平(0%),S引脚输出 PWM。
|
||||
- **停止/刹车**: W和S引脚均输出低电平(0%)。
|
||||
|
||||
## 核心 API
|
||||
|
||||
### 1. 初始化
|
||||
`void motor_init(void);`
|
||||
- 开启 TIM1 和 TIM2 的所有对应 PWM 通道。
|
||||
- 初始电机状态为停止。
|
||||
|
||||
### 2. 设置电机速度
|
||||
`void motor_set_speed(motor_id_t motor_id, int16_t speed);`
|
||||
- **motor_id**: `MOTOR_1` 到 `MOTOR_4`。
|
||||
- **speed**: 范围为 `-3599` 到 `3599`(对应 20kHz 频率下的 ARR 重装载值)。
|
||||
- 正数:正转。
|
||||
- 负数:反转。
|
||||
- 0:停止。
|
||||
|
||||
### 3. 停止电机
|
||||
`void motor_stop(motor_id_t motor_id);`
|
||||
- 立即将对应电机的两路占空比清零。
|
||||
|
||||
## 注意事项
|
||||
- 使用前请确保 `MX_TIM1_Init()` 和 `MX_TIM2_Init()` 已在 `main.c` 中正常调用。
|
||||
- 定时器的 `Period`(重装载值值)决定了最大速度的分辨率,当前配置为 16 位(65535)。
|
||||
134
Core/Bsp/bsp_hall.c
Normal file
134
Core/Bsp/bsp_hall.c
Normal file
@@ -0,0 +1,134 @@
|
||||
#include "bsp_hall.h"
|
||||
|
||||
|
||||
/* 霍尔传感器数据结构体定义描述 */
|
||||
static hall_sensor_t sensors[MOTOR_COUNT];
|
||||
|
||||
/**
|
||||
* @brief 霍尔引脚初始化 (本驱动依赖 CubeMX 预设的 GPIO_EXTI 模式)
|
||||
*/
|
||||
void hall_init(void)
|
||||
{
|
||||
for(int i = 0; i < MOTOR_COUNT; i++) {
|
||||
sensors[i].pulse_count = 0;
|
||||
sensors[i].speed_rpm = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HAL 层 GPIO 外部中断回调函数实现
|
||||
* @note 此函数重写了 HAL 库中的 __weak 定义
|
||||
*/
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
hall_pulse_callback(GPIO_Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 外部中断回调函数中的统计处理
|
||||
*/
|
||||
void hall_pulse_callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
/* 只负责计数,不再在中断中进行浮点运算和日志打印 */
|
||||
if (GPIO_Pin == M_I_1_Pin) {
|
||||
sensors[MOTOR_1].pulse_count++;
|
||||
} else if (GPIO_Pin == M_I_2_Pin) {
|
||||
sensors[MOTOR_2].pulse_count++;
|
||||
} else if (GPIO_Pin == M_I_3_Pin) {
|
||||
sensors[MOTOR_3].pulse_count++;
|
||||
} else if (GPIO_Pin == M_I_4_Pin) {
|
||||
sensors[MOTOR_4].pulse_count++;
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @brief 获取霍尔传感器脉冲计数
|
||||
// */
|
||||
// uint32_t hall_get_count(motor_id_t motor_id)
|
||||
// {
|
||||
// if (motor_id < MOTOR_COUNT) {
|
||||
// return sensors[motor_id].pulse_count;
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @brief 重置霍尔传感器计数值
|
||||
// */
|
||||
// void hall_reset_count(motor_id_t motor_id)
|
||||
// {
|
||||
// if (motor_id < MOTOR_COUNT) {
|
||||
// sensors[motor_id].pulse_count = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 计算并更新转速 (供应用层在定时任务中调用)
|
||||
* @param motor_id 电机 ID
|
||||
* @param interval_ms 两次调用之间的时间间隔 (ms)
|
||||
* @return float 计算出的 RPM
|
||||
*/
|
||||
float hall_update_speed(motor_id_t motor_id, uint32_t interval_ms)
|
||||
{
|
||||
if (motor_id >= MOTOR_COUNT || interval_ms == 0) return 0.0f;
|
||||
|
||||
/* 获取当前增量并重置计数 */
|
||||
uint32_t current_pulses = sensors[motor_id].pulse_count;
|
||||
sensors[motor_id].pulse_count = 0;
|
||||
|
||||
/* PPR = 330. RPM = (增量脉冲 / 间隔ms) * 60000ms / PPR */
|
||||
sensors[motor_id].speed_rpm = ((float)current_pulses / (float)interval_ms) * 60000.0f / 330.0f;
|
||||
|
||||
// /* 应用层打印日志 */
|
||||
// log_i("Motor[%d] Real-time: %.2f RPM (pulses: %d)", motor_id + 1, sensors[motor_id].speed_rpm, current_pulses);
|
||||
|
||||
return sensors[motor_id].speed_rpm;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @brief 计算转速 (由于只有一根线,仅支持根据脉冲频率计算速度)
|
||||
// */
|
||||
// float hall_calculate_speed(motor_id_t motor_id, uint32_t interval_ms)
|
||||
// {
|
||||
// if (motor_id >= MOTOR_COUNT || interval_ms == 0) return 0.0f;
|
||||
//
|
||||
// /* 获取当前脉冲数 */
|
||||
// uint32_t current_count = sensors[motor_id].pulse_count;
|
||||
//
|
||||
// /*
|
||||
// * 计算 RPM (转每分钟)
|
||||
// * 公式: (脉冲增量 / 采样时间ms) * 1000ms * 60s / PPR
|
||||
// * 注意:由于此处没有传入上一次的 count,我们假设 interval_ms 是相对于 count=0 开始的,
|
||||
// * 或者你可以在调用前手动 reset。这里先实现基础频率转换为 RPM 的逻辑。
|
||||
// * 假设 PPR (每圈脉冲数) 暂定为 11 (常见磁平衡霍尔) * 30 (减速比) = 330
|
||||
// */
|
||||
// const float PPR = 330.0f;
|
||||
// sensors[motor_id].speed_rpm = ((float)current_count / interval_ms) * 60000.0f / PPR;
|
||||
//
|
||||
// /* 输出日志:电机编号 + 转速 */
|
||||
// // log_i("Motor[%d] speed: %.2f RPM", motor_id + 1, sensors[motor_id].speed_rpm);
|
||||
//
|
||||
// /* 计算完后为了下一次增量计算,通常需要重置计数,或者记录旧值。这里保持框架。 */
|
||||
//
|
||||
// return sensors[motor_id].speed_rpm;
|
||||
// }
|
||||
|
||||
/* USER CODE BEGIN Header_speed_get */
|
||||
/**
|
||||
* @brief Function implementing the timerTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_speed_get */
|
||||
void speed_get(void *argument) {
|
||||
/* USER CODE BEGIN speed_get */
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
/* 在每 100ms 执行一次的任务中 */
|
||||
for (int i = 0; i < MOTOR_COUNT; i++) {
|
||||
hall_update_speed(i, 100);
|
||||
}
|
||||
osDelay(100); // 100ms
|
||||
}
|
||||
/* USER CODE END speed_get */
|
||||
}
|
||||
35
Core/Bsp/bsp_hall.h
Normal file
35
Core/Bsp/bsp_hall.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef __BSP_HALL_H
|
||||
#define __BSP_HALL_H
|
||||
|
||||
|
||||
#include "main.h"
|
||||
#include "bsp_motor.h" // 确保 motor_id_t 类型可见
|
||||
#include "elog.h"
|
||||
#include "cmsis_os.h"
|
||||
/**
|
||||
* @brief 霍尔周期/脉冲计数结构体
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t pulse_count; // 总脉冲计数值
|
||||
float speed_rpm; // 计算得到的转速 (RPM)
|
||||
} hall_sensor_t;
|
||||
|
||||
/* 初始化霍尔传感器 (GPIO 外部中断模式) */
|
||||
void hall_init(void);
|
||||
|
||||
/* 外部中断处理接口 (供 HAL 层调用,请勿在应用层直接调用) */
|
||||
void hall_pulse_callback(uint16_t GPIO_Pin);
|
||||
|
||||
// /* 获取指定霍尔传感器的计数值 */
|
||||
// uint32_t hall_get_count(motor_id_t motor_id);
|
||||
|
||||
/* 每隔固定时间调用此函数计算并更新转速 (例如在 100ms 任务中调用) */
|
||||
float hall_update_speed(motor_id_t motor_id, uint32_t interval_ms);
|
||||
|
||||
// /* 清位计数值 */
|
||||
// void hall_reset_count(motor_id_t motor_id);
|
||||
|
||||
// /* 计算转速的原始接口 (内部使用) */
|
||||
// float hall_calculate_speed(motor_id_t motor_id, uint32_t interval_ms);
|
||||
|
||||
#endif /* __BSP_HALL_H */
|
||||
122
Core/Bsp/bsp_motor.c
Normal file
122
Core/Bsp/bsp_motor.c
Normal file
@@ -0,0 +1,122 @@
|
||||
#include "bsp_motor.h"
|
||||
#include "tim.h"
|
||||
|
||||
/**
|
||||
* @file bsp_motor.c
|
||||
* @brief AT8236-MS 电机驱动实现 (PWM)
|
||||
*
|
||||
* AT8236-MS 驱动逻辑参考:
|
||||
* - IN1 (PWM) / IN2 (L) -> 正转
|
||||
* - IN1 (L) / IN2 (PWM) -> 反转
|
||||
* - IN1 (L) / IN2 (L) -> 停止/刹车 (视具体芯片配置而定)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief 初始化电机相关外设
|
||||
*/
|
||||
void motor_init(void)
|
||||
{
|
||||
/* 1. 开启 PWM 定时器硬件通道 (TIM1 用于 M1, M2) */
|
||||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
|
||||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
|
||||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);
|
||||
|
||||
/* --- 关键修改:强制使能 TIM1 的主输出 (仅高级定时器需要) --- */
|
||||
__HAL_TIM_MOE_ENABLE(&htim1);
|
||||
|
||||
/* 2. 开启 PWM 定时器硬件通道 (TIM2 用于 M3, M4) */
|
||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
|
||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
|
||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
|
||||
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4);
|
||||
|
||||
/* 3. 初始状态设置为停止 */
|
||||
motor_stop(MOTOR_1);
|
||||
motor_stop(MOTOR_2);
|
||||
motor_stop(MOTOR_3);
|
||||
motor_stop(MOTOR_4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置电机PWM速度和方向
|
||||
* @param motor_id 电机 ID (MOTOR_1 到 MOTOR_4)
|
||||
* @param speed 速度值 (-3599 到 3599,正数正转,负数反转)
|
||||
*/
|
||||
void motor_set_speed(motor_id_t motor_id, int16_t speed)
|
||||
{
|
||||
TIM_HandleTypeDef* htim_w = NULL;
|
||||
uint32_t channel_w = 0;
|
||||
TIM_HandleTypeDef* htim_s = NULL;
|
||||
uint32_t channel_s = 0;
|
||||
|
||||
/* 获取对应电机的 定时器句柄和通道 (根据 tim.c GPIO 复用定义) */
|
||||
switch (motor_id) {
|
||||
case MOTOR_1: // PE9->TIM1_CH1, PE11->TIM1_CH2
|
||||
htim_w = &htim1; channel_w = TIM_CHANNEL_1;
|
||||
htim_s = &htim1; channel_s = TIM_CHANNEL_2;
|
||||
break;
|
||||
case MOTOR_2: // PE13->TIM1_CH3, PE14->TIM1_CH4
|
||||
htim_w = &htim1; channel_w = TIM_CHANNEL_3;
|
||||
htim_s = &htim1; channel_s = TIM_CHANNEL_4;
|
||||
break;
|
||||
case MOTOR_3: // PA15->TIM2_CH1, PB3->TIM2_CH2
|
||||
htim_w = &htim2; channel_w = TIM_CHANNEL_1;
|
||||
htim_s = &htim2; channel_s = TIM_CHANNEL_2;
|
||||
break;
|
||||
case MOTOR_4: // PA2->TIM2_CH3, PA3->TIM2_CH4
|
||||
htim_w = &htim2; channel_w = TIM_CHANNEL_3;
|
||||
htim_s = &htim2; channel_s = TIM_CHANNEL_4;
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
/* 限制速度范围 (ARR=3599) */
|
||||
if (speed > 3599) speed = 3599;
|
||||
if (speed < -3599) speed = -3599;
|
||||
|
||||
/* 计算绝对值速度 */
|
||||
uint16_t pwm_val = (speed < 0) ? (uint16_t)(-speed) : (uint16_t)speed;
|
||||
|
||||
/* 根据速度判断方向 */
|
||||
if (speed > 0) {
|
||||
/* 正转:W 输出 PWM, S 输出低电平 (占空比 0) */
|
||||
__HAL_TIM_SET_COMPARE(htim_w, channel_w, pwm_val);
|
||||
__HAL_TIM_SET_COMPARE(htim_s, channel_s, 0);
|
||||
} else if (speed < 0) {
|
||||
/* 反转:W 输出低电平 (占空比 0), S 输出 PWM */
|
||||
__HAL_TIM_SET_COMPARE(htim_w, channel_w, 0);
|
||||
__HAL_TIM_SET_COMPARE(htim_s, channel_s, pwm_val);
|
||||
} else {
|
||||
motor_stop(motor_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 停止电机
|
||||
* @param motor_id 电机 ID
|
||||
*/
|
||||
void motor_stop(motor_id_t motor_id)
|
||||
{
|
||||
/* 设置对应通道占空比均为 0 以刹车/停止 */
|
||||
switch (motor_id) {
|
||||
case MOTOR_1:
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0);
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, 0);
|
||||
break;
|
||||
case MOTOR_2:
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, 0);
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, 0);
|
||||
break;
|
||||
case MOTOR_3:
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, 0);
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, 0);
|
||||
break;
|
||||
case MOTOR_4:
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_3, 0);
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, 0);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
35
Core/Bsp/bsp_motor.h
Normal file
35
Core/Bsp/bsp_motor.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef __BSP_MOTOR_H
|
||||
#define __BSP_MOTOR_H
|
||||
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief 电机选择枚举
|
||||
*/
|
||||
typedef enum {
|
||||
MOTOR_1 = 0,
|
||||
MOTOR_2,
|
||||
MOTOR_3,
|
||||
MOTOR_4,
|
||||
MOTOR_COUNT
|
||||
} motor_id_t;
|
||||
|
||||
/**
|
||||
* @brief 电机方向枚举
|
||||
*/
|
||||
typedef enum {
|
||||
MOTOR_FWD = 0, // 正转
|
||||
MOTOR_REV, // 反转
|
||||
MOTOR_STOP // 停止
|
||||
} motor_dir_t;
|
||||
|
||||
/* 电机初始化 */
|
||||
void motor_init(void);
|
||||
|
||||
/* 设置电机PWM占空比和方向 */
|
||||
void motor_set_speed(motor_id_t motor_id, int16_t speed);
|
||||
|
||||
/* 停止指定电机 */
|
||||
void motor_stop(motor_id_t motor_id);
|
||||
|
||||
#endif /* __BSP_MOTOR_H */
|
||||
@@ -64,7 +64,7 @@
|
||||
#define configTICK_RATE_HZ ((TickType_t)1000)
|
||||
#define configMAX_PRIORITIES ( 56 )
|
||||
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)3072)
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)10000)
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
|
||||
@@ -69,6 +69,7 @@ void Error_Handler(void);
|
||||
#define SDA_GPIO_Port GPIOC
|
||||
#define IOR_Pin GPIO_PIN_5
|
||||
#define IOR_GPIO_Port GPIOC
|
||||
#define IOR_EXTI_IRQn EXTI9_5_IRQn
|
||||
#define RST_Pin GPIO_PIN_0
|
||||
#define RST_GPIO_Port GPIOB
|
||||
#define M1_W_Pin GPIO_PIN_9
|
||||
@@ -81,12 +82,16 @@ void Error_Handler(void);
|
||||
#define M2_S_GPIO_Port GPIOE
|
||||
#define M_I_4_Pin GPIO_PIN_14
|
||||
#define M_I_4_GPIO_Port GPIOB
|
||||
#define M_I_4_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define M_I_3_Pin GPIO_PIN_15
|
||||
#define M_I_3_GPIO_Port GPIOB
|
||||
#define M_I_3_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define M_I_2_Pin GPIO_PIN_8
|
||||
#define M_I_2_GPIO_Port GPIOD
|
||||
#define M_I_2_EXTI_IRQn EXTI9_5_IRQn
|
||||
#define M_I_1_Pin GPIO_PIN_9
|
||||
#define M_I_1_GPIO_Port GPIOD
|
||||
#define M_I_1_EXTI_IRQn EXTI9_5_IRQn
|
||||
#define H4_Pin GPIO_PIN_11
|
||||
#define H4_GPIO_Port GPIOD
|
||||
#define H3_Pin GPIO_PIN_12
|
||||
|
||||
@@ -55,9 +55,11 @@ void DebugMon_Handler(void);
|
||||
void DMA1_Channel4_IRQHandler(void);
|
||||
void DMA1_Channel5_IRQHandler(void);
|
||||
void DMA1_Channel7_IRQHandler(void);
|
||||
void EXTI9_5_IRQHandler(void);
|
||||
void TIM4_IRQHandler(void);
|
||||
void USART1_IRQHandler(void);
|
||||
void USART2_IRQHandler(void);
|
||||
void TIM8_UP_IRQHandler(void);
|
||||
void EXTI15_10_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : freertos.c
|
||||
* Description : Code for freertos applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* File Name : freertos.c
|
||||
* Description : Code for freertos applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 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 ------------------------------------------------------------------*/
|
||||
@@ -25,11 +25,14 @@
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "bsp_uart.h"
|
||||
#include "bsp_beep.h"
|
||||
#include "usart.h"
|
||||
#include "bsp_motor.h"
|
||||
#include "bsp_uart.h"
|
||||
#include "elog.h"
|
||||
#include "protocol.h"
|
||||
#include "usart.h"
|
||||
#include "bsp_hall.h" // 添加对 bsp_hall.h 的包含
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -65,6 +68,13 @@ const osThreadAttr_t CarCtrlTask_attributes = {
|
||||
.stack_size = 256 * 4,
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
/* Definitions for timerTask */
|
||||
osThreadId_t timerTaskHandle;
|
||||
const osThreadAttr_t timerTask_attributes = {
|
||||
.name = "timerTask",
|
||||
.stack_size = 512 * 4,
|
||||
.priority = (osPriority_t) osPriorityBelowNormal,
|
||||
};
|
||||
/* Definitions for CmdQueue */
|
||||
osMessageQueueId_t CmdQueueHandle;
|
||||
const osMessageQueueAttr_t CmdQueue_attributes = {
|
||||
@@ -73,7 +83,7 @@ const osMessageQueueAttr_t CmdQueue_attributes = {
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
#ifdef __GNUC__
|
||||
#ifdef __GNUC__
|
||||
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
||||
#else
|
||||
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
|
||||
@@ -87,6 +97,7 @@ PUTCHAR_PROTOTYPE {
|
||||
|
||||
void StartDefaultTask(void *argument);
|
||||
void CarCtrl_Task(void *argument);
|
||||
void speed_get(void *argument);
|
||||
|
||||
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
|
||||
|
||||
@@ -100,7 +111,10 @@ void MX_FREERTOS_Init(void) {
|
||||
easylogger_init();
|
||||
BEEP_Init();
|
||||
BSP_UART1_Init();
|
||||
elog_raw("FreeRTOS Initialized\r\n");
|
||||
elog_raw("FreeRTOS Initialized\r\n");
|
||||
|
||||
motor_init(); // 初始化电机相关外设
|
||||
hall_init(); // 初始化霍尔传感器
|
||||
|
||||
|
||||
/* USER CODE END Init */
|
||||
@@ -132,6 +146,9 @@ void MX_FREERTOS_Init(void) {
|
||||
/* creation of CarCtrlTask */
|
||||
CarCtrlTaskHandle = osThreadNew(CarCtrl_Task, NULL, &CarCtrlTask_attributes);
|
||||
|
||||
/* creation of timerTask */
|
||||
timerTaskHandle = osThreadNew(speed_get, NULL, &timerTask_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
@@ -144,46 +161,62 @@ void MX_FREERTOS_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||
/**
|
||||
* @brief Function implementing the initTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
* @brief Function implementing the initTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_StartDefaultTask */
|
||||
void StartDefaultTask(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN StartDefaultTask */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
for (;;) {
|
||||
|
||||
HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin);
|
||||
|
||||
HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin);
|
||||
|
||||
osDelay(1000);
|
||||
|
||||
}
|
||||
/* USER CODE END StartDefaultTask */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_CarCtrl_Task */
|
||||
/**
|
||||
* @brief Function implementing the CarCtrlTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
* @brief Function implementing the CarCtrlTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_CarCtrl_Task */
|
||||
__weak void CarCtrl_Task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN CarCtrl_Task */
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
for (;;) {
|
||||
|
||||
osDelay(1); // osMessageQueueGet 已经是阻塞的,不需要额外的 osDelay
|
||||
}
|
||||
/* USER CODE END CarCtrl_Task */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_speed_get */
|
||||
/**
|
||||
* @brief Function implementing the timerTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_speed_get */
|
||||
__weak void speed_get(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN speed_get */
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
osDelay(1);
|
||||
}
|
||||
/* USER CODE END speed_get */
|
||||
}
|
||||
|
||||
/* Private application code --------------------------------------------------*/
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
|
||||
@@ -105,6 +105,13 @@ void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
||||
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
@@ -140,12 +140,13 @@ void SystemClock_Config(void)
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
@@ -178,7 +179,7 @@ void SystemClock_Config(void)
|
||||
|
||||
/**
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM8 interrupt took place, inside
|
||||
* @note This function is called when TIM4 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
@@ -189,7 +190,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM8)
|
||||
if (htim->Instance == TIM4)
|
||||
{
|
||||
HAL_IncTick();
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
TIM_HandleTypeDef htim8;
|
||||
TIM_HandleTypeDef htim4;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void TIM8_IRQHandler(void);
|
||||
void TIM4_IRQHandler(void);
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the TIM8 as a time base source.
|
||||
* @brief This function configures the TIM4 as a time base source.
|
||||
* The time source is configured to have 1ms time base with a dedicated
|
||||
* Tick interrupt priority.
|
||||
* @note This function is called automatically at the beginning of program after
|
||||
@@ -42,54 +42,63 @@ void TIM8_IRQHandler(void);
|
||||
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
RCC_ClkInitTypeDef clkconfig;
|
||||
uint32_t uwTimclock = 0U;
|
||||
uint32_t uwTimclock, uwAPB1Prescaler = 0U;
|
||||
|
||||
uint32_t uwPrescalerValue = 0U;
|
||||
uint32_t pFLatency;
|
||||
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Enable TIM8 clock */
|
||||
__HAL_RCC_TIM8_CLK_ENABLE();
|
||||
/* Enable TIM4 clock */
|
||||
__HAL_RCC_TIM4_CLK_ENABLE();
|
||||
|
||||
/* Get clock configuration */
|
||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||
|
||||
/* Compute TIM8 clock */
|
||||
uwTimclock = HAL_RCC_GetPCLK2Freq();
|
||||
/* Get APB1 prescaler */
|
||||
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
|
||||
/* Compute TIM4 clock */
|
||||
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
|
||||
{
|
||||
uwTimclock = HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
else
|
||||
{
|
||||
uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
|
||||
/* Compute the prescaler value to have TIM8 counter clock equal to 1MHz */
|
||||
/* Compute the prescaler value to have TIM4 counter clock equal to 1MHz */
|
||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
|
||||
|
||||
/* Initialize TIM8 */
|
||||
htim8.Instance = TIM8;
|
||||
/* Initialize TIM4 */
|
||||
htim4.Instance = TIM4;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
* Period = [(TIM8CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
* Period = [(TIM4CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
* Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
* ClockDivision = 0
|
||||
* Counter direction = Up
|
||||
*/
|
||||
htim8.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim8.Init.Prescaler = uwPrescalerValue;
|
||||
htim8.Init.ClockDivision = 0;
|
||||
htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
htim4.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim4.Init.Prescaler = uwPrescalerValue;
|
||||
htim4.Init.ClockDivision = 0;
|
||||
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
|
||||
status = HAL_TIM_Base_Init(&htim8);
|
||||
status = HAL_TIM_Base_Init(&htim4);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Start the TIM time Base generation in interrupt mode */
|
||||
status = HAL_TIM_Base_Start_IT(&htim8);
|
||||
status = HAL_TIM_Base_Start_IT(&htim4);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable the TIM8 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM8_UP_IRQn);
|
||||
/* Enable the TIM4 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM4_IRQn);
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
/* Configure the TIM IRQ priority */
|
||||
HAL_NVIC_SetPriority(TIM8_UP_IRQn, TickPriority, 0U);
|
||||
HAL_NVIC_SetPriority(TIM4_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
@@ -105,25 +114,25 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling TIM8 update interrupt.
|
||||
* @note Disable the tick increment by disabling TIM4 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable TIM8 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim8, TIM_IT_UPDATE);
|
||||
/* Disable TIM4 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim4, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling TIM8 update interrupt.
|
||||
* @note Enable the tick increment by Enabling TIM4 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Enable TIM8 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim8, TIM_IT_UPDATE);
|
||||
/* Enable TIM4 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim4, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ extern DMA_HandleTypeDef hdma_usart1_tx;
|
||||
extern DMA_HandleTypeDef hdma_usart2_tx;
|
||||
extern UART_HandleTypeDef huart1;
|
||||
extern UART_HandleTypeDef huart2;
|
||||
extern TIM_HandleTypeDef htim8;
|
||||
extern TIM_HandleTypeDef htim4;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
@@ -207,6 +207,36 @@ void DMA1_Channel7_IRQHandler(void)
|
||||
/* USER CODE END DMA1_Channel7_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI line[9:5] interrupts.
|
||||
*/
|
||||
void EXTI9_5_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI9_5_IRQn 0 */
|
||||
|
||||
/* USER CODE END EXTI9_5_IRQn 0 */
|
||||
HAL_GPIO_EXTI_IRQHandler(IOR_Pin);
|
||||
HAL_GPIO_EXTI_IRQHandler(M_I_2_Pin);
|
||||
HAL_GPIO_EXTI_IRQHandler(M_I_1_Pin);
|
||||
/* USER CODE BEGIN EXTI9_5_IRQn 1 */
|
||||
|
||||
/* USER CODE END EXTI9_5_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM4 global interrupt.
|
||||
*/
|
||||
void TIM4_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM4_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM4_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim4);
|
||||
/* USER CODE BEGIN TIM4_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM4_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART1 global interrupt.
|
||||
*/
|
||||
@@ -240,17 +270,18 @@ void USART2_IRQHandler(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM8 update interrupt.
|
||||
* @brief This function handles EXTI line[15:10] interrupts.
|
||||
*/
|
||||
void TIM8_UP_IRQHandler(void)
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM8_UP_IRQn 0 */
|
||||
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM8_UP_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim8);
|
||||
/* USER CODE BEGIN TIM8_UP_IRQn 1 */
|
||||
/* USER CODE END EXTI15_10_IRQn 0 */
|
||||
HAL_GPIO_EXTI_IRQHandler(M_I_4_Pin);
|
||||
HAL_GPIO_EXTI_IRQHandler(M_I_3_Pin);
|
||||
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM8_UP_IRQn 1 */
|
||||
/* USER CODE END EXTI15_10_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
@@ -46,10 +46,10 @@ void MX_TIM1_Init(void)
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 0;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 65535;
|
||||
htim1.Init.Period = 3599;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
@@ -117,9 +117,9 @@ void MX_TIM2_Init(void)
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = 0;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 65535;
|
||||
htim2.Init.Period = 3599;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
||||
148
f103_car.ioc
148
f103_car.ioc
@@ -39,10 +39,11 @@ Dma.USART2_TX.2.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
|
||||
Dma.USART2_TX.2.PeriphInc=DMA_PINC_DISABLE
|
||||
Dma.USART2_TX.2.Priority=DMA_PRIORITY_LOW
|
||||
Dma.USART2_TX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
|
||||
FREERTOS.FootprintOK=true
|
||||
FREERTOS.IPParameters=Tasks01,FootprintOK,Queues01
|
||||
FREERTOS.FootprintOK=false
|
||||
FREERTOS.IPParameters=Tasks01,FootprintOK,Queues01,configTOTAL_HEAP_SIZE
|
||||
FREERTOS.Queues01=CmdQueue,16,16,1,Dynamic,NULL,NULL
|
||||
FREERTOS.Tasks01=initTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;CarCtrlTask,24,256,CarCtrl_Task,As weak,NULL,Dynamic,NULL,NULL
|
||||
FREERTOS.Tasks01=initTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;CarCtrlTask,24,256,CarCtrl_Task,As weak,NULL,Dynamic,NULL,NULL;timerTask,16,512,speed_get,As weak,NULL,Dynamic,NULL,NULL
|
||||
FREERTOS.configTOTAL_HEAP_SIZE=10000
|
||||
File.Version=6
|
||||
GPIO.groupedBy=Group By Peripherals
|
||||
KeepUserPlacement=false
|
||||
@@ -64,40 +65,42 @@ Mcu.IPNb=12
|
||||
Mcu.Name=STM32F103V(C-D-E)Tx
|
||||
Mcu.Package=LQFP100
|
||||
Mcu.Pin0=PC13-TAMPER-RTC
|
||||
Mcu.Pin1=PA0-WKUP
|
||||
Mcu.Pin10=PE9
|
||||
Mcu.Pin11=PE11
|
||||
Mcu.Pin12=PE13
|
||||
Mcu.Pin13=PE14
|
||||
Mcu.Pin14=PB14
|
||||
Mcu.Pin15=PB15
|
||||
Mcu.Pin16=PD8
|
||||
Mcu.Pin17=PD9
|
||||
Mcu.Pin18=PD11
|
||||
Mcu.Pin19=PD12
|
||||
Mcu.Pin2=PA2
|
||||
Mcu.Pin20=PD13
|
||||
Mcu.Pin21=PD14
|
||||
Mcu.Pin22=PD15
|
||||
Mcu.Pin23=PC6
|
||||
Mcu.Pin24=PA9
|
||||
Mcu.Pin25=PA10
|
||||
Mcu.Pin26=PA13
|
||||
Mcu.Pin27=PA14
|
||||
Mcu.Pin28=PA15
|
||||
Mcu.Pin29=PD5
|
||||
Mcu.Pin3=PA3
|
||||
Mcu.Pin30=PD6
|
||||
Mcu.Pin31=PB3
|
||||
Mcu.Pin32=VP_FREERTOS_VS_CMSIS_V2
|
||||
Mcu.Pin33=VP_SYS_VS_tim8
|
||||
Mcu.Pin4=PA5
|
||||
Mcu.Pin5=PA6
|
||||
Mcu.Pin6=PA7
|
||||
Mcu.Pin7=PC4
|
||||
Mcu.Pin8=PC5
|
||||
Mcu.Pin9=PB0
|
||||
Mcu.PinsNb=34
|
||||
Mcu.Pin1=OSC_IN
|
||||
Mcu.Pin10=PC5
|
||||
Mcu.Pin11=PB0
|
||||
Mcu.Pin12=PE9
|
||||
Mcu.Pin13=PE11
|
||||
Mcu.Pin14=PE13
|
||||
Mcu.Pin15=PE14
|
||||
Mcu.Pin16=PB14
|
||||
Mcu.Pin17=PB15
|
||||
Mcu.Pin18=PD8
|
||||
Mcu.Pin19=PD9
|
||||
Mcu.Pin2=OSC_OUT
|
||||
Mcu.Pin20=PD11
|
||||
Mcu.Pin21=PD12
|
||||
Mcu.Pin22=PD13
|
||||
Mcu.Pin23=PD14
|
||||
Mcu.Pin24=PD15
|
||||
Mcu.Pin25=PC6
|
||||
Mcu.Pin26=PA9
|
||||
Mcu.Pin27=PA10
|
||||
Mcu.Pin28=PA13
|
||||
Mcu.Pin29=PA14
|
||||
Mcu.Pin3=PA0-WKUP
|
||||
Mcu.Pin30=PA15
|
||||
Mcu.Pin31=PD5
|
||||
Mcu.Pin32=PD6
|
||||
Mcu.Pin33=PB3
|
||||
Mcu.Pin34=VP_FREERTOS_VS_CMSIS_V2
|
||||
Mcu.Pin35=VP_SYS_VS_tim4
|
||||
Mcu.Pin4=PA2
|
||||
Mcu.Pin5=PA3
|
||||
Mcu.Pin6=PA5
|
||||
Mcu.Pin7=PA6
|
||||
Mcu.Pin8=PA7
|
||||
Mcu.Pin9=PC4
|
||||
Mcu.PinsNb=36
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F103VETx
|
||||
@@ -108,6 +111,8 @@ NVIC.DMA1_Channel4_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true
|
||||
NVIC.DMA1_Channel5_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true
|
||||
NVIC.DMA1_Channel7_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
||||
NVIC.EXTI15_10_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
||||
NVIC.EXTI9_5_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
||||
NVIC.ForceEnableDMAVector=true
|
||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
||||
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
||||
@@ -119,12 +124,16 @@ NVIC.SavedPendsvIrqHandlerGenerated=true
|
||||
NVIC.SavedSvcallIrqHandlerGenerated=true
|
||||
NVIC.SavedSystickIrqHandlerGenerated=true
|
||||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:true\:false
|
||||
NVIC.TIM8_UP_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true
|
||||
NVIC.TimeBase=TIM8_UP_IRQn
|
||||
NVIC.TimeBaseIP=TIM8
|
||||
NVIC.TIM4_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true
|
||||
NVIC.TimeBase=TIM4_IRQn
|
||||
NVIC.TimeBaseIP=TIM4
|
||||
NVIC.USART1_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
||||
NVIC.USART2_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
|
||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
|
||||
OSC_IN.Mode=HSE-External-Oscillator
|
||||
OSC_IN.Signal=RCC_OSC_IN
|
||||
OSC_OUT.Mode=HSE-External-Oscillator
|
||||
OSC_OUT.Signal=RCC_OSC_OUT
|
||||
PA0-WKUP.GPIOParameters=GPIO_Label
|
||||
PA0-WKUP.GPIO_Label=HC-SR04
|
||||
PA0-WKUP.Signal=ADCx_IN0
|
||||
@@ -265,32 +274,33 @@ 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_SPI1_Init-SPI1-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true,7-MX_TIM2_Init-TIM2-false-HAL-true,8-MX_USART1_UART_Init-USART1-false-HAL-true,9-MX_USART2_UART_Init-USART2-false-HAL-true,10-MX_TIM3_Init-TIM3-false-HAL-true
|
||||
RCC.ADCFreqValue=10666666.666666666
|
||||
RCC.ADCFreqValue=12000000
|
||||
RCC.ADCPresc=RCC_ADCPCLK2_DIV6
|
||||
RCC.AHBFreq_Value=64000000
|
||||
RCC.AHBFreq_Value=72000000
|
||||
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
||||
RCC.APB1Freq_Value=32000000
|
||||
RCC.APB1TimFreq_Value=64000000
|
||||
RCC.APB2Freq_Value=64000000
|
||||
RCC.APB2TimFreq_Value=64000000
|
||||
RCC.FCLKCortexFreq_Value=64000000
|
||||
RCC.FSMCFreq_Value=64000000
|
||||
RCC.APB1Freq_Value=36000000
|
||||
RCC.APB1TimFreq_Value=72000000
|
||||
RCC.APB2Freq_Value=72000000
|
||||
RCC.APB2TimFreq_Value=72000000
|
||||
RCC.FCLKCortexFreq_Value=72000000
|
||||
RCC.FSMCFreq_Value=72000000
|
||||
RCC.FamilyName=M
|
||||
RCC.HCLKFreq_Value=64000000
|
||||
RCC.I2S2Freq_Value=64000000
|
||||
RCC.I2S3Freq_Value=64000000
|
||||
RCC.IPParameters=ADCFreqValue,ADCPresc,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FSMCFreq_Value,FamilyName,HCLKFreq_Value,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,SDIOFreq_Value,SDIOHCLKDiv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value
|
||||
RCC.MCOFreq_Value=64000000
|
||||
RCC.PLLCLKFreq_Value=64000000
|
||||
RCC.PLLMCOFreq_Value=32000000
|
||||
RCC.PLLMUL=RCC_PLL_MUL16
|
||||
RCC.SDIOFreq_Value=64000000
|
||||
RCC.SDIOHCLKDiv2FreqValue=32000000
|
||||
RCC.SYSCLKFreq_VALUE=64000000
|
||||
RCC.HCLKFreq_Value=72000000
|
||||
RCC.I2S2Freq_Value=72000000
|
||||
RCC.I2S3Freq_Value=72000000
|
||||
RCC.IPParameters=ADCFreqValue,ADCPresc,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FSMCFreq_Value,FamilyName,HCLKFreq_Value,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SDIOFreq_Value,SDIOHCLKDiv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value
|
||||
RCC.MCOFreq_Value=72000000
|
||||
RCC.PLLCLKFreq_Value=72000000
|
||||
RCC.PLLMCOFreq_Value=36000000
|
||||
RCC.PLLMUL=RCC_PLL_MUL9
|
||||
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
||||
RCC.SDIOFreq_Value=72000000
|
||||
RCC.SDIOHCLKDiv2FreqValue=36000000
|
||||
RCC.SYSCLKFreq_VALUE=72000000
|
||||
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
|
||||
RCC.TimSysFreq_Value=64000000
|
||||
RCC.USBFreq_Value=64000000
|
||||
RCC.VCOOutput2Freq_Value=4000000
|
||||
RCC.TimSysFreq_Value=72000000
|
||||
RCC.USBFreq_Value=72000000
|
||||
RCC.VCOOutput2Freq_Value=8000000
|
||||
SH.ADCx_IN0.0=ADC1_IN0,IN0
|
||||
SH.ADCx_IN0.ConfNb=1
|
||||
SH.GPXTI14.0=GPIO_EXTI14
|
||||
@@ -322,21 +332,25 @@ SH.S_TIM2_CH4.ConfNb=1
|
||||
SH.S_TIM3_CH1.0=TIM3_CH1,PWM Generation1 CH1
|
||||
SH.S_TIM3_CH1.ConfNb=1
|
||||
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
|
||||
SPI1.CalculateBaudRate=16.0 MBits/s
|
||||
SPI1.CalculateBaudRate=18.0 MBits/s
|
||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler
|
||||
SPI1.Mode=SPI_MODE_MASTER
|
||||
SPI1.VirtualType=VM_MASTER
|
||||
TIM1.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
||||
TIM1.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||
TIM1.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||
TIM1.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
|
||||
TIM1.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
|
||||
TIM1.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4
|
||||
TIM1.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4,Period,AutoReloadPreload
|
||||
TIM1.Period=3599
|
||||
TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
||||
TIM2.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||
TIM2.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||
TIM2.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
|
||||
TIM2.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
|
||||
TIM2.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4
|
||||
TIM2.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4,Period,AutoReloadPreload
|
||||
TIM2.Period=3599
|
||||
TIM3.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||
TIM3.IPParameters=Channel-PWM Generation1 CH1
|
||||
USART1.IPParameters=VirtualMode
|
||||
@@ -345,7 +359,7 @@ USART2.IPParameters=VirtualMode
|
||||
USART2.VirtualMode=VM_ASYNC
|
||||
VP_FREERTOS_VS_CMSIS_V2.Mode=CMSIS_V2
|
||||
VP_FREERTOS_VS_CMSIS_V2.Signal=FREERTOS_VS_CMSIS_V2
|
||||
VP_SYS_VS_tim8.Mode=TIM8
|
||||
VP_SYS_VS_tim8.Signal=SYS_VS_tim8
|
||||
VP_SYS_VS_tim4.Mode=TIM4
|
||||
VP_SYS_VS_tim4.Signal=SYS_VS_tim4
|
||||
board=custom
|
||||
rtos.0.ip=FREERTOS
|
||||
|
||||
@@ -10,7 +10,7 @@ SendHex=0
|
||||
[DlgCreateServer]
|
||||
DlgServerPort=3456
|
||||
[Update]
|
||||
Time=1775059200
|
||||
Time=1775206716
|
||||
[SysOptions]
|
||||
SendBlSZforFile=10240
|
||||
SendBlITforFile=1
|
||||
|
||||
Reference in New Issue
Block a user