Modified version of the mbed library for use with the Nucleo boards.

Dependents:   EEPROMWrite Full-Project

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Sep 28 10:45:10 2015 +0100
Revision:
630:825f75ca301e
Parent:
441:d2c15dda23c1
Synchronized with git revision 54fbe4144faf309c37205a5d39fa665daa919f10

Full URL: https://github.com/mbedmicro/mbed/commit/54fbe4144faf309c37205a5d39fa665daa919f10/

NUCLEO_F031K6 : Add new target

Who changed what in which revision?

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