cancel
Showing results for 
Search instead for 
Did you mean: 

How to use TIMER event DMA from Memory to GPIO

Mnemocron
Associate III

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 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

6 REPLIES 6
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

That was it!

Thank you so much :)

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.

If you feel a post has answered your question, please click "Accept as Solution".

Done! Thanks for all the hints. For anyone looking for the full code:

https://github.com/mnemocron/STM32_PatternDriver

jlag
Associate III

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?

 

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