STM32Cube  Version 2.0
Create Projects for STM32L4 Series with STM32Cube HAL and STM32CubeMX
 All Files Functions Variables Macros 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 STM32L496G-DISCO
SPI Peripheral SPI 1
SPI Mode Full-Duplex Master
MOSI Pin PB6
MISO Pin PG10
SCK Pin PB5
NSS Pin PB5

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

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

Pinout tab

  1. Configure SPI1 mode
    • Peripherals SPI2: Mode=Full-Duplex Master, Hardware NSS Signal=ON

Clock Configuration tab

  1. Configure SPI1 Clock.

Configuration tab

  1. Under Connectivity open SPI1 Configuration:

    • optional DMA Settings: setup DMA transfers for Rx and Tx
      Add - Select SPI1_RX: Stream=DMA2 Channel 3, Direction=Peripheral to Memory, Priority=Low, DMA Request Settings: not used
      Add - Select SPI1_TX: Stream=DMA1 Channel 3, 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 SPI1_SCK Alternate No pull-up and no..High .
      PB12 SPI1_NSS Alternate No pull-up and no..High .
      PB14 SPI1_MISO Alternate No pull-up and no..High .
      PB15 SPI1_MOSI Alternate No pull-up and no..High .
    • NVIC Settings: enable interrupts
      Interrupt Table Enable Preemption Priority Sub Priority
      DMA2 channel 3 global interrupt ON 0 0
      DMA1 channel 3 global interrupt ON 0 0
      SPI1 global interrupt ON 0 0
    • Parameter Settings: not used
    • User Constants: not used

    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_SPI1_Init