【STM32+TIM+DMA】DMA搬运不中断,各路神仙进来帮忙看看啊~

2019-07-15 11:45发布

【基本情况】CPU:STM32F207IG 利用tiM5的CH2通道产生PWM波,开启DMA,利用TIM5更新事件请求DMA搬运。搬运数组数值到TIM5->ARR寄存器。  目前进不去DMA中断,不知道是哪里配置的问题……

【函数如下】
void TIM5_PWM_Configeration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOH, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOH,GPIO_PinSource11,GPIO_AF_TIM5);

TIM_DeInit(TIM5);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);
TIM_TimeBaseInitStruct.TIM_Period =1499;
TIM_TimeBaseInitStruct.TIM_Prescaler =CPU_FREQUENCE/F2TIME_PARA-1;
TIM_TimeBaseInitStruct.TIM_ClockDivision =TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode =TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseInitStruct);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 749;
TIM_OC2Init(TIM5, & TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM5, TIM_OCPreload_Enable);

Initial_DMA();
TIM_DMACmd(TIM5, TIM_DMA_Update, ENABLE);

TIM_ARRPreloadConfig(TIM5,ENABLE);
TIM_CtrlPWMOutputs(TIM5,ENABLE);
TIM_Cmd(TIM5,ENABLE);
}



void Initial_DMA(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);

DMA_DeInit(DMA1_Stream4);
DMA_StructInit(&DMA_InitStructure_M2);

DMA_InitStructure_M2.DMA_Channel = DMA_Channel_6;
DMA_InitStructure_M2.DMA_PeripheralBaseAddr = (uint32_t)TIM5_ARR_ADDRESS;   //
0x40000C2C
DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)0;
DMA_InitStructure_M2.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure_M2.DMA_BufferSize = 10;
DMA_InitStructure_M2.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure_M2.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure_M2.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure_M2.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure_M2.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure_M2.DMA_Priority = DMA_Priority_High;
DMA_InitStructure_M2.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure_M2.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure_M2.DMA_MemoryBurst = DMA_MemoryBurst_Single;

DMA_InitStructure_M2.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream4, &DMA_InitStructure_M2);

DMA_ClearFlag(DMA1_Stream4,DMA_FLAG_TCIF4);
DMA_ITConfig(DMA1_Stream4,DMA_IT_TC,ENABLE);
DMA_Cmd(DMA1_Stream4, DISABLE);

NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =PWM2_PreemptionPriority;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = PWM2_SubPriority;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}



补充一下,DMA配置函数中 DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)0; 并未赋值,在程序启动后进行了如下设置:


DMA_Cmd(DMA1_Stream4, DISABLE);
DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)addr; //搬运的是定时器需要配置的PWM频率数值
DMA_InitStructure_M2.DMA_BufferSize = len;  //希望DMA在搬运len长度数据以后进入DMA中断
DMA_Init(DMA1_Stream4, &DMA_InitStructure_M2);
DMA_Cmd(DMA1_Stream4, ENABLE);






友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
13条回答
loewe
1楼-- · 2019-07-16 09:30
 精彩回答 2  元偷偷看……
HARRY007
2楼-- · 2019-07-16 09:47
至此,应该可以结贴了。多谢了友商的协助,这个问题得到了解决。F1和F2在寄存器上还是有很多不一样的地方,移植要谨慎。
HARRY007
3楼-- · 2019-07-16 10:06
更新:DMA_PeripheralDataSize_HalfWord改为DMA_PeripheralDataSize_Word
DMA_MemoryDataSize_HalfWord改为DMA_MemoryDataSize_Word
同时内存数组也用32bit的来传。
HARRY007
4楼-- · 2019-07-16 15:51
更新:PWM出来了,不要更新TIM5->ARR就行。其他一些问题跟这个配置无关,就不贴了。至于配置应该是没有问题了,可以结贴了。网友后面有玩的可以参考一下这个代码,我就留在这里了。
HARRY007
5楼-- · 2019-07-16 16:09
额,谢谢楼上两位捧场了,虽然没有解决问题。
更新:咨询了技术支持后,更新时间触发DMA通道有专属的通道,我原先选择的通道是TIM5_CH2的事件通道。
新问题:PWM没了。待续……
小龙子714
6楼-- · 2019-07-16 19:15
 精彩回答 2  元偷偷看……

一周热门 更多>