The CMSIS-Driver SPI requires:
- Setup of SPIx input clock
- Setup of SPIx in Full-Duplex Master/Slave mode with optional DMA for Rx and Tx transfers
The example below uses correct settings for STM32F746G-Discovery:
- SPI2 Mode: Full-Duplex Master/Slave
For different boards, refer to the hardware schematics to reflect correct setup values.
The STM32CubeMX configuration steps for Pinout, Clock, and System Configuration are listed below. Enter the values that are marked bold.
Pinout tab
- Configure mode
- Peripherals SPI2: Mode=Full-Duplex Master, Hardware NSS Signal=ON
- Configure pin PB14, PB15, PI1 and pin PI0 as SPI2 peripheral alternative pins
- Click in chip diagram on pin PB14 and select SPI2_MISO
- Click in chip diagram on pin PB15 and select SPI2_MOSI
- Click in chip diagram on pin PI1 and select SPI2_SCK
- Click in chip diagram on pin PI0 and select SPI2_NSS
Clock Configuration tab
- Configure APB2 clock
- Setup "APB2 peripheral clocks (MHz)" to match application requirements
Configuration tab
Under Connectivity open SPI2 Configuration:
- optional DMA Settings: setup DMA transfers for Rx and Tx
Add - Select SPI2_RX: Stream=DMA1 Stream 3, Direction=Peripheral to Memory, Priority=Low, DMA Request Settings: not used
Add - Select SPI2_TX: Stream=DMA1 Stream 4, Direction=Memory to Peripheral, Priority=Low, DMA Request Settings: not used
- GPIO Settings: review settings, no changes required
| Pin Name | Signal on Pin | GPIO mode | GPIO Pull-up/Pull.. | Maximum out | User Label |
| PB14 | SPI2_MISO | Alternate | No pull-up and no.. | High | . |
| PB15 | SPI2_MOSI | Alternate | No pull-up and no.. | High | . |
| PI1 | SPI2_SCK | Alternate | No pull-up and no.. | High | . |
| PI0 | SPI2_NSS | Alternate | No pull-up and no.. | High | . |
- NVIC Settings: enable interrupts
| Interrupt Table | Enable | Preemption Priority | Sub Priority |
| DMA1 stream3 global interrupt | ON | 0 | 0 |
| DMA1 stream4 global interrupt | ON | 0 | 0 |
| SPI2 global interrupt | ON | 0 | 0 |
- Parameter Settings: not used
- User Constants: not used
Click OK to close the SPI2 Configuration dialog