cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup DMA to GPIO transfer using HAL in the CubeIDE? My goal is to transfer the contents of an integer array (8 bits per value) to 8 GPIO pins.

Broyildiz
Associate II

Using the CubeMX perspective in the CubeIDE (latest version) I configured the DMA2 to work with Timer1 in the memory to peripheral mode.

I am using the STM32 F4 Discovery board (STM32F407VG)

I need a Hello World on how to push one value of an array to the GPIO pins. The GPIO pins used are GPIOE pins 8 through 15.

If the array value is 1 (0xFF), the GPIO pins should have the values "1 1 1 1 1 1 1 1"

Configuration Tim1:

  • clock source: internal
  • counter settings:
  • prescaler: 0
  • period: 11
  • no clock division
  • auto-reload preload disabled

Configuration DMA:

  • DMA peripheral DMA2
  • Stream 5
  • DMA request: TIM1_UP
  • Direction: Memory to Peripheral
  • Priority Very High

The following code was used after initialization of the peripherals (initialization was done using auto generated code):

  1. /*The array filled with zeros*/
  2. #define BUFLEN (512)
  3. uint16_t dmabuf[BUFLEN];
  4.  
  5. HAL_DMA_Init(&hdma_tim1_up);
  6. HAL_DMA_Start_IT(&hdma_tim1_up, (uint32_t)dmabuf, (uint32_t)&GPIOE->ODR, BUFLEN);
  7. /* Enable the TIM Update DMA request */
  8. __HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_UPDATE);
  9. /* Enable the Peripheral */
  10. __HAL_TIM_ENABLE(&htim1);

The GPIO pins are set high at initialization. When this code runs they should be set low, because the values in the array are all zeros (did not include that code for simplicity).

  

When the code runs, it does execute the functions. It does not throw an error, I checked it with the status return value of the functions. It jumps into the DMA2_Stream5_IRQHandler afterwards, so I'm guessing it did something. The GPIO pins are however never set low.

  

What am I doing wrong?

How do I get the values from an array onto some GPIO pins using the DMA2 peripheral?

Thanks in advance!

11 REPLIES 11

Thanks, I tested it and edited my post.

Broyildiz

is your code working perfectly?