HAL SPI Overview

Introducing SPI

group SPI_Introduction

  • The SPI hardware abstraction layer provides a set of APIs to interface with the STM32 SPI (Serial Peripheral Interface) peripheral.

  • It simplifies the configuration, initialization, and management of SPI communication, by supporting various modes such as polling, interrupt, and DMA for efficient data transfer.

  • This abstraction layer ensures portability and ease of use across different STM32 series.

Module and files

The following diagram illustrates the SPI module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the SPI module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.


@startuml
<style>
componentDiagram {
   arrow {
      FontSize 8
   }
}
</style>

title SPI Software Component Diagram

package "HAL" {
    [HAL_SERVICE]
    [HAL_SPI]
    [HAL_DMA]
}

package "Low Layer" {
    [LL_SPI]
    [CMSIS]
    [SPI Interrupt routine service]
    [DMA Interrupt routine service]
}

package "HW" {
    [STM32_HW]
}

[Appli] --> [HAL_SPI] : HAL SPI API
[Appli] <-- [HAL_SPI] : SPI callback
[HAL_SPI] --> [LL_SPI] : LL SPI API
[HAL_SPI] -r-> [HAL_DMA] : HAL DMA_Start_IT\nHAL_DMA_Abort_IT
[HAL_SPI] -l-> [HAL_SERVICE] : HAL_GetTick
[HAL_SPI] <-- [SPI Interrupt routine service]
[HAL_SPI] <-r- [HAL_DMA]:Half transfer complete\nTransfer complete\nError
[LL_SPI] --> [CMSIS]:SPI register def
[HAL_DMA] <-d- [DMA Interrupt routine service]
[STM32_HW] -u--> [SPI Interrupt routine service]: SPIx Irq
[STM32_HW] -u--> [DMA Interrupt routine service] : DMA Channel Irq
[STM32_HW] <-u-- [LL_SPI] : SPI registers R/W
@enduml

Configuration table

The following table lists the configuration defines for the HAL SPI module, specifying their locations, default values, and descriptions:

group SPI_Configuration_Table

Configuration inside the SPI driver:

Software configuration defined in stm32c5xx_hal_conf.h:

Preprocessor flags

Default value

Comment

USE_HAL_SPI_MODULE

1

Enable HAL SPI driver module

USE_HAL_SPI_REGISTER_CALLBACKS

0

Allow the user to define their own callback

USE_HAL_SPI_DMA

1

Enable DMA code inside SPI

USE_HAL_CHECK_PARAM

0

Enable runtime parameter check

USE_HAL_SPI_CLK_ENABLE_MODEL

HAL_CLK_ENABLE_NO

Enable the gating of the peripheral clock

USE_HAL_CHECK_PROCESS_STATE

0

Enable atomicity of process state check

USE_HAL_MUTEX

0

Enable semaphore creation for OS

USE_HAL_SPI_USER_DATA

0

Add a user data inside HAL SPI handle

USE_HAL_SPI_GET_LAST_ERRORS

0

Enable retrieval of last processes error codes

USE_HAL_SPI_CRC

1

Enable the use of CRC feature inside driver

Software configuration defined in preprocessor environment:

Preprocessor flags

Default value

Comment

USE_ASSERT_DBG_PARAM

Not defined

Enable check param for HAL and LL

USE_ASSERT_DBG_STATE

Not defined

Enable check state for HAL