mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 610:813dcc80987e 1 /**
mbed_official 610:813dcc80987e 2 ******************************************************************************
mbed_official 610:813dcc80987e 3 * @file stm32l4xx_hal_spi.h
mbed_official 610:813dcc80987e 4 * @author MCD Application Team
mbed_official 610:813dcc80987e 5 * @version V1.0.0
mbed_official 610:813dcc80987e 6 * @date 26-June-2015
mbed_official 610:813dcc80987e 7 * @brief Header file of SPI HAL module.
mbed_official 610:813dcc80987e 8 ******************************************************************************
mbed_official 610:813dcc80987e 9 * @attention
mbed_official 610:813dcc80987e 10 *
mbed_official 610:813dcc80987e 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 610:813dcc80987e 12 *
mbed_official 610:813dcc80987e 13 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 610:813dcc80987e 14 * are permitted provided that the following conditions are met:
mbed_official 610:813dcc80987e 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 610:813dcc80987e 16 * this list of conditions and the following disclaimer.
mbed_official 610:813dcc80987e 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 610:813dcc80987e 18 * this list of conditions and the following disclaimer in the documentation
mbed_official 610:813dcc80987e 19 * and/or other materials provided with the distribution.
mbed_official 610:813dcc80987e 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 610:813dcc80987e 21 * may be used to endorse or promote products derived from this software
mbed_official 610:813dcc80987e 22 * without specific prior written permission.
mbed_official 610:813dcc80987e 23 *
mbed_official 610:813dcc80987e 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 610:813dcc80987e 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 610:813dcc80987e 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 610:813dcc80987e 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 610:813dcc80987e 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 610:813dcc80987e 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 610:813dcc80987e 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 610:813dcc80987e 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 610:813dcc80987e 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 610:813dcc80987e 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 610:813dcc80987e 34 *
mbed_official 610:813dcc80987e 35 ******************************************************************************
mbed_official 610:813dcc80987e 36 */
mbed_official 610:813dcc80987e 37
mbed_official 610:813dcc80987e 38 /* Define to prevent recursive inclusion -------------------------------------*/
mbed_official 610:813dcc80987e 39 #ifndef __STM32L4xx_HAL_SPI_H
mbed_official 610:813dcc80987e 40 #define __STM32L4xx_HAL_SPI_H
mbed_official 610:813dcc80987e 41
mbed_official 610:813dcc80987e 42 #ifdef __cplusplus
mbed_official 610:813dcc80987e 43 extern "C" {
mbed_official 610:813dcc80987e 44 #endif
mbed_official 610:813dcc80987e 45
mbed_official 610:813dcc80987e 46 /* Includes ------------------------------------------------------------------*/
mbed_official 610:813dcc80987e 47 #include "stm32l4xx_hal_def.h"
mbed_official 610:813dcc80987e 48
mbed_official 610:813dcc80987e 49 /** @addtogroup STM32L4xx_HAL_Driver
mbed_official 610:813dcc80987e 50 * @{
mbed_official 610:813dcc80987e 51 */
mbed_official 610:813dcc80987e 52
mbed_official 610:813dcc80987e 53 /** @addtogroup SPI
mbed_official 610:813dcc80987e 54 * @{
mbed_official 610:813dcc80987e 55 */
mbed_official 610:813dcc80987e 56
mbed_official 610:813dcc80987e 57 /* Exported types ------------------------------------------------------------*/
mbed_official 610:813dcc80987e 58 /** @defgroup SPI_Exported_Types SPI Exported Types
mbed_official 610:813dcc80987e 59 * @{
mbed_official 610:813dcc80987e 60 */
mbed_official 610:813dcc80987e 61
mbed_official 610:813dcc80987e 62 /**
mbed_official 610:813dcc80987e 63 * @brief SPI Configuration Structure definition
mbed_official 610:813dcc80987e 64 */
mbed_official 610:813dcc80987e 65 typedef struct
mbed_official 610:813dcc80987e 66 {
mbed_official 610:813dcc80987e 67 uint32_t Mode; /*!< Specifies the SPI operating mode.
mbed_official 610:813dcc80987e 68 This parameter can be a value of @ref SPI_Mode */
mbed_official 610:813dcc80987e 69
mbed_official 610:813dcc80987e 70 uint32_t Direction; /*!< Specifies the SPI bidirectional mode state.
mbed_official 610:813dcc80987e 71 This parameter can be a value of @ref SPI_Direction */
mbed_official 610:813dcc80987e 72
mbed_official 610:813dcc80987e 73 uint32_t DataSize; /*!< Specifies the SPI data size.
mbed_official 610:813dcc80987e 74 This parameter can be a value of @ref SPI_Data_Size */
mbed_official 610:813dcc80987e 75
mbed_official 610:813dcc80987e 76 uint32_t CLKPolarity; /*!< Specifies the serial clock steady state.
mbed_official 610:813dcc80987e 77 This parameter can be a value of @ref SPI_Clock_Polarity */
mbed_official 610:813dcc80987e 78
mbed_official 610:813dcc80987e 79 uint32_t CLKPhase; /*!< Specifies the clock active edge for the bit capture.
mbed_official 610:813dcc80987e 80 This parameter can be a value of @ref SPI_Clock_Phase */
mbed_official 610:813dcc80987e 81
mbed_official 610:813dcc80987e 82 uint32_t NSS; /*!< Specifies whether the NSS signal is managed by
mbed_official 610:813dcc80987e 83 hardware (NSS pin) or by software using the SSI bit.
mbed_official 610:813dcc80987e 84 This parameter can be a value of @ref SPI_Slave_Select_management */
mbed_official 610:813dcc80987e 85
mbed_official 610:813dcc80987e 86 uint32_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be
mbed_official 610:813dcc80987e 87 used to configure the transmit and receive SCK clock.
mbed_official 610:813dcc80987e 88 This parameter can be a value of @ref SPI_BaudRate_Prescaler
mbed_official 610:813dcc80987e 89 @note The communication clock is derived from the master
mbed_official 610:813dcc80987e 90 clock. The slave clock does not need to be set. */
mbed_official 610:813dcc80987e 91
mbed_official 610:813dcc80987e 92 uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
mbed_official 610:813dcc80987e 93 This parameter can be a value of @ref SPI_MSB_LSB_transmission */
mbed_official 610:813dcc80987e 94
mbed_official 610:813dcc80987e 95 uint32_t TIMode; /*!< Specifies if the TI mode is enabled or not .
mbed_official 610:813dcc80987e 96 This parameter can be a value of @ref SPI_TI_mode */
mbed_official 610:813dcc80987e 97
mbed_official 610:813dcc80987e 98 uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not.
mbed_official 610:813dcc80987e 99 This parameter can be a value of @ref SPI_CRC_Calculation */
mbed_official 610:813dcc80987e 100
mbed_official 610:813dcc80987e 101 uint32_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation.
mbed_official 610:813dcc80987e 102 This parameter must be a number between Min_Data = 0 and Max_Data = 65535 */
mbed_official 610:813dcc80987e 103
mbed_official 610:813dcc80987e 104 uint32_t CRCLength; /*!< Specifies the CRC Length used for the CRC calculation.
mbed_official 610:813dcc80987e 105 CRC Length is only used with Data8 and Data16, not other data size
mbed_official 610:813dcc80987e 106 This parameter can be a value of @ref SPI_CRC_length */
mbed_official 610:813dcc80987e 107
mbed_official 610:813dcc80987e 108 uint32_t NSSPMode; /*!< Specifies whether the NSSP signal is enabled or not .
mbed_official 610:813dcc80987e 109 This parameter can be a value of @ref SPI_NSSP_Mode
mbed_official 610:813dcc80987e 110 This mode is activated by the NSSP bit in the SPIx_CR2 register and
mbed_official 610:813dcc80987e 111 it takes effect only if the SPI interface is configured as Motorola SPI
mbed_official 610:813dcc80987e 112 master (FRF=0) with capture on the first edge (SPIx_CR1 CPHA = 0,
mbed_official 610:813dcc80987e 113 CPOL setting is ignored).. */
mbed_official 610:813dcc80987e 114 } SPI_InitTypeDef;
mbed_official 610:813dcc80987e 115
mbed_official 610:813dcc80987e 116 /**
mbed_official 610:813dcc80987e 117 * @brief HAL State structures definition
mbed_official 610:813dcc80987e 118 */
mbed_official 610:813dcc80987e 119 typedef enum
mbed_official 610:813dcc80987e 120 {
mbed_official 610:813dcc80987e 121 HAL_SPI_STATE_RESET = 0x00, /*!< Peripheral not Initialized */
mbed_official 610:813dcc80987e 122 HAL_SPI_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
mbed_official 610:813dcc80987e 123 HAL_SPI_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
mbed_official 610:813dcc80987e 124 HAL_SPI_STATE_BUSY_TX = 0x03, /*!< Data Transmission process is ongoing */
mbed_official 610:813dcc80987e 125 HAL_SPI_STATE_BUSY_RX = 0x04, /*!< Data Reception process is ongoing */
mbed_official 610:813dcc80987e 126 HAL_SPI_STATE_BUSY_TX_RX = 0x05, /*!< Data Transmission and Reception process is ongoing*/
mbed_official 610:813dcc80987e 127 HAL_SPI_STATE_ERROR = 0x06 /*!< SPI error state */
mbed_official 610:813dcc80987e 128 }HAL_SPI_StateTypeDef;
mbed_official 610:813dcc80987e 129
mbed_official 610:813dcc80987e 130 /**
mbed_official 610:813dcc80987e 131 * @brief SPI handle Structure definition
mbed_official 610:813dcc80987e 132 */
mbed_official 610:813dcc80987e 133 typedef struct __SPI_HandleTypeDef
mbed_official 610:813dcc80987e 134 {
mbed_official 610:813dcc80987e 135 SPI_TypeDef *Instance; /* SPI registers base address */
mbed_official 610:813dcc80987e 136
mbed_official 610:813dcc80987e 137 SPI_InitTypeDef Init; /* SPI communication parameters */
mbed_official 610:813dcc80987e 138
mbed_official 610:813dcc80987e 139 uint8_t *pTxBuffPtr; /* Pointer to SPI Tx transfer Buffer */
mbed_official 610:813dcc80987e 140
mbed_official 610:813dcc80987e 141 uint16_t TxXferSize; /* SPI Tx Transfer size */
mbed_official 610:813dcc80987e 142
mbed_official 610:813dcc80987e 143 uint16_t TxXferCount; /* SPI Tx Transfer Counter */
mbed_official 610:813dcc80987e 144
mbed_official 610:813dcc80987e 145 uint8_t *pRxBuffPtr; /* Pointer to SPI Rx transfer Buffer */
mbed_official 610:813dcc80987e 146
mbed_official 610:813dcc80987e 147 uint16_t RxXferSize; /* SPI Rx Transfer size */
mbed_official 610:813dcc80987e 148
mbed_official 610:813dcc80987e 149 uint16_t RxXferCount; /* SPI Rx Transfer Counter */
mbed_official 610:813dcc80987e 150
mbed_official 610:813dcc80987e 151 uint32_t CRCSize; /* SPI CRC size used for the transfer */
mbed_official 610:813dcc80987e 152
mbed_official 610:813dcc80987e 153 void (*RxISR)(struct __SPI_HandleTypeDef *hspi); /* function pointer on Rx IRQ handler */
mbed_official 610:813dcc80987e 154
mbed_official 610:813dcc80987e 155 void (*TxISR)(struct __SPI_HandleTypeDef *hspi); /* function pointer on Tx IRQ handler */
mbed_official 610:813dcc80987e 156
mbed_official 610:813dcc80987e 157 DMA_HandleTypeDef *hdmatx; /* SPI Tx DMA Handle parameters */
mbed_official 610:813dcc80987e 158
mbed_official 610:813dcc80987e 159 DMA_HandleTypeDef *hdmarx; /* SPI Rx DMA Handle parameters */
mbed_official 610:813dcc80987e 160
mbed_official 610:813dcc80987e 161 HAL_LockTypeDef Lock; /* Locking object */
mbed_official 610:813dcc80987e 162
mbed_official 610:813dcc80987e 163 HAL_SPI_StateTypeDef State; /* SPI communication state */
mbed_official 610:813dcc80987e 164
mbed_official 610:813dcc80987e 165 uint32_t ErrorCode; /* SPI Error code */
mbed_official 610:813dcc80987e 166
mbed_official 610:813dcc80987e 167 }SPI_HandleTypeDef;
mbed_official 610:813dcc80987e 168
mbed_official 610:813dcc80987e 169 /**
mbed_official 610:813dcc80987e 170 * @}
mbed_official 610:813dcc80987e 171 */
mbed_official 610:813dcc80987e 172
mbed_official 610:813dcc80987e 173 /* Exported constants --------------------------------------------------------*/
mbed_official 610:813dcc80987e 174
mbed_official 610:813dcc80987e 175 /** @defgroup SPI_Exported_Constants SPI Exported Constants
mbed_official 610:813dcc80987e 176 * @{
mbed_official 610:813dcc80987e 177 */
mbed_official 610:813dcc80987e 178
mbed_official 610:813dcc80987e 179 /** @defgroup SPI_Error_Code SPI Error Code
mbed_official 610:813dcc80987e 180 * @{
mbed_official 610:813dcc80987e 181 */
mbed_official 610:813dcc80987e 182 #define HAL_SPI_ERROR_NONE (uint32_t)0x00000000 /*!< No error */
mbed_official 610:813dcc80987e 183 #define HAL_SPI_ERROR_MODF (uint32_t)0x00000001 /*!< MODF error */
mbed_official 610:813dcc80987e 184 #define HAL_SPI_ERROR_CRC (uint32_t)0x00000002 /*!< CRC error */
mbed_official 610:813dcc80987e 185 #define HAL_SPI_ERROR_OVR (uint32_t)0x00000004 /*!< OVR error */
mbed_official 610:813dcc80987e 186 #define HAL_SPI_ERROR_FRE (uint32_t)0x00000008 /*!< FRE error */
mbed_official 610:813dcc80987e 187 #define HAL_SPI_ERROR_DMA (uint32_t)0x00000010 /*!< DMA transfer error */
mbed_official 610:813dcc80987e 188 #define HAL_SPI_ERROR_FLAG (uint32_t)0x00000020 /*!< Error on BSY/TXE/FTLVL/FRLVL Flag */
mbed_official 610:813dcc80987e 189 #define HAL_SPI_ERROR_UNKNOW (uint32_t)0x00000040 /*!< Unknown error */
mbed_official 610:813dcc80987e 190 /**
mbed_official 610:813dcc80987e 191 * @}
mbed_official 610:813dcc80987e 192 */
mbed_official 610:813dcc80987e 193
mbed_official 610:813dcc80987e 194
mbed_official 610:813dcc80987e 195 /** @defgroup SPI_Mode SPI Mode
mbed_official 610:813dcc80987e 196 * @{
mbed_official 610:813dcc80987e 197 */
mbed_official 610:813dcc80987e 198 #define SPI_MODE_SLAVE ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 199 #define SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI)
mbed_official 610:813dcc80987e 200 /**
mbed_official 610:813dcc80987e 201 * @}
mbed_official 610:813dcc80987e 202 */
mbed_official 610:813dcc80987e 203
mbed_official 610:813dcc80987e 204 /** @defgroup SPI_Direction SPI Direction Mode
mbed_official 610:813dcc80987e 205 * @{
mbed_official 610:813dcc80987e 206 */
mbed_official 610:813dcc80987e 207 #define SPI_DIRECTION_2LINES ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 208 #define SPI_DIRECTION_2LINES_RXONLY SPI_CR1_RXONLY
mbed_official 610:813dcc80987e 209 #define SPI_DIRECTION_1LINE SPI_CR1_BIDIMODE
mbed_official 610:813dcc80987e 210 /**
mbed_official 610:813dcc80987e 211 * @}
mbed_official 610:813dcc80987e 212 */
mbed_official 610:813dcc80987e 213
mbed_official 610:813dcc80987e 214 /** @defgroup SPI_Data_Size SPI Data Size
mbed_official 610:813dcc80987e 215 * @{
mbed_official 610:813dcc80987e 216 */
mbed_official 610:813dcc80987e 217 #define SPI_DATASIZE_4BIT ((uint32_t)0x0300)
mbed_official 610:813dcc80987e 218 #define SPI_DATASIZE_5BIT ((uint32_t)0x0400)
mbed_official 610:813dcc80987e 219 #define SPI_DATASIZE_6BIT ((uint32_t)0x0500)
mbed_official 610:813dcc80987e 220 #define SPI_DATASIZE_7BIT ((uint32_t)0x0600)
mbed_official 610:813dcc80987e 221 #define SPI_DATASIZE_8BIT ((uint32_t)0x0700)
mbed_official 610:813dcc80987e 222 #define SPI_DATASIZE_9BIT ((uint32_t)0x0800)
mbed_official 610:813dcc80987e 223 #define SPI_DATASIZE_10BIT ((uint32_t)0x0900)
mbed_official 610:813dcc80987e 224 #define SPI_DATASIZE_11BIT ((uint32_t)0x0A00)
mbed_official 610:813dcc80987e 225 #define SPI_DATASIZE_12BIT ((uint32_t)0x0B00)
mbed_official 610:813dcc80987e 226 #define SPI_DATASIZE_13BIT ((uint32_t)0x0C00)
mbed_official 610:813dcc80987e 227 #define SPI_DATASIZE_14BIT ((uint32_t)0x0D00)
mbed_official 610:813dcc80987e 228 #define SPI_DATASIZE_15BIT ((uint32_t)0x0E00)
mbed_official 610:813dcc80987e 229 #define SPI_DATASIZE_16BIT ((uint32_t)0x0F00)
mbed_official 610:813dcc80987e 230 /**
mbed_official 610:813dcc80987e 231 * @}
mbed_official 610:813dcc80987e 232 */
mbed_official 610:813dcc80987e 233
mbed_official 610:813dcc80987e 234 /** @defgroup SPI_Clock_Polarity SPI Clock Polarity
mbed_official 610:813dcc80987e 235 * @{
mbed_official 610:813dcc80987e 236 */
mbed_official 610:813dcc80987e 237 #define SPI_POLARITY_LOW ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 238 #define SPI_POLARITY_HIGH SPI_CR1_CPOL
mbed_official 610:813dcc80987e 239 /**
mbed_official 610:813dcc80987e 240 * @}
mbed_official 610:813dcc80987e 241 */
mbed_official 610:813dcc80987e 242
mbed_official 610:813dcc80987e 243 /** @defgroup SPI_Clock_Phase SPI Clock Phase
mbed_official 610:813dcc80987e 244 * @{
mbed_official 610:813dcc80987e 245 */
mbed_official 610:813dcc80987e 246 #define SPI_PHASE_1EDGE ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 247 #define SPI_PHASE_2EDGE SPI_CR1_CPHA
mbed_official 610:813dcc80987e 248 /**
mbed_official 610:813dcc80987e 249 * @}
mbed_official 610:813dcc80987e 250 */
mbed_official 610:813dcc80987e 251
mbed_official 610:813dcc80987e 252 /** @defgroup SPI_Slave_Select_management SPI Slave Select management
mbed_official 610:813dcc80987e 253 * @{
mbed_official 610:813dcc80987e 254 */
mbed_official 610:813dcc80987e 255 #define SPI_NSS_SOFT SPI_CR1_SSM
mbed_official 610:813dcc80987e 256 #define SPI_NSS_HARD_INPUT ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 257 #define SPI_NSS_HARD_OUTPUT ((uint32_t)0x00040000)
mbed_official 610:813dcc80987e 258 /**
mbed_official 610:813dcc80987e 259 * @}
mbed_official 610:813dcc80987e 260 */
mbed_official 610:813dcc80987e 261
mbed_official 610:813dcc80987e 262 /** @defgroup SPI_NSSP_Mode SPI NSS Pulse Mode
mbed_official 610:813dcc80987e 263 * @{
mbed_official 610:813dcc80987e 264 */
mbed_official 610:813dcc80987e 265 #define SPI_NSS_PULSE_ENABLE SPI_CR2_NSSP
mbed_official 610:813dcc80987e 266 #define SPI_NSS_PULSE_DISABLE ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 267 /**
mbed_official 610:813dcc80987e 268 * @}
mbed_official 610:813dcc80987e 269 */
mbed_official 610:813dcc80987e 270
mbed_official 610:813dcc80987e 271 /** @defgroup SPI_BaudRate_Prescaler SPI BaudRate Prescaler
mbed_official 610:813dcc80987e 272 * @{
mbed_official 610:813dcc80987e 273 */
mbed_official 610:813dcc80987e 274 #define SPI_BAUDRATEPRESCALER_2 ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 275 #define SPI_BAUDRATEPRESCALER_4 ((uint32_t)0x00000008)
mbed_official 610:813dcc80987e 276 #define SPI_BAUDRATEPRESCALER_8 ((uint32_t)0x00000010)
mbed_official 610:813dcc80987e 277 #define SPI_BAUDRATEPRESCALER_16 ((uint32_t)0x00000018)
mbed_official 610:813dcc80987e 278 #define SPI_BAUDRATEPRESCALER_32 ((uint32_t)0x00000020)
mbed_official 610:813dcc80987e 279 #define SPI_BAUDRATEPRESCALER_64 ((uint32_t)0x00000028)
mbed_official 610:813dcc80987e 280 #define SPI_BAUDRATEPRESCALER_128 ((uint32_t)0x00000030)
mbed_official 610:813dcc80987e 281 #define SPI_BAUDRATEPRESCALER_256 ((uint32_t)0x00000038)
mbed_official 610:813dcc80987e 282 /**
mbed_official 610:813dcc80987e 283 * @}
mbed_official 610:813dcc80987e 284 */
mbed_official 610:813dcc80987e 285
mbed_official 610:813dcc80987e 286 /** @defgroup SPI_MSB_LSB_transmission SPI MSB LSB transmission
mbed_official 610:813dcc80987e 287 * @{
mbed_official 610:813dcc80987e 288 */
mbed_official 610:813dcc80987e 289 #define SPI_FIRSTBIT_MSB ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 290 #define SPI_FIRSTBIT_LSB SPI_CR1_LSBFIRST
mbed_official 610:813dcc80987e 291 /**
mbed_official 610:813dcc80987e 292 * @}
mbed_official 610:813dcc80987e 293 */
mbed_official 610:813dcc80987e 294
mbed_official 610:813dcc80987e 295 /** @defgroup SPI_TI_mode SPI TI mode
mbed_official 610:813dcc80987e 296 * @{
mbed_official 610:813dcc80987e 297 */
mbed_official 610:813dcc80987e 298 #define SPI_TIMODE_DISABLE ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 299 #define SPI_TIMODE_ENABLE SPI_CR2_FRF
mbed_official 610:813dcc80987e 300 /**
mbed_official 610:813dcc80987e 301 * @}
mbed_official 610:813dcc80987e 302 */
mbed_official 610:813dcc80987e 303
mbed_official 610:813dcc80987e 304 /** @defgroup SPI_CRC_Calculation SPI CRC Calculation
mbed_official 610:813dcc80987e 305 * @{
mbed_official 610:813dcc80987e 306 */
mbed_official 610:813dcc80987e 307 #define SPI_CRCCALCULATION_DISABLE ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 308 #define SPI_CRCCALCULATION_ENABLE SPI_CR1_CRCEN
mbed_official 610:813dcc80987e 309 /**
mbed_official 610:813dcc80987e 310 * @}
mbed_official 610:813dcc80987e 311 */
mbed_official 610:813dcc80987e 312
mbed_official 610:813dcc80987e 313 /** @defgroup SPI_CRC_length SPI CRC Length
mbed_official 610:813dcc80987e 314 * @{
mbed_official 610:813dcc80987e 315 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 316 * SPI_CRC_LENGTH_DATASIZE: aligned with the data size
mbed_official 610:813dcc80987e 317 * SPI_CRC_LENGTH_8BIT : CRC 8bit
mbed_official 610:813dcc80987e 318 * SPI_CRC_LENGTH_16BIT : CRC 16bit
mbed_official 610:813dcc80987e 319 */
mbed_official 610:813dcc80987e 320 #define SPI_CRC_LENGTH_DATASIZE ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 321 #define SPI_CRC_LENGTH_8BIT ((uint32_t)0x00000001)
mbed_official 610:813dcc80987e 322 #define SPI_CRC_LENGTH_16BIT ((uint32_t)0x00000002)
mbed_official 610:813dcc80987e 323 /**
mbed_official 610:813dcc80987e 324 * @}
mbed_official 610:813dcc80987e 325 */
mbed_official 610:813dcc80987e 326
mbed_official 610:813dcc80987e 327 /** @defgroup SPI_FIFO_reception_threshold SPI FIFO Reception Threshold
mbed_official 610:813dcc80987e 328 * @{
mbed_official 610:813dcc80987e 329 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 330 * SPI_RXFIFO_THRESHOLD or SPI_RXFIFO_THRESHOLD_QF :
mbed_official 610:813dcc80987e 331 * RXNE event is generated if the FIFO
mbed_official 610:813dcc80987e 332 * level is greater or equal to 1/2(16-bits).
mbed_official 610:813dcc80987e 333 * SPI_RXFIFO_THRESHOLD_HF: RXNE event is generated if the FIFO
mbed_official 610:813dcc80987e 334 * level is greater or equal to 1/4(8 bits). */
mbed_official 610:813dcc80987e 335 #define SPI_RXFIFO_THRESHOLD SPI_CR2_FRXTH
mbed_official 610:813dcc80987e 336 #define SPI_RXFIFO_THRESHOLD_QF SPI_CR2_FRXTH
mbed_official 610:813dcc80987e 337 #define SPI_RXFIFO_THRESHOLD_HF ((uint32_t)0x00000000)
mbed_official 610:813dcc80987e 338
mbed_official 610:813dcc80987e 339 /**
mbed_official 610:813dcc80987e 340 * @}
mbed_official 610:813dcc80987e 341 */
mbed_official 610:813dcc80987e 342
mbed_official 610:813dcc80987e 343 /** @defgroup SPI_Interrupt_configuration_definition SPI Interrupt configuration definition
mbed_official 610:813dcc80987e 344 * @brief SPI Interrupt definition
mbed_official 610:813dcc80987e 345 * Elements values convention: 0xXXXXXXXX
mbed_official 610:813dcc80987e 346 * - XXXXXXXX : Interrupt control mask
mbed_official 610:813dcc80987e 347 * @{
mbed_official 610:813dcc80987e 348 */
mbed_official 610:813dcc80987e 349 #define SPI_IT_TXE SPI_CR2_TXEIE
mbed_official 610:813dcc80987e 350 #define SPI_IT_RXNE SPI_CR2_RXNEIE
mbed_official 610:813dcc80987e 351 #define SPI_IT_ERR SPI_CR2_ERRIE
mbed_official 610:813dcc80987e 352 /**
mbed_official 610:813dcc80987e 353 * @}
mbed_official 610:813dcc80987e 354 */
mbed_official 610:813dcc80987e 355
mbed_official 610:813dcc80987e 356
mbed_official 610:813dcc80987e 357 /** @defgroup SPI_Flag_definition SPI Flag definition
mbed_official 610:813dcc80987e 358 * @brief Flag definition
mbed_official 610:813dcc80987e 359 * Elements values convention: 0xXXXXYYYY
mbed_official 610:813dcc80987e 360 * - XXXX : Flag register Index
mbed_official 610:813dcc80987e 361 * - YYYY : Flag mask
mbed_official 610:813dcc80987e 362 * @{
mbed_official 610:813dcc80987e 363 */
mbed_official 610:813dcc80987e 364 #define SPI_FLAG_RXNE SPI_SR_RXNE /* SPI status flag: Rx buffer not empty flag */
mbed_official 610:813dcc80987e 365 #define SPI_FLAG_TXE SPI_SR_TXE /* SPI status flag: Tx buffer empty flag */
mbed_official 610:813dcc80987e 366 #define SPI_FLAG_BSY SPI_SR_BSY /* SPI status flag: Busy flag */
mbed_official 610:813dcc80987e 367 #define SPI_FLAG_CRCERR SPI_SR_CRCERR /* SPI Error flag: CRC error flag */
mbed_official 610:813dcc80987e 368 #define SPI_FLAG_MODF SPI_SR_MODF /* SPI Error flag: Mode fault flag */
mbed_official 610:813dcc80987e 369 #define SPI_FLAG_OVR SPI_SR_OVR /* SPI Error flag: Overrun flag */
mbed_official 610:813dcc80987e 370 #define SPI_FLAG_FRE SPI_SR_FRE /* SPI Error flag: TI mode frame format error flag */
mbed_official 610:813dcc80987e 371 #define SPI_FLAG_FTLVL SPI_SR_FTLVL /* SPI fifo transmission level */
mbed_official 610:813dcc80987e 372 #define SPI_FLAG_FRLVL SPI_SR_FRLVL /* SPI fifo reception level */
mbed_official 610:813dcc80987e 373 /**
mbed_official 610:813dcc80987e 374 * @}
mbed_official 610:813dcc80987e 375 */
mbed_official 610:813dcc80987e 376
mbed_official 610:813dcc80987e 377 /** @defgroup SPI_transmission_fifo_status_level SPI Transmission FIFO Status Level
mbed_official 610:813dcc80987e 378 * @{
mbed_official 610:813dcc80987e 379 */
mbed_official 610:813dcc80987e 380 #define SPI_FTLVL_EMPTY ((uint32_t)0x0000)
mbed_official 610:813dcc80987e 381 #define SPI_FTLVL_QUARTER_FULL ((uint32_t)0x0800)
mbed_official 610:813dcc80987e 382 #define SPI_FTLVL_HALF_FULL ((uint32_t)0x1000)
mbed_official 610:813dcc80987e 383 #define SPI_FTLVL_FULL ((uint32_t)0x1800)
mbed_official 610:813dcc80987e 384
mbed_official 610:813dcc80987e 385 /**
mbed_official 610:813dcc80987e 386 * @}
mbed_official 610:813dcc80987e 387 */
mbed_official 610:813dcc80987e 388
mbed_official 610:813dcc80987e 389 /** @defgroup SPI_reception_fifo_status_level SPI Reception FIFO Status Level
mbed_official 610:813dcc80987e 390 * @{
mbed_official 610:813dcc80987e 391 */
mbed_official 610:813dcc80987e 392 #define SPI_FRLVL_EMPTY ((uint32_t)0x0000)
mbed_official 610:813dcc80987e 393 #define SPI_FRLVL_QUARTER_FULL ((uint32_t)0x0200)
mbed_official 610:813dcc80987e 394 #define SPI_FRLVL_HALF_FULL ((uint32_t)0x0400)
mbed_official 610:813dcc80987e 395 #define SPI_FRLVL_FULL ((uint32_t)0x0600)
mbed_official 610:813dcc80987e 396 /**
mbed_official 610:813dcc80987e 397 * @}
mbed_official 610:813dcc80987e 398 */
mbed_official 610:813dcc80987e 399
mbed_official 610:813dcc80987e 400 /**
mbed_official 610:813dcc80987e 401 * @}
mbed_official 610:813dcc80987e 402 */
mbed_official 610:813dcc80987e 403
mbed_official 610:813dcc80987e 404 /* Exported macros ------------------------------------------------------------*/
mbed_official 610:813dcc80987e 405 /** @defgroup SPI_Exported_Macros SPI Exported Macros
mbed_official 610:813dcc80987e 406 * @{
mbed_official 610:813dcc80987e 407 */
mbed_official 610:813dcc80987e 408
mbed_official 610:813dcc80987e 409 /** @brief Reset SPI handle state.
mbed_official 610:813dcc80987e 410 * @param __HANDLE__: SPI handle.
mbed_official 610:813dcc80987e 411 * @retval None
mbed_official 610:813dcc80987e 412 */
mbed_official 610:813dcc80987e 413 #define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SPI_STATE_RESET)
mbed_official 610:813dcc80987e 414
mbed_official 610:813dcc80987e 415 /** @brief Enable or disable the specified SPI interrupts.
mbed_official 610:813dcc80987e 416 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 417 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 418 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
mbed_official 610:813dcc80987e 419 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 420 * @arg SPI_IT_TXE: Tx buffer empty interrupt enable
mbed_official 610:813dcc80987e 421 * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
mbed_official 610:813dcc80987e 422 * @arg SPI_IT_ERR: Error interrupt enable
mbed_official 610:813dcc80987e 423 * @retval None
mbed_official 610:813dcc80987e 424 */
mbed_official 610:813dcc80987e 425 #define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
mbed_official 610:813dcc80987e 426 #define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
mbed_official 610:813dcc80987e 427
mbed_official 610:813dcc80987e 428 /** @brief Check whether the specified SPI interrupt source is enabled or not.
mbed_official 610:813dcc80987e 429 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 430 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 431 * @param __INTERRUPT__: specifies the SPI interrupt source to check.
mbed_official 610:813dcc80987e 432 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 433 * @arg SPI_IT_TXE: Tx buffer empty interrupt enable
mbed_official 610:813dcc80987e 434 * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
mbed_official 610:813dcc80987e 435 * @arg SPI_IT_ERR: Error interrupt enable
mbed_official 610:813dcc80987e 436 * @retval The new state of __IT__ (TRUE or FALSE).
mbed_official 610:813dcc80987e 437 */
mbed_official 610:813dcc80987e 438 #define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
mbed_official 610:813dcc80987e 439
mbed_official 610:813dcc80987e 440 /** @brief Check whether the specified SPI flag is set or not.
mbed_official 610:813dcc80987e 441 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 442 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 443 * @param __FLAG__: specifies the flag to check.
mbed_official 610:813dcc80987e 444 * This parameter can be one of the following values:
mbed_official 610:813dcc80987e 445 * @arg SPI_FLAG_RXNE: Receive buffer not empty flag
mbed_official 610:813dcc80987e 446 * @arg SPI_FLAG_TXE: Transmit buffer empty flag
mbed_official 610:813dcc80987e 447 * @arg SPI_FLAG_CRCERR: CRC error flag
mbed_official 610:813dcc80987e 448 * @arg SPI_FLAG_MODF: Mode fault flag
mbed_official 610:813dcc80987e 449 * @arg SPI_FLAG_OVR: Overrun flag
mbed_official 610:813dcc80987e 450 * @arg SPI_FLAG_BSY: Busy flag
mbed_official 610:813dcc80987e 451 * @arg SPI_FLAG_FRE: Frame format error flag
mbed_official 610:813dcc80987e 452 * @arg SPI_FLAG_FTLVL: SPI fifo transmission level
mbed_official 610:813dcc80987e 453 * @arg SPI_FLAG_FRLVL: SPI fifo reception level
mbed_official 610:813dcc80987e 454 * @retval The new state of __FLAG__ (TRUE or FALSE).
mbed_official 610:813dcc80987e 455 */
mbed_official 610:813dcc80987e 456 #define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
mbed_official 610:813dcc80987e 457
mbed_official 610:813dcc80987e 458 /** @brief Clear the SPI CRCERR pending flag.
mbed_official 610:813dcc80987e 459 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 460 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 461 * @retval None
mbed_official 610:813dcc80987e 462 */
mbed_official 610:813dcc80987e 463 #define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR = (uint16_t)(~SPI_FLAG_CRCERR))
mbed_official 610:813dcc80987e 464
mbed_official 610:813dcc80987e 465 /** @brief Clear the SPI MODF pending flag.
mbed_official 610:813dcc80987e 466 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 467 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 468 *
mbed_official 610:813dcc80987e 469 * @retval None
mbed_official 610:813dcc80987e 470 */
mbed_official 610:813dcc80987e 471 #define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__) \
mbed_official 610:813dcc80987e 472 do{ \
mbed_official 610:813dcc80987e 473 __IO uint32_t tmpreg; \
mbed_official 610:813dcc80987e 474 tmpreg = (__HANDLE__)->Instance->SR; \
mbed_official 610:813dcc80987e 475 (__HANDLE__)->Instance->CR1 &= (~SPI_CR1_SPE); \
mbed_official 610:813dcc80987e 476 UNUSED(tmpreg); \
mbed_official 610:813dcc80987e 477 } while(0)
mbed_official 610:813dcc80987e 478
mbed_official 610:813dcc80987e 479 /** @brief Clear the SPI OVR pending flag.
mbed_official 610:813dcc80987e 480 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 481 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 482 *
mbed_official 610:813dcc80987e 483 * @retval None
mbed_official 610:813dcc80987e 484 */
mbed_official 610:813dcc80987e 485 #define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__) \
mbed_official 610:813dcc80987e 486 do{ \
mbed_official 610:813dcc80987e 487 __IO uint32_t tmpreg; \
mbed_official 610:813dcc80987e 488 tmpreg = (__HANDLE__)->Instance->DR; \
mbed_official 610:813dcc80987e 489 tmpreg = (__HANDLE__)->Instance->SR; \
mbed_official 610:813dcc80987e 490 UNUSED(tmpreg); \
mbed_official 610:813dcc80987e 491 } while(0)
mbed_official 610:813dcc80987e 492
mbed_official 610:813dcc80987e 493 /** @brief Clear the SPI FRE pending flag.
mbed_official 610:813dcc80987e 494 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 495 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 496 *
mbed_official 610:813dcc80987e 497 * @retval None
mbed_official 610:813dcc80987e 498 */
mbed_official 610:813dcc80987e 499 #define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__) \
mbed_official 610:813dcc80987e 500 do{ \
mbed_official 610:813dcc80987e 501 __IO uint32_t tmpreg; \
mbed_official 610:813dcc80987e 502 tmpreg = (__HANDLE__)->Instance->SR; \
mbed_official 610:813dcc80987e 503 UNUSED(tmpreg); \
mbed_official 610:813dcc80987e 504 } while(0)
mbed_official 610:813dcc80987e 505
mbed_official 610:813dcc80987e 506 /** @brief Enable the SPI peripheral.
mbed_official 610:813dcc80987e 507 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 508 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 509 * @retval None
mbed_official 610:813dcc80987e 510 */
mbed_official 610:813dcc80987e 511 #define __HAL_SPI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_SPE)
mbed_official 610:813dcc80987e 512
mbed_official 610:813dcc80987e 513 /** @brief Disable the SPI peripheral.
mbed_official 610:813dcc80987e 514 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 515 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 516 * @retval None
mbed_official 610:813dcc80987e 517 */
mbed_official 610:813dcc80987e 518 #define __HAL_SPI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= (~SPI_CR1_SPE))
mbed_official 610:813dcc80987e 519
mbed_official 610:813dcc80987e 520 /**
mbed_official 610:813dcc80987e 521 * @}
mbed_official 610:813dcc80987e 522 */
mbed_official 610:813dcc80987e 523
mbed_official 610:813dcc80987e 524 /* Private macros --------------------------------------------------------*/
mbed_official 610:813dcc80987e 525 /** @defgroup SPI_Private_Macros SPI Private Macros
mbed_official 610:813dcc80987e 526 * @{
mbed_official 610:813dcc80987e 527 */
mbed_official 610:813dcc80987e 528
mbed_official 610:813dcc80987e 529 /** @brief Set the SPI transmit-only mode.
mbed_official 610:813dcc80987e 530 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 531 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 532 * @retval None
mbed_official 610:813dcc80987e 533 */
mbed_official 610:813dcc80987e 534 #define SPI_1LINE_TX(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_BIDIOE)
mbed_official 610:813dcc80987e 535
mbed_official 610:813dcc80987e 536 /** @brief Set the SPI receive-only mode.
mbed_official 610:813dcc80987e 537 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 538 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 539 * @retval None
mbed_official 610:813dcc80987e 540 */
mbed_official 610:813dcc80987e 541 #define SPI_1LINE_RX(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= (~SPI_CR1_BIDIOE))
mbed_official 610:813dcc80987e 542
mbed_official 610:813dcc80987e 543 /** @brief Reset the CRC calculation of the SPI.
mbed_official 610:813dcc80987e 544 * @param __HANDLE__: specifies the SPI Handle.
mbed_official 610:813dcc80987e 545 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
mbed_official 610:813dcc80987e 546 * @retval None
mbed_official 610:813dcc80987e 547 */
mbed_official 610:813dcc80987e 548 #define SPI_RESET_CRC(__HANDLE__) do{(__HANDLE__)->Instance->CR1 &= (uint16_t)(~SPI_CR1_CRCEN);\
mbed_official 610:813dcc80987e 549 (__HANDLE__)->Instance->CR1 |= SPI_CR1_CRCEN;}while(0)
mbed_official 610:813dcc80987e 550
mbed_official 610:813dcc80987e 551 #define IS_SPI_MODE(MODE) (((MODE) == SPI_MODE_SLAVE) || \
mbed_official 610:813dcc80987e 552 ((MODE) == SPI_MODE_MASTER))
mbed_official 610:813dcc80987e 553
mbed_official 610:813dcc80987e 554 #define IS_SPI_DIRECTION(MODE) (((MODE) == SPI_DIRECTION_2LINES) || \
mbed_official 610:813dcc80987e 555 ((MODE) == SPI_DIRECTION_2LINES_RXONLY) ||\
mbed_official 610:813dcc80987e 556 ((MODE) == SPI_DIRECTION_1LINE))
mbed_official 610:813dcc80987e 557
mbed_official 610:813dcc80987e 558 #define IS_SPI_DIRECTION_2LINES(MODE) ((MODE) == SPI_DIRECTION_2LINES)
mbed_official 610:813dcc80987e 559
mbed_official 610:813dcc80987e 560 #define IS_SPI_DIRECTION_2LINES_OR_1LINE(MODE) (((MODE) == SPI_DIRECTION_2LINES)|| \
mbed_official 610:813dcc80987e 561 ((MODE) == SPI_DIRECTION_1LINE))
mbed_official 610:813dcc80987e 562
mbed_official 610:813dcc80987e 563 #define IS_SPI_DATASIZE(DATASIZE) (((DATASIZE) == SPI_DATASIZE_16BIT) || \
mbed_official 610:813dcc80987e 564 ((DATASIZE) == SPI_DATASIZE_15BIT) || \
mbed_official 610:813dcc80987e 565 ((DATASIZE) == SPI_DATASIZE_14BIT) || \
mbed_official 610:813dcc80987e 566 ((DATASIZE) == SPI_DATASIZE_13BIT) || \
mbed_official 610:813dcc80987e 567 ((DATASIZE) == SPI_DATASIZE_12BIT) || \
mbed_official 610:813dcc80987e 568 ((DATASIZE) == SPI_DATASIZE_11BIT) || \
mbed_official 610:813dcc80987e 569 ((DATASIZE) == SPI_DATASIZE_10BIT) || \
mbed_official 610:813dcc80987e 570 ((DATASIZE) == SPI_DATASIZE_9BIT) || \
mbed_official 610:813dcc80987e 571 ((DATASIZE) == SPI_DATASIZE_8BIT) || \
mbed_official 610:813dcc80987e 572 ((DATASIZE) == SPI_DATASIZE_7BIT) || \
mbed_official 610:813dcc80987e 573 ((DATASIZE) == SPI_DATASIZE_6BIT) || \
mbed_official 610:813dcc80987e 574 ((DATASIZE) == SPI_DATASIZE_5BIT) || \
mbed_official 610:813dcc80987e 575 ((DATASIZE) == SPI_DATASIZE_4BIT))
mbed_official 610:813dcc80987e 576
mbed_official 610:813dcc80987e 577 #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_POLARITY_LOW) || \
mbed_official 610:813dcc80987e 578 ((CPOL) == SPI_POLARITY_HIGH))
mbed_official 610:813dcc80987e 579
mbed_official 610:813dcc80987e 580 #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_PHASE_1EDGE) || \
mbed_official 610:813dcc80987e 581 ((CPHA) == SPI_PHASE_2EDGE))
mbed_official 610:813dcc80987e 582
mbed_official 610:813dcc80987e 583 #define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_SOFT) || \
mbed_official 610:813dcc80987e 584 ((NSS) == SPI_NSS_HARD_INPUT) || \
mbed_official 610:813dcc80987e 585 ((NSS) == SPI_NSS_HARD_OUTPUT))
mbed_official 610:813dcc80987e 586
mbed_official 610:813dcc80987e 587 #define IS_SPI_NSSP(NSSP) (((NSSP) == SPI_NSS_PULSE_ENABLE) || \
mbed_official 610:813dcc80987e 588 ((NSSP) == SPI_NSS_PULSE_DISABLE))
mbed_official 610:813dcc80987e 589
mbed_official 610:813dcc80987e 590 #define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BAUDRATEPRESCALER_2) || \
mbed_official 610:813dcc80987e 591 ((PRESCALER) == SPI_BAUDRATEPRESCALER_4) || \
mbed_official 610:813dcc80987e 592 ((PRESCALER) == SPI_BAUDRATEPRESCALER_8) || \
mbed_official 610:813dcc80987e 593 ((PRESCALER) == SPI_BAUDRATEPRESCALER_16) || \
mbed_official 610:813dcc80987e 594 ((PRESCALER) == SPI_BAUDRATEPRESCALER_32) || \
mbed_official 610:813dcc80987e 595 ((PRESCALER) == SPI_BAUDRATEPRESCALER_64) || \
mbed_official 610:813dcc80987e 596 ((PRESCALER) == SPI_BAUDRATEPRESCALER_128) || \
mbed_official 610:813dcc80987e 597 ((PRESCALER) == SPI_BAUDRATEPRESCALER_256))
mbed_official 610:813dcc80987e 598
mbed_official 610:813dcc80987e 599 #define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FIRSTBIT_MSB) || \
mbed_official 610:813dcc80987e 600 ((BIT) == SPI_FIRSTBIT_LSB))
mbed_official 610:813dcc80987e 601
mbed_official 610:813dcc80987e 602 #define IS_SPI_TIMODE(MODE) (((MODE) == SPI_TIMODE_DISABLE) || \
mbed_official 610:813dcc80987e 603 ((MODE) == SPI_TIMODE_ENABLE))
mbed_official 610:813dcc80987e 604
mbed_official 610:813dcc80987e 605 #define IS_SPI_CRC_CALCULATION(CALCULATION) (((CALCULATION) == SPI_CRCCALCULATION_DISABLE) || \
mbed_official 610:813dcc80987e 606 ((CALCULATION) == SPI_CRCCALCULATION_ENABLE))
mbed_official 610:813dcc80987e 607
mbed_official 610:813dcc80987e 608 #define IS_SPI_CRC_LENGTH(LENGTH) (((LENGTH) == SPI_CRC_LENGTH_DATASIZE) ||\
mbed_official 610:813dcc80987e 609 ((LENGTH) == SPI_CRC_LENGTH_8BIT) || \
mbed_official 610:813dcc80987e 610 ((LENGTH) == SPI_CRC_LENGTH_16BIT))
mbed_official 610:813dcc80987e 611
mbed_official 610:813dcc80987e 612 #define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) (((POLYNOMIAL) >= 0x1) && ((POLYNOMIAL) <= 0xFFFF))
mbed_official 610:813dcc80987e 613
mbed_official 610:813dcc80987e 614
mbed_official 610:813dcc80987e 615 /**
mbed_official 610:813dcc80987e 616 * @}
mbed_official 610:813dcc80987e 617 */
mbed_official 610:813dcc80987e 618
mbed_official 610:813dcc80987e 619 /* Include SPI HAL Extended module */
mbed_official 610:813dcc80987e 620 #include "stm32l4xx_hal_spi_ex.h"
mbed_official 610:813dcc80987e 621
mbed_official 610:813dcc80987e 622 /* Exported functions --------------------------------------------------------*/
mbed_official 610:813dcc80987e 623 /** @addtogroup SPI_Exported_Functions
mbed_official 610:813dcc80987e 624 * @{
mbed_official 610:813dcc80987e 625 */
mbed_official 610:813dcc80987e 626
mbed_official 610:813dcc80987e 627 /* Initialization and de-initialization functions ****************************/
mbed_official 610:813dcc80987e 628 /** @addtogroup SPI_Exported_Functions_Group1
mbed_official 610:813dcc80987e 629 * @{
mbed_official 610:813dcc80987e 630 */
mbed_official 610:813dcc80987e 631 HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 632 HAL_StatusTypeDef HAL_SPI_DeInit (SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 633 void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 634 void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 635 /**
mbed_official 610:813dcc80987e 636 * @}
mbed_official 610:813dcc80987e 637 */
mbed_official 610:813dcc80987e 638
mbed_official 610:813dcc80987e 639 /* IO operation functions *****************************************************/
mbed_official 610:813dcc80987e 640 /** @addtogroup SPI_Exported_Functions_Group2
mbed_official 610:813dcc80987e 641 * @{
mbed_official 610:813dcc80987e 642 */
mbed_official 610:813dcc80987e 643 HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
mbed_official 610:813dcc80987e 644 HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
mbed_official 610:813dcc80987e 645 HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
mbed_official 610:813dcc80987e 646 HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
mbed_official 610:813dcc80987e 647 HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
mbed_official 610:813dcc80987e 648 HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
mbed_official 610:813dcc80987e 649 HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
mbed_official 610:813dcc80987e 650 HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
mbed_official 610:813dcc80987e 651 HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
mbed_official 610:813dcc80987e 652 HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 653 HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 654 HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 655
mbed_official 610:813dcc80987e 656 void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 657 void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 658 void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 659 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 660 void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 661 void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 662 void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 663 void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 664 /**
mbed_official 610:813dcc80987e 665 * @}
mbed_official 610:813dcc80987e 666 */
mbed_official 610:813dcc80987e 667
mbed_official 610:813dcc80987e 668 /* Peripheral State and Error functions ***************************************/
mbed_official 610:813dcc80987e 669 /** @addtogroup SPI_Exported_Functions_Group3
mbed_official 610:813dcc80987e 670 * @{
mbed_official 610:813dcc80987e 671 */
mbed_official 610:813dcc80987e 672 HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 673 uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi);
mbed_official 610:813dcc80987e 674 /**
mbed_official 610:813dcc80987e 675 * @}
mbed_official 610:813dcc80987e 676 */
mbed_official 610:813dcc80987e 677
mbed_official 610:813dcc80987e 678 /**
mbed_official 610:813dcc80987e 679 * @}
mbed_official 610:813dcc80987e 680 */
mbed_official 610:813dcc80987e 681
mbed_official 610:813dcc80987e 682 /**
mbed_official 610:813dcc80987e 683 * @}
mbed_official 610:813dcc80987e 684 */
mbed_official 610:813dcc80987e 685
mbed_official 610:813dcc80987e 686 /**
mbed_official 610:813dcc80987e 687 * @}
mbed_official 610:813dcc80987e 688 */
mbed_official 610:813dcc80987e 689
mbed_official 610:813dcc80987e 690 #ifdef __cplusplus
mbed_official 610:813dcc80987e 691 }
mbed_official 610:813dcc80987e 692 #endif
mbed_official 610:813dcc80987e 693
mbed_official 610:813dcc80987e 694 #endif /* __STM32L4xx_HAL_SPI_H */
mbed_official 610:813dcc80987e 695
mbed_official 610:813dcc80987e 696 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/