STM32Cube  Version 2.0
Create Projects for STM32G4 Series with STM32Cube HAL and STM32CubeMX
CMSIS-Driver SPI

History

  • Version 1.1
    • Corrected Control function to support more than 16 data bits in DMA mode
  • Version 1.0
    • Initial release

Instances

Hardware resource relating to CMSIS-Driver instance is shown in the table below:

Driver Instance Hardware Resource
Driver_SPI1 SPI1
Driver_SPI2 SPI2
Driver_SPI3 SPI3
Driver_SPI4 SPI4

Limitations

STM32 HAL limitations:

  • Number of items to send, receive or transmit is limited to 65535
  • Mode Fault and Data Lost events can be detected only when reception is active
  • Settings changes using Control function activate upon send/receive/transfer operation start
Note
If SPI driver is used in IRQ mode, ensure that it has higher priority then any IRQ routine requiring longer processing time, because such IRQ routine can prevent SPI IRQ routine to correctly handle reception thus fail to receive all data correctly or fail to generate ARM_SPI_EVENT_TRANSFER_COMPLETE event. Previous limitation can also be avoided by using SPI driver in DMA mode.

STM32CubeMX Setup

The CMSIS-Driver SPI requires:

  • Setup of SPIx input clock
  • Setup of SPIx in Full-Duplex Master/Slave mode

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

Peripheral Resource NUCLEO-G474RE
SPI Peripheral SPI1
SPI Mode Full-Duplex Master
NSS Pin PA4
SCK Pin PA5
MISO Pin PA6
MOSI Pin PA7

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

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

Pinout view

  1. Configure SPI1 pins
    • PA4: SPI1_NSS
    • PA5: SPI1_SCK
    • PA6: SPI1_MISO
    • PA7: SPI1_MOSI

Pinout & Configuration tab

  1. Under Connectivity open SPI1:
    • Section Mode
      • Mode: Full-Duplex Master
      • Hardware NSS Signal: Hardware NSS Output Signal
    • Section Configuration
      • Parameter Settings: not used
      • User Constants: not used
      • NVIC Settings: configured later
      • DMA Settings: configured with DMA
      • GPIO Settings: check used pins
  2. Under System Core open GPIO:
    • Group By Peripherals - SPI:
      Pin Name Signal on Pin GPIO mode GPIO Pull-up/Pull.. Maximum out.. User Label
      PA4 SPI1_NSS Alternate F.. No pull-up and no.. Very High .
      PA5 SPI1_SCK Alternate F.. No pull-up and no.. Very High .
      PA6 SPI1_MISO Alternate F.. No pull-up and no.. Very High .
      PA7 SPI1_MOSI Alternate F.. No pull-up and no.. Very High .
  3. Under System Core open DMA:
    • Section Configuration
      • DMA1, DMA2
        • Click on Add button and add requests as in table below:
          DMA Request Channel Direction Priority
          SPI1_RX DMA1 Channel 1 Peripheral to Memory Low
          SPI1_TX DMA1 Channel 2 Memory to Peripheral Low
  4. Under System Core open NVIC:
    • Section Configuration
      • NVIC
        NVIC Interrupt Table Enabled Preemption Priority Sub Priority
        DMA1 channel1 global interrupt ON 0 0
        DMA1 channel2 global interrupt ON 0 0
        SPI1 global interrupt ON 0 0

Clock Configuration tab

  1. Configure SPI1 Clock.

Project Manager tab

  1. Open Advanced Settings:
    • enable Do Not Generate Function Call for MX_SPI1_Init.

Validation

Results of the CMSIS-Driver Validation for this driver can be found in the SPI_TestReport.txt file.