STM32Cube  Version 2.0
Create Projects for STM32F2 Series with STM32Cube HAL and STM32CubeMX
 All Files Pages
CMSIS-Driver SPI Setup

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

Valid settings for various evaluation boards are listed in the table below:

Peripheral Resource MCBSTM32F200 STM3220G-EVAL
SPI Mode SPI2: Full-Duplex MasterSPI2: Full-Duplex Master
MOSI pin PB15 PB15
MISO pin PB14 PB14
SCK pin PB10 PB10
NSS pin PB12 PB12

For different boards, refer to the hardware schematics to reflect correct setup values.

The STM32CubeMX configuration for MCBSTM32F200 with steps for Pinout, Clock, and System Configuration are listed below. Enter the values that are marked bold.

Pinout tab

  1. Configure mode
    • Peripherals SPI2: Mode=Full-Duplex Master, Hardware NSS Signal=ON
  1. Configure pins PB15, PB14, PB10 and pin PB12 as SPI2 peripheral alternative pins
    • Click in chip diagram on pin PB15 and select SPI2_MOSI
    • Click in chip diagram on pin PB14 and select SPI2_MISO
    • Click in chip diagram on pin PB10 and select SPI2_SCK
    • Click in chip diagram on pin PB12 and select SPI2_NSS

Clock Configuration tab

  1. Configure APB2 clock
    • Setup "APB2 peripheral clocks (MHz)" to match application requirements

Configuration tab

  1. 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
      PB10 SPI2_SCK Alternate No pull-up and no..High .
      PB12 SPI2_NSS Alternate No pull-up and no..High .
      PB14 SPI2_MISO Alternate No pull-up and no..High .
      PB15 SPI2_MOSI 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