打印
[STM32F1]

STM32cubeMX DMA配置

[复制链接]
336|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
abotomson|  楼主 | 2024-4-30 22:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

以F411(ADC-DMA)为例,STM32cubeMX配置后DMA还不能工作,需要加上部分代码才可以,
界面上选择Mode ,Increment Address 地址 ,Data Width ,Use Fifo 不使能

LL_DMA_SetChannelSelection(DMA2, LL_DMA_STREAM_0, LL_DMA_CHANNEL_0);  LL_DMA_SetDataTransferDirection(DMA2, LL_DMA_STREAM_0, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);  LL_DMA_SetStreamPriorityLevel(DMA2, LL_DMA_STREAM_0, LL_DMA_PRIORITY_MEDIUM);  LL_DMA_SetMode(DMA2, LL_DMA_STREAM_0, LL_DMA_MODE_CIRCULAR);  LL_DMA_SetPeriphIncMode(DMA2, LL_DMA_STREAM_0, LL_DMA_PERIPH_NOINCREMENT);  LL_DMA_SetMemoryIncMode(DMA2, LL_DMA_STREAM_0, LL_DMA_MEMORY_INCREMENT);  LL_DMA_SetPeriphSize(DMA2, LL_DMA_STREAM_0, LL_DMA_PDATAALIGN_HALFWORD);  LL_DMA_SetMemorySize(DMA2, LL_DMA_STREAM_0, LL_DMA_MDATAALIGN_HALFWORD);  LL_DMA_DisableFifoMode(DMA2, LL_DMA_STREAM_0);//加上代码        LL_DMA_SetDataLength(DMA2,LL_DMA_STREAM_0,5);//设置数据项宽度        LL_DMA_SetPeriphAddress(DMA2,LL_DMA_STREAM_0,LL_ADC_DMA_GetRegAddr(ADC1,LL_ADC_DMA_REG_REGULAR_DATA));//设置外设地址        LL_DMA_SetMemoryAddress(DMA2,LL_DMA_STREAM_0,(uint32_t)ADC1_Value);//设置存储器地址    LL_DMA_EnableStream(DMA2,LL_DMA_STREAM_0);//使能DMA

或者直接给DMA结构体直接赋值

        DMA_InitStructure.DMA_Channel = DMA_Channel_0;    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(ADC1->DR);    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&(ADC1_Value);    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;    DMA_InitStructure.DMA_BufferSize = 5;    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;    DMA_InitStructure.DMA_Priority = DMA_Priority_High;    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;    DMA_Init(DMA2_Stream0, &DMA_InitStructure); &(ADC1->DR);    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&(ADC1_Value);    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;    DMA_InitStructure.DMA_BufferSize = 5;    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;    DMA_InitStructure.DMA_Priority = DMA_Priority_High;    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;    DMA_Init(DMA2_Stream0, &DMA_InitStructu

使用特权

评论回复
沙发
nongfuxu| | 2024-5-11 08:29 | 只看该作者
天书

使用特权

评论回复
板凳
Bowclad| | 2024-5-12 23:30 | 只看该作者
整理下代码格式吧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

36

主题

1573

帖子

1

粉丝