news 2026/2/8 6:37:44

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/2/6 18:30:23

超详细教程:用windows-defender-remover彻底卸载Windows Defender

超详细教程&#xff1a;用windows-defender-remover彻底卸载Windows Defender 【免费下载链接】windows-defender-remover A tool which is uses to remove Windows Defender in Windows 8.x, Windows 10 (every version) and Windows 11. 项目地址: https://gitcode.com/gh_…

作者头像 李华
网站建设 2026/2/4 19:08:29

付费墙绕过工具终极指南:6款内容访问神器深度解析

付费墙绕过工具终极指南&#xff1a;6款内容访问神器深度解析 【免费下载链接】bypass-paywalls-chrome-clean 项目地址: https://gitcode.com/GitHub_Trending/by/bypass-paywalls-chrome-clean 在现代互联网环境中&#xff0c;优质内容往往被付费墙所阻挡&#xff0c…

作者头像 李华
网站建设 2026/2/7 12:19:21

PKHeX自动合法性修改终极指南:5分钟打造完美宝可梦

PKHeX自动合法性修改终极指南&#xff1a;5分钟打造完美宝可梦 【免费下载链接】PKHeX-Plugins Plugins for PKHeX 项目地址: https://gitcode.com/gh_mirrors/pk/PKHeX-Plugins 在宝可梦训练师的世界中&#xff0c;每个人都梦想拥有强大的对战队伍&#xff0c;但复杂的…

作者头像 李华
网站建设 2026/2/5 8:26:17

图像分割标注格式转换终极指南:3步掌握掩码与多边形互转技巧

图像分割标注格式转换终极指南&#xff1a;3步掌握掩码与多边形互转技巧 【免费下载链接】ultralytics ultralytics - 提供 YOLOv8 模型&#xff0c;用于目标检测、图像分割、姿态估计和图像分类&#xff0c;适合机器学习和计算机视觉领域的开发者。 项目地址: https://gitco…

作者头像 李华
网站建设 2026/2/6 9:45:21

25、XML链接与转换:从基础到应用

XML链接与转换:从基础到应用 1. XLink的实践操作 Fujitsu Limited的XLiP软件提供了多个示例文件,用于展示XLink的正确编码和使用方法。这些文件安装在系统的 xlinkdemo - 1.4\examples 目录下,包含 \extended 和 \simple 子目录,其中 \extended 目录下又有 Inbou…

作者头像 李华