Parcourir la source

CubeMx Pin Mapping
i2c / Spi Open
uart datacheck Function modified
Uart dataBufferCheck Added
Usart Define Added
Usart value Added
Main Usart DataCheck Added
Warning Removed
Uart ring buffer Added

june9152 il y a 6 ans
Parent
commit
66dcad7d89

+ 650 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_i2c.h

@@ -0,0 +1,650 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_i2c.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of I2C HAL module.
6
+  ******************************************************************************
7
+  * @attention
8
+  *
9
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10
+  *
11
+  * Redistribution and use in source and binary forms, with or without modification,
12
+  * are permitted provided that the following conditions are met:
13
+  *   1. Redistributions of source code must retain the above copyright notice,
14
+  *      this list of conditions and the following disclaimer.
15
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
16
+  *      this list of conditions and the following disclaimer in the documentation
17
+  *      and/or other materials provided with the distribution.
18
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
19
+  *      may be used to endorse or promote products derived from this software
20
+  *      without specific prior written permission.
21
+  *
22
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+  *
33
+  ******************************************************************************
34
+  */
35
+
36
+/* Define to prevent recursive inclusion -------------------------------------*/
37
+#ifndef __STM32F1xx_HAL_I2C_H
38
+#define __STM32F1xx_HAL_I2C_H
39
+
40
+#ifdef __cplusplus
41
+ extern "C" {
42
+#endif
43
+
44
+/* Includes ------------------------------------------------------------------*/
45
+#include "stm32f1xx_hal_def.h"
46
+
47
+/** @addtogroup STM32F1xx_HAL_Driver
48
+  * @{
49
+  */
50
+
51
+/** @addtogroup I2C
52
+  * @{
53
+  */
54
+
55
+/* Exported types ------------------------------------------------------------*/
56
+/** @defgroup I2C_Exported_Types I2C Exported Types
57
+  * @{
58
+  */
59
+   
60
+/**
61
+  * @brief  I2C Configuration Structure definition
62
+  */
63
+typedef struct
64
+{
65
+  uint32_t ClockSpeed;       /*!< Specifies the clock frequency.
66
+                                  This parameter must be set to a value lower than 400kHz */
67
+
68
+  uint32_t DutyCycle;        /*!< Specifies the I2C fast mode duty cycle.
69
+                                  This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */
70
+
71
+  uint32_t OwnAddress1;      /*!< Specifies the first device own address.
72
+                                  This parameter can be a 7-bit or 10-bit address. */
73
+
74
+  uint32_t AddressingMode;   /*!< Specifies if 7-bit or 10-bit addressing mode is selected.
75
+                                  This parameter can be a value of @ref I2C_addressing_mode */
76
+
77
+  uint32_t DualAddressMode;  /*!< Specifies if dual addressing mode is selected.
78
+                                  This parameter can be a value of @ref I2C_dual_addressing_mode */
79
+
80
+  uint32_t OwnAddress2;      /*!< Specifies the second device own address if dual addressing mode is selected
81
+                                  This parameter can be a 7-bit address. */
82
+
83
+  uint32_t GeneralCallMode;  /*!< Specifies if general call mode is selected.
84
+                                  This parameter can be a value of @ref I2C_general_call_addressing_mode */
85
+
86
+  uint32_t NoStretchMode;    /*!< Specifies if nostretch mode is selected.
87
+                                  This parameter can be a value of @ref I2C_nostretch_mode */
88
+
89
+}I2C_InitTypeDef;
90
+
91
+/**
92
+  * @brief  HAL State structure definition
93
+  * @note  HAL I2C State value coding follow below described bitmap :
94
+  *          b7-b6  Error information 
95
+  *             00 : No Error
96
+  *             01 : Abort (Abort user request on going)
97
+  *             10 : Timeout
98
+  *             11 : Error
99
+  *          b5     IP initilisation status
100
+  *             0  : Reset (IP not initialized)
101
+  *             1  : Init done (IP initialized and ready to use. HAL I2C Init function called)
102
+  *          b4     (not used)
103
+  *             x  : Should be set to 0
104
+  *          b3
105
+  *             0  : Ready or Busy (No Listen mode ongoing)
106
+  *             1  : Listen (IP in Address Listen Mode)
107
+  *          b2     Intrinsic process state
108
+  *             0  : Ready
109
+  *             1  : Busy (IP busy with some configuration or internal operations)
110
+  *          b1     Rx state
111
+  *             0  : Ready (no Rx operation ongoing)
112
+  *             1  : Busy (Rx operation ongoing)
113
+  *          b0     Tx state
114
+  *             0  : Ready (no Tx operation ongoing)
115
+  *             1  : Busy (Tx operation ongoing)
116
+  */
117
+typedef enum
118
+{
119
+  HAL_I2C_STATE_RESET             = 0x00U,   /*!< Peripheral is not yet Initialized         */
120
+  HAL_I2C_STATE_READY             = 0x20U,   /*!< Peripheral Initialized and ready for use  */
121
+  HAL_I2C_STATE_BUSY              = 0x24U,   /*!< An internal process is ongoing            */
122
+  HAL_I2C_STATE_BUSY_TX           = 0x21U,   /*!< Data Transmission process is ongoing      */
123
+  HAL_I2C_STATE_BUSY_RX           = 0x22U,   /*!< Data Reception process is ongoing         */
124
+  HAL_I2C_STATE_LISTEN            = 0x28U,   /*!< Address Listen Mode is ongoing            */
125
+  HAL_I2C_STATE_BUSY_TX_LISTEN    = 0x29U,   /*!< Address Listen Mode and Data Transmission
126
+                                                 process is ongoing                         */
127
+  HAL_I2C_STATE_BUSY_RX_LISTEN    = 0x2AU,   /*!< Address Listen Mode and Data Reception
128
+                                                 process is ongoing                         */
129
+  HAL_I2C_STATE_ABORT             = 0x60U,   /*!< Abort user request ongoing                */
130
+  HAL_I2C_STATE_TIMEOUT           = 0xA0U,   /*!< Timeout state                             */
131
+  HAL_I2C_STATE_ERROR             = 0xE0U    /*!< Error                                     */
132
+
133
+}HAL_I2C_StateTypeDef;
134
+
135
+/**
136
+  * @brief  HAL Mode structure definition
137
+  * @note  HAL I2C Mode value coding follow below described bitmap :
138
+  *          b7     (not used)
139
+  *             x  : Should be set to 0
140
+  *          b6
141
+  *             0  : None
142
+  *             1  : Memory (HAL I2C communication is in Memory Mode)
143
+  *          b5
144
+  *             0  : None
145
+  *             1  : Slave (HAL I2C communication is in Slave Mode)
146
+  *          b4
147
+  *             0  : None
148
+  *             1  : Master (HAL I2C communication is in Master Mode)
149
+  *          b3-b2-b1-b0  (not used)
150
+  *             xxxx : Should be set to 0000
151
+  */
152
+typedef enum
153
+{
154
+  HAL_I2C_MODE_NONE               = 0x00U,   /*!< No I2C communication on going             */
155
+  HAL_I2C_MODE_MASTER             = 0x10U,   /*!< I2C communication is in Master Mode       */
156
+  HAL_I2C_MODE_SLAVE              = 0x20U,   /*!< I2C communication is in Slave Mode        */
157
+  HAL_I2C_MODE_MEM                = 0x40U    /*!< I2C communication is in Memory Mode       */
158
+
159
+}HAL_I2C_ModeTypeDef;
160
+
161
+/**
162
+  * @brief  I2C handle Structure definition
163
+  */
164
+typedef struct
165
+{
166
+  I2C_TypeDef                *Instance;      /*!< I2C registers base address               */
167
+                                             
168
+  I2C_InitTypeDef            Init;           /*!< I2C communication parameters             */
169
+                                             
170
+  uint8_t                    *pBuffPtr;      /*!< Pointer to I2C transfer buffer           */
171
+                                             
172
+  uint16_t                   XferSize;       /*!< I2C transfer size                        */
173
+                                             
174
+  __IO uint16_t              XferCount;      /*!< I2C transfer counter                     */
175
+                                             
176
+  __IO uint32_t              XferOptions;    /*!< I2C transfer options                     */
177
+                                             
178
+  __IO uint32_t              PreviousState;  /*!< I2C communication Previous state and mode
179
+                                                  context for internal usage               */
180
+                                             
181
+  DMA_HandleTypeDef          *hdmatx;        /*!< I2C Tx DMA handle parameters             */
182
+                                             
183
+  DMA_HandleTypeDef          *hdmarx;        /*!< I2C Rx DMA handle parameters             */
184
+                                             
185
+  HAL_LockTypeDef            Lock;           /*!< I2C locking object                       */
186
+                                             
187
+  __IO HAL_I2C_StateTypeDef  State;          /*!< I2C communication state                  */
188
+                                             
189
+  __IO HAL_I2C_ModeTypeDef   Mode;           /*!< I2C communication mode                   */
190
+                                             
191
+  __IO uint32_t              ErrorCode;      /*!< I2C Error code                           */
192
+
193
+  __IO uint32_t              Devaddress;     /*!< I2C Target device address                */
194
+
195
+  __IO uint32_t              Memaddress;     /*!< I2C Target memory address                */
196
+
197
+  __IO uint32_t              MemaddSize;     /*!< I2C Target memory address  size          */
198
+
199
+  __IO uint32_t              EventCount;     /*!< I2C Event counter                        */
200
+	
201
+}I2C_HandleTypeDef;
202
+
203
+/**
204
+  * @}
205
+  */
206
+
207
+/* Exported constants --------------------------------------------------------*/
208
+/** @defgroup I2C_Exported_Constants I2C Exported Constants
209
+  * @{
210
+  */
211
+
212
+/** @defgroup I2C_Error_Code I2C Error Code
213
+  * @brief    I2C Error Code 
214
+  * @{
215
+  */ 
216
+#define HAL_I2C_ERROR_NONE       0x00000000U    /*!< No error           */
217
+#define HAL_I2C_ERROR_BERR       0x00000001U    /*!< BERR error         */
218
+#define HAL_I2C_ERROR_ARLO       0x00000002U    /*!< ARLO error         */
219
+#define HAL_I2C_ERROR_AF         0x00000004U    /*!< AF error           */
220
+#define HAL_I2C_ERROR_OVR        0x00000008U    /*!< OVR error          */
221
+#define HAL_I2C_ERROR_DMA        0x00000010U    /*!< DMA transfer error */
222
+#define HAL_I2C_ERROR_TIMEOUT    0x00000020U    /*!< Timeout Error      */
223
+/**
224
+  * @}
225
+  */
226
+
227
+/** @defgroup I2C_duty_cycle_in_fast_mode I2C duty cycle in fast mode
228
+  * @{
229
+  */
230
+#define I2C_DUTYCYCLE_2                 0x00000000U
231
+#define I2C_DUTYCYCLE_16_9              I2C_CCR_DUTY
232
+/**
233
+  * @}
234
+  */
235
+
236
+/** @defgroup I2C_addressing_mode I2C addressing mode
237
+  * @{
238
+  */
239
+#define I2C_ADDRESSINGMODE_7BIT         0x00004000U
240
+#define I2C_ADDRESSINGMODE_10BIT        (I2C_OAR1_ADDMODE | 0x00004000U)
241
+/**
242
+  * @}
243
+  */
244
+
245
+/** @defgroup I2C_dual_addressing_mode  I2C dual addressing mode
246
+  * @{
247
+  */
248
+#define I2C_DUALADDRESS_DISABLE        0x00000000U
249
+#define I2C_DUALADDRESS_ENABLE         I2C_OAR2_ENDUAL
250
+/**
251
+  * @}
252
+  */
253
+
254
+/** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode
255
+  * @{
256
+  */
257
+#define I2C_GENERALCALL_DISABLE        0x00000000U
258
+#define I2C_GENERALCALL_ENABLE         I2C_CR1_ENGC
259
+/**
260
+  * @}
261
+  */
262
+
263
+/** @defgroup I2C_nostretch_mode I2C nostretch mode
264
+  * @{
265
+  */
266
+#define I2C_NOSTRETCH_DISABLE          0x00000000U
267
+#define I2C_NOSTRETCH_ENABLE           I2C_CR1_NOSTRETCH
268
+/**
269
+  * @}
270
+  */
271
+
272
+/** @defgroup I2C_Memory_Address_Size I2C Memory Address Size
273
+  * @{
274
+  */
275
+#define I2C_MEMADD_SIZE_8BIT            0x00000001U
276
+#define I2C_MEMADD_SIZE_16BIT           0x00000010U
277
+/**
278
+  * @}
279
+  */
280
+
281
+/** @defgroup I2C_XferDirection_definition I2C XferDirection definition
282
+  * @{
283
+  */
284
+#define I2C_DIRECTION_RECEIVE           0x00000000U 
285
+#define I2C_DIRECTION_TRANSMIT          0x00000001U
286
+/**
287
+  * @}
288
+  */
289
+
290
+/** @defgroup I2C_XferOptions_definition I2C XferOptions definition
291
+  * @{
292
+  */
293
+#define  I2C_FIRST_FRAME                0x00000001U
294
+#define  I2C_NEXT_FRAME                 0x00000002U
295
+#define  I2C_FIRST_AND_LAST_FRAME       0x00000004U
296
+#define  I2C_LAST_FRAME                 0x00000008U
297
+/**
298
+  * @}
299
+  */
300
+
301
+/** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition
302
+  * @{
303
+  */
304
+#define I2C_IT_BUF                      I2C_CR2_ITBUFEN
305
+#define I2C_IT_EVT                      I2C_CR2_ITEVTEN
306
+#define I2C_IT_ERR                      I2C_CR2_ITERREN
307
+/**
308
+  * @}
309
+  */
310
+
311
+/** @defgroup I2C_Flag_definition I2C Flag definition
312
+  * @{
313
+  */
314
+#define I2C_FLAG_SMBALERT               0x00018000U
315
+#define I2C_FLAG_TIMEOUT                0x00014000U
316
+#define I2C_FLAG_PECERR                 0x00011000U
317
+#define I2C_FLAG_OVR                    0x00010800U
318
+#define I2C_FLAG_AF                     0x00010400U
319
+#define I2C_FLAG_ARLO                   0x00010200U
320
+#define I2C_FLAG_BERR                   0x00010100U
321
+#define I2C_FLAG_TXE                    0x00010080U
322
+#define I2C_FLAG_RXNE                   0x00010040U
323
+#define I2C_FLAG_STOPF                  0x00010010U
324
+#define I2C_FLAG_ADD10                  0x00010008U
325
+#define I2C_FLAG_BTF                    0x00010004U
326
+#define I2C_FLAG_ADDR                   0x00010002U
327
+#define I2C_FLAG_SB                     0x00010001U
328
+#define I2C_FLAG_DUALF                  0x00100080U
329
+#define I2C_FLAG_SMBHOST                0x00100040U
330
+#define I2C_FLAG_SMBDEFAULT             0x00100020U
331
+#define I2C_FLAG_GENCALL                0x00100010U
332
+#define I2C_FLAG_TRA                    0x00100004U
333
+#define I2C_FLAG_BUSY                   0x00100002U
334
+#define I2C_FLAG_MSL                    0x00100001U
335
+/**
336
+  * @}
337
+  */
338
+
339
+/**
340
+  * @}
341
+  */
342
+
343
+/* Exported macro ------------------------------------------------------------*/
344
+/** @defgroup I2C_Exported_Macros I2C Exported Macros
345
+  * @{
346
+  */
347
+
348
+/** @brief Reset I2C handle state
349
+  * @param  __HANDLE__: specifies the I2C Handle.
350
+  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
351
+  * @retval None
352
+  */
353
+#define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
354
+
355
+/** @brief  Enable or disable the specified I2C interrupts.
356
+  * @param  __HANDLE__: specifies the I2C Handle.
357
+  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
358
+  * @param  __INTERRUPT__: specifies the interrupt source to enable or disable.
359
+  *         This parameter can be one of the following values:
360
+  *            @arg I2C_IT_BUF: Buffer interrupt enable
361
+  *            @arg I2C_IT_EVT: Event interrupt enable
362
+  *            @arg I2C_IT_ERR: Error interrupt enable
363
+  * @retval None
364
+  */
365
+#define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
366
+#define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
367
+
368
+/** @brief  Checks if the specified I2C interrupt source is enabled or disabled.
369
+  * @param  __HANDLE__: specifies the I2C Handle.
370
+  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
371
+  * @param  __INTERRUPT__: specifies the I2C interrupt source to check.
372
+  *          This parameter can be one of the following values:
373
+  *            @arg I2C_IT_BUF: Buffer interrupt enable
374
+  *            @arg I2C_IT_EVT: Event interrupt enable
375
+  *            @arg I2C_IT_ERR: Error interrupt enable
376
+  * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
377
+  */
378
+#define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
379
+
380
+/** @brief  Checks whether the specified I2C flag is set or not.
381
+  * @param  __HANDLE__: specifies the I2C Handle.
382
+  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
383
+  * @param  __FLAG__: specifies the flag to check.
384
+  *         This parameter can be one of the following values:
385
+  *            @arg I2C_FLAG_SMBALERT: SMBus Alert flag
386
+  *            @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
387
+  *            @arg I2C_FLAG_PECERR: PEC error in reception flag
388
+  *            @arg I2C_FLAG_OVR: Overrun/Underrun flag
389
+  *            @arg I2C_FLAG_AF: Acknowledge failure flag
390
+  *            @arg I2C_FLAG_ARLO: Arbitration lost flag
391
+  *            @arg I2C_FLAG_BERR: Bus error flag
392
+  *            @arg I2C_FLAG_TXE: Data register empty flag
393
+  *            @arg I2C_FLAG_RXNE: Data register not empty flag
394
+  *            @arg I2C_FLAG_STOPF: Stop detection flag
395
+  *            @arg I2C_FLAG_ADD10: 10-bit header sent flag
396
+  *            @arg I2C_FLAG_BTF: Byte transfer finished flag
397
+  *            @arg I2C_FLAG_ADDR: Address sent flag
398
+  *                                Address matched flag
399
+  *            @arg I2C_FLAG_SB: Start bit flag
400
+  *            @arg I2C_FLAG_DUALF: Dual flag
401
+  *            @arg I2C_FLAG_SMBHOST: SMBus host header
402
+  *            @arg I2C_FLAG_SMBDEFAULT: SMBus default header
403
+  *            @arg I2C_FLAG_GENCALL: General call header flag
404
+  *            @arg I2C_FLAG_TRA: Transmitter/Receiver flag
405
+  *            @arg I2C_FLAG_BUSY: Bus busy flag
406
+  *            @arg I2C_FLAG_MSL: Master/Slave flag
407
+  * @retval The new state of __FLAG__ (TRUE or FALSE).
408
+  */
409
+#define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \
410
+                                                 ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)))
411
+
412
+/** @brief  Clears the I2C pending flags which are cleared by writing 0 in a specific bit.
413
+  * @param  __HANDLE__: specifies the I2C Handle.
414
+  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
415
+  * @param  __FLAG__: specifies the flag to clear.
416
+  *         This parameter can be any combination of the following values:
417
+  *            @arg I2C_FLAG_SMBALERT: SMBus Alert flag
418
+  *            @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
419
+  *            @arg I2C_FLAG_PECERR: PEC error in reception flag
420
+  *            @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
421
+  *            @arg I2C_FLAG_AF: Acknowledge failure flag
422
+  *            @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
423
+  *            @arg I2C_FLAG_BERR: Bus error flag
424
+  * @retval None
425
+  */
426
+#define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & I2C_FLAG_MASK))
427
+
428
+/** @brief  Clears the I2C ADDR pending flag.
429
+  * @param  __HANDLE__: specifies the I2C Handle.
430
+  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
431
+  * @retval None
432
+  */
433
+#define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__)    \
434
+  do{                                           \
435
+    __IO uint32_t tmpreg = 0x00U;               \
436
+    tmpreg = (__HANDLE__)->Instance->SR1;       \
437
+    tmpreg = (__HANDLE__)->Instance->SR2;       \
438
+    UNUSED(tmpreg);                             \
439
+  } while(0U)
440
+
441
+/** @brief  Clears the I2C STOPF pending flag.
442
+  * @param  __HANDLE__: specifies the I2C Handle.
443
+  *         This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
444
+  * @retval None
445
+  */
446
+#define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__)    \
447
+  do{                                           \
448
+    __IO uint32_t tmpreg = 0x00U;               \
449
+    tmpreg = (__HANDLE__)->Instance->SR1;       \
450
+    (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE;  \
451
+    UNUSED(tmpreg);                             \
452
+  } while(0U)
453
+    
454
+/** @brief  Enable the I2C peripheral.
455
+  * @param  __HANDLE__: specifies the I2C Handle.
456
+  *         This parameter can be I2Cx where x: 1 or 2  to select the I2C peripheral.
457
+  * @retval None
458
+  */
459
+#define __HAL_I2C_ENABLE(__HANDLE__)                             ((__HANDLE__)->Instance->CR1 |=  I2C_CR1_PE)
460
+
461
+/** @brief  Disable the I2C peripheral.
462
+  * @param  __HANDLE__: specifies the I2C Handle.
463
+  *         This parameter can be I2Cx where x: 1 or 2  to select the I2C peripheral.
464
+  * @retval None
465
+  */
466
+#define __HAL_I2C_DISABLE(__HANDLE__)                            ((__HANDLE__)->Instance->CR1 &=  ~I2C_CR1_PE)
467
+
468
+/**
469
+  * @}
470
+  */
471
+
472
+/* Exported functions --------------------------------------------------------*/
473
+/** @addtogroup I2C_Exported_Functions
474
+  * @{
475
+  */
476
+
477
+/** @addtogroup I2C_Exported_Functions_Group1
478
+  * @{
479
+  */
480
+/* Initialization/de-initialization functions  **********************************/
481
+HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c);
482
+HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c);
483
+void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c);
484
+void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c);
485
+/**
486
+  * @}
487
+  */
488
+
489
+/** @addtogroup I2C_Exported_Functions_Group2
490
+  * @{
491
+  */
492
+/* I/O operation functions  *****************************************************/
493
+/******* Blocking mode: Polling */
494
+HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
495
+HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
496
+HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
497
+HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
498
+HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout);
499
+HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout);
500
+HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);
501
+
502
+/******* Non-Blocking mode: Interrupt */
503
+HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
504
+HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
505
+HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
506
+HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
507
+HAL_StatusTypeDef HAL_I2C_Mem_Write_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
508
+HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
509
+
510
+HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
511
+HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
512
+HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
513
+HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions);
514
+HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress);
515
+HAL_StatusTypeDef HAL_I2C_EnableListen_IT(I2C_HandleTypeDef *hi2c);
516
+HAL_StatusTypeDef HAL_I2C_DisableListen_IT(I2C_HandleTypeDef *hi2c);
517
+
518
+/******* Non-Blocking mode: DMA */
519
+HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
520
+HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);
521
+HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
522
+HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);
523
+HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
524
+HAL_StatusTypeDef HAL_I2C_Mem_Read_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
525
+
526
+/******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
527
+void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c);
528
+void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c);
529
+void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c);
530
+void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c);
531
+void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c);
532
+void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c);
533
+void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode);
534
+void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c);
535
+void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c);
536
+void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c);
537
+void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c);
538
+void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c);
539
+/**
540
+  * @}
541
+  */
542
+
543
+/** @addtogroup I2C_Exported_Functions_Group3
544
+  * @{
545
+  */
546
+/* Peripheral State, Mode and Errors functions  *********************************/
547
+HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c);
548
+HAL_I2C_ModeTypeDef HAL_I2C_GetMode(I2C_HandleTypeDef *hi2c);
549
+uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c);
550
+
551
+/**
552
+  * @}
553
+  */
554
+
555
+/**
556
+  * @}
557
+  */
558
+/* Private types -------------------------------------------------------------*/
559
+/* Private variables ---------------------------------------------------------*/
560
+/* Private constants ---------------------------------------------------------*/
561
+/** @defgroup I2C_Private_Constants I2C Private Constants
562
+  * @{
563
+  */
564
+#define I2C_FLAG_MASK                    0x0000FFFFU
565
+#define I2C_MIN_PCLK_FREQ_STANDARD       2000000U     /*!< 2 MHz                     */
566
+#define I2C_MIN_PCLK_FREQ_FAST           4000000U     /*!< 4 MHz                     */
567
+/**
568
+  * @}
569
+  */
570
+
571
+/* Private macros ------------------------------------------------------------*/
572
+/** @defgroup I2C_Private_Macros I2C Private Macros
573
+  * @{
574
+  */
575
+
576
+#define I2C_MIN_PCLK_FREQ(__PCLK__, __SPEED__)             (((__SPEED__) <= 100000U) ? ((__PCLK__) < I2C_MIN_PCLK_FREQ_STANDARD) : ((__PCLK__) < I2C_MIN_PCLK_FREQ_FAST))
577
+#define I2C_CCR_CALCULATION(__PCLK__, __SPEED__, __COEFF__)     (((((__PCLK__) - 1U)/((__SPEED__) * (__COEFF__))) + 1U) & I2C_CCR_CCR)
578
+#define I2C_FREQRANGE(__PCLK__)                            ((__PCLK__)/1000000U)
579
+#define I2C_RISE_TIME(__FREQRANGE__, __SPEED__)            (((__SPEED__) <= 100000U) ? ((__FREQRANGE__) + 1U) : ((((__FREQRANGE__) * 300U) / 1000U) + 1U))
580
+#define I2C_SPEED_STANDARD(__PCLK__, __SPEED__)            ((I2C_CCR_CALCULATION((__PCLK__), (__SPEED__), 2U) < 4U)? 4U:I2C_CCR_CALCULATION((__PCLK__), (__SPEED__), 2U))
581
+#define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? I2C_CCR_CALCULATION((__PCLK__), (__SPEED__), 3U) : (I2C_CCR_CALCULATION((__PCLK__), (__SPEED__), 25U) | I2C_DUTYCYCLE_16_9))
582
+#define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__)      (((__SPEED__) <= 100000U)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \
583
+                                                                  ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0U)? 1U : \
584
+                                                                  ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS))
585
+
586
+#define I2C_7BIT_ADD_WRITE(__ADDRESS__)                    ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0)))
587
+#define I2C_7BIT_ADD_READ(__ADDRESS__)                     ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
588
+
589
+#define I2C_10BIT_ADDRESS(__ADDRESS__)                     ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
590
+#define I2C_10BIT_HEADER_WRITE(__ADDRESS__)                ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300U))) >> 7U) | (uint16_t)(0x00F0U))))
591
+#define I2C_10BIT_HEADER_READ(__ADDRESS__)                 ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300U))) >> 7U) | (uint16_t)(0x00F1U))))
592
+
593
+#define I2C_MEM_ADD_MSB(__ADDRESS__)                       ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00U))) >> 8U)))
594
+#define I2C_MEM_ADD_LSB(__ADDRESS__)                       ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
595
+
596
+/** @defgroup I2C_IS_RTC_Definitions I2C Private macros to check input parameters
597
+  * @{
598
+  */
599
+#define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \
600
+                                  ((CYCLE) == I2C_DUTYCYCLE_16_9))
601
+#define IS_I2C_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == I2C_ADDRESSINGMODE_7BIT) || \
602
+                                         ((ADDRESS) == I2C_ADDRESSINGMODE_10BIT))
603
+#define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \
604
+                                      ((ADDRESS) == I2C_DUALADDRESS_ENABLE))
605
+#define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \
606
+                                   ((CALL) == I2C_GENERALCALL_ENABLE))
607
+#define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \
608
+                                    ((STRETCH) == I2C_NOSTRETCH_ENABLE))
609
+#define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
610
+                                  ((SIZE) == I2C_MEMADD_SIZE_16BIT))
611
+#define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0) && ((SPEED) <= 400000U))
612
+#define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & (uint32_t)(0xFFFFFC00U)) == 0U)
613
+#define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & (uint32_t)(0xFFFFFF01U)) == 0U)
614
+#define IS_I2C_TRANSFER_OPTIONS_REQUEST(REQUEST)      (((REQUEST) == I2C_FIRST_FRAME)              || \
615
+                                                       ((REQUEST) == I2C_NEXT_FRAME)               || \
616
+                                                       ((REQUEST) == I2C_FIRST_AND_LAST_FRAME)     || \
617
+                                                       ((REQUEST) == I2C_LAST_FRAME))
618
+/**
619
+  * @}
620
+  */
621
+
622
+/**
623
+  * @}
624
+  */
625
+
626
+/* Private functions ---------------------------------------------------------*/
627
+/** @defgroup I2C_Private_Functions I2C Private Functions
628
+  * @{
629
+  */
630
+
631
+/**
632
+  * @}
633
+  */
634
+
635
+/**
636
+  * @}
637
+  */
638
+
639
+/**
640
+  * @}
641
+  */
642
+
643
+#ifdef __cplusplus
644
+}
645
+#endif
646
+
647
+
648
+#endif /* __STM32F1xx_HAL_I2C_H */
649
+
650
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 587 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h

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

Fichier diff supprimé car celui-ci est trop grand
+ 5588 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c


Fichier diff supprimé car celui-ci est trop grand
+ 3264 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c


+ 231 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi_ex.c

@@ -0,0 +1,231 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_spi_ex.c
4
+  * @author  MCD Application Team
5
+  * @brief   Extended SPI HAL module driver.
6
+  *    
7
+  *          This file provides firmware functions to manage the following 
8
+  *          functionalities SPI extension peripheral:
9
+  *           + Extended Peripheral Control functions
10
+  *  
11
+  ******************************************************************************
12
+  * @attention
13
+  *
14
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
15
+  *
16
+  * Redistribution and use in source and binary forms, with or without modification,
17
+  * are permitted provided that the following conditions are met:
18
+  *   1. Redistributions of source code must retain the above copyright notice,
19
+  *      this list of conditions and the following disclaimer.
20
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
21
+  *      this list of conditions and the following disclaimer in the documentation
22
+  *      and/or other materials provided with the distribution.
23
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
24
+  *      may be used to endorse or promote products derived from this software
25
+  *      without specific prior written permission.
26
+  *
27
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
+  *
38
+  ******************************************************************************
39
+  */
40
+
41
+/* Includes ------------------------------------------------------------------*/
42
+#include "stm32f1xx_hal.h"
43
+
44
+/** @addtogroup STM32F1xx_HAL_Driver
45
+  * @{
46
+  */
47
+
48
+/** @addtogroup SPI
49
+  * @{
50
+  */
51
+#ifdef HAL_SPI_MODULE_ENABLED
52
+
53
+/** @defgroup SPI_Private_Variables SPI Private Variables
54
+  * @{
55
+  */
56
+#if (USE_SPI_CRC != 0U)
57
+/* Variable used to determine if device is impacted by implementation of workaround
58
+   related to wrong CRC errors detection on SPI2. Conditions in which this workaround has to be applied, are:
59
+    - STM32F101CDE/STM32F103CDE
60
+    - Revision ID : Z
61
+    - SPI2
62
+    - In receive only mode, with CRC calculation enabled, at the end of the CRC reception,
63
+      the software needs to check the CRCERR flag. If it is found set, read back the SPI_RXCRC:
64
+        + If the value is 0, the complete data transfer is successful.
65
+        + Otherwise, one or more errors have been detected during the data transfer by CPU or DMA.
66
+      If CRCERR is found reset, the complete data transfer is considered successful.
67
+*/
68
+uint8_t uCRCErrorWorkaroundCheck = 0U;
69
+#endif /* USE_SPI_CRC */
70
+/**
71
+  * @}
72
+  */
73
+
74
+
75
+/* Private typedef -----------------------------------------------------------*/
76
+/* Private define ------------------------------------------------------------*/
77
+/* Private macro -------------------------------------------------------------*/
78
+/* Private variables ---------------------------------------------------------*/
79
+/* Private function prototypes -----------------------------------------------*/
80
+/* Private functions ---------------------------------------------------------*/
81
+
82
+/** @addtogroup SPI_Exported_Functions
83
+  * @{
84
+  */
85
+
86
+/** @addtogroup SPI_Exported_Functions_Group1
87
+  *
88
+  * @{
89
+  */
90
+
91
+/**
92
+  * @brief  Initializes the SPI according to the specified parameters 
93
+  *         in the SPI_InitTypeDef and create the associated handle.
94
+  * @param  hspi: pointer to a SPI_HandleTypeDef structure that contains
95
+  *                the configuration information for SPI module.
96
+  * @retval HAL status
97
+  */
98
+HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi)
99
+{
100
+  /* Check the SPI handle allocation */
101
+  if(hspi == NULL)
102
+  {
103
+    return HAL_ERROR;
104
+  }
105
+
106
+  /* Check the parameters */
107
+  assert_param(IS_SPI_ALL_INSTANCE(hspi->Instance));
108
+  assert_param(IS_SPI_MODE(hspi->Init.Mode));
109
+  assert_param(IS_SPI_DIRECTION(hspi->Init.Direction));
110
+  assert_param(IS_SPI_DATASIZE(hspi->Init.DataSize));
111
+  assert_param(IS_SPI_CPOL(hspi->Init.CLKPolarity));
112
+  assert_param(IS_SPI_CPHA(hspi->Init.CLKPhase));
113
+  assert_param(IS_SPI_NSS(hspi->Init.NSS));
114
+  assert_param(IS_SPI_BAUDRATE_PRESCALER(hspi->Init.BaudRatePrescaler));
115
+  assert_param(IS_SPI_FIRST_BIT(hspi->Init.FirstBit));
116
+
117
+#if (USE_SPI_CRC != 0U)
118
+  assert_param(IS_SPI_CRC_CALCULATION(hspi->Init.CRCCalculation));
119
+  if(hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE)
120
+  {
121
+    assert_param(IS_SPI_CRC_POLYNOMIAL(hspi->Init.CRCPolynomial));
122
+  }
123
+#else
124
+  hspi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
125
+#endif /* USE_SPI_CRC */
126
+
127
+  if(hspi->State == HAL_SPI_STATE_RESET)
128
+  {
129
+    /* Init the low level hardware : GPIO, CLOCK, NVIC... */
130
+    HAL_SPI_MspInit(hspi);
131
+  }
132
+  
133
+  hspi->State = HAL_SPI_STATE_BUSY;
134
+
135
+  /* Disble the selected SPI peripheral */
136
+  __HAL_SPI_DISABLE(hspi);
137
+
138
+  /*----------------------- SPIx CR1 & CR2 Configuration ---------------------*/
139
+  /* Configure : SPI Mode, Communication Mode, Data size, Clock polarity and phase, NSS management,
140
+  Communication speed, First bit and CRC calculation state */
141
+  WRITE_REG(hspi->Instance->CR1, (hspi->Init.Mode | hspi->Init.Direction | hspi->Init.DataSize |
142
+                                  hspi->Init.CLKPolarity | hspi->Init.CLKPhase | (hspi->Init.NSS & SPI_CR1_SSM) |
143
+                                  hspi->Init.BaudRatePrescaler | hspi->Init.FirstBit  | hspi->Init.CRCCalculation) );
144
+
145
+  /* Configure : NSS management */
146
+  WRITE_REG(hspi->Instance->CR2, (((hspi->Init.NSS >> 16U) & SPI_CR2_SSOE) | hspi->Init.TIMode));
147
+
148
+  /*---------------------------- SPIx CRCPOLY Configuration ------------------*/
149
+  /* Configure : CRC Polynomial */
150
+  WRITE_REG(hspi->Instance->CRCPR, hspi->Init.CRCPolynomial);
151
+
152
+#if defined(SPI_I2SCFGR_I2SMOD)
153
+  /* Activate the SPI mode (Make sure that I2SMOD bit in I2SCFGR register is reset) */
154
+  CLEAR_BIT(hspi->Instance->I2SCFGR, SPI_I2SCFGR_I2SMOD);
155
+#endif /* SPI_I2SCFGR_I2SMOD */
156
+
157
+#if (USE_SPI_CRC != 0U)
158
+#if defined (STM32F101xE) || defined (STM32F103xE)
159
+  /* Check RevisionID value for identifying if Device is Rev Z (0x0001) in order to enable workaround for
160
+     CRC errors wrongly detected */
161
+  /* Pb is that ES_STM32F10xxCDE also identify an issue in Debug registers access while not in Debug mode.
162
+     Revision ID information is only available in Debug mode, so Workaround could not be implemented
163
+     to distinguish Rev Z devices (issue present) from more recent version (issue fixed).
164
+     So, in case of Revison Z F101 or F103 devices, below variable should be assigned to 1 */
165
+  uCRCErrorWorkaroundCheck = 0U;
166
+#else
167
+  uCRCErrorWorkaroundCheck = 0U;
168
+#endif /* STM32F101xE || STM32F103xE */
169
+#endif /* USE_SPI_CRC */
170
+
171
+  hspi->ErrorCode = HAL_SPI_ERROR_NONE;
172
+  hspi->State = HAL_SPI_STATE_READY;
173
+  
174
+  return HAL_OK;
175
+}
176
+
177
+/**
178
+  * @}
179
+  */
180
+
181
+/**
182
+  * @}
183
+  */
184
+
185
+/** @addtogroup SPI_Private_Functions
186
+  * @{
187
+  */
188
+#if (USE_SPI_CRC != 0U)
189
+/**
190
+  * @brief  Checks if encountered CRC error could be corresponding to wrongly detected errors 
191
+  *         according to SPI instance, Device type, and revision ID.
192
+  * @param  hspi: pointer to a SPI_HandleTypeDef structure that contains
193
+  *               the configuration information for SPI module.
194
+  * @retval CRC error validity (SPI_INVALID_CRC_ERROR or SPI_VALID_CRC_ERROR).  
195
+*/
196
+uint8_t SPI_ISCRCErrorValid(SPI_HandleTypeDef *hspi)
197
+{
198
+#if defined(STM32F101xE) || defined(STM32F103xE)
199
+  /* Check how to handle this CRC error (workaround to be applied or not) */
200
+  /* If CRC errors could be wrongly detected (issue 2.15.2 in STM32F10xxC/D/E silicon limitations ES (DocID14732 Rev 13) */
201
+  if((uCRCErrorWorkaroundCheck != 0U) && (hspi->Instance == SPI2))
202
+  {
203
+    if(hspi->Instance->RXCRCR == 0U)
204
+    {
205
+      return (SPI_INVALID_CRC_ERROR);
206
+    }
207
+  }
208
+  return (SPI_VALID_CRC_ERROR);
209
+#else
210
+  /* Prevent unused argument(s) compilation warning */
211
+  UNUSED(hspi);
212
+
213
+  return (SPI_VALID_CRC_ERROR);
214
+#endif
215
+}
216
+#endif /* USE_SPI_CRC */
217
+
218
+/**
219
+  * @}
220
+  */
221
+
222
+#endif /* HAL_SPI_MODULE_ENABLED */
223
+/**
224
+  * @}
225
+  */
226
+
227
+/**
228
+  * @}
229
+  */
230
+
231
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 12 - 7
Inc/Uart.h

@@ -7,19 +7,24 @@ extern void Uart3_Data_Send(uint8_t* data,uint8_t size);
7 7
 extern void Uart2_Data_Send(uint8_t* data,uint8_t size);
8 8
 extern void Uart1_Data_Send(uint8_t* data,uint8_t size);
9 9
 extern int _write (int file, uint8_t *ptr, uint16_t len);
10
-extern void Uart_dataCheck(uint8_t* cnt);
10
+extern void Uart_dataCheck(uint8_t Usart_Num ,uint8_t* cnt);
11
+extern void UartDataBufferCheck(void);
11 12
 
12
-extern uint8_t buf[buf_size];
13
-extern uint8_t ring_buf[buf_size];
14
-extern uint8_t count_in1 ;//, count_out ;
15
-extern uint8_t count_in2 ;//, count_out ;
16
-extern uint8_t count_in3 , count_out ;
13
+#define USART_CNT 2
14
+#define buf_size 100
15
+#define USART1_CNT 0
16
+#define USART2_CNT 1
17
+
18
+extern uint8_t buf[USART_CNT][buf_size];
19
+extern uint8_t count_in1 , count_out1;
20
+extern uint8_t count_in2 , count_out2;
17 21
 
18 22
 extern uint8_t rx1_data[1];
19 23
 extern uint8_t rx2_data[1];
20
-extern uint8_t rx3_data[1];
21 24
 
22 25
 extern UART_HandleTypeDef huart1;
23 26
 extern UART_HandleTypeDef huart2;
24 27
 extern UART_HandleTypeDef huart3;
25 28
 
29
+extern volatile uint32_t UartTimerCnt;
30
+

+ 56 - 5
Inc/main.h

@@ -49,13 +49,15 @@ extern "C" {
49 49
 
50 50
 /* Includes ------------------------------------------------------------------*/
51 51
 #include "stm32f1xx_hal.h"
52
-#include <stdint.h>
52
+
53 53
 /* Private includes ----------------------------------------------------------*/
54 54
 /* USER CODE BEGIN Includes */
55 55
 #include "sth30_crc.h"
56 56
 #include <string.h>
57 57
 #include "RGB_Controller.h"
58 58
 #include "core_cm3.h"
59
+#include <stdint.h>
60
+#include "Uart.h"
59 61
 /* USER CODE END Includes */
60 62
 
61 63
 /* Exported types ------------------------------------------------------------*/
@@ -90,7 +92,7 @@ extern void RGB_SensorIDAutoSet(uint8_t set);
90 92
 extern uint8_t RGB_SensorIDAutoGet(void);
91 93
 extern void Flash_write(uint8_t*);
92 94
 extern void UartDataRecvSet(uint8_t val);
93
-extern void Uart_dataCheck(uint8_t* cnt);
95
+extern void Uart_dataCheck(uint8_t Usart_Num ,uint8_t* cnt);
94 96
 extern void Uart1_Data_Send(uint8_t* data,uint8_t size);
95 97
 
96 98
 /* USER CODE END EM */
@@ -125,10 +127,9 @@ typedef enum{
125 127
 #define     RGB_SensorDataResponse_Length 15
126 128
 #define     RGB_SensorDataResponseData_Length RGB_SensorDataResponse_Length - 3
127 129
 
128
-#define buf_size 100
129 130
 
130
-extern uint8_t buf[buf_size];
131
-extern uint8_t ring_buf[buf_size];
131
+
132
+extern uint8_t buf[USART_CNT][buf_size];
132 133
 extern uint8_t count_in1 ;//, count_out ;
133 134
 extern uint8_t count_in2 ;//, count_out ;
134 135
 extern uint8_t count_in3 , count_out ;
@@ -139,6 +140,56 @@ extern uint8_t rx3_data[1];
139 140
 /* USER CODE END EFP */
140 141
 
141 142
 /* Private defines -----------------------------------------------------------*/
143
+#define BOOT_LED_Pin GPIO_PIN_15
144
+#define BOOT_LED_GPIO_Port GPIOC
145
+#define SX1276_DIO0_Pin GPIO_PIN_4
146
+#define SX1276_DIO0_GPIO_Port GPIOA
147
+#define SX1276_DIO1_Pin GPIO_PIN_5
148
+#define SX1276_DIO1_GPIO_Port GPIOA
149
+#define SX1276_DIO2_Pin GPIO_PIN_6
150
+#define SX1276_DIO2_GPIO_Port GPIOA
151
+#define SX1276_DIO3_Pin GPIO_PIN_7
152
+#define SX1276_DIO3_GPIO_Port GPIOA
153
+#define SX1276_DIO4_Pin GPIO_PIN_4
154
+#define SX1276_DIO4_GPIO_Port GPIOC
155
+#define SX1276_DIO5_Pin GPIO_PIN_5
156
+#define SX1276_DIO5_GPIO_Port GPIOC
157
+#define SX1276_RESET_Pin GPIO_PIN_0
158
+#define SX1276_RESET_GPIO_Port GPIOB
159
+#define LED_ALARM_Pin GPIO_PIN_12
160
+#define LED_ALARM_GPIO_Port GPIOB
161
+#define SENSOR_EN1_Pin GPIO_PIN_13
162
+#define SENSOR_EN1_GPIO_Port GPIOB
163
+#define SENSOR_EN2_Pin GPIO_PIN_14
164
+#define SENSOR_EN2_GPIO_Port GPIOB
165
+#define SENSOR_EN3_Pin GPIO_PIN_15
166
+#define SENSOR_EN3_GPIO_Port GPIOB
167
+#define SENSOR_EN4_Pin GPIO_PIN_6
168
+#define SENSOR_EN4_GPIO_Port GPIOC
169
+#define SENSOR_EN5_Pin GPIO_PIN_7
170
+#define SENSOR_EN5_GPIO_Port GPIOC
171
+#define SENSOR_EN6_Pin GPIO_PIN_8
172
+#define SENSOR_EN6_GPIO_Port GPIOC
173
+#define SENSOR_EN7_Pin GPIO_PIN_9
174
+#define SENSOR_EN7_GPIO_Port GPIOC
175
+#define SENSOR_EN8_Pin GPIO_PIN_8
176
+#define SENSOR_EN8_GPIO_Port GPIOA
177
+#define LED_CH1_Pin GPIO_PIN_10
178
+#define LED_CH1_GPIO_Port GPIOC
179
+#define LED_CH2_Pin GPIO_PIN_11
180
+#define LED_CH2_GPIO_Port GPIOC
181
+#define LED_CH3_Pin GPIO_PIN_12
182
+#define LED_CH3_GPIO_Port GPIOC
183
+#define LED_CH4_Pin GPIO_PIN_2
184
+#define LED_CH4_GPIO_Port GPIOD
185
+#define LED_CH5_Pin GPIO_PIN_6
186
+#define LED_CH5_GPIO_Port GPIOB
187
+#define LED_CH6_Pin GPIO_PIN_7
188
+#define LED_CH6_GPIO_Port GPIOB
189
+#define LED_CH7_Pin GPIO_PIN_8
190
+#define LED_CH7_GPIO_Port GPIOB
191
+#define LED_CH8_Pin GPIO_PIN_9
192
+#define LED_CH8_GPIO_Port GPIOB
142 193
 /* USER CODE BEGIN Private defines */
143 194
 
144 195
 

+ 2 - 2
Inc/stm32f1xx_hal_conf.h

@@ -60,7 +60,7 @@
60 60
 /*#define HAL_ETH_MODULE_ENABLED   */
61 61
 /*#define HAL_FLASH_MODULE_ENABLED   */
62 62
 #define HAL_GPIO_MODULE_ENABLED
63
-/*#define HAL_I2C_MODULE_ENABLED   */
63
+#define HAL_I2C_MODULE_ENABLED
64 64
 /*#define HAL_I2S_MODULE_ENABLED   */
65 65
 /*#define HAL_IRDA_MODULE_ENABLED   */
66 66
 /*#define HAL_IWDG_MODULE_ENABLED   */
@@ -76,7 +76,7 @@
76 76
 /*#define HAL_MMC_MODULE_ENABLED   */
77 77
 /*#define HAL_SDRAM_MODULE_ENABLED   */
78 78
 /*#define HAL_SMARTCARD_MODULE_ENABLED   */
79
-/*#define HAL_SPI_MODULE_ENABLED   */
79
+#define HAL_SPI_MODULE_ENABLED
80 80
 /*#define HAL_SRAM_MODULE_ENABLED   */
81 81
 #define HAL_TIM_MODULE_ENABLED
82 82
 #define HAL_UART_MODULE_ENABLED

+ 0 - 1
Inc/stm32f1xx_it.h

@@ -73,7 +73,6 @@ void PendSV_Handler(void);
73 73
 void SysTick_Handler(void);
74 74
 void USART1_IRQHandler(void);
75 75
 void USART2_IRQHandler(void);
76
-void USART3_IRQHandler(void);
77 76
 void TIM6_IRQHandler(void);
78 77
 /* USER CODE BEGIN EFP */
79 78
 

+ 130 - 56
STM32F103_RGBController.ioc

@@ -2,20 +2,21 @@
2 2
 File.Version=6
3 3
 KeepUserPlacement=false
4 4
 Mcu.Family=STM32F1
5
-Mcu.IP0=NVIC
6
-Mcu.IP1=RCC
7
-Mcu.IP2=SYS
8
-Mcu.IP3=TIM6
9
-Mcu.IP4=USART1
10
-Mcu.IP5=USART2
11
-Mcu.IP6=USART3
12
-Mcu.IPNb=7
5
+Mcu.IP0=I2C2
6
+Mcu.IP1=NVIC
7
+Mcu.IP2=RCC
8
+Mcu.IP3=SPI1
9
+Mcu.IP4=SYS
10
+Mcu.IP5=TIM6
11
+Mcu.IP6=USART1
12
+Mcu.IP7=USART2
13
+Mcu.IPNb=8
13 14
 Mcu.Name=STM32F103R(C-D-E)Tx
14 15
 Mcu.Package=LQFP64
15
-Mcu.Pin0=PC13-TAMPER-RTC
16
-Mcu.Pin1=PC15-OSC32_OUT
17
-Mcu.Pin10=PA7
18
-Mcu.Pin11=PC4
16
+Mcu.Pin0=PC15-OSC32_OUT
17
+Mcu.Pin1=PD0-OSC_IN
18
+Mcu.Pin10=PC5
19
+Mcu.Pin11=PB0
19 20
 Mcu.Pin12=PB10
20 21
 Mcu.Pin13=PB11
21 22
 Mcu.Pin14=PB12
@@ -24,27 +25,37 @@ Mcu.Pin16=PB14
24 25
 Mcu.Pin17=PB15
25 26
 Mcu.Pin18=PC6
26 27
 Mcu.Pin19=PC7
27
-Mcu.Pin2=PD0-OSC_IN
28
+Mcu.Pin2=PD1-OSC_OUT
28 29
 Mcu.Pin20=PC8
29 30
 Mcu.Pin21=PC9
30 31
 Mcu.Pin22=PA8
31 32
 Mcu.Pin23=PA9
32 33
 Mcu.Pin24=PA10
33 34
 Mcu.Pin25=PA13
34
-Mcu.Pin26=PC10
35
-Mcu.Pin27=PC11
36
-Mcu.Pin28=PC12
37
-Mcu.Pin29=VP_SYS_VS_ND
38
-Mcu.Pin3=PD1-OSC_OUT
39
-Mcu.Pin30=VP_SYS_VS_Systick
40
-Mcu.Pin31=VP_TIM6_VS_ClockSourceINT
41
-Mcu.Pin4=PC3
42
-Mcu.Pin5=PA2
43
-Mcu.Pin6=PA3
44
-Mcu.Pin7=PA4
45
-Mcu.Pin8=PA5
46
-Mcu.Pin9=PA6
47
-Mcu.PinsNb=32
35
+Mcu.Pin26=PA14
36
+Mcu.Pin27=PA15
37
+Mcu.Pin28=PC10
38
+Mcu.Pin29=PC11
39
+Mcu.Pin3=PA2
40
+Mcu.Pin30=PC12
41
+Mcu.Pin31=PD2
42
+Mcu.Pin32=PB3
43
+Mcu.Pin33=PB4
44
+Mcu.Pin34=PB5
45
+Mcu.Pin35=PB6
46
+Mcu.Pin36=PB7
47
+Mcu.Pin37=PB8
48
+Mcu.Pin38=PB9
49
+Mcu.Pin39=VP_SYS_VS_ND
50
+Mcu.Pin4=PA3
51
+Mcu.Pin40=VP_SYS_VS_Systick
52
+Mcu.Pin41=VP_TIM6_VS_ClockSourceINT
53
+Mcu.Pin5=PA4
54
+Mcu.Pin6=PA5
55
+Mcu.Pin7=PA6
56
+Mcu.Pin8=PA7
57
+Mcu.Pin9=PC4
58
+Mcu.PinsNb=42
48 59
 Mcu.ThirdPartyNb=0
49 60
 Mcu.UserConstants=
50 61
 Mcu.UserName=STM32F103RCTx
@@ -59,76 +70,133 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false
59 70
 NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
60 71
 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false
61 72
 NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false
62
-NVIC.TIM6_IRQn=true\:0\:0\:false\:true\:true\:4\:true
73
+NVIC.TIM6_IRQn=true\:0\:0\:false\:true\:true\:3\:true
63 74
 NVIC.USART1_IRQn=true\:0\:0\:false\:true\:true\:2\:true
64
-NVIC.USART2_IRQn=true\:0\:0\:false\:true\:true\:3\:true
65
-NVIC.USART3_IRQn=true\:0\:0\:false\:true\:true\:1\:true
75
+NVIC.USART2_IRQn=true\:0\:0\:false\:true\:true\:1\:true
66 76
 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false
67
-PA10.GPIOParameters=GPIO_PuPd,GPIO_Mode
68
-PA10.GPIO_Mode=GPIO_MODE_INPUT
69
-PA10.GPIO_PuPd=GPIO_PULLUP
70
-PA10.Locked=true
71 77
 PA10.Mode=Asynchronous
72 78
 PA10.Signal=USART1_RX
73 79
 PA13.Locked=true
74
-PA13.Signal=GPIO_Output
75
-PA2.Locked=true
80
+PA13.Signal=SYS_JTMS-SWDIO
81
+PA14.Locked=true
82
+PA14.Signal=SYS_JTCK-SWCLK
83
+PA15.Locked=true
84
+PA15.Mode=NSS_Signal_Hard_Output
85
+PA15.Signal=SPI1_NSS
76 86
 PA2.Mode=Asynchronous
77 87
 PA2.Signal=USART2_TX
78
-PA3.GPIOParameters=GPIO_PuPd
79
-PA3.GPIO_PuPd=GPIO_PULLUP
80
-PA3.Locked=true
81 88
 PA3.Mode=Asynchronous
82 89
 PA3.Signal=USART2_RX
90
+PA4.GPIOParameters=GPIO_Label
91
+PA4.GPIO_Label=SX1276_DIO0
83 92
 PA4.Locked=true
84 93
 PA4.Signal=GPIO_Output
94
+PA5.GPIOParameters=GPIO_Label
95
+PA5.GPIO_Label=SX1276_DIO1
85 96
 PA5.Locked=true
86 97
 PA5.Signal=GPIO_Output
98
+PA6.GPIOParameters=GPIO_Label
99
+PA6.GPIO_Label=SX1276_DIO2
87 100
 PA6.Locked=true
88 101
 PA6.Signal=GPIO_Output
102
+PA7.GPIOParameters=GPIO_Label
103
+PA7.GPIO_Label=SX1276_DIO3
89 104
 PA7.Locked=true
90 105
 PA7.Signal=GPIO_Output
106
+PA8.GPIOParameters=GPIO_Label
107
+PA8.GPIO_Label=SENSOR_EN8
91 108
 PA8.Locked=true
92 109
 PA8.Signal=GPIO_Output
93
-PA9.Locked=true
94 110
 PA9.Mode=Asynchronous
95 111
 PA9.Signal=USART1_TX
112
+PB0.GPIOParameters=GPIO_Label
113
+PB0.GPIO_Label=SX1276_RESET
114
+PB0.Locked=true
115
+PB0.Signal=GPIO_Output
96 116
 PB10.Locked=true
97
-PB10.Mode=Asynchronous
98
-PB10.Signal=USART3_TX
99
-PB11.GPIOParameters=GPIO_PuPd
100
-PB11.GPIO_PuPd=GPIO_PULLUP
101
-PB11.Locked=true
102
-PB11.Mode=Asynchronous
103
-PB11.Signal=USART3_RX
117
+PB10.Mode=I2C
118
+PB10.Signal=I2C2_SCL
119
+PB11.Mode=I2C
120
+PB11.Signal=I2C2_SDA
121
+PB12.GPIOParameters=GPIO_Label
122
+PB12.GPIO_Label=LED_ALARM
104 123
 PB12.Locked=true
105 124
 PB12.Signal=GPIO_Output
125
+PB13.GPIOParameters=GPIO_Label
126
+PB13.GPIO_Label=SENSOR_EN1
106 127
 PB13.Locked=true
107 128
 PB13.Signal=GPIO_Output
129
+PB14.GPIOParameters=GPIO_Label
130
+PB14.GPIO_Label=SENSOR_EN2
108 131
 PB14.Locked=true
109 132
 PB14.Signal=GPIO_Output
133
+PB15.GPIOParameters=GPIO_Label
134
+PB15.GPIO_Label=SENSOR_EN3
110 135
 PB15.Locked=true
111 136
 PB15.Signal=GPIO_Output
137
+PB3.Locked=true
138
+PB3.Mode=Full_Duplex_Master
139
+PB3.Signal=SPI1_SCK
140
+PB4.Locked=true
141
+PB4.Mode=Full_Duplex_Master
142
+PB4.Signal=SPI1_MISO
143
+PB5.Locked=true
144
+PB5.Mode=Full_Duplex_Master
145
+PB5.Signal=SPI1_MOSI
146
+PB6.GPIOParameters=GPIO_Label
147
+PB6.GPIO_Label=LED_CH5
148
+PB6.Locked=true
149
+PB6.Signal=GPIO_Output
150
+PB7.GPIOParameters=GPIO_Label
151
+PB7.GPIO_Label=LED_CH6
152
+PB7.Locked=true
153
+PB7.Signal=GPIO_Output
154
+PB8.GPIOParameters=GPIO_Label
155
+PB8.GPIO_Label=LED_CH7
156
+PB8.Locked=true
157
+PB8.Signal=GPIO_Output
158
+PB9.GPIOParameters=GPIO_Label
159
+PB9.GPIO_Label=LED_CH8
160
+PB9.Locked=true
161
+PB9.Signal=GPIO_Output
162
+PC10.GPIOParameters=GPIO_Label
163
+PC10.GPIO_Label=LED_CH1
112 164
 PC10.Locked=true
113 165
 PC10.Signal=GPIO_Output
166
+PC11.GPIOParameters=GPIO_Label
167
+PC11.GPIO_Label=LED_CH2
114 168
 PC11.Locked=true
115 169
 PC11.Signal=GPIO_Output
170
+PC12.GPIOParameters=GPIO_Label
171
+PC12.GPIO_Label=LED_CH3
116 172
 PC12.Locked=true
117 173
 PC12.Signal=GPIO_Output
118
-PC13-TAMPER-RTC.Locked=true
119
-PC13-TAMPER-RTC.Signal=GPIO_Output
174
+PC15-OSC32_OUT.GPIOParameters=GPIO_Label
175
+PC15-OSC32_OUT.GPIO_Label=BOOT_LED
120 176
 PC15-OSC32_OUT.Locked=true
121 177
 PC15-OSC32_OUT.Signal=GPIO_Output
122
-PC3.Locked=true
123
-PC3.Signal=GPIO_Output
178
+PC4.GPIOParameters=GPIO_Label
179
+PC4.GPIO_Label=SX1276_DIO4
124 180
 PC4.Locked=true
125 181
 PC4.Signal=GPIO_Output
182
+PC5.GPIOParameters=GPIO_Label
183
+PC5.GPIO_Label=SX1276_DIO5
184
+PC5.Locked=true
185
+PC5.Signal=GPIO_Output
186
+PC6.GPIOParameters=GPIO_Label
187
+PC6.GPIO_Label=SENSOR_EN4
126 188
 PC6.Locked=true
127 189
 PC6.Signal=GPIO_Output
190
+PC7.GPIOParameters=GPIO_Label
191
+PC7.GPIO_Label=SENSOR_EN5
128 192
 PC7.Locked=true
129 193
 PC7.Signal=GPIO_Output
194
+PC8.GPIOParameters=GPIO_Label
195
+PC8.GPIO_Label=SENSOR_EN6
130 196
 PC8.Locked=true
131 197
 PC8.Signal=GPIO_Output
198
+PC9.GPIOParameters=GPIO_Label
199
+PC9.GPIO_Label=SENSOR_EN7
132 200
 PC9.Locked=true
133 201
 PC9.Signal=GPIO_Output
134 202
 PCC.Checker=false
@@ -139,12 +207,14 @@ PCC.Seq0=0
139 207
 PCC.Series=STM32F1
140 208
 PCC.Temperature=25
141 209
 PCC.Vdd=3.3
142
-PD0-OSC_IN.Locked=true
143 210
 PD0-OSC_IN.Mode=HSE-External-Oscillator
144 211
 PD0-OSC_IN.Signal=RCC_OSC_IN
145
-PD1-OSC_OUT.Locked=true
146 212
 PD1-OSC_OUT.Mode=HSE-External-Oscillator
147 213
 PD1-OSC_OUT.Signal=RCC_OSC_OUT
214
+PD2.GPIOParameters=GPIO_Label
215
+PD2.GPIO_Label=LED_CH4
216
+PD2.Locked=true
217
+PD2.Signal=GPIO_Output
148 218
 PinOutPanel.RotationAngle=0
149 219
 ProjectManager.AskForMigrate=true
150 220
 ProjectManager.BackupPrevious=false
@@ -172,7 +242,7 @@ ProjectManager.StackSize=0x400
172 242
 ProjectManager.TargetToolchain=TrueSTUDIO
173 243
 ProjectManager.ToolChainLocation=
174 244
 ProjectManager.UnderRoot=true
175
-ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_TIM6_Init-TIM6-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_USART2_UART_Init-USART2-false-HAL-true,6-MX_USART3_UART_Init-USART3-false-HAL-true
245
+ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_TIM6_Init-TIM6-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_USART2_UART_Init-USART2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_I2C2_Init-I2C2-false-HAL-true
176 246
 RCC.ADCFreqValue=8000000
177 247
 RCC.AHBFreq_Value=16000000
178 248
 RCC.APB1CLKDivider=RCC_HCLK_DIV2
@@ -197,6 +267,12 @@ RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
197 267
 RCC.TimSysFreq_Value=16000000
198 268
 RCC.USBFreq_Value=16000000
199 269
 RCC.VCOOutput2Freq_Value=8000000
270
+SPI1.CalculateBaudRate=8.0 MBits/s
271
+SPI1.Direction=SPI_DIRECTION_2LINES
272
+SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,VirtualNSS
273
+SPI1.Mode=SPI_MODE_MASTER
274
+SPI1.VirtualNSS=VM_NSSHARD
275
+SPI1.VirtualType=VM_MASTER
200 276
 TIM6.IPParameters=Prescaler,Period
201 277
 TIM6.Period=10-1
202 278
 TIM6.Prescaler=1600-1
@@ -204,8 +280,6 @@ USART1.IPParameters=VirtualMode
204 280
 USART1.VirtualMode=VM_ASYNC
205 281
 USART2.IPParameters=VirtualMode
206 282
 USART2.VirtualMode=VM_ASYNC
207
-USART3.IPParameters=VirtualMode
208
-USART3.VirtualMode=VM_ASYNC
209 283
 VP_SYS_VS_ND.Mode=No_Debug
210 284
 VP_SYS_VS_ND.Signal=SYS_VS_ND
211 285
 VP_SYS_VS_Systick.Mode=SysTick

+ 10 - 7
Src/RGB_Controller.c

@@ -13,27 +13,30 @@ for(uint8_t i = 0; i < 10; i++){
13 13
 #endif
14 14
     switch(type){
15 15
         case RGB_Status_Data_Request: 
16
-            Uart1_Data_Send(data,RGB_SensorDataRequest_Length);
16
+            Uart2_Data_Send(data,RGB_SensorDataRequest_Length);
17 17
             break;
18 18
         case RGB_ControllerID_SET: 
19
-            Uart3_Data_Send(data,RGB_ControllerID_SET_Length);
19
+            Uart1_Data_Send(data,RGB_ControllerID_SET_Length);
20 20
             break;
21 21
         case RGB_SensorID_SET:  
22
-            Uart1_Data_Send(data,RGB_SensorIDAutoSetRequest_Length);
22
+            Uart2_Data_Send(data,RGB_SensorIDAutoSetRequest_Length);
23 23
             break;        
24 24
         case RGB_Status_Data_Response:
25
-            Uart3_Data_Send(data,RGB_SensorDataResponse_Length);
25
+            Uart1_Data_Send(data,RGB_SensorDataResponse_Length);
26 26
             break;
27 27
         case RGB_ControllerLimitSet:
28
-            Uart3_Data_Send(data,data[blucell_length] + 3);
28
+            Uart1_Data_Send(data,data[blucell_length] + 3);
29 29
             Flash_write(&data[0]);
30 30
             break;
31 31
         case RGB_Sensor_Start:    
32 32
         case RGB_Sensor_Check:
33
-            Uart1_Data_Send(data,RGB_SensorIDAutoSetRequest_Length);
33
+            Uart2_Data_Send(data,RGB_SensorIDAutoSetRequest_Length);
34 34
             break;
35 35
         case RGB_Sensor_Ack:
36
-            Uart3_Data_Send(data,data[blucell_length] + 3);
36
+            Uart2_Data_Send(data,data[blucell_length] + 3);
37
+            break;
38
+        case RGB_Reset:
39
+        case RGB_SensorID_SET_Success:
37 40
             break;
38 41
              
39 42
     }

+ 43 - 48
Src/Uart.c

@@ -2,64 +2,61 @@
2 2
 
3 3
 void UartDataRecvSet(uint8_t val);
4 4
 uint8_t UartDataRecvGet(void);
5
-void Uart3_Data_Send(uint8_t* data,uint8_t size);
6 5
 void Uart2_Data_Send(uint8_t* data,uint8_t size);
7 6
 void Uart1_Data_Send(uint8_t* data,uint8_t size);
8 7
 int _write (int file, uint8_t *ptr, uint16_t len);
9
-void Uart_dataCheck(uint8_t* cnt);
8
+void Uart_dataCheck(uint8_t Usart_Num ,uint8_t* cnt);
9
+void QueueCheck(uint8_t Usart_Num,uint8_t* header,uint8_t* tail);
10
+void UartDataBufferCheck(void);
10 11
 
11
-uint8_t UartDataisReved;
12
-uint8_t rx1_data[1];
13
-uint8_t rx2_data[1];
14
-uint8_t rx3_data[1];
15 12
 
16 13
 
17
-uint8_t ring_buf[buf_size];
18
-uint8_t count_in1 = 0;//, count_out = 0;
19
-uint8_t count_in2 = 0;//, count_out = 0;
20
-uint8_t count_in3 = 0, count_out = 0;
21 14
 
22
-uint8_t buf[buf_size] = {0,};
15
+uint8_t UartDataisReved;
16
+uint8_t rx1_data[1];
17
+uint8_t rx2_data[1];
23 18
 
19
+uint8_t count_in1 = 0, count_out1 = 0;
20
+uint8_t count_in2 = 0, count_out2 = 0;
21
+
22
+uint8_t buf[USART_CNT][buf_size] = {0,};
23
+uint8_t Uart_RxData[USART_CNT][buf_size] = {0,};
24
+uint8_t Uart_Rxcnt = 0;
25
+typedef struct{
26
+    uint8_t Rx_Header;
27
+    uint8_t Rx_Tail;
28
+    uint8_t buf[USART_CNT][buf_size];
29
+}BlueUsart_t;
30
+    
24 31
 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
25 32
 {
26 33
     if(huart->Instance == USART1)//RGB Comunication 
27 34
     {
28
-        buf[count_in1] = rx1_data[0];//(uint8_t)USART2->DR;
29
-//        printf("data %02x \r\n",rx1_data[0]);
30
-        if(buf[count_in1++] == 0xEB){
31
-            if(buf[blucell_length] == (count_in1 - 3))
32
-                UartDataRecvSet(1);
33
-            else
34
-                count_in1 = 0;
35
-        }
35
+        buf[USART1_CNT][count_in1] = rx1_data[0];
36
+        if(++count_in1>=100){ count_in1 = 0; }
36 37
         HAL_UART_Receive_IT(&huart1,&rx1_data[0],1);
37 38
     }
38
-    if(huart->Instance == USART2) // Lora?? ?†µ?‹ ?•˜?Š” ?�¬?Џ
39
+    if(huart->Instance == USART2) 
39 40
     {
40
-        buf[count_in2] = rx2_data[0];//(uint8_t)USART2->DR;
41
-//        if(buf[count_in++] == 0xEB)UartDataRecvSet(1);
42
-        if(buf[count_in2++] == 0xEB){
43
-            if(buf[blucell_length] == (count_in2 - 3))
44
-                UartDataRecvSet(2);
45
-            else
46
-                count_in1 = 0;
47
-//                printf("UART 2 %d",((count_in2 -1) - 3));
48
-        }
49
-
41
+        buf[USART2_CNT][count_in2] = rx2_data[0];
42
+        if(++count_in2>=100){ count_in2 = 0; }
50 43
         HAL_UART_Receive_IT(&huart2,&rx2_data[0],1);
51 44
     }
52
-    if(huart->Instance == USART3) //GUI ?? ?†µ?‹ ?•˜?Š” Port
53
-    {
54
-        buf[count_in3] = rx3_data[0];//(uint8_t)USART2->DR;
55
-        if(buf[count_in3++] == 0xEB)UartDataRecvSet(3);
56
-        /*ring_buf[count_in] = rx2_data[0];//(uint8_t)USART2->DR;
57
-        if(++count_in>=buf_size) count_in=0;*/
58
-        HAL_UART_Receive_IT(&huart3,&rx3_data[0],1);
59
-    }
60 45
     
61 46
 }
47
+void QueueCheck(uint8_t Usart_Num,uint8_t* header,uint8_t* tail){
62 48
 
49
+     if(*tail != *header){ 
50
+        Uart_RxData[Usart_Num][Uart_Rxcnt++] = buf[Usart_Num][*tail++];
51
+        if(*tail>= 100){ *tail = 0; }
52
+        UartTimerCnt = 0;
53
+        UartDataRecvSet(Usart_Num + 1);
54
+    }
55
+}
56
+void UartDataBufferCheck(void){
57
+    QueueCheck(USART1_CNT,&count_in1,&count_out1);
58
+    QueueCheck(USART2_CNT,&count_in2,&count_out2);
59
+}
63 60
 void UartDataRecvSet(uint8_t val){
64 61
     UartDataisReved = val;
65 62
 }
@@ -68,9 +65,6 @@ uint8_t UartDataRecvGet(void){
68 65
 }
69 66
 
70 67
 
71
-void Uart3_Data_Send(uint8_t* data,uint8_t size){
72
-    HAL_UART_Transmit(&huart3, data,size, 10); 
73
-}
74 68
 void Uart2_Data_Send(uint8_t* data,uint8_t size){
75 69
     HAL_UART_Transmit(&huart2, data,size, 10); 
76 70
 }
@@ -80,10 +74,10 @@ void Uart1_Data_Send(uint8_t* data,uint8_t size){
80 74
 
81 75
 int _write (int file, uint8_t *ptr, uint16_t len) 
82 76
 {
83
-    HAL_UART_Transmit (&huart3, ptr, len, 10); 
77
+    HAL_UART_Transmit (&huart1, ptr, len, 10); 
84 78
     return len;
85 79
 }
86
-void Uart_dataCheck(uint8_t* cnt){
80
+void Uart_dataCheck(uint8_t Usart_Num ,uint8_t* cnt){
87 81
 
88 82
     etError crccheck = 0;
89 83
 #if 0
@@ -93,15 +87,16 @@ void Uart_dataCheck(uint8_t* cnt){
93 87
         printf("\r\n");
94 88
 #endif  
95 89
 
96
-    crccheck = STH30_CheckCrc(&buf[blucell_type],buf[blucell_length],buf[buf[blucell_length] + 1]);
90
+    crccheck = STH30_CheckCrc(&Uart_RxData[Usart_Num][blucell_type],Uart_RxData[Usart_Num][blucell_length],Uart_RxData[Usart_Num][Uart_RxData[Usart_Num][blucell_length] + 1]);
97 91
     if(crccheck == CHECKSUM_ERROR){
98 92
         for(uint8_t i = 0; i < (*cnt); i++){
99
-            printf("%02x ",buf[i]);
93
+            printf("%02x ",Uart_RxData[Usart_Num][i]);
100 94
         }
101
-        printf("Original CRC : %02x RecvCRC : %02x \r\n",crccheck,buf[buf[blucell_length] + 1]);
95
+        printf("Original CRC : %02x RecvCRC : %02x \r\n",crccheck,Uart_RxData[Usart_Num][Uart_RxData[Usart_Num][blucell_length] + 1]);
102 96
     }
103 97
     else if(crccheck == NO_ERROR){
104
-        RGB_Controller_Func(&buf[blucell_stx]);
98
+        RGB_Controller_Func(&Uart_RxData[Usart_Num][blucell_stx]);\
99
+        UartDataRecvSet(0);
105 100
     }
106 101
     else{
107 102
          printf("What Happen?\r\n");
@@ -110,7 +105,7 @@ void Uart_dataCheck(uint8_t* cnt){
110 105
 
111 106
     *cnt = 0;
112 107
     
113
-    memset(buf,0x00,buf_size);
108
+    memset(Uart_RxData[Usart_Num],0x00,buf_size);
114 109
 }
115 110
 
116 111
 

+ 219 - 156
Src/main.c

@@ -62,11 +62,14 @@
62 62
 /* USER CODE END PM */
63 63
 
64 64
 /* Private variables ---------------------------------------------------------*/
65
+I2C_HandleTypeDef hi2c2;
66
+
67
+SPI_HandleTypeDef hspi1;
68
+
65 69
 TIM_HandleTypeDef htim6;
66 70
 
67 71
 UART_HandleTypeDef huart1;
68 72
 UART_HandleTypeDef huart2;
69
-UART_HandleTypeDef huart3;
70 73
 
71 74
 /* USER CODE BEGIN PV */
72 75
 
@@ -91,7 +94,8 @@ static void MX_GPIO_Init(void);
91 94
 static void MX_TIM6_Init(void);
92 95
 static void MX_USART1_UART_Init(void);
93 96
 static void MX_USART2_UART_Init(void);
94
-static void MX_USART3_UART_Init(void);
97
+static void MX_SPI1_Init(void);
98
+static void MX_I2C2_Init(void);
95 99
 static void MX_NVIC_Init(void);
96 100
 /* USER CODE BEGIN PFP */
97 101
 void RGB_SensorIDAutoSet(uint8_t set);
@@ -109,7 +113,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
109 113
 {
110 114
 
111 115
     if(htim->Instance == TIM6){
112
-//        UartTimerCnt++;
116
+        UartTimerCnt++;
113 117
         LedTimerCnt++;
114 118
         
115 119
     }
@@ -129,104 +133,107 @@ void RGB_Sensor_PowerOnOff(uint8_t id){
129 133
 
130 134
     switch(id){
131 135
         case 0:
132
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
133
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);            
134
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_SET);            
135
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);
136
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
137
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_SET);
138
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_SET);
139
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_SET);   
136
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
137
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);            
138
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);            
139
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
140
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
141
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
142
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_SET);
143
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_SET);   
140 144
             break;
141 145
         case 1:
142
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_RESET);
146
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_RESET);
143 147
             HAL_Delay(50);
144
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
145
-
146
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_RESET);            
147
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_RESET);            
148
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_RESET);
149
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);
150
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);
151
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_RESET);
152
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET);
148
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
149
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_RESET);            
150
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_RESET);            
151
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_RESET);
152
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_RESET);
153
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
154
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
155
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
153 156
             break;
154 157
         case 2:
155
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);        
156
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
157
-
158
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_RESET);            
159
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_RESET);
160
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);
161
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);
162
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_RESET);
163
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET);
158
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
159
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);        
160
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_RESET);            
161
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_RESET);
162
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_RESET);
163
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
164
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
165
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
164 166
             break;
165 167
         case 3:
166
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_SET);     
167
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET); 
168
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
169
-
170
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_RESET);
171
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);
172
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);
173
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_RESET);
174
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET);
168
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
169
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);        
170
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);   
171
+
172
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_RESET);
173
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_RESET);
174
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
175
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
176
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
177
+
175 178
             break;
176 179
         case 4:
177
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);
178
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);    
179
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
180
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_SET);            
181
-
182
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);
183
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);          
184
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_RESET);
185
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET);
180
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
181
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);        
182
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);   
183
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
184
+
185
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_RESET);
186
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
187
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
188
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
189
+
186 190
             break;
187 191
         case 5:
188
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
189
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);    
190
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
191
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_SET);            
192
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);
193
-
194
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);
195
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_RESET);
196
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET);
192
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
193
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);        
194
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);   
195
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
196
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
197
+
198
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
199
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
200
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
201
+
197 202
             break;
198 203
         case 6:
199
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_SET);
200
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);    
201
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
202
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_SET);            
203
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);
204
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
205
-
206
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_RESET);
207
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET);
204
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
205
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);        
206
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);   
207
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
208
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
209
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
210
+
211
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
212
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
213
+
208 214
             break;
209 215
         case 7:
210
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_SET);
211
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);    
212
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
213
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_SET);            
214
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);
215
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
216
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_SET); 
217
-
218
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET);
216
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
217
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);        
218
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);   
219
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
220
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
221
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
222
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_SET);
223
+
224
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
225
+
219 226
             break;
220 227
         case 8:
221
-            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_SET);
222
-
223
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);    
224
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13,GPIO_PIN_SET);
225
-            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_SET);            
226
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);
227
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
228
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_SET);           
229
-            HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_SET);
228
+            HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
229
+            HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);        
230
+            HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);   
231
+            HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
232
+            HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
233
+            HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
234
+            HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_SET);
235
+            HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_SET);
236
+
230 237
             break;
231 238
     }
232 239
 }
@@ -366,13 +373,13 @@ void Flash_InitRead(void) // 쓰기함수
366 373
     Address = StartAddr;
367 374
     for(uint8_t i = 1; i <= 8; i++ ){
368 375
         RGB_SensorRedLimit_Buf[i]   = (*(uint16_t*)Address);
369
-        printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
376
+//        printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
370 377
         Address += 2;
371 378
         RGB_SensorGreenLimit_Buf[i] = (*(uint16_t*)Address);
372
-        printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
379
+//        printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
373 380
         Address += 2;        
374 381
         RGB_SensorBlueLimit_Buf[i] = (*(uint16_t*)Address);
375
-        printf("%08x : %04X \n",Address ,*(uint16_t*)Address);        
382
+//        printf("%08x : %04X \n",Address ,*(uint16_t*)Address);        
376 383
         Address += 2;
377 384
     }
378 385
 
@@ -416,7 +423,8 @@ int main(void)
416 423
   MX_TIM6_Init();
417 424
   MX_USART1_UART_Init();
418 425
   MX_USART2_UART_Init();
419
-  MX_USART3_UART_Init();
426
+  MX_SPI1_Init();
427
+  MX_I2C2_Init();
420 428
 
421 429
   /* Initialize interrupts */
422 430
   MX_NVIC_Init();
@@ -424,8 +432,7 @@ int main(void)
424 432
   HAL_TIM_Base_Start_IT(&htim6);
425 433
   HAL_UART_Receive_IT(&huart1, &rx1_data[0],1);
426 434
   HAL_UART_Receive_IT(&huart2, &rx2_data[0],1);
427
-  HAL_UART_Receive_IT(&huart3, &rx3_data[0],1);
428
-  setbuf(stdout, NULL); // \n ?��?��?��, printf �???????��?���?????? ?��?��?��  
435
+  setbuf(stdout, NULL); // \n 을 적을 떄만 
429 436
 #if 1 // PYJ.2019.03.04_BEGIN -- 
430 437
       printf("****************************************\r\n");
431 438
       printf("RGB Project\r\n");
@@ -435,27 +442,31 @@ int main(void)
435 442
 #endif // PYJ.2019.03.04_END -- 
436 443
   RGB_SensorIDAutoSet(1);
437 444
   Flash_InitRead();
438
-
439 445
   /* USER CODE END 2 */
440 446
 
441 447
   /* Infinite loop */
442 448
   /* USER CODE BEGIN WHILE */
443
-  uint8_t uartdatarecv = 0;
444
-
445 449
 
446 450
   while (1)
447 451
   {
452
+#if 0 // PYJ.2019.04.11_BEGIN -- 
448 453
     uartdatarecv = UartDataRecvGet(); 
449 454
     if(uartdatarecv != 0){
450 455
         if(uartdatarecv == 1){
451
-            Uart_dataCheck(&count_in1);
456
+            Uart_dataCheck(USART1_CNT,&count_in1);
452 457
         }else if(uartdatarecv == 2){
453
-            Uart_dataCheck(&count_in2);
454
-        }else if(uartdatarecv == 3){
455
-            Uart_dataCheck(&count_in3);
456
-        }   
458
+            Uart_dataCheck(USART2_CNT,&count_in2);
459
+        }
457 460
         UartDataRecvSet(0);
458 461
     }
462
+#else
463
+    UartDataBufferCheck();
464
+    if(UartDataRecvGet() >= 1 && UartTimerCnt > 100){
465
+        Uart_dataCheck(USART1_CNT,&count_in1);
466
+    }
467
+
468
+
469
+#endif // PYJ.2019.04.11_END -- 
459 470
     else{
460 471
         if(LedTimerCnt > 500){
461 472
             if(RGB_SensorIDAutoGet() == 1){
@@ -533,20 +544,89 @@ void SystemClock_Config(void)
533 544
   */
534 545
 static void MX_NVIC_Init(void)
535 546
 {
536
-  /* USART3_IRQn interrupt configuration */
537
-  HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
538
-  HAL_NVIC_EnableIRQ(USART3_IRQn);
539
-  /* USART1_IRQn interrupt configuration */
540
-  HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
541
-  HAL_NVIC_EnableIRQ(USART1_IRQn);
542 547
   /* USART2_IRQn interrupt configuration */
543 548
   HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
544 549
   HAL_NVIC_EnableIRQ(USART2_IRQn);
550
+  /* USART1_IRQn interrupt configuration */
551
+  HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
552
+  HAL_NVIC_EnableIRQ(USART1_IRQn);
545 553
   /* TIM6_IRQn interrupt configuration */
546 554
   HAL_NVIC_SetPriority(TIM6_IRQn, 0, 0);
547 555
   HAL_NVIC_EnableIRQ(TIM6_IRQn);
548 556
 }
549 557
 
558
+/**
559
+  * @brief I2C2 Initialization Function
560
+  * @param None
561
+  * @retval None
562
+  */
563
+static void MX_I2C2_Init(void)
564
+{
565
+
566
+  /* USER CODE BEGIN I2C2_Init 0 */
567
+
568
+  /* USER CODE END I2C2_Init 0 */
569
+
570
+  /* USER CODE BEGIN I2C2_Init 1 */
571
+
572
+  /* USER CODE END I2C2_Init 1 */
573
+  hi2c2.Instance = I2C2;
574
+  hi2c2.Init.ClockSpeed = 100000;
575
+  hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
576
+  hi2c2.Init.OwnAddress1 = 0;
577
+  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
578
+  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
579
+  hi2c2.Init.OwnAddress2 = 0;
580
+  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
581
+  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
582
+  if (HAL_I2C_Init(&hi2c2) != HAL_OK)
583
+  {
584
+    Error_Handler();
585
+  }
586
+  /* USER CODE BEGIN I2C2_Init 2 */
587
+
588
+  /* USER CODE END I2C2_Init 2 */
589
+
590
+}
591
+
592
+/**
593
+  * @brief SPI1 Initialization Function
594
+  * @param None
595
+  * @retval None
596
+  */
597
+static void MX_SPI1_Init(void)
598
+{
599
+
600
+  /* USER CODE BEGIN SPI1_Init 0 */
601
+
602
+  /* USER CODE END SPI1_Init 0 */
603
+
604
+  /* USER CODE BEGIN SPI1_Init 1 */
605
+
606
+  /* USER CODE END SPI1_Init 1 */
607
+  /* SPI1 parameter configuration*/
608
+  hspi1.Instance = SPI1;
609
+  hspi1.Init.Mode = SPI_MODE_MASTER;
610
+  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
611
+  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
612
+  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
613
+  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
614
+  hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
615
+  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
616
+  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
617
+  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
618
+  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
619
+  hspi1.Init.CRCPolynomial = 10;
620
+  if (HAL_SPI_Init(&hspi1) != HAL_OK)
621
+  {
622
+    Error_Handler();
623
+  }
624
+  /* USER CODE BEGIN SPI1_Init 2 */
625
+
626
+  /* USER CODE END SPI1_Init 2 */
627
+
628
+}
629
+
550 630
 /**
551 631
   * @brief TIM6 Initialization Function
552 632
   * @param None
@@ -651,39 +731,6 @@ static void MX_USART2_UART_Init(void)
651 731
 
652 732
 }
653 733
 
654
-/**
655
-  * @brief USART3 Initialization Function
656
-  * @param None
657
-  * @retval None
658
-  */
659
-static void MX_USART3_UART_Init(void)
660
-{
661
-
662
-  /* USER CODE BEGIN USART3_Init 0 */
663
-
664
-  /* USER CODE END USART3_Init 0 */
665
-
666
-  /* USER CODE BEGIN USART3_Init 1 */
667
-
668
-  /* USER CODE END USART3_Init 1 */
669
-  huart3.Instance = USART3;
670
-  huart3.Init.BaudRate = 115200;
671
-  huart3.Init.WordLength = UART_WORDLENGTH_8B;
672
-  huart3.Init.StopBits = UART_STOPBITS_1;
673
-  huart3.Init.Parity = UART_PARITY_NONE;
674
-  huart3.Init.Mode = UART_MODE_TX_RX;
675
-  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
676
-  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
677
-  if (HAL_UART_Init(&huart3) != HAL_OK)
678
-  {
679
-    Error_Handler();
680
-  }
681
-  /* USER CODE BEGIN USART3_Init 2 */
682
-
683
-  /* USER CODE END USART3_Init 2 */
684
-
685
-}
686
-
687 734
 /**
688 735
   * @brief GPIO Initialization Function
689 736
   * @param None
@@ -700,44 +747,60 @@ static void MX_GPIO_Init(void)
700 747
   __HAL_RCC_GPIOB_CLK_ENABLE();
701 748
 
702 749
   /*Configure GPIO pin Output Level */
703
-  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4 
704
-                          |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9 
705
-                          |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET);
750
+  HAL_GPIO_WritePin(GPIOC, BOOT_LED_Pin|SX1276_DIO4_Pin|SX1276_DIO5_Pin|SENSOR_EN4_Pin 
751
+                          |SENSOR_EN5_Pin|SENSOR_EN6_Pin|SENSOR_EN7_Pin|LED_CH1_Pin 
752
+                          |LED_CH2_Pin|LED_CH3_Pin, GPIO_PIN_RESET);
753
+
754
+  /*Configure GPIO pin Output Level */
755
+  HAL_GPIO_WritePin(GPIOA, SX1276_DIO0_Pin|SX1276_DIO1_Pin|SX1276_DIO2_Pin|SX1276_DIO3_Pin 
756
+                          |SENSOR_EN8_Pin, GPIO_PIN_RESET);
706 757
 
707 758
   /*Configure GPIO pin Output Level */
708
-  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7 
709
-                          |GPIO_PIN_8|GPIO_PIN_13, GPIO_PIN_RESET);
759
+  HAL_GPIO_WritePin(GPIOB, SX1276_RESET_Pin|LED_ALARM_Pin|SENSOR_EN1_Pin|SENSOR_EN2_Pin 
760
+                          |SENSOR_EN3_Pin|LED_CH5_Pin|LED_CH6_Pin|LED_CH7_Pin 
761
+                          |LED_CH8_Pin, GPIO_PIN_RESET);
710 762
 
711 763
   /*Configure GPIO pin Output Level */
712
-  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
713
-
714
-  /*Configure GPIO pins : PC13 PC15 PC3 PC4 
715
-                           PC6 PC7 PC8 PC9 
716
-                           PC10 PC11 PC12 */
717
-  GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4 
718
-                          |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9 
719
-                          |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
764
+  HAL_GPIO_WritePin(LED_CH4_GPIO_Port, LED_CH4_Pin, GPIO_PIN_RESET);
765
+
766
+  /*Configure GPIO pins : BOOT_LED_Pin SX1276_DIO4_Pin SX1276_DIO5_Pin SENSOR_EN4_Pin 
767
+                           SENSOR_EN5_Pin SENSOR_EN6_Pin SENSOR_EN7_Pin LED_CH1_Pin 
768
+                           LED_CH2_Pin LED_CH3_Pin */
769
+  GPIO_InitStruct.Pin = BOOT_LED_Pin|SX1276_DIO4_Pin|SX1276_DIO5_Pin|SENSOR_EN4_Pin 
770
+                          |SENSOR_EN5_Pin|SENSOR_EN6_Pin|SENSOR_EN7_Pin|LED_CH1_Pin 
771
+                          |LED_CH2_Pin|LED_CH3_Pin;
720 772
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
721 773
   GPIO_InitStruct.Pull = GPIO_NOPULL;
722 774
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
723 775
   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
724 776
 
725
-  /*Configure GPIO pins : PA4 PA5 PA6 PA7 
726
-                           PA8 PA13 */
727
-  GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7 
728
-                          |GPIO_PIN_8|GPIO_PIN_13;
777
+  /*Configure GPIO pins : SX1276_DIO0_Pin SX1276_DIO1_Pin SX1276_DIO2_Pin SX1276_DIO3_Pin 
778
+                           SENSOR_EN8_Pin */
779
+  GPIO_InitStruct.Pin = SX1276_DIO0_Pin|SX1276_DIO1_Pin|SX1276_DIO2_Pin|SX1276_DIO3_Pin 
780
+                          |SENSOR_EN8_Pin;
729 781
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
730 782
   GPIO_InitStruct.Pull = GPIO_NOPULL;
731 783
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
732 784
   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
733 785
 
734
-  /*Configure GPIO pins : PB12 PB13 PB14 PB15 */
735
-  GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
786
+  /*Configure GPIO pins : SX1276_RESET_Pin LED_ALARM_Pin SENSOR_EN1_Pin SENSOR_EN2_Pin 
787
+                           SENSOR_EN3_Pin LED_CH5_Pin LED_CH6_Pin LED_CH7_Pin 
788
+                           LED_CH8_Pin */
789
+  GPIO_InitStruct.Pin = SX1276_RESET_Pin|LED_ALARM_Pin|SENSOR_EN1_Pin|SENSOR_EN2_Pin 
790
+                          |SENSOR_EN3_Pin|LED_CH5_Pin|LED_CH6_Pin|LED_CH7_Pin 
791
+                          |LED_CH8_Pin;
736 792
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
737 793
   GPIO_InitStruct.Pull = GPIO_NOPULL;
738 794
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
739 795
   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
740 796
 
797
+  /*Configure GPIO pin : LED_CH4_Pin */
798
+  GPIO_InitStruct.Pin = LED_CH4_Pin;
799
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
800
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
801
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
802
+  HAL_GPIO_Init(LED_CH4_GPIO_Port, &GPIO_InitStruct);
803
+
741 804
 }
742 805
 
743 806
 /* USER CODE BEGIN 4 */

+ 153 - 49
Src/stm32f1xx_hal_msp.c

@@ -101,6 +101,157 @@ void HAL_MspInit(void)
101 101
   /* USER CODE END MspInit 1 */
102 102
 }
103 103
 
104
+/**
105
+* @brief I2C MSP Initialization
106
+* This function configures the hardware resources used in this example
107
+* @param hi2c: I2C handle pointer
108
+* @retval None
109
+*/
110
+void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
111
+{
112
+
113
+  GPIO_InitTypeDef GPIO_InitStruct = {0};
114
+  if(hi2c->Instance==I2C2)
115
+  {
116
+  /* USER CODE BEGIN I2C2_MspInit 0 */
117
+
118
+  /* USER CODE END I2C2_MspInit 0 */
119
+  
120
+    __HAL_RCC_GPIOB_CLK_ENABLE();
121
+    /**I2C2 GPIO Configuration    
122
+    PB10     ------> I2C2_SCL
123
+    PB11     ------> I2C2_SDA 
124
+    */
125
+    GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
126
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
127
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
128
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
129
+
130
+    /* Peripheral clock enable */
131
+    __HAL_RCC_I2C2_CLK_ENABLE();
132
+  /* USER CODE BEGIN I2C2_MspInit 1 */
133
+
134
+  /* USER CODE END I2C2_MspInit 1 */
135
+  }
136
+
137
+}
138
+
139
+/**
140
+* @brief I2C MSP De-Initialization
141
+* This function freeze the hardware resources used in this example
142
+* @param hi2c: I2C handle pointer
143
+* @retval None
144
+*/
145
+
146
+void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
147
+{
148
+
149
+  if(hi2c->Instance==I2C2)
150
+  {
151
+  /* USER CODE BEGIN I2C2_MspDeInit 0 */
152
+
153
+  /* USER CODE END I2C2_MspDeInit 0 */
154
+    /* Peripheral clock disable */
155
+    __HAL_RCC_I2C2_CLK_DISABLE();
156
+  
157
+    /**I2C2 GPIO Configuration    
158
+    PB10     ------> I2C2_SCL
159
+    PB11     ------> I2C2_SDA 
160
+    */
161
+    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
162
+
163
+  /* USER CODE BEGIN I2C2_MspDeInit 1 */
164
+
165
+  /* USER CODE END I2C2_MspDeInit 1 */
166
+  }
167
+
168
+}
169
+
170
+/**
171
+* @brief SPI MSP Initialization
172
+* This function configures the hardware resources used in this example
173
+* @param hspi: SPI handle pointer
174
+* @retval None
175
+*/
176
+void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
177
+{
178
+
179
+  GPIO_InitTypeDef GPIO_InitStruct = {0};
180
+  if(hspi->Instance==SPI1)
181
+  {
182
+  /* USER CODE BEGIN SPI1_MspInit 0 */
183
+
184
+  /* USER CODE END SPI1_MspInit 0 */
185
+    /* Peripheral clock enable */
186
+    __HAL_RCC_SPI1_CLK_ENABLE();
187
+  
188
+    __HAL_RCC_GPIOA_CLK_ENABLE();
189
+    __HAL_RCC_GPIOB_CLK_ENABLE();
190
+    /**SPI1 GPIO Configuration    
191
+    PA15     ------> SPI1_NSS
192
+    PB3     ------> SPI1_SCK
193
+    PB4     ------> SPI1_MISO
194
+    PB5     ------> SPI1_MOSI 
195
+    */
196
+    GPIO_InitStruct.Pin = GPIO_PIN_15;
197
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
198
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
199
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
200
+
201
+    GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_5;
202
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
203
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
204
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
205
+
206
+    GPIO_InitStruct.Pin = GPIO_PIN_4;
207
+    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
208
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
209
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
210
+
211
+    __HAL_AFIO_REMAP_SPI1_ENABLE();
212
+
213
+  /* USER CODE BEGIN SPI1_MspInit 1 */
214
+
215
+  /* USER CODE END SPI1_MspInit 1 */
216
+  }
217
+
218
+}
219
+
220
+/**
221
+* @brief SPI MSP De-Initialization
222
+* This function freeze the hardware resources used in this example
223
+* @param hspi: SPI handle pointer
224
+* @retval None
225
+*/
226
+
227
+void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
228
+{
229
+
230
+  if(hspi->Instance==SPI1)
231
+  {
232
+  /* USER CODE BEGIN SPI1_MspDeInit 0 */
233
+
234
+  /* USER CODE END SPI1_MspDeInit 0 */
235
+    /* Peripheral clock disable */
236
+    __HAL_RCC_SPI1_CLK_DISABLE();
237
+  
238
+    /**SPI1 GPIO Configuration    
239
+    PA15     ------> SPI1_NSS
240
+    PB3     ------> SPI1_SCK
241
+    PB4     ------> SPI1_MISO
242
+    PB5     ------> SPI1_MOSI 
243
+    */
244
+    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_15);
245
+
246
+    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
247
+
248
+  /* USER CODE BEGIN SPI1_MspDeInit 1 */
249
+
250
+  /* USER CODE END SPI1_MspDeInit 1 */
251
+  }
252
+
253
+}
254
+
104 255
 /**
105 256
 * @brief TIM_Base MSP Initialization
106 257
 * This function configures the hardware resources used in this example
@@ -181,7 +332,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
181 332
 
182 333
     GPIO_InitStruct.Pin = GPIO_PIN_10;
183 334
     GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
184
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
335
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
185 336
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
186 337
 
187 338
   /* USER CODE BEGIN USART1_MspInit 1 */
@@ -208,40 +359,13 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
208 359
 
209 360
     GPIO_InitStruct.Pin = GPIO_PIN_3;
210 361
     GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
211
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
362
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
212 363
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
213 364
 
214 365
   /* USER CODE BEGIN USART2_MspInit 1 */
215 366
 
216 367
   /* USER CODE END USART2_MspInit 1 */
217 368
   }
218
-  else if(huart->Instance==USART3)
219
-  {
220
-  /* USER CODE BEGIN USART3_MspInit 0 */
221
-
222
-  /* USER CODE END USART3_MspInit 0 */
223
-    /* Peripheral clock enable */
224
-    __HAL_RCC_USART3_CLK_ENABLE();
225
-  
226
-    __HAL_RCC_GPIOB_CLK_ENABLE();
227
-    /**USART3 GPIO Configuration    
228
-    PB10     ------> USART3_TX
229
-    PB11     ------> USART3_RX 
230
-    */
231
-    GPIO_InitStruct.Pin = GPIO_PIN_10;
232
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
233
-    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
234
-    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
235
-
236
-    GPIO_InitStruct.Pin = GPIO_PIN_11;
237
-    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
238
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
239
-    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
240
-
241
-  /* USER CODE BEGIN USART3_MspInit 1 */
242
-
243
-  /* USER CODE END USART3_MspInit 1 */
244
-  }
245 369
 
246 370
 }
247 371
 
@@ -295,26 +419,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
295 419
 
296 420
   /* USER CODE END USART2_MspDeInit 1 */
297 421
   }
298
-  else if(huart->Instance==USART3)
299
-  {
300
-  /* USER CODE BEGIN USART3_MspDeInit 0 */
301
-
302
-  /* USER CODE END USART3_MspDeInit 0 */
303
-    /* Peripheral clock disable */
304
-    __HAL_RCC_USART3_CLK_DISABLE();
305
-  
306
-    /**USART3 GPIO Configuration    
307
-    PB10     ------> USART3_TX
308
-    PB11     ------> USART3_RX 
309
-    */
310
-    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
311
-
312
-    /* USART3 interrupt DeInit */
313
-    HAL_NVIC_DisableIRQ(USART3_IRQn);
314
-  /* USER CODE BEGIN USART3_MspDeInit 1 */
315
-
316
-  /* USER CODE END USART3_MspDeInit 1 */
317
-  }
318 422
 
319 423
 }
320 424
 

+ 0 - 15
Src/stm32f1xx_it.c

@@ -74,7 +74,6 @@
74 74
 extern TIM_HandleTypeDef htim6;
75 75
 extern UART_HandleTypeDef huart1;
76 76
 extern UART_HandleTypeDef huart2;
77
-extern UART_HandleTypeDef huart3;
78 77
 /* USER CODE BEGIN EV */
79 78
 
80 79
 /* USER CODE END EV */
@@ -243,20 +242,6 @@ void USART2_IRQHandler(void)
243 242
   /* USER CODE END USART2_IRQn 1 */
244 243
 }
245 244
 
246
-/**
247
-  * @brief This function handles USART3 global interrupt.
248
-  */
249
-void USART3_IRQHandler(void)
250
-{
251
-  /* USER CODE BEGIN USART3_IRQn 0 */
252
-
253
-  /* USER CODE END USART3_IRQn 0 */
254
-  HAL_UART_IRQHandler(&huart3);
255
-  /* USER CODE BEGIN USART3_IRQn 1 */
256
-
257
-  /* USER CODE END USART3_IRQn 1 */
258
-}
259
-
260 245
 /**
261 246
   * @brief This function handles TIM6 global interrupt.
262 247
   */