I2C_EEPROM

Committer:
jhon309
Date:
Thu Aug 13 00:23:16 2015 +0000
Revision:
0:ac8863619623
I2C

Who changed what in which revision?

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