2021-12-13 12:12 PM
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/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?
/* 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:
Solved! Go to Solution.
2021-12-13 12:32 PM
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.
2021-12-13 12:32 PM
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.
2021-12-13 12:37 PM
That was it!
Thank you so much :)
2021-12-13 12:41 PM
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.
2021-12-13 11:26 PM
Done! Thanks for all the hints. For anyone looking for the full code:
2024-09-09 01:38 PM
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?
2024-09-10 02:21 AM
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