Fork of the official mbed C/C SDK provides the software platform and libraries to build your applications for RenBED.

Dependents:   1-RenBuggyTimed RenBED_RGB RenBED_RGB_PWM RenBED_RGB

Fork of mbed by mbed official

Committer:
elijahorr
Date:
Thu Apr 14 07:28:54 2016 +0000
Revision:
121:672067c3ada4
Parent:
107:4f6c30876dfa
.

Who changed what in which revision?

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