001
targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_spi.h@0:13413ea9a877, 2022-06-12 (annotated)
- Committer:
- ganlikun
- Date:
- Sun Jun 12 14:02:44 2022 +0000
- Revision:
- 0:13413ea9a877
00
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ganlikun | 0:13413ea9a877 | 1 | /** |
ganlikun | 0:13413ea9a877 | 2 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 3 | * @file stm32f4xx_hal_spi.h |
ganlikun | 0:13413ea9a877 | 4 | * @author MCD Application Team |
ganlikun | 0:13413ea9a877 | 5 | * @version V1.7.1 |
ganlikun | 0:13413ea9a877 | 6 | * @date 14-April-2017 |
ganlikun | 0:13413ea9a877 | 7 | * @brief Header file of SPI HAL module. |
ganlikun | 0:13413ea9a877 | 8 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 9 | * @attention |
ganlikun | 0:13413ea9a877 | 10 | * |
ganlikun | 0:13413ea9a877 | 11 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
ganlikun | 0:13413ea9a877 | 12 | * |
ganlikun | 0:13413ea9a877 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
ganlikun | 0:13413ea9a877 | 14 | * are permitted provided that the following conditions are met: |
ganlikun | 0:13413ea9a877 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
ganlikun | 0:13413ea9a877 | 16 | * this list of conditions and the following disclaimer. |
ganlikun | 0:13413ea9a877 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ganlikun | 0:13413ea9a877 | 18 | * this list of conditions and the following disclaimer in the documentation |
ganlikun | 0:13413ea9a877 | 19 | * and/or other materials provided with the distribution. |
ganlikun | 0:13413ea9a877 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
ganlikun | 0:13413ea9a877 | 21 | * may be used to endorse or promote products derived from this software |
ganlikun | 0:13413ea9a877 | 22 | * without specific prior written permission. |
ganlikun | 0:13413ea9a877 | 23 | * |
ganlikun | 0:13413ea9a877 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ganlikun | 0:13413ea9a877 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ganlikun | 0:13413ea9a877 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ganlikun | 0:13413ea9a877 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
ganlikun | 0:13413ea9a877 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ganlikun | 0:13413ea9a877 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
ganlikun | 0:13413ea9a877 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ganlikun | 0:13413ea9a877 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ganlikun | 0:13413ea9a877 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ganlikun | 0:13413ea9a877 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ganlikun | 0:13413ea9a877 | 34 | * |
ganlikun | 0:13413ea9a877 | 35 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 36 | */ |
ganlikun | 0:13413ea9a877 | 37 | |
ganlikun | 0:13413ea9a877 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 39 | #ifndef __STM32F4xx_HAL_SPI_H |
ganlikun | 0:13413ea9a877 | 40 | #define __STM32F4xx_HAL_SPI_H |
ganlikun | 0:13413ea9a877 | 41 | |
ganlikun | 0:13413ea9a877 | 42 | #ifdef __cplusplus |
ganlikun | 0:13413ea9a877 | 43 | extern "C" { |
ganlikun | 0:13413ea9a877 | 44 | #endif |
ganlikun | 0:13413ea9a877 | 45 | |
ganlikun | 0:13413ea9a877 | 46 | /* Includes ------------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 47 | #include "stm32f4xx_hal_def.h" |
ganlikun | 0:13413ea9a877 | 48 | |
ganlikun | 0:13413ea9a877 | 49 | /** @addtogroup STM32F4xx_HAL_Driver |
ganlikun | 0:13413ea9a877 | 50 | * @{ |
ganlikun | 0:13413ea9a877 | 51 | */ |
ganlikun | 0:13413ea9a877 | 52 | |
ganlikun | 0:13413ea9a877 | 53 | /** @addtogroup SPI |
ganlikun | 0:13413ea9a877 | 54 | * @{ |
ganlikun | 0:13413ea9a877 | 55 | */ |
ganlikun | 0:13413ea9a877 | 56 | |
ganlikun | 0:13413ea9a877 | 57 | /* Exported types ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 58 | /** @defgroup SPI_Exported_Types SPI Exported Types |
ganlikun | 0:13413ea9a877 | 59 | * @{ |
ganlikun | 0:13413ea9a877 | 60 | */ |
ganlikun | 0:13413ea9a877 | 61 | |
ganlikun | 0:13413ea9a877 | 62 | /** |
ganlikun | 0:13413ea9a877 | 63 | * @brief SPI Configuration Structure definition |
ganlikun | 0:13413ea9a877 | 64 | */ |
ganlikun | 0:13413ea9a877 | 65 | typedef struct |
ganlikun | 0:13413ea9a877 | 66 | { |
ganlikun | 0:13413ea9a877 | 67 | uint32_t Mode; /*!< Specifies the SPI operating mode. |
ganlikun | 0:13413ea9a877 | 68 | This parameter can be a value of @ref SPI_Mode */ |
ganlikun | 0:13413ea9a877 | 69 | |
ganlikun | 0:13413ea9a877 | 70 | uint32_t Direction; /*!< Specifies the SPI bidirectional mode state. |
ganlikun | 0:13413ea9a877 | 71 | This parameter can be a value of @ref SPI_Direction */ |
ganlikun | 0:13413ea9a877 | 72 | |
ganlikun | 0:13413ea9a877 | 73 | uint32_t DataSize; /*!< Specifies the SPI data size. |
ganlikun | 0:13413ea9a877 | 74 | This parameter can be a value of @ref SPI_Data_Size */ |
ganlikun | 0:13413ea9a877 | 75 | |
ganlikun | 0:13413ea9a877 | 76 | uint32_t CLKPolarity; /*!< Specifies the serial clock steady state. |
ganlikun | 0:13413ea9a877 | 77 | This parameter can be a value of @ref SPI_Clock_Polarity */ |
ganlikun | 0:13413ea9a877 | 78 | |
ganlikun | 0:13413ea9a877 | 79 | uint32_t CLKPhase; /*!< Specifies the clock active edge for the bit capture. |
ganlikun | 0:13413ea9a877 | 80 | This parameter can be a value of @ref SPI_Clock_Phase */ |
ganlikun | 0:13413ea9a877 | 81 | |
ganlikun | 0:13413ea9a877 | 82 | uint32_t NSS; /*!< Specifies whether the NSS signal is managed by |
ganlikun | 0:13413ea9a877 | 83 | hardware (NSS pin) or by software using the SSI bit. |
ganlikun | 0:13413ea9a877 | 84 | This parameter can be a value of @ref SPI_Slave_Select_management */ |
ganlikun | 0:13413ea9a877 | 85 | |
ganlikun | 0:13413ea9a877 | 86 | uint32_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be |
ganlikun | 0:13413ea9a877 | 87 | used to configure the transmit and receive SCK clock. |
ganlikun | 0:13413ea9a877 | 88 | This parameter can be a value of @ref SPI_BaudRate_Prescaler |
ganlikun | 0:13413ea9a877 | 89 | @note The communication clock is derived from the master |
ganlikun | 0:13413ea9a877 | 90 | clock. The slave clock does not need to be set. */ |
ganlikun | 0:13413ea9a877 | 91 | |
ganlikun | 0:13413ea9a877 | 92 | uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit. |
ganlikun | 0:13413ea9a877 | 93 | This parameter can be a value of @ref SPI_MSB_LSB_transmission */ |
ganlikun | 0:13413ea9a877 | 94 | |
ganlikun | 0:13413ea9a877 | 95 | uint32_t TIMode; /*!< Specifies if the TI mode is enabled or not. |
ganlikun | 0:13413ea9a877 | 96 | This parameter can be a value of @ref SPI_TI_mode */ |
ganlikun | 0:13413ea9a877 | 97 | |
ganlikun | 0:13413ea9a877 | 98 | uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not. |
ganlikun | 0:13413ea9a877 | 99 | This parameter can be a value of @ref SPI_CRC_Calculation */ |
ganlikun | 0:13413ea9a877 | 100 | |
ganlikun | 0:13413ea9a877 | 101 | uint32_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation. |
ganlikun | 0:13413ea9a877 | 102 | This parameter must be a number between Min_Data = 0 and Max_Data = 65535 */ |
ganlikun | 0:13413ea9a877 | 103 | }SPI_InitTypeDef; |
ganlikun | 0:13413ea9a877 | 104 | |
ganlikun | 0:13413ea9a877 | 105 | /** |
ganlikun | 0:13413ea9a877 | 106 | * @brief HAL SPI State structure definition |
ganlikun | 0:13413ea9a877 | 107 | */ |
ganlikun | 0:13413ea9a877 | 108 | typedef enum |
ganlikun | 0:13413ea9a877 | 109 | { |
ganlikun | 0:13413ea9a877 | 110 | HAL_SPI_STATE_RESET = 0x00U, /*!< Peripheral not Initialized */ |
ganlikun | 0:13413ea9a877 | 111 | HAL_SPI_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */ |
ganlikun | 0:13413ea9a877 | 112 | HAL_SPI_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */ |
ganlikun | 0:13413ea9a877 | 113 | HAL_SPI_STATE_BUSY_TX = 0x03U, /*!< Data Transmission process is ongoing */ |
ganlikun | 0:13413ea9a877 | 114 | HAL_SPI_STATE_BUSY_RX = 0x04U, /*!< Data Reception process is ongoing */ |
ganlikun | 0:13413ea9a877 | 115 | HAL_SPI_STATE_BUSY_TX_RX = 0x05U, /*!< Data Transmission and Reception process is ongoing */ |
ganlikun | 0:13413ea9a877 | 116 | HAL_SPI_STATE_ERROR = 0x06U /*!< SPI error state */ |
ganlikun | 0:13413ea9a877 | 117 | }HAL_SPI_StateTypeDef; |
ganlikun | 0:13413ea9a877 | 118 | |
ganlikun | 0:13413ea9a877 | 119 | /** |
ganlikun | 0:13413ea9a877 | 120 | * @brief SPI handle Structure definition |
ganlikun | 0:13413ea9a877 | 121 | */ |
ganlikun | 0:13413ea9a877 | 122 | typedef struct __SPI_HandleTypeDef |
ganlikun | 0:13413ea9a877 | 123 | { |
ganlikun | 0:13413ea9a877 | 124 | SPI_TypeDef *Instance; /* SPI registers base address */ |
ganlikun | 0:13413ea9a877 | 125 | |
ganlikun | 0:13413ea9a877 | 126 | SPI_InitTypeDef Init; /* SPI communication parameters */ |
ganlikun | 0:13413ea9a877 | 127 | |
ganlikun | 0:13413ea9a877 | 128 | uint8_t *pTxBuffPtr; /* Pointer to SPI Tx transfer Buffer */ |
ganlikun | 0:13413ea9a877 | 129 | |
ganlikun | 0:13413ea9a877 | 130 | uint16_t TxXferSize; /* SPI Tx Transfer size */ |
ganlikun | 0:13413ea9a877 | 131 | |
ganlikun | 0:13413ea9a877 | 132 | __IO uint16_t TxXferCount; /* SPI Tx Transfer Counter */ |
ganlikun | 0:13413ea9a877 | 133 | |
ganlikun | 0:13413ea9a877 | 134 | uint8_t *pRxBuffPtr; /* Pointer to SPI Rx transfer Buffer */ |
ganlikun | 0:13413ea9a877 | 135 | |
ganlikun | 0:13413ea9a877 | 136 | uint16_t RxXferSize; /* SPI Rx Transfer size */ |
ganlikun | 0:13413ea9a877 | 137 | |
ganlikun | 0:13413ea9a877 | 138 | __IO uint16_t RxXferCount; /* SPI Rx Transfer Counter */ |
ganlikun | 0:13413ea9a877 | 139 | |
ganlikun | 0:13413ea9a877 | 140 | void (*RxISR)(struct __SPI_HandleTypeDef * hspi); /* function pointer on Rx ISR */ |
ganlikun | 0:13413ea9a877 | 141 | |
ganlikun | 0:13413ea9a877 | 142 | void (*TxISR)(struct __SPI_HandleTypeDef * hspi); /* function pointer on Tx ISR */ |
ganlikun | 0:13413ea9a877 | 143 | |
ganlikun | 0:13413ea9a877 | 144 | DMA_HandleTypeDef *hdmatx; /* SPI Tx DMA Handle parameters */ |
ganlikun | 0:13413ea9a877 | 145 | |
ganlikun | 0:13413ea9a877 | 146 | DMA_HandleTypeDef *hdmarx; /* SPI Rx DMA Handle parameters */ |
ganlikun | 0:13413ea9a877 | 147 | |
ganlikun | 0:13413ea9a877 | 148 | HAL_LockTypeDef Lock; /* Locking object */ |
ganlikun | 0:13413ea9a877 | 149 | |
ganlikun | 0:13413ea9a877 | 150 | __IO HAL_SPI_StateTypeDef State; /* SPI communication state */ |
ganlikun | 0:13413ea9a877 | 151 | |
ganlikun | 0:13413ea9a877 | 152 | __IO uint32_t ErrorCode; /* SPI Error code */ |
ganlikun | 0:13413ea9a877 | 153 | |
ganlikun | 0:13413ea9a877 | 154 | }SPI_HandleTypeDef; |
ganlikun | 0:13413ea9a877 | 155 | |
ganlikun | 0:13413ea9a877 | 156 | /** |
ganlikun | 0:13413ea9a877 | 157 | * @} |
ganlikun | 0:13413ea9a877 | 158 | */ |
ganlikun | 0:13413ea9a877 | 159 | |
ganlikun | 0:13413ea9a877 | 160 | /* Exported constants --------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 161 | /** @defgroup SPI_Exported_Constants SPI Exported Constants |
ganlikun | 0:13413ea9a877 | 162 | * @{ |
ganlikun | 0:13413ea9a877 | 163 | */ |
ganlikun | 0:13413ea9a877 | 164 | |
ganlikun | 0:13413ea9a877 | 165 | /** @defgroup SPI_Error_Code SPI Error Code |
ganlikun | 0:13413ea9a877 | 166 | * @{ |
ganlikun | 0:13413ea9a877 | 167 | */ |
ganlikun | 0:13413ea9a877 | 168 | #define HAL_SPI_ERROR_NONE 0x00000000U /*!< No error */ |
ganlikun | 0:13413ea9a877 | 169 | #define HAL_SPI_ERROR_MODF 0x00000001U /*!< MODF error */ |
ganlikun | 0:13413ea9a877 | 170 | #define HAL_SPI_ERROR_CRC 0x00000002U /*!< CRC error */ |
ganlikun | 0:13413ea9a877 | 171 | #define HAL_SPI_ERROR_OVR 0x00000004U /*!< OVR error */ |
ganlikun | 0:13413ea9a877 | 172 | #define HAL_SPI_ERROR_FRE 0x00000008U /*!< FRE error */ |
ganlikun | 0:13413ea9a877 | 173 | #define HAL_SPI_ERROR_DMA 0x00000010U /*!< DMA transfer error */ |
ganlikun | 0:13413ea9a877 | 174 | #define HAL_SPI_ERROR_FLAG 0x00000020U /*!< Flag: RXNE,TXE, BSY */ |
ganlikun | 0:13413ea9a877 | 175 | /** |
ganlikun | 0:13413ea9a877 | 176 | * @} |
ganlikun | 0:13413ea9a877 | 177 | */ |
ganlikun | 0:13413ea9a877 | 178 | |
ganlikun | 0:13413ea9a877 | 179 | /** @defgroup SPI_Mode SPI Mode |
ganlikun | 0:13413ea9a877 | 180 | * @{ |
ganlikun | 0:13413ea9a877 | 181 | */ |
ganlikun | 0:13413ea9a877 | 182 | #define SPI_MODE_SLAVE 0x00000000U |
ganlikun | 0:13413ea9a877 | 183 | #define SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) |
ganlikun | 0:13413ea9a877 | 184 | /** |
ganlikun | 0:13413ea9a877 | 185 | * @} |
ganlikun | 0:13413ea9a877 | 186 | */ |
ganlikun | 0:13413ea9a877 | 187 | |
ganlikun | 0:13413ea9a877 | 188 | /** @defgroup SPI_Direction SPI Direction Mode |
ganlikun | 0:13413ea9a877 | 189 | * @{ |
ganlikun | 0:13413ea9a877 | 190 | */ |
ganlikun | 0:13413ea9a877 | 191 | #define SPI_DIRECTION_2LINES 0x00000000U |
ganlikun | 0:13413ea9a877 | 192 | #define SPI_DIRECTION_2LINES_RXONLY SPI_CR1_RXONLY |
ganlikun | 0:13413ea9a877 | 193 | #define SPI_DIRECTION_1LINE SPI_CR1_BIDIMODE |
ganlikun | 0:13413ea9a877 | 194 | /** |
ganlikun | 0:13413ea9a877 | 195 | * @} |
ganlikun | 0:13413ea9a877 | 196 | */ |
ganlikun | 0:13413ea9a877 | 197 | |
ganlikun | 0:13413ea9a877 | 198 | /** @defgroup SPI_Data_Size SPI Data Size |
ganlikun | 0:13413ea9a877 | 199 | * @{ |
ganlikun | 0:13413ea9a877 | 200 | */ |
ganlikun | 0:13413ea9a877 | 201 | #define SPI_DATASIZE_8BIT 0x00000000U |
ganlikun | 0:13413ea9a877 | 202 | #define SPI_DATASIZE_16BIT SPI_CR1_DFF |
ganlikun | 0:13413ea9a877 | 203 | /** |
ganlikun | 0:13413ea9a877 | 204 | * @} |
ganlikun | 0:13413ea9a877 | 205 | */ |
ganlikun | 0:13413ea9a877 | 206 | |
ganlikun | 0:13413ea9a877 | 207 | /** @defgroup SPI_Clock_Polarity SPI Clock Polarity |
ganlikun | 0:13413ea9a877 | 208 | * @{ |
ganlikun | 0:13413ea9a877 | 209 | */ |
ganlikun | 0:13413ea9a877 | 210 | #define SPI_POLARITY_LOW 0x00000000U |
ganlikun | 0:13413ea9a877 | 211 | #define SPI_POLARITY_HIGH SPI_CR1_CPOL |
ganlikun | 0:13413ea9a877 | 212 | /** |
ganlikun | 0:13413ea9a877 | 213 | * @} |
ganlikun | 0:13413ea9a877 | 214 | */ |
ganlikun | 0:13413ea9a877 | 215 | |
ganlikun | 0:13413ea9a877 | 216 | /** @defgroup SPI_Clock_Phase SPI Clock Phase |
ganlikun | 0:13413ea9a877 | 217 | * @{ |
ganlikun | 0:13413ea9a877 | 218 | */ |
ganlikun | 0:13413ea9a877 | 219 | #define SPI_PHASE_1EDGE 0x00000000U |
ganlikun | 0:13413ea9a877 | 220 | #define SPI_PHASE_2EDGE SPI_CR1_CPHA |
ganlikun | 0:13413ea9a877 | 221 | /** |
ganlikun | 0:13413ea9a877 | 222 | * @} |
ganlikun | 0:13413ea9a877 | 223 | */ |
ganlikun | 0:13413ea9a877 | 224 | |
ganlikun | 0:13413ea9a877 | 225 | /** @defgroup SPI_Slave_Select_management SPI Slave Select Management |
ganlikun | 0:13413ea9a877 | 226 | * @{ |
ganlikun | 0:13413ea9a877 | 227 | */ |
ganlikun | 0:13413ea9a877 | 228 | #define SPI_NSS_SOFT SPI_CR1_SSM |
ganlikun | 0:13413ea9a877 | 229 | #define SPI_NSS_HARD_INPUT 0x00000000U |
ganlikun | 0:13413ea9a877 | 230 | #define SPI_NSS_HARD_OUTPUT 0x00040000U |
ganlikun | 0:13413ea9a877 | 231 | /** |
ganlikun | 0:13413ea9a877 | 232 | * @} |
ganlikun | 0:13413ea9a877 | 233 | */ |
ganlikun | 0:13413ea9a877 | 234 | |
ganlikun | 0:13413ea9a877 | 235 | /** @defgroup SPI_BaudRate_Prescaler SPI BaudRate Prescaler |
ganlikun | 0:13413ea9a877 | 236 | * @{ |
ganlikun | 0:13413ea9a877 | 237 | */ |
ganlikun | 0:13413ea9a877 | 238 | #define SPI_BAUDRATEPRESCALER_2 0x00000000U |
ganlikun | 0:13413ea9a877 | 239 | #define SPI_BAUDRATEPRESCALER_4 0x00000008U |
ganlikun | 0:13413ea9a877 | 240 | #define SPI_BAUDRATEPRESCALER_8 0x00000010U |
ganlikun | 0:13413ea9a877 | 241 | #define SPI_BAUDRATEPRESCALER_16 0x00000018U |
ganlikun | 0:13413ea9a877 | 242 | #define SPI_BAUDRATEPRESCALER_32 0x00000020U |
ganlikun | 0:13413ea9a877 | 243 | #define SPI_BAUDRATEPRESCALER_64 0x00000028U |
ganlikun | 0:13413ea9a877 | 244 | #define SPI_BAUDRATEPRESCALER_128 0x00000030U |
ganlikun | 0:13413ea9a877 | 245 | #define SPI_BAUDRATEPRESCALER_256 0x00000038U |
ganlikun | 0:13413ea9a877 | 246 | /** |
ganlikun | 0:13413ea9a877 | 247 | * @} |
ganlikun | 0:13413ea9a877 | 248 | */ |
ganlikun | 0:13413ea9a877 | 249 | |
ganlikun | 0:13413ea9a877 | 250 | /** @defgroup SPI_MSB_LSB_transmission SPI MSB LSB Transmission |
ganlikun | 0:13413ea9a877 | 251 | * @{ |
ganlikun | 0:13413ea9a877 | 252 | */ |
ganlikun | 0:13413ea9a877 | 253 | #define SPI_FIRSTBIT_MSB 0x00000000U |
ganlikun | 0:13413ea9a877 | 254 | #define SPI_FIRSTBIT_LSB SPI_CR1_LSBFIRST |
ganlikun | 0:13413ea9a877 | 255 | /** |
ganlikun | 0:13413ea9a877 | 256 | * @} |
ganlikun | 0:13413ea9a877 | 257 | */ |
ganlikun | 0:13413ea9a877 | 258 | |
ganlikun | 0:13413ea9a877 | 259 | /** @defgroup SPI_TI_mode SPI TI Mode |
ganlikun | 0:13413ea9a877 | 260 | * @{ |
ganlikun | 0:13413ea9a877 | 261 | */ |
ganlikun | 0:13413ea9a877 | 262 | #define SPI_TIMODE_DISABLE 0x00000000U |
ganlikun | 0:13413ea9a877 | 263 | #define SPI_TIMODE_ENABLE SPI_CR2_FRF |
ganlikun | 0:13413ea9a877 | 264 | /** |
ganlikun | 0:13413ea9a877 | 265 | * @} |
ganlikun | 0:13413ea9a877 | 266 | */ |
ganlikun | 0:13413ea9a877 | 267 | |
ganlikun | 0:13413ea9a877 | 268 | /** @defgroup SPI_CRC_Calculation SPI CRC Calculation |
ganlikun | 0:13413ea9a877 | 269 | * @{ |
ganlikun | 0:13413ea9a877 | 270 | */ |
ganlikun | 0:13413ea9a877 | 271 | #define SPI_CRCCALCULATION_DISABLE 0x00000000U |
ganlikun | 0:13413ea9a877 | 272 | #define SPI_CRCCALCULATION_ENABLE SPI_CR1_CRCEN |
ganlikun | 0:13413ea9a877 | 273 | /** |
ganlikun | 0:13413ea9a877 | 274 | * @} |
ganlikun | 0:13413ea9a877 | 275 | */ |
ganlikun | 0:13413ea9a877 | 276 | |
ganlikun | 0:13413ea9a877 | 277 | /** @defgroup SPI_Interrupt_definition SPI Interrupt Definition |
ganlikun | 0:13413ea9a877 | 278 | * @{ |
ganlikun | 0:13413ea9a877 | 279 | */ |
ganlikun | 0:13413ea9a877 | 280 | #define SPI_IT_TXE SPI_CR2_TXEIE |
ganlikun | 0:13413ea9a877 | 281 | #define SPI_IT_RXNE SPI_CR2_RXNEIE |
ganlikun | 0:13413ea9a877 | 282 | #define SPI_IT_ERR SPI_CR2_ERRIE |
ganlikun | 0:13413ea9a877 | 283 | /** |
ganlikun | 0:13413ea9a877 | 284 | * @} |
ganlikun | 0:13413ea9a877 | 285 | */ |
ganlikun | 0:13413ea9a877 | 286 | |
ganlikun | 0:13413ea9a877 | 287 | /** @defgroup SPI_Flags_definition SPI Flags Definition |
ganlikun | 0:13413ea9a877 | 288 | * @{ |
ganlikun | 0:13413ea9a877 | 289 | */ |
ganlikun | 0:13413ea9a877 | 290 | #define SPI_FLAG_RXNE SPI_SR_RXNE /* SPI status flag: Rx buffer not empty flag */ |
ganlikun | 0:13413ea9a877 | 291 | #define SPI_FLAG_TXE SPI_SR_TXE /* SPI status flag: Tx buffer empty flag */ |
ganlikun | 0:13413ea9a877 | 292 | #define SPI_FLAG_BSY SPI_SR_BSY /* SPI status flag: Busy flag */ |
ganlikun | 0:13413ea9a877 | 293 | #define SPI_FLAG_CRCERR SPI_SR_CRCERR /* SPI Error flag: CRC error flag */ |
ganlikun | 0:13413ea9a877 | 294 | #define SPI_FLAG_MODF SPI_SR_MODF /* SPI Error flag: Mode fault flag */ |
ganlikun | 0:13413ea9a877 | 295 | #define SPI_FLAG_OVR SPI_SR_OVR /* SPI Error flag: Overrun flag */ |
ganlikun | 0:13413ea9a877 | 296 | #define SPI_FLAG_FRE SPI_SR_FRE /* SPI Error flag: TI mode frame format error flag */ |
ganlikun | 0:13413ea9a877 | 297 | /** |
ganlikun | 0:13413ea9a877 | 298 | * @} |
ganlikun | 0:13413ea9a877 | 299 | */ |
ganlikun | 0:13413ea9a877 | 300 | |
ganlikun | 0:13413ea9a877 | 301 | /** |
ganlikun | 0:13413ea9a877 | 302 | * @} |
ganlikun | 0:13413ea9a877 | 303 | */ |
ganlikun | 0:13413ea9a877 | 304 | |
ganlikun | 0:13413ea9a877 | 305 | /* Exported macro ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 306 | /** @defgroup SPI_Exported_Macros SPI Exported Macros |
ganlikun | 0:13413ea9a877 | 307 | * @{ |
ganlikun | 0:13413ea9a877 | 308 | */ |
ganlikun | 0:13413ea9a877 | 309 | |
ganlikun | 0:13413ea9a877 | 310 | /** @brief Reset SPI handle state. |
ganlikun | 0:13413ea9a877 | 311 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 312 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 313 | * @retval None |
ganlikun | 0:13413ea9a877 | 314 | */ |
ganlikun | 0:13413ea9a877 | 315 | #define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SPI_STATE_RESET) |
ganlikun | 0:13413ea9a877 | 316 | |
ganlikun | 0:13413ea9a877 | 317 | /** @brief Enable or disable the specified SPI interrupts. |
ganlikun | 0:13413ea9a877 | 318 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 319 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 320 | * @param __INTERRUPT__: specifies the interrupt source to enable or disable. |
ganlikun | 0:13413ea9a877 | 321 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 322 | * @arg SPI_IT_TXE: Tx buffer empty interrupt enable |
ganlikun | 0:13413ea9a877 | 323 | * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable |
ganlikun | 0:13413ea9a877 | 324 | * @arg SPI_IT_ERR: Error interrupt enable |
ganlikun | 0:13413ea9a877 | 325 | * @retval None |
ganlikun | 0:13413ea9a877 | 326 | */ |
ganlikun | 0:13413ea9a877 | 327 | #define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__)) |
ganlikun | 0:13413ea9a877 | 328 | #define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__))) |
ganlikun | 0:13413ea9a877 | 329 | |
ganlikun | 0:13413ea9a877 | 330 | /** @brief Check whether the specified SPI interrupt source is enabled or not. |
ganlikun | 0:13413ea9a877 | 331 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 332 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 333 | * @param __INTERRUPT__: specifies the SPI interrupt source to check. |
ganlikun | 0:13413ea9a877 | 334 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 335 | * @arg SPI_IT_TXE: Tx buffer empty interrupt enable |
ganlikun | 0:13413ea9a877 | 336 | * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable |
ganlikun | 0:13413ea9a877 | 337 | * @arg SPI_IT_ERR: Error interrupt enable |
ganlikun | 0:13413ea9a877 | 338 | * @retval The new state of __IT__ (TRUE or FALSE). |
ganlikun | 0:13413ea9a877 | 339 | */ |
ganlikun | 0:13413ea9a877 | 340 | #define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) |
ganlikun | 0:13413ea9a877 | 341 | |
ganlikun | 0:13413ea9a877 | 342 | /** @brief Check whether the specified SPI flag is set or not. |
ganlikun | 0:13413ea9a877 | 343 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 344 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 345 | * @param __FLAG__: specifies the flag to check. |
ganlikun | 0:13413ea9a877 | 346 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 347 | * @arg SPI_FLAG_RXNE: Receive buffer not empty flag |
ganlikun | 0:13413ea9a877 | 348 | * @arg SPI_FLAG_TXE: Transmit buffer empty flag |
ganlikun | 0:13413ea9a877 | 349 | * @arg SPI_FLAG_CRCERR: CRC error flag |
ganlikun | 0:13413ea9a877 | 350 | * @arg SPI_FLAG_MODF: Mode fault flag |
ganlikun | 0:13413ea9a877 | 351 | * @arg SPI_FLAG_OVR: Overrun flag |
ganlikun | 0:13413ea9a877 | 352 | * @arg SPI_FLAG_BSY: Busy flag |
ganlikun | 0:13413ea9a877 | 353 | * @arg SPI_FLAG_FRE: Frame format error flag |
ganlikun | 0:13413ea9a877 | 354 | * @retval The new state of __FLAG__ (TRUE or FALSE). |
ganlikun | 0:13413ea9a877 | 355 | */ |
ganlikun | 0:13413ea9a877 | 356 | #define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__)) |
ganlikun | 0:13413ea9a877 | 357 | |
ganlikun | 0:13413ea9a877 | 358 | /** @brief Clear the SPI CRCERR pending flag. |
ganlikun | 0:13413ea9a877 | 359 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 360 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 361 | * @retval None |
ganlikun | 0:13413ea9a877 | 362 | */ |
ganlikun | 0:13413ea9a877 | 363 | #define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR = (uint16_t)(~SPI_FLAG_CRCERR)) |
ganlikun | 0:13413ea9a877 | 364 | |
ganlikun | 0:13413ea9a877 | 365 | /** @brief Clear the SPI MODF pending flag. |
ganlikun | 0:13413ea9a877 | 366 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 367 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 368 | * @retval None |
ganlikun | 0:13413ea9a877 | 369 | */ |
ganlikun | 0:13413ea9a877 | 370 | #define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__) \ |
ganlikun | 0:13413ea9a877 | 371 | do{ \ |
ganlikun | 0:13413ea9a877 | 372 | __IO uint32_t tmpreg_modf = 0x00U; \ |
ganlikun | 0:13413ea9a877 | 373 | tmpreg_modf = (__HANDLE__)->Instance->SR; \ |
ganlikun | 0:13413ea9a877 | 374 | (__HANDLE__)->Instance->CR1 &= (~SPI_CR1_SPE); \ |
ganlikun | 0:13413ea9a877 | 375 | UNUSED(tmpreg_modf); \ |
ganlikun | 0:13413ea9a877 | 376 | } while(0U) |
ganlikun | 0:13413ea9a877 | 377 | |
ganlikun | 0:13413ea9a877 | 378 | /** @brief Clear the SPI OVR pending flag. |
ganlikun | 0:13413ea9a877 | 379 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 380 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 381 | * @retval None |
ganlikun | 0:13413ea9a877 | 382 | */ |
ganlikun | 0:13413ea9a877 | 383 | #define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__) \ |
ganlikun | 0:13413ea9a877 | 384 | do{ \ |
ganlikun | 0:13413ea9a877 | 385 | __IO uint32_t tmpreg_ovr = 0x00U; \ |
ganlikun | 0:13413ea9a877 | 386 | tmpreg_ovr = (__HANDLE__)->Instance->DR; \ |
ganlikun | 0:13413ea9a877 | 387 | tmpreg_ovr = (__HANDLE__)->Instance->SR; \ |
ganlikun | 0:13413ea9a877 | 388 | UNUSED(tmpreg_ovr); \ |
ganlikun | 0:13413ea9a877 | 389 | } while(0U) |
ganlikun | 0:13413ea9a877 | 390 | |
ganlikun | 0:13413ea9a877 | 391 | /** @brief Clear the SPI FRE pending flag. |
ganlikun | 0:13413ea9a877 | 392 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 393 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 394 | * @retval None |
ganlikun | 0:13413ea9a877 | 395 | */ |
ganlikun | 0:13413ea9a877 | 396 | #define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__) \ |
ganlikun | 0:13413ea9a877 | 397 | do{ \ |
ganlikun | 0:13413ea9a877 | 398 | __IO uint32_t tmpreg_fre = 0x00U; \ |
ganlikun | 0:13413ea9a877 | 399 | tmpreg_fre = (__HANDLE__)->Instance->SR; \ |
ganlikun | 0:13413ea9a877 | 400 | UNUSED(tmpreg_fre); \ |
ganlikun | 0:13413ea9a877 | 401 | }while(0U) |
ganlikun | 0:13413ea9a877 | 402 | |
ganlikun | 0:13413ea9a877 | 403 | /** @brief Enable the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 404 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 405 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 406 | * @retval None |
ganlikun | 0:13413ea9a877 | 407 | */ |
ganlikun | 0:13413ea9a877 | 408 | #define __HAL_SPI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_SPE) |
ganlikun | 0:13413ea9a877 | 409 | |
ganlikun | 0:13413ea9a877 | 410 | /** @brief Disable the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 411 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 412 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 413 | * @retval None |
ganlikun | 0:13413ea9a877 | 414 | */ |
ganlikun | 0:13413ea9a877 | 415 | #define __HAL_SPI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= (~SPI_CR1_SPE)) |
ganlikun | 0:13413ea9a877 | 416 | /** |
ganlikun | 0:13413ea9a877 | 417 | * @} |
ganlikun | 0:13413ea9a877 | 418 | */ |
ganlikun | 0:13413ea9a877 | 419 | |
ganlikun | 0:13413ea9a877 | 420 | /* Exported functions --------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 421 | /** @addtogroup SPI_Exported_Functions |
ganlikun | 0:13413ea9a877 | 422 | * @{ |
ganlikun | 0:13413ea9a877 | 423 | */ |
ganlikun | 0:13413ea9a877 | 424 | |
ganlikun | 0:13413ea9a877 | 425 | /** @addtogroup SPI_Exported_Functions_Group1 |
ganlikun | 0:13413ea9a877 | 426 | * @{ |
ganlikun | 0:13413ea9a877 | 427 | */ |
ganlikun | 0:13413ea9a877 | 428 | /* Initialization/de-initialization functions **********************************/ |
ganlikun | 0:13413ea9a877 | 429 | HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 430 | HAL_StatusTypeDef HAL_SPI_DeInit (SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 431 | void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 432 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 433 | /** |
ganlikun | 0:13413ea9a877 | 434 | * @} |
ganlikun | 0:13413ea9a877 | 435 | */ |
ganlikun | 0:13413ea9a877 | 436 | |
ganlikun | 0:13413ea9a877 | 437 | /** @addtogroup SPI_Exported_Functions_Group2 |
ganlikun | 0:13413ea9a877 | 438 | * @{ |
ganlikun | 0:13413ea9a877 | 439 | */ |
ganlikun | 0:13413ea9a877 | 440 | /* I/O operation functions *****************************************************/ |
ganlikun | 0:13413ea9a877 | 441 | HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
ganlikun | 0:13413ea9a877 | 442 | HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
ganlikun | 0:13413ea9a877 | 443 | HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout); |
ganlikun | 0:13413ea9a877 | 444 | HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 445 | HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 446 | HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 447 | HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 448 | HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 449 | HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 450 | HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 451 | HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 452 | HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 453 | /* Transfer Abort functions */ |
ganlikun | 0:13413ea9a877 | 454 | HAL_StatusTypeDef HAL_SPI_Abort(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 455 | HAL_StatusTypeDef HAL_SPI_Abort_IT(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 456 | |
ganlikun | 0:13413ea9a877 | 457 | void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 458 | void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 459 | void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 460 | void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 461 | void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 462 | void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 463 | void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 464 | void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 465 | void HAL_SPI_AbortCpltCallback(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 466 | /** |
ganlikun | 0:13413ea9a877 | 467 | * @} |
ganlikun | 0:13413ea9a877 | 468 | */ |
ganlikun | 0:13413ea9a877 | 469 | |
ganlikun | 0:13413ea9a877 | 470 | /** @addtogroup SPI_Exported_Functions_Group3 |
ganlikun | 0:13413ea9a877 | 471 | * @{ |
ganlikun | 0:13413ea9a877 | 472 | */ |
ganlikun | 0:13413ea9a877 | 473 | /* Peripheral State and Error functions ***************************************/ |
ganlikun | 0:13413ea9a877 | 474 | HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 475 | uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi); |
ganlikun | 0:13413ea9a877 | 476 | /** |
ganlikun | 0:13413ea9a877 | 477 | * @} |
ganlikun | 0:13413ea9a877 | 478 | */ |
ganlikun | 0:13413ea9a877 | 479 | |
ganlikun | 0:13413ea9a877 | 480 | /** |
ganlikun | 0:13413ea9a877 | 481 | * @} |
ganlikun | 0:13413ea9a877 | 482 | */ |
ganlikun | 0:13413ea9a877 | 483 | |
ganlikun | 0:13413ea9a877 | 484 | /* Private types -------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 485 | /* Private variables ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 486 | /* Private constants ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 487 | |
ganlikun | 0:13413ea9a877 | 488 | /* Private macros ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 489 | /** @defgroup SPI_Private_Macros SPI Private Macros |
ganlikun | 0:13413ea9a877 | 490 | * @{ |
ganlikun | 0:13413ea9a877 | 491 | */ |
ganlikun | 0:13413ea9a877 | 492 | |
ganlikun | 0:13413ea9a877 | 493 | /** @brief Set the SPI transmit-only mode. |
ganlikun | 0:13413ea9a877 | 494 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 495 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 496 | * @retval None |
ganlikun | 0:13413ea9a877 | 497 | */ |
ganlikun | 0:13413ea9a877 | 498 | #define SPI_1LINE_TX(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SPI_CR1_BIDIOE) |
ganlikun | 0:13413ea9a877 | 499 | |
ganlikun | 0:13413ea9a877 | 500 | /** @brief Set the SPI receive-only mode. |
ganlikun | 0:13413ea9a877 | 501 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 502 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 503 | * @retval None |
ganlikun | 0:13413ea9a877 | 504 | */ |
ganlikun | 0:13413ea9a877 | 505 | #define SPI_1LINE_RX(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= (~SPI_CR1_BIDIOE)) |
ganlikun | 0:13413ea9a877 | 506 | |
ganlikun | 0:13413ea9a877 | 507 | /** @brief Reset the CRC calculation of the SPI. |
ganlikun | 0:13413ea9a877 | 508 | * @param __HANDLE__: specifies the SPI Handle. |
ganlikun | 0:13413ea9a877 | 509 | * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. |
ganlikun | 0:13413ea9a877 | 510 | * @retval None |
ganlikun | 0:13413ea9a877 | 511 | */ |
ganlikun | 0:13413ea9a877 | 512 | #define SPI_RESET_CRC(__HANDLE__) do{(__HANDLE__)->Instance->CR1 &= (uint16_t)(~SPI_CR1_CRCEN);\ |
ganlikun | 0:13413ea9a877 | 513 | (__HANDLE__)->Instance->CR1 |= SPI_CR1_CRCEN;}while(0U) |
ganlikun | 0:13413ea9a877 | 514 | |
ganlikun | 0:13413ea9a877 | 515 | #define IS_SPI_MODE(MODE) (((MODE) == SPI_MODE_SLAVE) || \ |
ganlikun | 0:13413ea9a877 | 516 | ((MODE) == SPI_MODE_MASTER)) |
ganlikun | 0:13413ea9a877 | 517 | |
ganlikun | 0:13413ea9a877 | 518 | #define IS_SPI_DIRECTION(MODE) (((MODE) == SPI_DIRECTION_2LINES) || \ |
ganlikun | 0:13413ea9a877 | 519 | ((MODE) == SPI_DIRECTION_2LINES_RXONLY) || \ |
ganlikun | 0:13413ea9a877 | 520 | ((MODE) == SPI_DIRECTION_1LINE)) |
ganlikun | 0:13413ea9a877 | 521 | |
ganlikun | 0:13413ea9a877 | 522 | #define IS_SPI_DIRECTION_2LINES(MODE) ((MODE) == SPI_DIRECTION_2LINES) |
ganlikun | 0:13413ea9a877 | 523 | |
ganlikun | 0:13413ea9a877 | 524 | #define IS_SPI_DIRECTION_2LINES_OR_1LINE(MODE) (((MODE) == SPI_DIRECTION_2LINES) || \ |
ganlikun | 0:13413ea9a877 | 525 | ((MODE) == SPI_DIRECTION_1LINE)) |
ganlikun | 0:13413ea9a877 | 526 | |
ganlikun | 0:13413ea9a877 | 527 | #define IS_SPI_DATASIZE(DATASIZE) (((DATASIZE) == SPI_DATASIZE_16BIT) || \ |
ganlikun | 0:13413ea9a877 | 528 | ((DATASIZE) == SPI_DATASIZE_8BIT)) |
ganlikun | 0:13413ea9a877 | 529 | |
ganlikun | 0:13413ea9a877 | 530 | #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_POLARITY_LOW) || \ |
ganlikun | 0:13413ea9a877 | 531 | ((CPOL) == SPI_POLARITY_HIGH)) |
ganlikun | 0:13413ea9a877 | 532 | |
ganlikun | 0:13413ea9a877 | 533 | #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_PHASE_1EDGE) || \ |
ganlikun | 0:13413ea9a877 | 534 | ((CPHA) == SPI_PHASE_2EDGE)) |
ganlikun | 0:13413ea9a877 | 535 | |
ganlikun | 0:13413ea9a877 | 536 | #define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_SOFT) || \ |
ganlikun | 0:13413ea9a877 | 537 | ((NSS) == SPI_NSS_HARD_INPUT) || \ |
ganlikun | 0:13413ea9a877 | 538 | ((NSS) == SPI_NSS_HARD_OUTPUT)) |
ganlikun | 0:13413ea9a877 | 539 | |
ganlikun | 0:13413ea9a877 | 540 | #define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BAUDRATEPRESCALER_2) || \ |
ganlikun | 0:13413ea9a877 | 541 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_4) || \ |
ganlikun | 0:13413ea9a877 | 542 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_8) || \ |
ganlikun | 0:13413ea9a877 | 543 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_16) || \ |
ganlikun | 0:13413ea9a877 | 544 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_32) || \ |
ganlikun | 0:13413ea9a877 | 545 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_64) || \ |
ganlikun | 0:13413ea9a877 | 546 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_128) || \ |
ganlikun | 0:13413ea9a877 | 547 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_256)) |
ganlikun | 0:13413ea9a877 | 548 | |
ganlikun | 0:13413ea9a877 | 549 | #define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FIRSTBIT_MSB) || \ |
ganlikun | 0:13413ea9a877 | 550 | ((BIT) == SPI_FIRSTBIT_LSB)) |
ganlikun | 0:13413ea9a877 | 551 | |
ganlikun | 0:13413ea9a877 | 552 | #define IS_SPI_TIMODE(MODE) (((MODE) == SPI_TIMODE_DISABLE) || \ |
ganlikun | 0:13413ea9a877 | 553 | ((MODE) == SPI_TIMODE_ENABLE)) |
ganlikun | 0:13413ea9a877 | 554 | |
ganlikun | 0:13413ea9a877 | 555 | #define IS_SPI_CRC_CALCULATION(CALCULATION) (((CALCULATION) == SPI_CRCCALCULATION_DISABLE) || \ |
ganlikun | 0:13413ea9a877 | 556 | ((CALCULATION) == SPI_CRCCALCULATION_ENABLE)) |
ganlikun | 0:13413ea9a877 | 557 | |
ganlikun | 0:13413ea9a877 | 558 | #define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) (((POLYNOMIAL) >= 0x01U) && ((POLYNOMIAL) <= 0xFFFFU)) |
ganlikun | 0:13413ea9a877 | 559 | |
ganlikun | 0:13413ea9a877 | 560 | /** |
ganlikun | 0:13413ea9a877 | 561 | * @} |
ganlikun | 0:13413ea9a877 | 562 | */ |
ganlikun | 0:13413ea9a877 | 563 | |
ganlikun | 0:13413ea9a877 | 564 | /* Private functions ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 565 | /** @defgroup SPI_Private_Functions SPI Private Functions |
ganlikun | 0:13413ea9a877 | 566 | * @{ |
ganlikun | 0:13413ea9a877 | 567 | */ |
ganlikun | 0:13413ea9a877 | 568 | |
ganlikun | 0:13413ea9a877 | 569 | /** |
ganlikun | 0:13413ea9a877 | 570 | * @} |
ganlikun | 0:13413ea9a877 | 571 | */ |
ganlikun | 0:13413ea9a877 | 572 | |
ganlikun | 0:13413ea9a877 | 573 | /** |
ganlikun | 0:13413ea9a877 | 574 | * @} |
ganlikun | 0:13413ea9a877 | 575 | */ |
ganlikun | 0:13413ea9a877 | 576 | |
ganlikun | 0:13413ea9a877 | 577 | /** |
ganlikun | 0:13413ea9a877 | 578 | * @} |
ganlikun | 0:13413ea9a877 | 579 | */ |
ganlikun | 0:13413ea9a877 | 580 | |
ganlikun | 0:13413ea9a877 | 581 | #ifdef __cplusplus |
ganlikun | 0:13413ea9a877 | 582 | } |
ganlikun | 0:13413ea9a877 | 583 | #endif |
ganlikun | 0:13413ea9a877 | 584 | |
ganlikun | 0:13413ea9a877 | 585 | #endif /* __STM32F4xx_HAL_SPI_H */ |
ganlikun | 0:13413ea9a877 | 586 | |
ganlikun | 0:13413ea9a877 | 587 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
ganlikun | 0:13413ea9a877 | 588 |