Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
hal库
DMA+ADC
ART-PI使用HAL库的DMA进行ADC数据采集问题。
发布于 2021-08-06 18:51:33 浏览:1383
订阅该版
根据官方的HAL库使用adc设备教程可以进行轮询方式下的ADC数据的采集 但使用DMA的方式打开ADC,程序就会卡死。 使用这个函数时程序就会卡死。 ```c HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length) ``` 函数原型为: ```c HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length) { HAL_StatusTypeDef tmp_hal_status; uint32_t tmp_multimode_config = LL_ADC_GetMultimode(__LL_ADC_COMMON_INSTANCE(hadc->Instance)); /* Check the parameters */ assert_param(IS_ADC_ALL_INSTANCE(hadc->Instance)); /* Perform ADC enable and conversion start if no conversion is on going */ if (LL_ADC_REG_IsConversionOngoing(hadc->Instance) == 0UL) { /* Process locked */ __HAL_LOCK(hadc); /* Ensure that multimode regular conversions are not enabled. */ /* Otherwise, dedicated API HAL_ADCEx_MultiModeStart_DMA() must be used. */ if ((tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT) || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_SIMULT) || (tmp_multimode_config == LL_ADC_MULTI_DUAL_INJ_ALTERN) ) { /* Enable the ADC peripheral */ tmp_hal_status = ADC_Enable(hadc); /* Start conversion if ADC is effectively enabled */ if (tmp_hal_status == HAL_OK) { /* Set ADC state */ /* - Clear state bitfield related to regular group conversion results */ /* - Set state bitfield related to regular operation */ ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_REG_OVR | HAL_ADC_STATE_REG_EOSMP, HAL_ADC_STATE_REG_BUSY); /* Reset HAL_ADC_STATE_MULTIMODE_SLAVE bit - if ADC instance is master or if multimode feature is not available - if multimode setting is disabled (ADC instance slave in independent mode) */ if ((__LL_ADC_MULTI_INSTANCE_MASTER(hadc->Instance) == hadc->Instance) || (tmp_multimode_config == LL_ADC_MULTI_INDEPENDENT) ) { CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE); } /* Check if a conversion is on going on ADC group injected */ if ((hadc->State & HAL_ADC_STATE_INJ_BUSY) != 0UL) { /* Reset ADC error code fields related to regular conversions only */ CLEAR_BIT(hadc->ErrorCode, (HAL_ADC_ERROR_OVR | HAL_ADC_ERROR_DMA)); } else { /* Reset all ADC error code fields */ ADC_CLEAR_ERRORCODE(hadc); } /* Set the DMA transfer complete callback */ hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt; /* Set the DMA half transfer complete callback */ hadc->DMA_Handle->XferHalfCpltCallback = ADC_DMAHalfConvCplt; /* Set the DMA error callback */ hadc->DMA_Handle->XferErrorCallback = ADC_DMAError; /* Manage ADC and DMA start: ADC overrun interruption, DMA start, */ /* ADC start (in case of SW start): */ /* Clear regular group conversion flag and overrun flag */ /* (To ensure of no unknown state from potential previous ADC */ /* operations) */ __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_EOC | ADC_FLAG_EOS | ADC_FLAG_OVR)); /* Process unlocked */ /* Unlock before starting ADC conversions: in case of potential */ /* interruption, to let the process to ADC IRQ Handler. */ __HAL_UNLOCK(hadc); /* With DMA, overrun event is always considered as an error even if hadc->Init.Overrun is set to ADC_OVR_DATA_OVERWRITTEN. Therefore, ADC_IT_OVR is enabled. */ __HAL_ADC_ENABLE_IT(hadc, ADC_IT_OVR); /* Enable ADC DMA mode*/ #if defined(ADC_VER_V5_V90) if (hadc->Instance == ADC3) { LL_ADC_REG_SetDMATransferMode(hadc->Instance, ADC3_CFGR_DMACONTREQ((uint32_t)hadc->Init.DMAContinuousRequests)); LL_ADC_EnableDMAReq(hadc->Instance); } else { LL_ADC_REG_SetDataTransferMode(hadc->Instance, ADC_CFGR_DMACONTREQ((uint32_t)hadc->Init.ConversionDataManagement)); } #else LL_ADC_REG_SetDataTransferMode(hadc->Instance, (uint32_t)hadc->Init.ConversionDataManagement); #endif /* Start the DMA channel */ tmp_hal_status = HAL_DMA_Start_IT(hadc->DMA_Handle, (uint32_t)&hadc->Instance->DR, (uint32_t)pData, Length); /* Enable conversion of regular group. */ /* If software start has been selected, conversion starts immediately. */ /* If external trigger has been selected, conversion will start at next */ /* trigger event. */ /* Start ADC group regular conversion */ LL_ADC_REG_StartConversion(hadc->Instance); } else { /* Process unlocked */ __HAL_UNLOCK(hadc); } } else { tmp_hal_status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hadc); } } else { tmp_hal_status = HAL_BUSY; } /* Return function status */ return tmp_hal_status; } ``` 经过测试发现程序卡在这一句: ```c LL_ADC_REG_StartConversion(hadc->Instance); ``` 注释掉这句,程序正常运行。 但是采集到数组内的数据为0
查看更多
2
个回答
默认排序
按发布时间排序
StackYuan
2021-08-07
这家伙很懒,什么也没写!
看是pulling方式开始采集的时候adc陷入while(flag)等待了,楼主注意检查下adc的哪些配置不太对,或者dma模式等有哪些细节上的处理忽视了。
xianshunZ
2021-08-07
这家伙很懒,什么也没写!
解决了 移植的时候发现DMA中断只有一个函数声明,把stm32h7xx_it.c下的中断函数原型复制出来。让DMA中断函数可以找到函数原型就好了。 或者直接关掉DMA中断也可以
撰写答案
登录
注册新账号
关注者
0
被浏览
1.4k
关于作者
xianshunZ
这家伙很懒,什么也没写!
提问
3
回答
1
被采纳
0
关注TA
发私信
相关问题
1
STMCUBEMX生成工程和rthread使用时钟的兼容
2
STM32的HAL库里面的hal_xxx_ex.h头文件是用来做什么的?
3
请问有没有STM32的HAL库的API帮助文档?
4
rtt studio中hal库的调用
5
直接把用hal库写的文件移植到rtthread中能运行吗
6
RTthread nano 调用其他串口
7
如何在stm32f103移植rt-thread的操作系统后, 继续使用使用裸系统的HAL库等方法?
8
请问一下,rt-thread studio上怎样添加ADC+DMA
9
在stm32中移植了ADC+DMA+TIM周期采集电池电压,第二次调用会出现IBUSERR的段错误
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
五分钟玩转RT-Thread新社区
5
国产MCU移植系列教程汇总,欢迎查看!
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
RyanMqtt 移植指南(三)
2
RyanMqtt QOS质量测试(二)
3
WCH APT 零等待FLASH的思考
4
RyanMqtt使用介绍和示例代码(一)
5
RTT平台 zephyr_polling软件包 Bluenrg2 蓝牙芯片启动流程
热门标签
RT-Thread Studio
串口
Env
LWIP
AT
SPI
Bootloader
FinSH
ART-Pi
CAN总线
Hardfault
USB
文件系统
DMA
RT-Thread
SCons
线程
RT-Thread Nano
MQTT
stm32
ESP8266
rt-smart
WIZnet_W5500
RTC
flash
ota
UART
FAL
packages_软件包
I2C
freemodbus
cubemx
潘多拉开发板_Pandora
定时器
PWM
BSP
ADC
socket
AB32VG1
SDIO
keil_MDK
中断
消息队列_msg_queue
编译报错
Debug
C++_cpp
msh
QEMU
SFUD
MicroPython
本月问答贡献
出出啊
1463
个答案
324
次被采纳
小小李sunny
1379
个答案
274
次被采纳
张世争
700
个答案
155
次被采纳
crystal266
518
个答案
152
次被采纳
whj467467222
1215
个答案
146
次被采纳
本月文章贡献
出出啊
1
篇文章
11
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
4
篇文章
6
次点赞
crystal266
2
篇文章
5
次点赞
whj467467222
2
篇文章
4
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部