As a result STM32Cube marked 12 GPIOs which are used for SPI communication:

SPI1_SCK

SPI1_MOSI

SPI1_MISO

SPI2_SCK

SPI2_MOSI

SPI2_MISO

SPI3_SCK

SPI3_MOSI

SPI3_MISO

SPI4_SCK

SPI4_MOSI

SPI4_MISO

Let’s open the configuration tab. To activate the DMA channels for SPI modules we should add some extra configuration. So, click on the SPI1 button.

In the window that appears we are interested in the “DMA Settings” tab. In order to add the DMA channel to SPI1 we should click on the “Add” button and choose the necessary DMA channel. In this example we’ll use only SPI1_TX DMA request:

Moreover, let’s enable the DMA interrupt. It will occure, when the transmission is completed. Thus, we’ll be able to start the new data exchange:

Now, we should repeat all these steps for other SPI peripherals (SPI2, SPI3, SPI4). There are no differences between the configurations of different modules, so, we won’t stop on this point.

After that, the configuration is fully completed, so, we can begin the programming process 🙂

Let’s look at some generated functions using the SPI1 module as an example. First of all, the initialization function is called:

All interrupts are located in the file stm32f4xx_it.c (if you use another microcontroller this file could have another name, for example, stm32f1xx_it.c. As we activated four interrupt requests, let’s define four flags which will indicate the transmission status for all SPIs:

If the “completed1” flag is set to 1, the data exchange via SPI 1 is finished. If it is set to 0, the SPI1 peripheral is busy. Thus, we should reset the flag when starting the transmission and set it when the transmission is completed. Let’s edit the interrupt handlers: