RTEMS 6.1-rc6
Loading...
Searching...
No Matches
stm32h7xx_hal_spi.c File Reference

SPI HAL module driver. This file provides firmware functions to manage the following functionalities of the Serial Peripheral Interface (SPI) peripheral: More...

#include "stm32h7xx_hal.h"

Detailed Description

SPI HAL module driver. This file provides firmware functions to manage the following functionalities of the Serial Peripheral Interface (SPI) peripheral:

Author
MCD Application Team
  • Initialization and de-initialization functions
  • IO operation functions
  • Peripheral Control functions
  • Peripheral State functions
Attention

Copyright (c) 2017 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

==============================================================================
                      ##### How to use this driver #####
==============================================================================
  [..]
    The SPI HAL driver can be used as follows:

    (#) Declare a SPI_HandleTypeDef handle structure, for example:
        SPI_HandleTypeDef  hspi;

    (#)Initialize the SPI low level resources by implementing the HAL_SPI_MspInit() API:
        (##) Enable the SPIx interface clock
        (##) SPI pins configuration
            (+++) Enable the clock for the SPI GPIOs
            (+++) Configure these SPI pins as alternate function push-pull
        (##) NVIC configuration if you need to use interrupt process or DMA process
            (+++) Configure the SPIx interrupt priority
            (+++) Enable the NVIC SPI IRQ handle
        (##) DMA Configuration if you need to use DMA process
            (+++) Declare a DMA_HandleTypeDef handle structure for the transmit or receive Stream/Channel
            (+++) Enable the DMAx clock
            (+++) Configure the DMA handle parameters
            (+++) Configure the DMA Tx or Rx Stream/Channel
            (+++) Associate the initialized hdma_tx handle to the hspi DMA Tx or Rx handle
            (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx
                  or Rx Stream/Channel

    (#) Program the Mode, BidirectionalMode , Data size, Baudrate Prescaler, NSS
        management, Clock polarity and phase, FirstBit and CRC configuration in the hspi Init structure.

    (#) Initialize the SPI registers by calling the HAL_SPI_Init() API:
        (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
            by calling the customized HAL_SPI_MspInit() API.
   [..]
     Callback registration:

    (#) The compilation flag USE_HAL_SPI_REGISTER_CALLBACKS when set to 1UL
        allows the user to configure dynamically the driver callbacks.
        Use Functions HAL_SPI_RegisterCallback() to register an interrupt callback.

        Function HAL_SPI_RegisterCallback() allows to register following callbacks:
          (+) TxCpltCallback        : SPI Tx Completed callback
          (+) RxCpltCallback        : SPI Rx Completed callback
          (+) TxRxCpltCallback      : SPI TxRx Completed callback
          (+) TxHalfCpltCallback    : SPI Tx Half Completed callback
          (+) RxHalfCpltCallback    : SPI Rx Half Completed callback
          (+) TxRxHalfCpltCallback  : SPI TxRx Half Completed callback
          (+) ErrorCallback         : SPI Error callback
          (+) AbortCpltCallback     : SPI Abort callback
          (+) SuspendCallback       : SPI Suspend callback
          (+) MspInitCallback       : SPI Msp Init callback
          (+) MspDeInitCallback     : SPI Msp DeInit callback
        This function takes as parameters the HAL peripheral handle, the Callback ID
        and a pointer to the user callback function.


    (#) Use function HAL_SPI_UnRegisterCallback to reset a callback to the default
        weak function.
        HAL_SPI_UnRegisterCallback takes as parameters the HAL peripheral handle,
        and the Callback ID.
        This function allows to reset following callbacks:
          (+) TxCpltCallback        : SPI Tx Completed callback
          (+) RxCpltCallback        : SPI Rx Completed callback
          (+) TxRxCpltCallback      : SPI TxRx Completed callback
          (+) TxHalfCpltCallback    : SPI Tx Half Completed callback
          (+) RxHalfCpltCallback    : SPI Rx Half Completed callback
          (+) TxRxHalfCpltCallback  : SPI TxRx Half Completed callback
          (+) ErrorCallback         : SPI Error callback
          (+) AbortCpltCallback     : SPI Abort callback
          (+) SuspendCallback       : SPI Suspend callback
          (+) MspInitCallback       : SPI Msp Init callback
          (+) MspDeInitCallback     : SPI Msp DeInit callback

     By default, after the HAL_SPI_Init() and when the state is HAL_SPI_STATE_RESET
     all callbacks are set to the corresponding weak functions:
     examples HAL_SPI_MasterTxCpltCallback(), HAL_SPI_MasterRxCpltCallback().
     Exception done for MspInit and MspDeInit functions that are
     reset to the legacy weak functions in the HAL_SPI_Init()/ HAL_SPI_DeInit() only when
     these callbacks are null (not registered beforehand).
     If MspInit or MspDeInit are not null, the HAL_SPI_Init()/ HAL_SPI_DeInit()
     keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.

     Callbacks can be registered/unregistered in HAL_SPI_STATE_READY state only.
     Exception done MspInit/MspDeInit functions that can be registered/unregistered
     in HAL_SPI_STATE_READY or HAL_SPI_STATE_RESET state,
     thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
     Then, the user first registers the MspInit/MspDeInit user callbacks
     using HAL_SPI_RegisterCallback() before calling HAL_SPI_DeInit()
     or HAL_SPI_Init() function.

     When The compilation define USE_HAL_PPP_REGISTER_CALLBACKS is set to 0 or not defined,
     the callback registering feature is not available and weak callbacks are used.

     SuspendCallback restriction:
         SuspendCallback is called only when MasterReceiverAutoSusp is enabled and
     EOT interrupt is activated. SuspendCallback is used in relation with functions
     HAL_SPI_Transmit_IT, HAL_SPI_Receive_IT and HAL_SPI_TransmitReceive_IT.

  [..]
    Circular mode restriction:
    (+) The DMA circular mode cannot be used when the SPI is configured in these modes:
        (++) Master 2Lines RxOnly
        (++) Master 1Line Rx
    (+) The CRC feature is not managed when the DMA circular mode is enabled
    (+) The functions HAL_SPI_DMAPause()/ HAL_SPI_DMAResume() are not supported. Return always
        HAL_ERROR with ErrorCode set to HAL_SPI_ERROR_NOT_SUPPORTED.
        Those functions are maintained for backward compatibility reasons.