news 2026/4/3 3:00:24

Freertos手把手教STM32CubeMx设置STM32F4芯片DMA发送ADC数据(三)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Freertos手把手教STM32CubeMx设置STM32F4芯片DMA发送ADC数据(三)

前置文章:

Freertos手把手教STM32CubeMx设置STM32F4芯片DMA发送ADC数据(一)-CSDN博客Freertos手把手教STM32CubeMx设置STM32F4芯片DMA发送ADC数据(二)-CSDN博客

在以上章节完成了对框架的初步探索以及对CubeMx的配置

在freertos的task中对buffer进行了一些测试

完成了队列的发送接收测试

下面继续上一章的内容继续完成本次目标

本期目标

理清本工程系统框架

弄懂CubeMx配置相关原理及设置的背后含义

对DMA以及ADC相关的重要API接口使用详解

梳理代码设计流程

3.发送消息对列或任务通知(邮箱)给线程A

/* USER CODE BEGIN Includes */ #include <stdlib.h> #include "queue.h" /* USER CODE END Includes */

第一步先包含头文件

* \defgroup xQueueSend xQueueSend * \ingroup QueueManagement */ #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) /** * queue. h * <pre> BaseType_t xQueueOverwrite( QueueHandle_t xQueue, const void * pvItemToQueue

找到对应函数

xQueueSend( xQueue, pvItemToQueue, xTicksToWait )

第一个形参依旧是句柄

所以要先创建队列 , 再传参进来

第二个形参

P就是指针

v是variables(变量)

传入的是变量的地址

第三个形参是等待时间

xQueueCreate( uxQueueLength, uxItemSize )

在点h文件里找到队列创建函数

第一个形参是队列的长度

第二个形参是队列里每一个元素的大小

假如一个队列被分成了四份,这个份数就是由第一个形参决定

而分成了四份后的大小就是由第二个形参决定

假设第二个形参是4

那么总的队列长度就是4x4 = 16

xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold. ITEM_SIZE // The size of each item in the queue &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue. &xQueueBuffer ); // The buffer that will hold the queue structure.

创建队列使用样板

xQueueReceive()

BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )

void StartDefaultTask(void *argument) { /* USER CODE BEGIN StartDefaultTask */ buffer1 = (uint32_t *)malloc((sizeof(uint32_t)* BUFFER_SIZE)); buffer2 = (uint32_t *)malloc((sizeof(uint32_t)* BUFFER_SIZE)); if(NULL == buffer1) { printf("buffer1 malloc failed \r\n"); } if(NULL == buffer2) { printf("buffer2 malloc failed \r\n"); return; } printf("buffer1 , buffer2 malloc success\r\n "); memset(buffer1, 0xff , (sizeof(uint32_t)* BUFFER_SIZE)); memset(buffer2, 0xff , (sizeof(uint32_t)* BUFFER_SIZE)); printf("Unit test ADC + DMA\r\n "); HAL_StatusTypeDef ret1 = HAL_OK; HAL_StatusTypeDef ret2 = HAL_OK; ret1 = HAL_ADC_Start_DMA(&hadc1, buffer1, BUFFER_SIZE); ret2 = HAL_ADC_Start_DMA(&hadc1, buffer2, BUFFER_SIZE); if(HAL_OK != ret1) { printf("HAL_ADC1 call failed "); } if(HAL_OK != ret2) { printf("HAL_ADC2 call failed "); } //UnitTest Queue send and receive QueueHandle_t xQueue1 = NULL; xQueue1 = xQueueCreate(10 , 4 ); if(NULL == xQueue1) { printf("Queue create failed \r\n"); return ; } uint32_t queue_data_1 = 123; BaseType_t ret_queue = pdPASS; ret_queue = xQueueSend( xQueue1, &queue_data_1, 0 ); printf("QueueSend ret_queue = [%ld]\r\n" , ret_queue); ret_queue = pdPASS; uint32_t queue_data_2 = 0xff; ret_queue = xQueueReceive( xQueue1, &queue_data_2, 0 ); printf("xQueueSend ret_queue = [%ld]\r\n" , ret_queue); printf("xQueueReceive queue_data_2 = [%d]\r\n" , queue_data_2); /* Infinite loop */ for(;;) { printf("hello world \r\n"); //printf("buffer1 data = [%d] \r\n" , buffer1[0]); //printf("buffer2 data = [%d] \r\n" , buffer2[0]); osDelay(1000); } /* USER CODE END StartDefaultTask */ }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/27 4:43:38

B站4K超清视频下载完整指南:免费工具快速上手教程

B站4K超清视频下载完整指南&#xff1a;免费工具快速上手教程 【免费下载链接】bilibili-downloader B站视频下载&#xff0c;支持下载大会员清晰度4K&#xff0c;持续更新中 项目地址: https://gitcode.com/gh_mirrors/bil/bilibili-downloader 想要永久珍藏B站上那些精…

作者头像 李华
网站建设 2026/4/1 20:14:46

AssetStudio GUI快速实战指南:Unity资源高效管理全流程

AssetStudio GUI快速实战指南&#xff1a;Unity资源高效管理全流程 【免费下载链接】AssetStudio AssetStudio is a tool for exploring, extracting and exporting assets and assetbundles. 项目地址: https://gitcode.com/gh_mirrors/as/AssetStudio AssetStudio GUI…

作者头像 李华
网站建设 2026/3/29 18:57:40

Mac鼠标滚动优化神器:Mos让你的滚轮体验媲美触控板

Mac鼠标滚动优化神器&#xff1a;Mos让你的滚轮体验媲美触控板 【免费下载链接】Mos 一个用于在 macOS 上平滑你的鼠标滚动效果或单独设置滚动方向的小工具, 让你的滚轮爽如触控板 | A lightweight tool used to smooth scrolling and set scroll direction independently for …

作者头像 李华
网站建设 2026/3/28 0:06:59

7天从零掌握KKManager:新手必学的终极Mod管理技巧

7天从零掌握KKManager&#xff1a;新手必学的终极Mod管理技巧 【免费下载链接】KKManager Mod, plugin and card manager for games by Illusion that use BepInEx 项目地址: https://gitcode.com/gh_mirrors/kk/KKManager 还在为Mod安装后游戏崩溃而烦恼吗&#xff1f;…

作者头像 李华
网站建设 2026/3/27 12:07:53

py连接Redis

与mongo和mysql不同&#xff0c;redis多用于存储中间层&#xff0c;目前我多用于查重去重&#xff0c;我们需要安装一个库&#xff1a; pip install redis之前的aioredis合并到redis中了 同步操作 建立连接 import redis # 同步操作都这样导包 client_syn redis.Redis(host&q…

作者头像 李华