gr55xx_hal_spi.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_hal_spi.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of SPI HAL library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup HAL_DRIVER HAL Driver
43 * @{
44 */
45
46 /** @defgroup HAL_SPI SPI
47 * @brief SPI HAL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_SPI_H__
53 #define __GR55xx_HAL_SPI_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_spi.h"
61 #include "gr55xx_hal_def.h"
62
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_SPI_ENUMERATIONS Enumerations
65 * @{
66 */
67
68 /** @defgroup HAL_SPI_state HAL SPI state
69 * @{
70 */
71
72 /**
73 * @brief HAL SPI State Enumerations definition
74 */
75 typedef enum
76 {
77 HAL_SPI_STATE_RESET = 0x00, /**< Peripheral not initialized */
78 HAL_SPI_STATE_READY = 0x01, /**< Peripheral initialized and ready for use */
79 HAL_SPI_STATE_BUSY = 0x02, /**< An internal process is ongoing */
80 HAL_SPI_STATE_BUSY_TX = 0x12, /**< Data Transmission process is ongoing */
81 HAL_SPI_STATE_BUSY_RX = 0x22, /**< Data Reception process is ongoing */
82 HAL_SPI_STATE_BUSY_TX_RX = 0x32, /**< Data Transmission and Reception process is ongoing */
83 HAL_SPI_STATE_ABORT = 0x08, /**< Peripheral with abort request ongoing */
84 HAL_SPI_STATE_ERROR = 0x04 /**< Peripheral in error */
85
86 } hal_spi_state_t;
87
88 /** @} */
89
90 /** @} */
91
92 /** @addtogroup HAL_SPI_STRUCTURES Structures
93 * @{
94 */
95
96 /** @defgroup SPI_Configuration SPI Configuration
97 * @{
98 */
99
100 /**
101 * @brief SPI init Structure definition
102 */
103 typedef struct _spi_init
104 {
105 uint32_t data_size; /**< Specifies the SPI data size.
106 This parameter can be a value of @ref SPI_Data_Size */
107
108 uint32_t clock_polarity; /**< Specifies the serial clock steady state.
109 This parameter can be a value of @ref SPI_Clock_Polarity */
110
111 uint32_t clock_phase; /**< Specifies the clock active edge for the bit capture.
112 This parameter can be a value of @ref SPI_Clock_Phase */
113
114 uint32_t baudrate_prescaler; /**< Specifies the BaudRate prescaler value which will be
115 used to configure the transmit and receive SCK clock.
116 @note The communication clock is derived from the master
117 clock. The slave clock does not need to be set. */
118
119 uint32_t ti_mode; /**< Specifies if the TI mode is enabled or not.
120 This parameter can be a value of @ref SPI_TI_Mode */
121
122 uint32_t slave_select; /**< Specifies the slaves to be selected.
123 This parameter can be a value of @ref SPI_Slave_Select */
124 } spi_init_t;
125 /** @} */
126
127 /** @defgroup SPI_handle SPI handle
128 * @{
129 */
130
131 /**
132 * @brief SPI handle Structure definition
133 */
134 typedef struct _spi_handle
135 {
136 ssi_regs_t *p_instance; /**< SPI registers base address */
137
138 spi_init_t init; /**< SPI communication parameters */
139
140 uint8_t *p_tx_buffer; /**< Pointer to SPI Tx transfer Buffer */
141
142 __IO uint32_t tx_xfer_size; /**< SPI Tx Transfer size */
143
144 __IO uint32_t tx_xfer_count; /**< SPI Tx Transfer Counter */
145
146 uint8_t *p_rx_buffer; /**< Pointer to SPI Rx transfer Buffer */
147
148 __IO uint32_t rx_xfer_size; /**< SPI Rx Transfer size */
149
150 __IO uint32_t rx_xfer_count; /**< SPI Rx Transfer Counter */
151
152 void (*write_fifo)(struct _spi_handle *p_spi); /**< Pointer to SPI Tx transfer FIFO write function */
153
154 void (*read_fifo)(struct _spi_handle *p_spi); /**< Pointer to SPI Rx transfer FIFO read function */
155
156 void (*read_write_fifo)(struct _spi_handle *p_spi); /**< Pointer to SPI transfer FIFO read and write function */
157
158 dma_handle_t *p_dmatx; /**< SPI Tx DMA Handle parameters */
159
160 dma_handle_t *p_dmarx; /**< SPI Rx DMA Handle parameters */
161
162 __IO hal_lock_t lock; /**< Locking object */
163
164 __IO hal_spi_state_t state; /**< SPI communication state */
165
166 __IO uint32_t error_code; /**< SPI Error code */
167
168 uint32_t timeout; /**< Timeout for the SPI memory access */
169
170 #if defined(HAL_SPI_V2_MODULE_ENABLED)
171 uint32_t retention[9]; /**< SPI important register information. */
172 #else
173 uint32_t retention[8]; /**< SPI important register information. */
174 #endif
175 } spi_handle_t;
176 /** @} */
177
178 /** @} */
179
180 /** @addtogroup HAL_SPI_CALLBACK_STRUCTURES Callback Structures
181 * @{
182 */
183
184 /** @defgroup HAL_SPI_Callback Callback
185 * @{
186 */
187
188 /**
189 * @brief HAL_SPI Callback function definition
190 */
191
192 typedef struct _hal_spi_callback
193 {
194 void (*spi_msp_init)(spi_handle_t *p_spi); /**< SPI init MSP callback */
195 void (*spi_msp_deinit)(spi_handle_t *p_spi); /**< SPI de-init MSP callback */
196 void (*spi_error_callback)(spi_handle_t *p_spi); /**< SPI error callback */
197 void (*spi_abort_cplt_callback)(spi_handle_t *p_spi); /**< SPI abort completed callback */
198 void (*spi_rx_cplt_callback)(spi_handle_t *p_spi); /**< SPI rx transfer completed callback */
199 void (*spi_tx_cplt_callback)(spi_handle_t *p_spi); /**< SPI tx transfer completed callback */
200 void (*spi_tx_rx_cplt_callback)(spi_handle_t *p_spi); /**< SPI tx/rx transfer completed callback */
201 } hal_spi_callback_t;
202
203 /** @} */
204
205 /** @} */
206
207 /**
208 * @defgroup HAL_SPI_MACRO Defines
209 * @{
210 */
211
212 /* Exported constants --------------------------------------------------------*/
213 /** @defgroup SPI_Exported_Constants SPI Exported Constants
214 * @{
215 */
216
217 /** @defgroup SPI_Direction SPI Direction
218 * @{
219 */
220 #define SPI_DIRECTION_FULL_DUPLEX LL_SSI_FULL_DUPLEX /**< Full Duplex: Transmit & Receive */
221 #define SPI_DIRECTION_SIMPLEX_TX LL_SSI_SIMPLEX_TX /**< Simplex Tx: Transmit only */
222 #define SPI_DIRECTION_SIMPLEX_RX LL_SSI_SIMPLEX_RX /**< Simplex Rx: Receive only */
223 #define SPI_DIRECTION_READ_EEPROM LL_SSI_READ_EEPROM /**< Read EEPROM */
224 /** @} */
225
226 /** @defgroup SPI_Error_Code SPI Error Code
227 * @{
228 */
229 #define HAL_SPI_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
230 #define HAL_SPI_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
231 #define HAL_SPI_ERROR_TRANSFER ((uint32_t)0x00000002) /**< Transfer error */
232 #define HAL_SPI_ERROR_DMA ((uint32_t)0x00000004) /**< DMA transfer error */
233 #define HAL_SPI_ERROR_INVALID_PARAM ((uint32_t)0x00000008) /**< Invalid parameters error */
234 /** @} */
235
236 /** @defgroup SPI_Data_Size SPI Data Size
237 * @{
238 */
239 #define SPI_DATASIZE_4BIT LL_SSI_DATASIZE_4BIT /**< 4-bit serial data transfer */
240 #define SPI_DATASIZE_5BIT LL_SSI_DATASIZE_5BIT /**< 5-bit serial data transfer */
241 #define SPI_DATASIZE_6BIT LL_SSI_DATASIZE_6BIT /**< 6-bit serial data transfer */
242 #define SPI_DATASIZE_7BIT LL_SSI_DATASIZE_7BIT /**< 7-bit serial data transfer */
243 #define SPI_DATASIZE_8BIT LL_SSI_DATASIZE_8BIT /**< 8-bit serial data transfer */
244 #define SPI_DATASIZE_9BIT LL_SSI_DATASIZE_9BIT /**< 9-bit serial data transfer */
245 #define SPI_DATASIZE_10BIT LL_SSI_DATASIZE_10BIT /**< 10-bit serial data transfer */
246 #define SPI_DATASIZE_11BIT LL_SSI_DATASIZE_11BIT /**< 11-bit serial data transfer */
247 #define SPI_DATASIZE_12BIT LL_SSI_DATASIZE_12BIT /**< 12-bit serial data transfer */
248 #define SPI_DATASIZE_13BIT LL_SSI_DATASIZE_13BIT /**< 13-bit serial data transfer */
249 #define SPI_DATASIZE_14BIT LL_SSI_DATASIZE_14BIT /**< 14-bit serial data transfer */
250 #define SPI_DATASIZE_15BIT LL_SSI_DATASIZE_15BIT /**< 15-bit serial data transfer */
251 #define SPI_DATASIZE_16BIT LL_SSI_DATASIZE_16BIT /**< 16-bit serial data transfer */
252 #define SPI_DATASIZE_17BIT LL_SSI_DATASIZE_17BIT /**< 17-bit serial data transfer */
253 #define SPI_DATASIZE_18BIT LL_SSI_DATASIZE_18BIT /**< 18-bit serial data transfer */
254 #define SPI_DATASIZE_19BIT LL_SSI_DATASIZE_19BIT /**< 19-bit serial data transfer */
255 #define SPI_DATASIZE_20BIT LL_SSI_DATASIZE_20BIT /**< 20-bit serial data transfer */
256 #define SPI_DATASIZE_21BIT LL_SSI_DATASIZE_21BIT /**< 21-bit serial data transfer */
257 #define SPI_DATASIZE_22BIT LL_SSI_DATASIZE_22BIT /**< 22-bit serial data transfer */
258 #define SPI_DATASIZE_23BIT LL_SSI_DATASIZE_23BIT /**< 23-bit serial data transfer */
259 #define SPI_DATASIZE_24BIT LL_SSI_DATASIZE_24BIT /**< 24-bit serial data transfer */
260 #define SPI_DATASIZE_25BIT LL_SSI_DATASIZE_25BIT /**< 25-bit serial data transfer */
261 #define SPI_DATASIZE_26BIT LL_SSI_DATASIZE_26BIT /**< 26-bit serial data transfer */
262 #define SPI_DATASIZE_27BIT LL_SSI_DATASIZE_27BIT /**< 27-bit serial data transfer */
263 #define SPI_DATASIZE_28BIT LL_SSI_DATASIZE_28BIT /**< 28-bit serial data transfer */
264 #define SPI_DATASIZE_29BIT LL_SSI_DATASIZE_29BIT /**< 29-bit serial data transfer */
265 #define SPI_DATASIZE_30BIT LL_SSI_DATASIZE_30BIT /**< 30-bit serial data transfer */
266 #define SPI_DATASIZE_31BIT LL_SSI_DATASIZE_31BIT /**< 31-bit serial data transfer */
267 #define SPI_DATASIZE_32BIT LL_SSI_DATASIZE_32BIT /**< 32-bit serial data transfer */
268 /** @} */
269
270 /** @defgroup SPI_Clock_Polarity SPI Clock Polarity
271 * @{
272 */
273 #define SPI_POLARITY_LOW LL_SSI_SCPOL_LOW /**< Inactive state of CLK is low */
274 #define SPI_POLARITY_HIGH LL_SSI_SCPOL_HIGH /**< Inactive state of CLK is high */
275 /** @} */
276
277 /** @defgroup SPI_Clock_Phase SPI Clock Phase
278 * @{
279 */
280 #define SPI_PHASE_1EDGE LL_SSI_SCPHA_1EDGE /**< CLK toggles at start of first data bit */
281 #define SPI_PHASE_2EDGE LL_SSI_SCPHA_2EDGE /**< CLK toggles in middle of first data bit */
282 /** @} */
283
284 /** @defgroup SPI_TI_Mode SPI TI Mode
285 * @{
286 */
287 #define SPI_TIMODE_DISABLE ((uint32_t)0x00000000) /**< SPI TI mode disable */
288 #define SPI_TIMODE_ENABLE LL_SSI_PROTOCOL_TI /**< SPI TI mode enable */
289 /** @} */
290
291 /** @defgroup SPI_Slave_Select SPI Slave Select
292 * @{
293 */
294 #define SPI_SLAVE_SELECT_0 LL_SSI_SLAVE0 /**< SPIM Select Slave 0 */
295 #define SPI_SLAVE_SELECT_1 LL_SSI_SLAVE1 /**< SPIM Select Slave 1 */
296 #define SPI_SLAVE_SELECT_ALL (LL_SSI_SLAVE0 | LL_SSI_SLAVE1) /**< SPIM Select All Slave */
297 /** @} */
298
299 /** @defgroup SPI_FIFO_LEVEL_MAX SPI FIFO Level Max
300 * @{
301 */
302 #define SPI_TX_FIFO_LEVEL_MAX 8 /**< SPI TX FIFO Level Max Value */
303 #define SPI_RX_FIFO_LEVEL_MAX 8 /**< SPI RX FIFO Level Max Value */
304 /** @} */
305
306 /** @defgroup SPI_Flags_definition SPI Flags Definition
307 * @{
308 */
309 #define SPI_FLAG_DCOL LL_SSI_SR_DCOL /**< Data collision error flag */
310 #define SPI_FLAG_TXE LL_SSI_SR_TXE /**< Transmission error flag */
311 #define SPI_FLAG_RFF LL_SSI_SR_RFF /**< Rx FIFO full flag */
312 #define SPI_FLAG_RFNE LL_SSI_SR_RFNE /**< Rx FIFO not empty flag */
313 #define SPI_FLAG_TFE LL_SSI_SR_TFE /**< Tx FIFO empty flag */
314 #define SPI_FLAG_TFNF LL_SSI_SR_TFNF /**< Tx FIFO not full flag */
315 #define SPI_FLAG_BUSY LL_SSI_SR_BUSY /**< Busy flag */
316 /** @} */
317
318 /** @defgroup SPI_Interrupt_definition SPI Interrupt Definition
319 * @{
320 */
321 #define SPI_IT_MST LL_SSI_IS_MST /**< Multi-Master Contention Interrupt flag */
322 #define SPI_IT_RXF LL_SSI_IS_RXF /**< Receive FIFO Full Interrupt flag */
323 #define SPI_IT_RXO LL_SSI_IS_RXO /**< Receive FIFO Overflow Interrupt flag */
324 #define SPI_IT_RXU LL_SSI_IS_RXU /**< Receive FIFO Underflow Interrupt flag */
325 #define SPI_IT_TXO LL_SSI_IS_TXO /**< Transmit FIFO Overflow Interrupt flag */
326 #define SPI_IT_TXE LL_SSI_IS_TXE /**< Transmit FIFO Empty Interrupt flag */
327 /** @} */
328
329 /** @defgroup SPI_Timeout_definition SPI Timeout_definition
330 * @{
331 */
332 #define HAL_SPI_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000) /**< 5s */
333 /** @} */
334
335 /** @} */
336
337 /* Exported macro ------------------------------------------------------------*/
338 /** @defgroup SPI_Exported_Macros SPI Exported Macros
339 * @{
340 */
341
342 /** @brief Reset SPI handle states.
343 * @param __HANDLE__ SPI handle.
344 * @retval None
345 */
346 #define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_SPI_STATE_RESET)
347
348 /** @brief Enable the specified SPI peripheral.
349 * @param __HANDLE__ Specifies the SPI Handle.
350 * @retval None
351 */
352 #define __HAL_SPI_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->SSI_EN, SSI_SSIEN_EN)
353
354 /** @brief Disable the specified SPI peripheral.
355 * @param __HANDLE__ Specifies the SPI Handle.
356 * @retval None
357 */
358 #define __HAL_SPI_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->SSI_EN, SSI_SSIEN_EN)
359
360 /** @brief Enable the SPI DMA TX Request.
361 * @param __HANDLE__ Specifies the SPI Handle.
362 * @retval None
363 */
364 #define __HAL_SPI_ENABLE_DMATX(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->DMAC, SSI_DMAC_TDMAE)
365
366 /** @brief Enable the SPI DMA RX Request.
367 * @param __HANDLE__ Specifies the SPI Handle.
368 * @retval None
369 */
370 #define __HAL_SPI_ENABLE_DMARX(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->DMAC, SSI_DMAC_RDMAE)
371
372 /** @brief Disable the SPI DMA TX Request.
373 * @param __HANDLE__ Specifies the SPI Handle.
374 * @retval None
375 */
376 #define __HAL_SPI_DISABLE_DMATX(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->DMAC, SSI_DMAC_TDMAE)
377
378 /** @brief Disable the SPI DMA RX Request.
379 * @param __HANDLE__ Specifies the SPI Handle.
380 * @retval None
381 */
382 #define __HAL_SPI_DISABLE_DMARX(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->DMAC, SSI_DMAC_RDMAE)
383
384 /** @brief Enable the specified SPI interrupts.
385 * @param __HANDLE__ Specifies the SPI Handle.
386 * @param __INTERRUPT__ Specifies the interrupt source to enable.
387 * This parameter can be one of the following values:
388 * @arg @ref SPI_IT_MST Multi-Master Contention Interrupt enable
389 * @arg @ref SPI_IT_RXF Receive FIFO Full Interrupt enable
390 * @arg @ref SPI_IT_RXO Receive FIFO Overflow Interrupt enable
391 * @arg @ref SPI_IT_RXU Receive FIFO Underflow Interrupt enable
392 * @arg @ref SPI_IT_TXO Transmit FIFO Overflow Interrupt enable
393 * @arg @ref SPI_IT_TXE Transmit FIFO Empty Interrupt enable
394 * @retval None
395 */
396 #define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BITS((__HANDLE__)->p_instance->INTMASK, (__INTERRUPT__))
397
398 /** @brief Disable the specified SPI interrupts.
399 * @param __HANDLE__ Specifies the SPI handle.
400 * @param __INTERRUPT__ Specifies the interrupt source to disable.
401 * This parameter can be one of the following values:
402 * @arg @ref SPI_IT_MST Multi-Master Contention Interrupt enable
403 * @arg @ref SPI_IT_RXF Receive FIFO Full Interrupt enable
404 * @arg @ref SPI_IT_RXO Receive FIFO Overflow Interrupt enable
405 * @arg @ref SPI_IT_RXU Receive FIFO Underflow Interrupt enable
406 * @arg @ref SPI_IT_TXO Transmit FIFO Overflow Interrupt enable
407 * @arg @ref SPI_IT_TXE Transmit FIFO Empty Interrupt enable
408 * @retval None
409 */
410 #define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BITS((__HANDLE__)->p_instance->INTMASK, (__INTERRUPT__))
411
412 /** @brief Check whether the specified SPI interrupt source is enabled or not.
413 * @param __HANDLE__ Specifies the SPI Handle.
414 * @param __INTERRUPT__ Specifies the interrupt source to check.
415 * This parameter can be one of the following values:
416 * @arg @ref SPI_IT_MST Multi-Master Contention Interrupt enable
417 * @arg @ref SPI_IT_RXF Receive FIFO Full Interrupt enable
418 * @arg @ref SPI_IT_RXO Receive FIFO Overflow Interrupt enable
419 * @arg @ref SPI_IT_RXU Receive FIFO Underflow Interrupt enable
420 * @arg @ref SPI_IT_TXO Transmit FIFO Overflow Interrupt enable
421 * @arg @ref SPI_IT_TXE Transmit FIFO Empty Interrupt enable
422 * @retval The new state of __IT__ (TRUE or FALSE).
423 */
424 #define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (READ_BITS((__HANDLE__)->p_instance->INTSTAT, (__INTERRUPT__)) == (__INTERRUPT__))
425
426 /** @brief Check whether the specified SPI flag is set or not.
427 * @param __HANDLE__ Specifies the SPI Handle.
428 * @param __FLAG__ Specifies the flag to check.
429 * This parameter can be one of the following values:
430 * @arg @ref SPI_FLAG_DCOL Data collision error flag
431 * @arg @ref SPI_FLAG_TXE Transmission error flag
432 * @arg @ref SPI_FLAG_RFF Rx FIFO full flag
433 * @arg @ref SPI_FLAG_RFNE Rx FIFO not empty flag
434 * @arg @ref SPI_FLAG_TFE Tx FIFO empty flag
435 * @arg @ref SPI_FLAG_TFNF Tx FIFO not full flag
436 * @arg @ref SPI_FLAG_BUSY Busy flag
437 * @retval The new state of __FLAG__ (TRUE or FALSE).
438 */
439 #define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->STAT, (__FLAG__)) != 0) ? SET : RESET)
440
441 /** @brief Clear the specified SPI flag.
442 * @param __HANDLE__ Specifies the SPI Handle.
443 * @param __FLAG__ Specifies the flag to clear.
444 * This parameter can be one of the following values:
445 * @arg @ref SPI_FLAG_DCOL Data collision error flag
446 * @arg @ref SPI_FLAG_TXE Transmission error flag
447 * @arg @ref SPI_FLAG_RFF Rx FIFO full flag
448 * @arg @ref SPI_FLAG_RFNE Rx FIFO not empty flag
449 * @arg @ref SPI_FLAG_TFE Tx FIFO empty flag
450 * @arg @ref SPI_FLAG_TFNF Tx FIFO not full flag
451 * @arg @ref SPI_FLAG_BUSY Busy flag
452 * @retval None
453 */
454 #define __HAL_SPI_CLEAR_FLAG(__HANDLE__, __FLAG__) READ_BITS((__HANDLE__)->p_instance->STAT, (__FLAG__))
455
456 /** @} */
457
458 /* Private macros ------------------------------------------------------------*/
459 /** @defgroup SPI_Private_Macro SPI Private Macros
460 * @{
461 */
462
463 /** @brief Check if SPI Direction Mode is valid.
464 * @param __MODE__ SPI Direction Mode.
465 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
466 */
467 #define IS_SPI_DIRECTION(__MODE__) (((__MODE__) == SPI_DIRECTION_FULL_DUPLEX) || \
468 ((__MODE__) == SPI_DIRECTION_SIMPLEX_TX) || \
469 ((__MODE__) == SPI_DIRECTION_SIMPLEX_RX) || \
470 ((__MODE__) == SPI_DIRECTION_READ_EEPROM))
471
472 /** @brief Check if SPI Data Size is valid.
473 * @param __DATASIZE__ SPI Data Size.
474 * @retval SET (__DATASIZE__ is valid) or RESET (__DATASIZE__ is invalid)
475 */
476 #define IS_SPI_DATASIZE(__DATASIZE__) (((__DATASIZE__) >= SPI_DATASIZE_4BIT) && \
477 ((__DATASIZE__) <= SPI_DATASIZE_32BIT))
478
479 /** @brief Check if SPI Clock Polarity is valid.
480 * @param __CPOL__ SPI Clock Polarity.
481 * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
482 */
483 #define IS_SPI_CPOL(__CPOL__) (((__CPOL__) == SPI_POLARITY_LOW) || \
484 ((__CPOL__) == SPI_POLARITY_HIGH))
485
486 /** @brief Check if SPI Clock Phase is valid.
487 * @param __CPHA__ SPI Clock Phase.
488 * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
489 */
490 #define IS_SPI_CPHA(__CPHA__) (((__CPHA__) == SPI_PHASE_1EDGE) || \
491 ((__CPHA__) == SPI_PHASE_2EDGE))
492
493 /** @brief Check if SPI BaudRate Prescaler is valid.
494 * @param __PRESCALER__ SPI BaudRate Prescaler.
495 * @retval SET (__PRESCALER__ is valid) or RESET (__PRESCALER__ is invalid)
496 */
497 #define IS_SPI_BAUDRATE_PRESCALER(__PRESCALER__) ((__PRESCALER__) <= 0xFFFF)
498
499 /** @brief Check if SPI TI Mode is valid.
500 * @param __MODE__ SPI TI Mode.
501 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
502 */
503 #define IS_SPI_TIMODE(__MODE__) (((__MODE__) == SPI_TIMODE_DISABLE) || \
504 ((__MODE__) == SPI_TIMODE_ENABLE))
505
506 /** @brief Check if SPI Slave Select is valid.
507 * @param __SLAVE__ SPI Slave Select.
508 * @retval SET (__SLAVE__ is valid) or RESET (__SLAVE__ is invalid)
509 */
510 #define IS_SPI_SLAVE(__SLAVE__) (((__SLAVE__) == SPI_SLAVE_SELECT_0) || \
511 ((__SLAVE__) == SPI_SLAVE_SELECT_1) || \
512 ((__SLAVE__) == SPI_SLAVE_SELECT_ALL))
513
514 /** @brief Check if SPI Receive Sample Delay Value is valid.
515 * @param __DLY__ SPI Receive Sample Delay Value
516 * @retval SET (__DLY__ is valid) or RESET (__DLY__ is invalid)
517 */
518 #define IS_SPI_RX_SAMPLE_DLY(__DLY__) (((__DLY__) >= 0) && ((__DLY__) <= 7))
519
520
521 /** @brief Check if SPI FIFO Threshold is valid.
522 * @param __THR__ SPI FIFO Threshold.
523 * @retval SET (__THR__ is valid) or RESET (__THR__ is invalid)
524 */
525 #define IS_SPI_FIFO_THRESHOLD(__THR__) (((__THR__) >= 0) && ((__THR__) <= 7))
526
527 /** @} */
528
529 /** @} */
530
531 /* Exported functions --------------------------------------------------------*/
532 /** @addtogroup HAL_SPI_DRIVER_FUNCTIONS Functions
533 * @{
534 */
535
536 /** @defgroup SPI_Exported_Functions_Group1 Initialization and de-initialization functions
537 * @brief Initialization and de-initialization functions
538 *
539 @verbatim
540 ===============================================================================
541 ##### Initialization and de-initialization functions #####
542 ===============================================================================
543 [..] This subsection provides a set of functions allowing to initialize and
544 de-initialize the SPIx peripheral:
545
546 (+) User must implement hal_spi_msp_init() function in which he configures
547 all related peripherals resources (GPIO, DMA, IT and NVIC ).
548
549 (+) Call the function hal_spi_init() to configure the selected device with
550 the selected configuration:
551 (++) Direction
552 (++) Data Size
553 (++) Clock Polarity and Phase
554 (++) BaudRate Prescaler
555 (++) TIMode
556 (++) Slave Select
557
558 (+) Call the function hal_spi_deinit() to restore the default configuration
559 of the selected SPIx peripheral.
560
561 @endverbatim
562 * @{
563 */
564
565 /**
566 ****************************************************************************************
567 * @brief Initialize the SPI according to the specified parameters
568 * in the spi_init_t and initialize the associated handle.
569 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
570 * @retval ::HAL_OK: Operation is OK.
571 * @retval ::HAL_ERROR: Parameter error or operation not supported.
572 * @retval ::HAL_BUSY: Driver is busy.
573 * @retval ::HAL_TIMEOUT: Timeout occurred.
574 ****************************************************************************************
575 */
576 hal_status_t hal_spi_init(spi_handle_t *p_spi);
577
578 /**
579 ****************************************************************************************
580 * @brief De-initialize the SPI peripheral.
581 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
582 * @retval ::HAL_OK: Operation is OK.
583 * @retval ::HAL_ERROR: Parameter error or operation not supported.
584 * @retval ::HAL_BUSY: Driver is busy.
585 * @retval ::HAL_TIMEOUT: Timeout occurred.
586 ****************************************************************************************
587 */
588 hal_status_t hal_spi_deinit(spi_handle_t *p_spi);
589
590 /**
591 ****************************************************************************************
592 * @brief Initialize the SPI MSP.
593 * @note This function should not be modified. When the callback is needed,
594 the hal_spi_msp_deinit can be implemented in the user file.
595 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
596 ****************************************************************************************
597 */
598 void hal_spi_msp_init(spi_handle_t *p_spi);
599
600 /**
601 ****************************************************************************************
602 * @brief De-initialize the SPI MSP.
603 * @note This function should not be modified. When the callback is needed,
604 the hal_spi_msp_deinit can be implemented in the user file.
605 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
606 ****************************************************************************************
607 */
608 void hal_spi_msp_deinit(spi_handle_t *p_spi);
609
610 /** @} */
611
612 /** @defgroup SPI_Exported_Functions_Group2 IO operation functions
613 * @brief Data transfer functions
614 *
615 @verbatim
616 ==============================================================================
617 ##### IO operation functions #####
618 ===============================================================================
619 [..]
620 This subsection provides a set of functions allowing to manage the SPI
621 data transfer.
622
623 [..] The SPI supports master and slave mode:
624
625 (#) There are two modes of transfer:
626 (++) Blocking mode: The communication is performed in polling mode.
627 The HAL status of all data processing is returned by the same function
628 after finishing transfer.
629 (++) No-Blocking mode: The communication is performed using Interrupts
630 or DMA, These APIs return the HAL status.
631 The end of the data processing will be indicated through the
632 dedicated SPI IRQ when using Interrupt mode or the DMA IRQ when
633 using DMA mode.
634 The hal_spi_tx_cplt_callback(), hal_spi_rx_cplt_callback() and hal_spi_txrx_cplt_callback() user callbacks
635 will be executed respectively at the end of the transmit or Receive process
636 The hal_spi_error_callback() user callback will be executed when a communication error is detected.
637
638 (#) APIs provided for these 2 transfer modes (Blocking mode or Non blocking mode using either Interrupt or DMA)
639 exist for 1-Line (simplex) and 2-Line (full duplex) modes.
640
641 @endverbatim
642 * @{
643 */
644
645 /**
646 ****************************************************************************************
647 * @brief Transmit an amount of data in blocking mode.
648 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
649 * @param[in] p_data: Pointer to data buffer
650 * @param[in] length: Amount of data to be sent in bytes
651 * @param[in] timeout: Timeout duration
652 * @retval ::HAL_OK: Operation is OK.
653 * @retval ::HAL_ERROR: Parameter error or operation not supported.
654 * @retval ::HAL_BUSY: Driver is busy.
655 * @retval ::HAL_TIMEOUT: Timeout occurred.
656 ****************************************************************************************
657 */
658 hal_status_t hal_spi_transmit(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length, uint32_t timeout);
659
660 /**
661 ****************************************************************************************
662 * @brief Receive an amount of data in blocking mode.
663 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
664 * @param[out] p_data: Pointer to data buffer
665 * @param[in] length: Amount of data to be received in bytes
666 * @param[in] timeout: Timeout duration
667 * @retval ::HAL_OK: Operation is OK.
668 * @retval ::HAL_ERROR: Parameter error or operation not supported.
669 * @retval ::HAL_BUSY: Driver is busy.
670 * @retval ::HAL_TIMEOUT: Timeout occurred.
671 ****************************************************************************************
672 */
673 hal_status_t hal_spi_receive(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length, uint32_t timeout);
674
675 /**
676 ****************************************************************************************
677 * @brief Transmit and Receive an amount of data in blocking mode.
678 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
679 * @param[in] p_tx_data: Pointer to transmission data buffer
680 * @param[out] p_rx_data: Pointer to reception data buffer
681 * @param[in] length: Amount of data to be sent and received in bytes
682 * @param[in] timeout: Timeout duration
683 * @retval ::HAL_OK: Operation is OK.
684 * @retval ::HAL_ERROR: Parameter error or operation not supported.
685 * @retval ::HAL_BUSY: Driver is busy.
686 * @retval ::HAL_TIMEOUT: Timeout occurred.
687 ****************************************************************************************
688 */
689 hal_status_t hal_spi_transmit_receive(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length, uint32_t timeout);
690
691 /**
692 ****************************************************************************************
693 * @brief Read an amount of data from EEPROM in blocking mode.
694 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
695 * @param[in] p_tx_data: Pointer to transmission data buffer
696 * @param[out] p_rx_data: Pointer to reception data buffer
697 * @param[in] tx_number_data: Amount of data to be sent in bytes
698 * @param[in] rx_number_data: Amount of data to be received in bytes
699 * @param[in] timeout: Timeout duration
700 * @retval ::HAL_OK: Operation is OK.
701 * @retval ::HAL_ERROR: Parameter error or operation not supported.
702 * @retval ::HAL_BUSY: Driver is busy.
703 * @retval ::HAL_TIMEOUT: Timeout occurred.
704 ****************************************************************************************
705 */
706 hal_status_t hal_spi_read_eeprom(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data, uint32_t timeout);
707
708 /**
709 ****************************************************************************************
710 * @brief Transmit an amount of data in non-blocking mode with Interrupt.
711 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
712 * @param[in] p_data: Pointer to data buffer
713 * @param[in] length: Amount of data to be sent in bytes
714 * @retval ::HAL_OK: Operation is OK.
715 * @retval ::HAL_ERROR: Parameter error or operation not supported.
716 * @retval ::HAL_BUSY: Driver is busy.
717 * @retval ::HAL_TIMEOUT: Timeout occurred.
718 ****************************************************************************************
719 */
720 hal_status_t hal_spi_transmit_it(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length);
721
722 /**
723 ****************************************************************************************
724 * @brief Receive an amount of data in non-blocking mode with Interrupt.
725 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
726 * @param[out] p_data: Pointer to data buffer
727 * @param[in] length: Amount of data to be sent in bytes
728 * @retval ::HAL_OK: Operation is OK.
729 * @retval ::HAL_ERROR: Parameter error or operation not supported.
730 * @retval ::HAL_BUSY: Driver is busy.
731 * @retval ::HAL_TIMEOUT: Timeout occurred.
732 ****************************************************************************************
733 */
734 hal_status_t hal_spi_receive_it(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length);
735
736 /**
737 ****************************************************************************************
738 * @brief Transmit and Receive an amount of data in non-blocking mode with Interrupt.
739 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
740 * @param[in] p_tx_data: Pointer to transmission data buffer
741 * @param[out] p_rx_data: Pointer to reception data buffer
742 * @param[in] length: Amount of data to be sent and received in bytes
743 * @retval ::HAL_OK: Operation is OK.
744 * @retval ::HAL_ERROR: Parameter error or operation not supported.
745 * @retval ::HAL_BUSY: Driver is busy.
746 * @retval ::HAL_TIMEOUT: Timeout occurred.
747 ****************************************************************************************
748 */
749 hal_status_t hal_spi_transmit_receive_it(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length);
750
751 /**
752 ****************************************************************************************
753 * @brief Read an amount of data from EEPROM in non-blocking mode with Interrupt.
754 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
755 * @param[in] p_tx_data: Pointer to transmission data buffer
756 * @param[out] p_rx_data: Pointer to reception data buffer
757 * @param[in] tx_number_data: Amount of data to be sent in bytes
758 * @param[in] rx_number_data: Amount of data to be received in bytes
759 * @retval ::HAL_OK: Operation is OK.
760 * @retval ::HAL_ERROR: Parameter error or operation not supported.
761 * @retval ::HAL_BUSY: Driver is busy.
762 * @retval ::HAL_TIMEOUT: Timeout occurred.
763 ****************************************************************************************
764 */
765 hal_status_t hal_spi_read_eeprom_it(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data);
766
767 /**
768 ****************************************************************************************
769 * @brief Transmit an amount of data in non-blocking mode with DMA.
770 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
771 * @param[in] p_data: Pointer to data buffer
772 * @param[in] length: Amount of data to be sent in bytes, ranging between 0 and 4095.
773 * @retval ::HAL_OK: Operation is OK.
774 * @retval ::HAL_ERROR: Parameter error or operation not supported.
775 * @retval ::HAL_BUSY: Driver is busy.
776 * @retval ::HAL_TIMEOUT: Timeout occurred.
777 ****************************************************************************************
778 */
779 hal_status_t hal_spi_transmit_dma(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length);
780
781 /**
782 ****************************************************************************************
783 * @brief Receive an amount of data in non-blocking mode with DMA.
784 * @note In case of MASTER mode and SPI_DIRECTION_2LINES direction, p_dmatx shall be defined.
785 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
786 * @param[out] p_data: Pointer to data buffer
787 * @param[in] length: Amount of data to be sent in bytes, ranging between 0 and 4095.
788 * @retval ::HAL_OK: Operation is OK.
789 * @retval ::HAL_ERROR: Parameter error or operation not supported.
790 * @retval ::HAL_BUSY: Driver is busy.
791 * @retval ::HAL_TIMEOUT: Timeout occurred.
792 ****************************************************************************************
793 */
794 hal_status_t hal_spi_receive_dma(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length);
795
796 /**
797 ****************************************************************************************
798 * @brief Transmit and Receive an amount of data in non-blocking mode with DMA.
799 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
800 * @param[in] p_tx_data: Pointer to transmission data buffer
801 * @param[out] p_rx_data: Pointer to reception data buffer
802 * @param[in] length: Amount of data to be sent in bytes, ranging between 0 and 4095.
803 * @retval ::HAL_OK: Operation is OK.
804 * @retval ::HAL_ERROR: Parameter error or operation not supported.
805 * @retval ::HAL_BUSY: Driver is busy.
806 * @retval ::HAL_TIMEOUT: Timeout occurred.
807 ****************************************************************************************
808 */
809 hal_status_t hal_spi_transmit_receive_dma(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length);
810
811 /**
812 ****************************************************************************************
813 * @brief Read an amount of data from EEPROM in non-blocking mode with DMA.
814 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
815 * @param[in] p_tx_data: Pointer to transmission data buffer
816 * @param[out] p_rx_data: Pointer to reception data buffer
817 * @param[in] tx_number_data: Amount of data to be sent in bytes
818 * @param[in] rx_number_data: Amount of data to be received in bytes, ranging between 0 and 4095.
819 * @retval ::HAL_OK: Operation is OK.
820 * @retval ::HAL_ERROR: Parameter error or operation not supported.
821 * @retval ::HAL_BUSY: Driver is busy.
822 * @retval ::HAL_TIMEOUT: Timeout occurred.
823 ****************************************************************************************
824 */
825 hal_status_t hal_spi_read_eeprom_dma(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data);
826
827 /**
828 ****************************************************************************************
829 * @brief Abort ongoing transfer (blocking mode).
830 * @param[in] p_spi: SPI handle.
831 * @note This procedure could be used for aborting any ongoing transfer (Tx and Rx),
832 * started in Interrupt or DMA mode.
833 * This procedure performs following operations :
834 * - Disable SPI Interrupts (depending of transfer direction)
835 * - Disable the DMA transfer in the peripheral register (if enabled)
836 * - Abort DMA transfer by calling hal_dma_abort (in case of transfer in DMA mode)
837 * - Set handle State to READY
838 * @note This procedure is executed in blocking mode: when exiting function, Abort is considered as completed.
839 * @retval ::HAL_OK: Operation is OK.
840 * @retval ::HAL_ERROR: Parameter error or operation not supported.
841 * @retval ::HAL_BUSY: Driver is busy.
842 * @retval ::HAL_TIMEOUT: Timeout occurred.
843 ****************************************************************************************
844 */
845 hal_status_t hal_spi_abort(spi_handle_t *p_spi);
846
847 /**
848 ****************************************************************************************
849 * @brief Abort ongoing transfer (Interrupt mode).
850 * @param[in] p_spi: SPI handle.
851 * @note This procedure could be used for aborting any ongoing transfer (Tx and Rx),
852 * started in Interrupt or DMA mode.
853 * This procedure performs following operations :
854 * - Disable SPI Interrupts (depending of transfer direction)
855 * - Disable the DMA transfer in the peripheral register (if enabled)
856 * - Abort DMA transfer by calling hal_dma_abort_it (in case of transfer in DMA mode)
857 * - Set handle State to READY
858 * - At abort completion, call user abort complete callback
859 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
860 * considered as completed only when user abort complete callback is executed (not when exiting function).
861 * @retval ::HAL_OK: Operation is OK.
862 * @retval ::HAL_ERROR: Parameter error or operation not supported.
863 * @retval ::HAL_BUSY: Driver is busy.
864 * @retval ::HAL_TIMEOUT: Timeout occurred.
865 ****************************************************************************************
866 */
867 hal_status_t hal_spi_abort_it(spi_handle_t *p_spi);
868
869 /** @} */
870
871 /** @addtogroup SPI_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
872 * @brief IRQ Handler and Callbacks functions
873 * @{
874 */
875
876 /**
877 ****************************************************************************************
878 * @brief Handle SPI interrupt request.
879 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
880 ****************************************************************************************
881 */
882 void hal_spi_irq_handler(spi_handle_t *p_spi);
883
884 /**
885 ****************************************************************************************
886 * @brief Tx Transfer completed callback.
887 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
888 ****************************************************************************************
889 */
890 void hal_spi_tx_cplt_callback(spi_handle_t *p_spi);
891
892 /**
893 ****************************************************************************************
894 * @brief Rx Transfer completed callback.
895 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
896 ****************************************************************************************
897 */
898 void hal_spi_rx_cplt_callback(spi_handle_t *p_spi);
899
900 /**
901 ****************************************************************************************
902 * @brief Tx and Rx Transfer completed callback.
903 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
904 ****************************************************************************************
905 */
906 void hal_spi_tx_rx_cplt_callback(spi_handle_t *p_spi);
907
908 /**
909 ****************************************************************************************
910 * @brief SPI error callback.
911 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
912 ****************************************************************************************
913 */
914 void hal_spi_error_callback(spi_handle_t *p_spi);
915
916 /**
917 ****************************************************************************************
918 * @brief SPI Abort Completed callback.
919 * @param[in] p_spi: SPI handle.
920 ****************************************************************************************
921 */
922 void hal_spi_abort_cplt_callback(spi_handle_t *p_spi);
923
924 /** @} */
925
926 /** @defgroup SPI_Exported_Functions_Group3 Peripheral State and Errors functions
927 * @brief SPI control functions
928 *
929 @verbatim
930 ===============================================================================
931 ##### Peripheral State and Errors functions #####
932 ===============================================================================
933 [..]
934 This subsection provides a set of functions allowing to control the SPI.
935 (+) hal_spi_get_state() API can be helpful to check in run-time the state of the SPI peripheral
936 (+) hal_spi_get_error() check in run-time Errors occurring during communication
937 (+) hal_spi_set_timeout() set the timeout during internal process
938 (+) hal_spi_set_tx_fifo_threshold() set the TX FIFO Threshold
939 (+) hal_spi_set_rx_fifo_threshold() set the RX FIFO Threshold
940 (+) hal_spi_get_tx_fifo_threshold() get the TX FIFO Threshold
941 (+) hal_spi_get_rx_fifo_threshold() get the RX FIFO Threshold
942 @endverbatim
943 * @{
944 */
945
946 /**
947 ****************************************************************************************
948 * @brief Return the SPI handle state.
949 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
950 * @retval ::HAL_SPI_STATE_RESET: Peripheral not initialized.
951 * @retval ::HAL_SPI_STATE_READY: Peripheral initialized and ready for use.
952 * @retval ::HAL_SPI_STATE_BUSY: An internal process is ongoing.
953 * @retval ::HAL_SPI_STATE_BUSY_TX: Data Transmission process is ongoing.
954 * @retval ::HAL_SPI_STATE_BUSY_RX: Data Reception process is ongoing.
955 * @retval ::HAL_SPI_STATE_BUSY_TX_RX: Data Transmission and Reception process is ongoing.
956 * @retval ::HAL_SPI_STATE_ABORT: Peripheral with abort request ongoing.
957 * @retval ::HAL_SPI_STATE_ERROR: Peripheral in error.
958 ****************************************************************************************
959 */
960 hal_spi_state_t hal_spi_get_state(spi_handle_t *p_spi);
961
962 /**
963 ****************************************************************************************
964 * @brief Return the SPI error code.
965 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
966 * @return SPI error code in bitmap format
967 ****************************************************************************************
968 */
969 uint32_t hal_spi_get_error(spi_handle_t *p_spi);
970
971 /**
972 ****************************************************************************************
973 * @brief Set the SPI internal process timeout value.
974 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
975 * @param[in] timeout: Internal process timeout value.
976 ****************************************************************************************
977 */
978 void hal_spi_set_timeout(spi_handle_t *p_spi, uint32_t timeout);
979
980 /**
981 ****************************************************************************************
982 * @brief Set the TX FIFO threshold.
983 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
984 * @param[in] threshold: TX FIFO threshold value ranging bwtween 0x0U ~ 0x7U.
985 * @retval ::HAL_OK: Operation is OK.
986 * @retval ::HAL_ERROR: Parameter error or operation not supported.
987 * @retval ::HAL_BUSY: Driver is busy.
988 * @retval ::HAL_TIMEOUT: Timeout occurred.
989 ****************************************************************************************
990 */
991 hal_status_t hal_spi_set_tx_fifo_threshold(spi_handle_t *p_spi, uint32_t threshold);
992
993 /**
994 ****************************************************************************************
995 * @brief Set the RX FIFO threshold.
996 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
997 * @param[in] threshold: RX FIFO threshold value ranging bwtween 0x0U ~ 0x7U.
998 * @retval ::HAL_OK: Operation is OK.
999 * @retval ::HAL_ERROR: Parameter error or operation not supported.
1000 * @retval ::HAL_BUSY: Driver is busy.
1001 * @retval ::HAL_TIMEOUT: Timeout occurred.
1002 ****************************************************************************************
1003 */
1004 hal_status_t hal_spi_set_rx_fifo_threshold(spi_handle_t *p_spi, uint32_t threshold);
1005
1006 /**
1007 ****************************************************************************************
1008 * @brief Get the TX FIFO threshold.
1009 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
1010 * @return TX FIFO threshold
1011 ****************************************************************************************
1012 */
1013 uint32_t hal_spi_get_tx_fifo_threshold(spi_handle_t *p_spi);
1014
1015 /**
1016 ****************************************************************************************
1017 * @brief Get the RX FIFO threshold.
1018 * @param[in] p_spi: Pointer to an SPI handle which contains the configuration information for the specified SPI module.
1019 * @return RX FIFO threshold
1020 ****************************************************************************************
1021 */
1022 uint32_t hal_spi_get_rx_fifo_threshold(spi_handle_t *p_spi);
1023
1024 /**
1025 ****************************************************************************************
1026 * @brief Suspend some registers related to SPI configuration before sleep.
1027 * @param[in] p_spi: Pointer to a SPI handle which contains the configuration
1028 * information for the specified SPI module.
1029 * @retval ::HAL_OK: Operation is OK.
1030 * @retval ::HAL_ERROR: Parameter error or operation not supported.
1031 * @retval ::HAL_BUSY: Driver is busy.
1032 * @retval ::HAL_TIMEOUT: Timeout occurred.
1033 ****************************************************************************************
1034 */
1035 hal_status_t hal_spi_suspend_reg(spi_handle_t *p_spi);
1036
1037 /**
1038 ****************************************************************************************
1039 * @brief Restore some registers related to SPI configuration after sleep.
1040 * This function must be used in conjunction with the hal_spi_suspend_reg().
1041 * @param[in] p_spi: Pointer to a SPI handle which contains the configuration
1042 * information for the specified SPI module.
1043 * @retval ::HAL_OK: Operation is OK.
1044 * @retval ::HAL_ERROR: Parameter error or operation not supported.
1045 * @retval ::HAL_BUSY: Driver is busy.
1046 * @retval ::HAL_TIMEOUT: Timeout occurred.
1047 ****************************************************************************************
1048 */
1049 hal_status_t hal_spi_resume_reg(spi_handle_t *p_spi);
1050
1051
1052 /** @} */
1053
1054 /** @} */
1055
1056 #ifdef __cplusplus
1057 }
1058 #endif
1059
1060 #endif /* __GR55xx_HAL_SPI_H__ */
1061
1062 /** @} */
1063
1064 /** @} */
1065
1066 /** @} */
hal_spi_abort_cplt_callback
void hal_spi_abort_cplt_callback(spi_handle_t *p_spi)
SPI Abort Completed callback.
hal_spi_get_state
hal_spi_state_t hal_spi_get_state(spi_handle_t *p_spi)
Return the SPI handle state.
_hal_spi_callback::spi_rx_cplt_callback
void(* spi_rx_cplt_callback)(spi_handle_t *p_spi)
SPI rx transfer completed callback
Definition: gr55xx_hal_spi.h:198
HAL_SPI_STATE_READY
@ HAL_SPI_STATE_READY
Peripheral initialized and ready for use
Definition: gr55xx_hal_spi.h:78
_spi_handle
SPI handle Structure definition.
Definition: gr55xx_hal_spi.h:135
hal_spi_deinit
hal_status_t hal_spi_deinit(spi_handle_t *p_spi)
De-initialize the SPI peripheral.
_spi_init::ti_mode
uint32_t ti_mode
Specifies if the TI mode is enabled or not.
Definition: gr55xx_hal_spi.h:119
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
hal_spi_abort
hal_status_t hal_spi_abort(spi_handle_t *p_spi)
Abort ongoing transfer (blocking mode).
_hal_spi_callback::spi_abort_cplt_callback
void(* spi_abort_cplt_callback)(spi_handle_t *p_spi)
SPI abort completed callback
Definition: gr55xx_hal_spi.h:197
_hal_spi_callback::spi_tx_cplt_callback
void(* spi_tx_cplt_callback)(spi_handle_t *p_spi)
SPI tx transfer completed callback
Definition: gr55xx_hal_spi.h:199
hal_spi_callback_t
struct _hal_spi_callback hal_spi_callback_t
HAL_SPI Callback function definition.
hal_spi_error_callback
void hal_spi_error_callback(spi_handle_t *p_spi)
SPI error callback.
_spi_init::slave_select
uint32_t slave_select
Specifies the slaves to be selected.
Definition: gr55xx_hal_spi.h:122
_spi_handle::read_fifo
void(* read_fifo)(struct _spi_handle *p_spi)
Pointer to SPI Rx transfer FIFO read function
Definition: gr55xx_hal_spi.h:154
hal_spi_init
hal_status_t hal_spi_init(spi_handle_t *p_spi)
Initialize the SPI according to the specified parameters in the spi_init_t and initialize the associa...
_spi_handle::p_instance
ssi_regs_t * p_instance
SPI registers base address
Definition: gr55xx_hal_spi.h:136
hal_spi_get_tx_fifo_threshold
uint32_t hal_spi_get_tx_fifo_threshold(spi_handle_t *p_spi)
Get the TX FIFO threshold.
HAL_SPI_STATE_ERROR
@ HAL_SPI_STATE_ERROR
Peripheral in error
Definition: gr55xx_hal_spi.h:84
hal_spi_transmit_dma
hal_status_t hal_spi_transmit_dma(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length)
Transmit an amount of data in non-blocking mode with DMA.
hal_spi_transmit
hal_status_t hal_spi_transmit(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length, uint32_t timeout)
Transmit an amount of data in blocking mode.
hal_spi_read_eeprom_dma
hal_status_t hal_spi_read_eeprom_dma(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data)
Read an amount of data from EEPROM in non-blocking mode with DMA.
_spi_handle::p_tx_buffer
uint8_t * p_tx_buffer
Pointer to SPI Tx transfer Buffer.
Definition: gr55xx_hal_spi.h:140
_spi_init
SPI init Structure definition.
Definition: gr55xx_hal_spi.h:104
HAL_SPI_STATE_BUSY_TX
@ HAL_SPI_STATE_BUSY_TX
Data Transmission process is ongoing
Definition: gr55xx_hal_spi.h:80
_spi_handle::retention
uint32_t retention[8]
SPI important register information.
Definition: gr55xx_hal_spi.h:173
_spi_handle::tx_xfer_count
__IO uint32_t tx_xfer_count
SPI Tx Transfer Counter
Definition: gr55xx_hal_spi.h:144
hal_spi_receive_dma
hal_status_t hal_spi_receive_dma(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length)
Receive an amount of data in non-blocking mode with DMA.
hal_spi_tx_cplt_callback
void hal_spi_tx_cplt_callback(spi_handle_t *p_spi)
Tx Transfer completed callback.
hal_spi_read_eeprom
hal_status_t hal_spi_read_eeprom(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data, uint32_t timeout)
Read an amount of data from EEPROM in blocking mode.
hal_spi_state_t
hal_spi_state_t
HAL SPI State Enumerations definition.
Definition: gr55xx_hal_spi.h:76
hal_spi_rx_cplt_callback
void hal_spi_rx_cplt_callback(spi_handle_t *p_spi)
Rx Transfer completed callback.
_spi_handle::p_dmatx
dma_handle_t * p_dmatx
SPI Tx DMA Handle parameters
Definition: gr55xx_hal_spi.h:158
_spi_handle::timeout
uint32_t timeout
Timeout for the SPI memory access.
Definition: gr55xx_hal_spi.h:168
_spi_handle::p_rx_buffer
uint8_t * p_rx_buffer
Pointer to SPI Rx transfer Buffer.
Definition: gr55xx_hal_spi.h:146
_hal_spi_callback::spi_error_callback
void(* spi_error_callback)(spi_handle_t *p_spi)
SPI error callback
Definition: gr55xx_hal_spi.h:196
_spi_handle::error_code
__IO uint32_t error_code
SPI Error code
Definition: gr55xx_hal_spi.h:166
HAL_SPI_STATE_BUSY
@ HAL_SPI_STATE_BUSY
An internal process is ongoing
Definition: gr55xx_hal_spi.h:79
_spi_handle::rx_xfer_count
__IO uint32_t rx_xfer_count
SPI Rx Transfer Counter
Definition: gr55xx_hal_spi.h:150
hal_spi_irq_handler
void hal_spi_irq_handler(spi_handle_t *p_spi)
Handle SPI interrupt request.
_hal_spi_callback::spi_msp_init
void(* spi_msp_init)(spi_handle_t *p_spi)
SPI init MSP callback
Definition: gr55xx_hal_spi.h:194
hal_spi_suspend_reg
hal_status_t hal_spi_suspend_reg(spi_handle_t *p_spi)
Suspend some registers related to SPI configuration before sleep.
_hal_spi_callback::spi_tx_rx_cplt_callback
void(* spi_tx_rx_cplt_callback)(spi_handle_t *p_spi)
SPI tx/rx transfer completed callback
Definition: gr55xx_hal_spi.h:200
_spi_handle::tx_xfer_size
__IO uint32_t tx_xfer_size
SPI Tx Transfer size
Definition: gr55xx_hal_spi.h:142
hal_spi_resume_reg
hal_status_t hal_spi_resume_reg(spi_handle_t *p_spi)
Restore some registers related to SPI configuration after sleep.
_spi_handle::p_dmarx
dma_handle_t * p_dmarx
SPI Rx DMA Handle parameters
Definition: gr55xx_hal_spi.h:160
hal_spi_transmit_receive
hal_status_t hal_spi_transmit_receive(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length, uint32_t timeout)
Transmit and Receive an amount of data in blocking mode.
hal_spi_set_rx_fifo_threshold
hal_status_t hal_spi_set_rx_fifo_threshold(spi_handle_t *p_spi, uint32_t threshold)
Set the RX FIFO threshold.
hal_spi_get_rx_fifo_threshold
uint32_t hal_spi_get_rx_fifo_threshold(spi_handle_t *p_spi)
Get the RX FIFO threshold.
spi_handle_t
struct _spi_handle spi_handle_t
SPI handle Structure definition.
HAL_SPI_STATE_ABORT
@ HAL_SPI_STATE_ABORT
Peripheral with abort request ongoing
Definition: gr55xx_hal_spi.h:83
HAL_SPI_STATE_BUSY_RX
@ HAL_SPI_STATE_BUSY_RX
Data Reception process is ongoing
Definition: gr55xx_hal_spi.h:81
_spi_handle::init
spi_init_t init
SPI communication parameters
Definition: gr55xx_hal_spi.h:138
hal_spi_abort_it
hal_status_t hal_spi_abort_it(spi_handle_t *p_spi)
Abort ongoing transfer (Interrupt mode).
HAL_SPI_STATE_RESET
@ HAL_SPI_STATE_RESET
Peripheral not initialized
Definition: gr55xx_hal_spi.h:77
hal_spi_transmit_it
hal_status_t hal_spi_transmit_it(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length)
Transmit an amount of data in non-blocking mode with Interrupt.
hal_spi_receive_it
hal_status_t hal_spi_receive_it(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length)
Receive an amount of data in non-blocking mode with Interrupt.
HAL_SPI_STATE_BUSY_TX_RX
@ HAL_SPI_STATE_BUSY_TX_RX
Data Transmission and Reception process is ongoing
Definition: gr55xx_hal_spi.h:82
gr55xx_ll_spi.h
Header file containing functions prototypes of SPI LL library.
hal_spi_msp_deinit
void hal_spi_msp_deinit(spi_handle_t *p_spi)
De-initialize the SPI MSP.
hal_spi_receive
hal_status_t hal_spi_receive(spi_handle_t *p_spi, uint8_t *p_data, uint32_t length, uint32_t timeout)
Receive an amount of data in blocking mode.
spi_init_t
struct _spi_init spi_init_t
SPI init Structure definition.
_hal_spi_callback::spi_msp_deinit
void(* spi_msp_deinit)(spi_handle_t *p_spi)
SPI de-init MSP callback
Definition: gr55xx_hal_spi.h:195
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
_spi_init::clock_polarity
uint32_t clock_polarity
Specifies the serial clock steady state.
Definition: gr55xx_hal_spi.h:108
_spi_init::baudrate_prescaler
uint32_t baudrate_prescaler
Specifies the BaudRate prescaler value which will be used to configure the transmit and receive SCK c...
Definition: gr55xx_hal_spi.h:114
hal_spi_set_tx_fifo_threshold
hal_status_t hal_spi_set_tx_fifo_threshold(spi_handle_t *p_spi, uint32_t threshold)
Set the TX FIFO threshold.
_spi_handle::read_write_fifo
void(* read_write_fifo)(struct _spi_handle *p_spi)
Pointer to SPI transfer FIFO read and write function
Definition: gr55xx_hal_spi.h:156
hal_spi_msp_init
void hal_spi_msp_init(spi_handle_t *p_spi)
Initialize the SPI MSP.
_spi_handle::state
__IO hal_spi_state_t state
SPI communication state
Definition: gr55xx_hal_spi.h:164
hal_spi_tx_rx_cplt_callback
void hal_spi_tx_rx_cplt_callback(spi_handle_t *p_spi)
Tx and Rx Transfer completed callback.
_spi_handle::rx_xfer_size
__IO uint32_t rx_xfer_size
SPI Rx Transfer size
Definition: gr55xx_hal_spi.h:148
hal_spi_transmit_receive_dma
hal_status_t hal_spi_transmit_receive_dma(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length)
Transmit and Receive an amount of data in non-blocking mode with DMA.
hal_spi_read_eeprom_it
hal_status_t hal_spi_read_eeprom_it(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data)
Read an amount of data from EEPROM in non-blocking mode with Interrupt.
hal_spi_transmit_receive_it
hal_status_t hal_spi_transmit_receive_it(spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length)
Transmit and Receive an amount of data in non-blocking mode with Interrupt.
hal_spi_get_error
uint32_t hal_spi_get_error(spi_handle_t *p_spi)
Return the SPI error code.
_spi_init::clock_phase
uint32_t clock_phase
Specifies the clock active edge for the bit capture.
Definition: gr55xx_hal_spi.h:111
_spi_handle::lock
__IO hal_lock_t lock
Locking object
Definition: gr55xx_hal_spi.h:162
_hal_spi_callback
HAL_SPI Callback function definition.
Definition: gr55xx_hal_spi.h:193
_dma_handle
DMA handle Structure definition.
Definition: gr55xx_hal_dma.h:179
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
_spi_handle::write_fifo
void(* write_fifo)(struct _spi_handle *p_spi)
Pointer to SPI Tx transfer FIFO write function.
Definition: gr55xx_hal_spi.h:152
_spi_init::data_size
uint32_t data_size
Specifies the SPI data size.
Definition: gr55xx_hal_spi.h:105
hal_spi_set_timeout
void hal_spi_set_timeout(spi_handle_t *p_spi, uint32_t timeout)
Set the SPI internal process timeout value.