AnsweredAssumed Answered

STM32F103 DMA transfer trigger with output compare

Question asked by minthemerciless on May 21, 2016
Latest reply on May 23, 2016 by minthemerciless
Hi,
I am trying to configure timer 1 channel 3 to output a varying signal in output compare toggle mode and driving the CCR with DMA1 channel 5.  Thus far I can get the DMA transfer triggering using the TIM_DMA_Update request, but when changing the request to TIM_DMA_CC3 it stops working and the DMA requests are no longer triggered.  The output compare interrupt is firing, tested that with a serial print, but no DMA transfer and the DMA_GetCurrentDataCounter never changes.   Below is my timer, GPIO and DMA configuration code.  I'm clearly missing something, but a can't for the life of me find what it is.  Just to double check, is this possible?  The result I am after is to be able to toggle the output pin for the timer multiple time before a reset.  E.g start with pin off and timer at 0, then turn on at 1000, off at 2000, on at 3000, off at 4000.  (This is just an example, the real sequence is more complicated).  Any info would be great.

Thanks in advance



01.uint16_t SRC_Buffer[4] = {1000,2000,3000,4000};
02.uint16_t TimerPeriod = 10000;
03. 
04.    GPIO_InitTypeDef            GPIO_InitStructure;
05.    DMA_InitTypeDef             DMA_InitStructure;
06.    TIM_OCInitTypeDef           TIM_OCInitStructure;
07.    TIM_TimeBaseInitTypeDef     TIM_TimeBaseStructure;
08. 
09.    /* TIM 1 */
10.    /* channel 3 pin configuration as outputs for PWM mode */
11.    /* Maple pin D8 */
12.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
13.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
14.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
15.    GPIO_Init(GPIOA, &GPIO_InitStructure);
16. 
17.    /* DMA1 Channel5 Config */
18.    DMA_DeInit(DMA1_Channel5);
19. 
20.    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&TIM1->CCR3;
21.    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SRC_Buffer;
22.    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
23.    DMA_InitStructure.DMA_BufferSize = 4;
24.    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
25.    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
26.    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
27.    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
28.    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
29.    DMA_InitStructure.DMA_Priority = DMA_Priority_High;
30.    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
31. 
32.    DMA_Init(DMA1_Channel5, &DMA_InitStructure);
33. 
34.    /* DMA1 Channel5 enable */
35.    DMA_Cmd(DMA1_Channel5, ENABLE);
36. 
37.    /* TIM1 Peripheral Configuration --------------------------------------------*/
38.    /* Time Base configuration */
39.    TIM_TimeBaseStructure.TIM_Prescaler = 0;
40.    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
41.    TIM_TimeBaseStructure.TIM_Period = TimerPeriod;
42.    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
43.    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
44. 
45.    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
46. 
47.    /* Channel 3 Configuration in PWM mode */
48.    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
49.    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
50.    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
51.    TIM_OCInitStructure.TIM_Pulse = SRC_Buffer[0];
52.    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
53.    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
54.    TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
55.    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
56. 
57.    TIM_OC3Init(TIM1, &TIM_OCInitStructure);
58.    //--------//
59.    TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Disable);
60. 
61.    /* TIM1 Update DMA Request enable */
62.    TIM_DMACmd(TIM1, TIM_DMA_CC3, ENABLE);
63. 
64.    /* TIM1 counter enable */
65.    TIM_Cmd(TIM1, ENABLE);
66. 
67.    TIM_ITConfig(TIM1, TIM_IT_CC3, ENABLE);
68. 
69.    /* Main Output Enable */
70.    TIM_CtrlPWMOutputs(TIM1, ENABLE);

Outcomes