雄介 太田 / mbed

Fork of mbed by mbed official

Committer:
Kojto
Date:
Tue Feb 03 15:31:20 2015 +0000
Revision:
93:e188a91d3eaa
Release 93 of the mbed library

Main changes:

- Renesas RZ_A1H bugfixes - i2c, ticker
- new targets - Nucleo F303RE, Nucleo F070RB, BLE SMURFS,
Dragonfly 411RE,
- BusXXX - is connected method, plus operators addition
- LPC8xx - I2c fixes
- timestamp_t reverted to uint32_t
- RTX - fixes regarding stack (alignment, magic word)

Who changed what in which revision?

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