Home | Projects | Notes > Direct Memory Access (DMA) > Exercise 1: GPIO Polling & Interrupt

Exercise 1: GPIO Polling & Interrupt

 

Create a Project using STM32CubeMX

  1. Identify the GPIO port to which LED is connected. (e.g., GPIOA Pin 5)

  2. Identify the bus interface to which the GPIOA peripheral is connected. (e.g., AHB1)

     

    stm32f446xx-block-diagram

     

  3. Identify which bus master can talk to AHB1 peripherals.

    In this example, we want to read data from SRAM and write it to GPIOA peripheral. According to the following diagram, DMA1 can read data from SRAM but is not capable of communicating with the AHB1 bus. So, our choice must be DMA2.

     

    system-architecture-for-stm32f446xx-devices

     

  4. Create a project using STM32CubeMX.

    Select "MDK-ARM" for Toolchain/IDE option. (ARM Keil MDK must be installed already!)

    Select "No" to "Initialize all peripherals with their default Mode?" question. We only want the initialization code for the peripherals we want in our project.

  5. Check the GPIOA Pin 5 configuration. (Default configuration is good.)

     

    stm32cubemx-gpioa-pin5-configuration

     

  6. Add DMA2 peripheral to the project.

    "Memory to Memory" is just the way STM32CubeMX names it. This can handle data transfer between memory and other peripherals.

     

    stm32cubemx-dma-configuration

     

  7. Check the NVIC configuration.

    For "Code generation", leave on only the SysTick Timer.

     

    stm32cubemx-nvic-configuration

    stm32cubemx-nvic-code-generation-configuration

 

 

LED Toggling using DMA (Polling)

 

LED Toggling using DMA (Interrupt)