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:
Kojto
Date:
Wed Nov 25 13:21:40 2015 +0000
Revision:
110:165afa46840b
Release 110  of the mbed library

Changes:
- new platforms - STM32F410R, DISCO_F429ZI, DISCO_F469NI
- Nucleo L476 - gcc and uvision template
- k22,k64f targets - ADC channels A addition
- EFM32 - bugfixes in sleep, serial and spi
- Delta DFCM NNN40 - pinnames update

Who changed what in which revision?

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