dr16好了

This commit is contained in:
Robofish 2026-01-06 01:08:52 +08:00
parent 21c0f7a4cd
commit 31147537b5
27 changed files with 219 additions and 147 deletions

View File

@ -57,20 +57,10 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
# User/component sources # User/component sources
User/component/ahrs.c User/component/ahrs.c
# User/component/ahrs sources
User/component/ahrs/ahrs.c
# User/component sources
User/component/crc16.c User/component/crc16.c
User/component/crc8.c User/component/crc8.c
User/component/error_detect.c User/component/error_detect.c
User/component/filter.c User/component/filter.c
# User/component/filter sources
User/component/filter/filter.c
# User/component sources
User/component/freertos_cli.c User/component/freertos_cli.c
User/component/limiter.c User/component/limiter.c
User/component/pid.c User/component/pid.c
@ -92,6 +82,7 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
# User/task sources # User/task sources
User/task/ai.c User/task/ai.c
User/task/init.c User/task/init.c
User/task/rc.c
User/task/user_task.c User/task/user_task.c
) )

View File

@ -98,7 +98,7 @@ void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN RTOS_THREADS */ /* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */ /* add threads, ... */
osThreadNew(Task_Init, NULL, &attr_init); // 创建初始化任务 osThreadNew(Task_Init, NULL, &attr_init); // 创建初始化任务
/* USER CODE END RTOS_THREADS */ /* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */ /* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */ /* add events, ... */
@ -117,7 +117,7 @@ void StartDefaultTask(void *argument)
{ {
/* USER CODE BEGIN StartDefaultTask */ /* USER CODE BEGIN StartDefaultTask */
osThreadTerminate(osThreadGetId()); osThreadTerminate(osThreadGetId());
/* USER CODE END StartDefaultTask */ /* USER CODE END StartDefaultTask */
} }
/* Private application code --------------------------------------------------*/ /* Private application code --------------------------------------------------*/

View File

@ -80,14 +80,6 @@ int main(void)
/* USER CODE END 1 */ /* USER CODE END 1 */
/* Enable the CPU Cache */
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
/* MCU Configuration--------------------------------------------------------*/ /* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

View File

@ -229,6 +229,17 @@ SECTIONS
PROVIDE( __bss_start = __tbss_start ); PROVIDE( __bss_start = __tbss_start );
PROVIDE( __bss_size = __bss_end - __bss_start ); PROVIDE( __bss_size = __bss_end - __bss_start );
/* DMA buffer section in RAM_D2 (SRAM1/2) for STM32H7 DMA access */
.dma_buffer (NOLOAD) : ALIGN(32)
{
. = ALIGN(32);
_sdma_buffer = .;
*(.dma_buffer)
*(.dma_buffer*)
. = ALIGN(32);
_edma_buffer = .;
} >RAM_D2
/* User_heap_stack section, used to check that there is enough RAM left */ /* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack (NOLOAD) : ._user_heap_stack (NOLOAD) :
{ {

View File

@ -5,3 +5,10 @@
function: Task_ai function: Task_ai
name: ai name: ai
stack: 256 stack: 256
- delay: 0
description: ''
freq_control: true
frequency: 500.0
function: Task_rc
name: rc
stack: 256

View File

@ -31,6 +31,7 @@ void Task_Init(void *argument) {
/* 创建任务线程 */ /* 创建任务线程 */
task_runtime.thread.ai = osThreadNew(Task_ai, NULL, &attr_ai); task_runtime.thread.ai = osThreadNew(Task_ai, NULL, &attr_ai);
task_runtime.thread.rc = osThreadNew(Task_rc, NULL, &attr_rc);
// 创建消息队列 // 创建消息队列
/* USER MESSAGE BEGIN */ /* USER MESSAGE BEGIN */

56
User/task/rc.c Normal file
View File

@ -0,0 +1,56 @@
/*
rc Task
- DR16遥控器数据接收
*/
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
#include "device/dr16.h"
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
/* STM32H7: 整个DR16结构体放在DMA可访问的SRAM区域 */
static DR16_t dr16 __attribute__((section(".dma_buffer"))) __attribute__((aligned(32)));
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
void Task_rc(void *argument) {
(void)argument; /* 未使用argument消除警告 */
/* 计算任务运行到指定频率需要等待的tick数 */
const uint32_t delay_tick = osKernelGetTickFreq() / RC_FREQ;
osDelay(RC_INIT_DELAY); /* 延时一段时间再开启任务 */
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
/* 初始化DR16遥控器 */
DR16_Init(&dr16);
/* USER CODE INIT END */
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
/* 启动DMA接收 */
DR16_StartDmaRecv(&dr16);
/* 等待DMA接收完成超时时间20ms */
if (DR16_WaitDmaCplt(20)) {
/* DMA接收成功解析数据 */
DR16_ParseData(&dr16);
} else {
/* DMA接收超时标记离线 */
DR16_Offline(&dr16);
}
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
}

View File

@ -14,3 +14,8 @@ const osThreadAttr_t attr_ai = {
.priority = osPriorityNormal, .priority = osPriorityNormal,
.stack_size = 256 * 4, .stack_size = 256 * 4,
}; };
const osThreadAttr_t attr_rc = {
.name = "rc",
.priority = osPriorityNormal,
.stack_size = 256 * 4,
};

View File

@ -14,10 +14,12 @@ extern "C" {
/* Exported constants ------------------------------------------------------- */ /* Exported constants ------------------------------------------------------- */
/* 任务运行频率 */ /* 任务运行频率 */
#define AI_FREQ (500.0) #define AI_FREQ (500.0)
#define RC_FREQ (500.0)
/* 任务初始化延时ms */ /* 任务初始化延时ms */
#define TASK_INIT_DELAY (100u) #define TASK_INIT_DELAY (100u)
#define AI_INIT_DELAY (0) #define AI_INIT_DELAY (0)
#define RC_INIT_DELAY (0)
/* Exported defines --------------------------------------------------------- */ /* Exported defines --------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */ /* Exported macro ----------------------------------------------------------- */
@ -28,6 +30,7 @@ typedef struct {
/* 各任务,也可以叫做线程 */ /* 各任务,也可以叫做线程 */
struct { struct {
osThreadId_t ai; osThreadId_t ai;
osThreadId_t rc;
} thread; } thread;
/* USER MESSAGE BEGIN */ /* USER MESSAGE BEGIN */
@ -50,16 +53,19 @@ typedef struct {
/* 各任务的stack使用 */ /* 各任务的stack使用 */
struct { struct {
UBaseType_t ai; UBaseType_t ai;
UBaseType_t rc;
} stack_water_mark; } stack_water_mark;
/* 各任务运行频率 */ /* 各任务运行频率 */
struct { struct {
float ai; float ai;
float rc;
} freq; } freq;
/* 任务最近运行时间 */ /* 任务最近运行时间 */
struct { struct {
float ai; float ai;
float rc;
} last_up_time; } last_up_time;
} Task_Runtime_t; } Task_Runtime_t;
@ -70,10 +76,12 @@ extern Task_Runtime_t task_runtime;
/* 初始化任务句柄 */ /* 初始化任务句柄 */
extern const osThreadAttr_t attr_init; extern const osThreadAttr_t attr_init;
extern const osThreadAttr_t attr_ai; extern const osThreadAttr_t attr_ai;
extern const osThreadAttr_t attr_rc;
/* 任务函数声明 */ /* 任务函数声明 */
void Task_Init(void *argument); void Task_Init(void *argument);
void Task_ai(void *argument); void Task_ai(void *argument);
void Task_rc(void *argument);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -38,8 +38,8 @@ Bdma.SPI6_TX.0.SyncSignalID=NONE
CAD.formats= CAD.formats=
CAD.pinconfig= CAD.pinconfig=
CAD.provider= CAD.provider=
CORTEX_M7.CPU_DCache=Enabled CORTEX_M7.CPU_DCache=Disabled
CORTEX_M7.CPU_ICache=Enabled CORTEX_M7.CPU_ICache=Disabled
CORTEX_M7.Enable-Cortex_Memory_Protection_Unit_Region0_Settings=MPU_REGION_ENABLE CORTEX_M7.Enable-Cortex_Memory_Protection_Unit_Region0_Settings=MPU_REGION_ENABLE
CORTEX_M7.IPParameters=CPU_DCache,CPU_ICache,MPU_Control,Enable-Cortex_Memory_Protection_Unit_Region0_Settings,default_mode_Activation CORTEX_M7.IPParameters=CPU_DCache,CPU_ICache,MPU_Control,Enable-Cortex_Memory_Protection_Unit_Region0_Settings,default_mode_Activation
CORTEX_M7.MPU_Control=__NULL CORTEX_M7.MPU_Control=__NULL
@ -900,3 +900,4 @@ VP_MEMORYMAP_VS_MEMORYMAP.Signal=MEMORYMAP_VS_MEMORYMAP
VP_SYS_VS_tim4.Mode=TIM4 VP_SYS_VS_tim4.Mode=TIM4
VP_SYS_VS_tim4.Signal=SYS_VS_tim4 VP_SYS_VS_tim4.Signal=SYS_VS_tim4
board=custom board=custom
rtos.0.ip=FREERTOS