STM32Cube  Version 2.0
Create Projects for STM32F3 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 STM32303C-EVAL
SPI Peripheral SPI2
SPI Mode Full-Duplex Master
MOSI Pin PB15
MISO Pin PB14
SCK Pin PF9

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

The STM32CubeMX configuration for STMicroelectronics STM32303C-EVAL Board with steps for Pinout, Clock, and System Configuration are listed below. Enter the values that are marked bold.

Pinout tab

  1. Configure peripheral
    • Peripherals SPI2: Mode=Full-Duplex Master, Hardware NSS Signal=Disable
  2. Configure pins PB14, PB15 and PF9 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 PF9 and select SPI2_SCK

Clock Configuration tab

  1. Configure APB1 Clock (maximum frequency is 36 MHz)
    • Setup "APB1 peripheral clocks (MHz)" to match application requirements

Configuration tab

  1. Under Connectivity open SPI2 Configuration:
    • Parameter Settings: not used
    • User Constants: not used
    • NVIC Settings: enable interrupts
      Interrupt Table Enabled Preemption Priority Sub Priority
      DMA1 channel4 global interrupt ON 0 0
      DMA1 channel5 global interrupt ON 0 0
      SPI2 global interrupt ON 0 0
    • optional DMA Settings: setup DMA transfers for Rx and Tx (DMA is optional)
      Add - Select SPI1_RX: Stream=DMA1 Channel 4, Direction=Peripheral to Memory, Priority=Low
      DMA Request Settings Label Peripheral Memory
      Mode: Normal Increment Address OFF ON
      . Data Width Byte Byte
      Add - Select SPI1_TX: Stream=DMA1 Channel 5, Direction=Memory to Peripheral, Priority=Low
      DMA Request Settings Label Peripheral Memory
      Mode: Normal Increment Address OFF ON
      . Data Width Byte Byte
    • GPIO Settings: review settings
      Pin Name Signal on Pin GPIO output..GPIO mode GPIO Pull-up/Pull..Maximum out Fast Mode User Label
      PF9 SPI2_SCK n/a Alternate ..No pull-up and no..High n/a .
      PB14 SPI2_MISO n/a Alternate ..No pull-up and no..High n/a .
      PB15 SPI2_MOSI n/a Alternate ..No pull-up and no..High n/a .
      Click OK to close the SPI2 Configuration dialog
  2. Open Project - Settings - Advanced Settings from the menu and enable "Not Generate Function call" for MX_SPI2_Init