AnsweredAssumed Answered

DMA fails to trigger on STM32F446

Question asked by Luke on Apr 30, 2016
Latest reply on May 3, 2016 by Luke
I'm using the STM32F446 nucleo board and am trying to simply trigger a DMA transfer onto gpio when an OC triggers. Although I've done this many times on other boards (particularly F0 boards) I cannot figure out why it is not working this time. It seems if I use the same code but switch to TIM1 triggering DMA2 eventd this code works fine, but for TIM3 and TIM4 I get no output on GPIO. The OC is outputting a signal on its AF pin and I can manually set the GPIO output so it seems to be a DMA/triggering issue. The event mappings seem to be correct according to the manual. Is there something different on DMA1 or TIM3/4 when implementing this code as opposed to a DMA2+TIM1 config which works fine???

Any ideas?

uint8_t txbuf[4] = {0xff,0x00,0xff,0xff};
void test() {
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);


     GPIO_InitTypeDef GPIO_InitStructure;
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//100MHz;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//OD;//
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//NOPULL;//DOWN;
     GPIO_Init(GPIOA, &GPIO_InitStructure);


     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//100MHz;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//OD;//
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//DOWN;
     GPIO_Init(GPIOB, &GPIO_InitStructure);
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_TIM3);


     TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
     TIM_TimeBaseStructure.TIM_Period = 100-1;
     TIM_TimeBaseStructure.TIM_Prescaler = 0;
     TIM_TimeBaseStructure.TIM_ClockDivision = 0;
     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
     TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
     TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);


     TIM_OCInitTypeDef  TIM_OCInitStructure;
     TIM_OCStructInit(&TIM_OCInitStructure);
     TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;//Active;//Toggle;//Timing;
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_Pulse = 1;
     TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;//Low;//High;
     TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
     TIM_OC1Init(TIM3, &TIM_OCInitStructure);


     DMA_InitTypeDef DMA_InitStructure;
     DMA_Cmd(DMA1_Stream4, DISABLE);
     DMA_DeInit(DMA1_Stream4);          // Reset DMA channel
     DMA_InitStructure.DMA_Channel = DMA_Channel_5;
     DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(GPIOB->ODR);
     DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&txbuf[0];
     DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
     DMA_InitStructure.DMA_BufferSize = 4;
     DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
     DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
     DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
     DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
     DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //
     DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
     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(DMA1_Stream4, &DMA_InitStructure);
     TIM_DMACmd(TIM3, TIM_DMA_CC1, ENABLE);


     TIM_Cmd(TIM3, ENABLE);
     DMA_Cmd(DMA1_Stream4, ENABLE);
}

Thanks for your time.

Outcomes