1

I want to control GPIO output using DMA and Timer. The target is generating a CLK signal of 1MHz and control PB0 synchronized with the CLK.

I am using Nucleo-F411RE as the development board. I have followed the instructions from the forum and configured the program.

Configuration:

HCLK: 100MHz

Timer3:

enter image description here

enter image description here

Program in main.c:

uint32_t dummy_data[7] = {0} ;
dummy_data[0] = 0x00000001 ;
dummy_data[1] = 0x00010000 ;
dummy_data[2] = 0x00000000 ;
dummy_data[3] = 0x00000000 ;
dummy_data[4] = 0x00000001 ;
dummy_data[5] = 0x00010000 ;
dummy_data[6] = 0x00000000 ;

HAL_DMA_Start(&hdma_tim3_ch4_up, (uint32_t)dummy_data, (uint32_t)&(GPIOB->BSRR), 7) ;
HAL_TIM_Base_Start(&htim3) ;
HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4) ;
TIM3->DIER |= (1 << 8 )  ;

I am expecting to see a pulse in PB0 synchronized with PC9(Output compare pin) PWM. But as output, I am getting only 1MHz PWM in PC9 and there is no change in PB0. Am I missing something? Any suggestions would be helpful.

3
  • 1
    You omitted too much of your code. Is PB0 initialized as a GPIO output? (Good.) Is dummy_data a local variable? (Bad.) Commented Aug 22, 2024 at 7:26
  • Did you enable clock for DMA? At the end of the day, DMA is a peripheral like any other and needs to have its clock enabled just like any GPIO port. Commented Aug 22, 2024 at 8:11
  • @Ilya the clock for DMA is enabled. Commented Aug 23, 2024 at 0:08

1 Answer 1

2

For STM32 F4 there is no connectivity from the DMA1 to AHB peripherals. So, Instead of DMA1 in TIM3, I have configured the TIM1 PWM CN1 (APB2) to trigger the DMA2 Stream 5 in Memory to peripheral mode to write words in GPIOB->BSRR. Now it works (Can write the GPIOB->BSRR register successfully).

Simply for STM32 F411RE:

GPIOB(AHB1) is connected with DMA2 (Using DMA2 Stream 5)
DMA2 is connected with APB2 (Using TIM1 PWM CN1)
Sign up to request clarification or add additional context in comments.

1 Comment

Good catch! And thanks for sharing that resource of gotchas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.