Skip to main content
Visitor II
December 13, 2021
Solved

How to use TIMER event DMA from Memory to GPIO

  • December 13, 2021
  • 2 replies
  • 9817 views

My goal is to send bit patterns from an array directly to GPIO, using a Timer as a sample clock / DMA trigger.

More concretely: TIM2 Update Event --> DMA --> memory to GPIO Port ODR transfer

I am on STM32f103rb (Nucleo-64)

Similar questions have been asked here, of which none helped me so far.

https://community.st.com/s/question/0D53W000003yufESAQ/how-to-setup-dma-to-gpio-transfer-using-hal-in-the-cubeidemy-goal-is-to-transfer-the-contents-of-an-integer-array-8-bits-per-value-to-8-gpio-pins

https://community.st.com/s/question/0D50X0000C7eDobSQE/dma-gpio-stm32f103

I use the following initialization of the TIM2 peripheral and the code below to start the DMA. Pins PC0 to PC3 are configured as outputs.

On the oscilloscope I get the TIM2_CH1 Output Compare signal at 500 Hz.

But the DMA does not affect the GPIOC->ODR state. Why?

0693W00000HoTGBQA3.png 

0693W00000HoTGVQA3.png 

/* USER CODE BEGIN 2 */
 uint16_t pixelclock[8] = {0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0x0000, 0xffff, 0x0000};
 
 HAL_DMA_Start(&hdma_tim2_up, (uint32_t)pixelclock, (uint32_t)&(GPIOC->ODR), 8);
 
 HAL_TIM_Base_Start(&htim2);
 HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_1);
 /* USER CODE END 2 */

Debugger state:

0693W00000HoTFSQA3.png0693W00000HoTFhQAN.png0693W00000HoTFmQAN.png 

    This topic has been closed for replies.
    Best answer by TDK

    HAL isn't set up to do this, but it can be done.

    Ensure UDE is set in TIMx_DIER. If that's not it, show the contents of the TIM2 registers.

    2 replies

    TDKAnswer
    Super User
    December 13, 2021

    HAL isn't set up to do this, but it can be done.

    Ensure UDE is set in TIMx_DIER. If that's not it, show the contents of the TIM2 registers.

    MnemocronAuthor
    Visitor II
    December 13, 2021

    That was it!

    Thank you so much :)

    Super User
    December 13, 2021

    Glad to help. Consider using the GPIOx_BSRR register instead (with 32-bit words) in order to change only PC0-PC3 and leave PC4-PC15 alone.

    Graduate II
    September 9, 2024

    This is a great solution.

    I am wondering, for STM32F303, if this could be implemented on only 4 of the IO pins on a port (leaving the other pins on the port for different functions)

    When we assign the port to the DMA does it basically take over the entire port (all pins) or is it possible to select specific pins for our DMA PWM?

     

    Super User
    September 10, 2024

    As @TDK said above, use GPIO_BSRR for this.

    Next time, please don't hijack an old thread, instead, start your own, describing your particular problem and setup, and perhaps linking to any other relevant thread.

    JW