Pārlūkot izejas kodu

sx1276 Default value 설정
와치독 추가 // 아직 사용 불가
Usart Timer 1, 2 각각 추가
main loop 함수 별로 정리

june9152 6 gadi atpakaļ
vecāks
revīzija
db06c9a170

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 180 - 180
.cproject


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2 - 2
.mxproject


BIN
Debug/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.o


+ 2 - 0
Debug/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.su

@@ -0,0 +1,2 @@
1
+stm32f1xx_hal_iwdg.c:162:19:HAL_IWDG_Init	16	static
2
+stm32f1xx_hal_iwdg.c:230:19:HAL_IWDG_Refresh	0	static

BIN
Debug/STM32F103_RGB_Controller.bin


BIN
Debug/STM32F103_RGB_Controller.binary


BIN
Debug/STM32F103_RGB_Controller.elf


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1203 - 1160
Debug/STM32F103_RGB_Controller.hex


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 7749 - 7500
Debug/STM32F103_RGB_Controller.list


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 848 - 769
Debug/STM32F103_RGB_Controller.map


BIN
Debug/Src/GPIO_SPI.o


BIN
Debug/Src/M24C32.o


BIN
Debug/Src/RGB_Controller.o


+ 16 - 13
Debug/Src/RGB_Controller.su

@@ -1,13 +1,16 @@
1
-RGB_Controller.c:59:10:RGB_Limit_Address_Check	0	static
2
-RGB_Controller.c:73:10:RGB_Location_Address_Check	0	static
3
-RGB_Controller.c:23:6:RGB_Data_Init	48	static
4
-RGB_Controller.c:88:6:RGB_Response_Func	32	static
5
-RGB_Controller.c:170:6:RGB_Sensor_LED_Alarm_ON	8	static
6
-RGB_Controller.c:208:6:RGB_Sensor_LED_Alarm_OFF	8	static
7
-RGB_Controller.c:247:6:RGB_Alarm_Operate	32	static
8
-RGB_Controller.c:290:9:RGB_DeviceStatusCheck	12	static
9
-RGB_Controller.c:363:9:RGB_BufCal	0	static
10
-RGB_Controller.c:337:6:RGB_Data_Stack	24	static
11
-RGB_Controller.c:263:6:RGB_Alarm_Check	48	static
12
-RGB_Controller.c:377:9:RGB_LimitData_Get	0	static
13
-RGB_Controller.c:391:6:RGB_Controller_Func	120	static
1
+core_cm3.h:1616:22:NVIC_SystemReset	0	static
2
+RGB_Controller.c:65:10:RGB_Limit_Address_Check	0	static
3
+RGB_Controller.c:79:10:RGB_Location_Address_Check	0	static
4
+RGB_Controller.c:24:6:RGB_Data_Init	48	static
5
+RGB_Controller.c:94:6:DataSendStop_Set	0	static
6
+RGB_Controller.c:97:6:DataSendStop_Get	0	static
7
+RGB_Controller.c:101:6:RGB_Response_Func	32	static
8
+RGB_Controller.c:198:6:RGB_Sensor_LED_Alarm_ON	8	static
9
+RGB_Controller.c:236:6:RGB_Sensor_LED_Alarm_OFF	8	static
10
+RGB_Controller.c:275:6:RGB_Alarm_Operate	32	static
11
+RGB_Controller.c:318:9:RGB_DeviceStatusCheck	12	static
12
+RGB_Controller.c:397:9:RGB_BufCal	0	static
13
+RGB_Controller.c:368:6:RGB_Data_Stack	24	static
14
+RGB_Controller.c:291:6:RGB_Alarm_Check	48	static
15
+RGB_Controller.c:411:9:RGB_LimitData_Get	0	static
16
+RGB_Controller.c:426:6:RGB_Controller_Func	120	static

BIN
Debug/Src/RGB_Lora.o


BIN
Debug/Src/SX1276.o


+ 16 - 15
Debug/Src/SX1276.su

@@ -1,3 +1,4 @@
1
+core_cm3.h:1616:22:NVIC_SystemReset	0	static
1 2
 SX1276.c:22:13:SX1276_hw_SetNSS	0	static
2 3
 SX1276.c:17:13:SX1276_hw_init	8	static
3 4
 SX1276.c:46:6:SX1276_hw_SPICommand	8	static
@@ -12,20 +13,20 @@ SX1276.c:98:6:SX1276_SPIWrite	16	static
12 13
 SX1276.c:107:6:SX1276_SPIBurstRead	24	static
13 14
 SX1276.c:125:6:SX1276_SPIBurstWrite	0	static
14 15
 SX1276.c:215:6:SX1276_set_power	0	static
15
-SX1276.c:281:6:SX1276_standby	8	static
16
-SX1276.c:286:6:SX1276_sleep	8	static
17
-SX1276.c:291:6:SX1276_entryLoRa	0	static
16
+SX1276.c:278:6:SX1276_standby	8	static
17
+SX1276.c:285:6:SX1276_sleep	8	static
18
+SX1276.c:292:6:SX1276_entryLoRa	0	static
18 19
 SX1276.c:226:6:SX1276_config	32	static
19 20
 SX1276.c:221:6:SX1276_defaultConfig	32	static
20
-SX1276.c:295:6:SX1276_clearLoRaIrq	0	static
21
-SX1276.c:299:5:SX1276_LoRaEntryRx	16	static
22
-SX1276.c:331:9:SX1276_LoRaRxPacket	16	static
23
-SX1276.c:357:5:SX1276_LoRaEntryTx	16	static
24
-SX1276.c:388:5:SX1276_LoRaTxPacket	16	static
25
-SX1276.c:409:6:SX1276_begin	40	static
26
-SX1276.c:422:5:SX1276_transmit	24	static
27
-SX1276.c:430:5:SX1276_receive	0	static
28
-SX1276.c:434:9:SX1276_available	0	static
29
-SX1276.c:438:9:SX1276_read	16	static
30
-SX1276.c:447:9:SX1276_RSSI_LoRa	8	static
31
-SX1276.c:454:9:SX1276_RSSI	8	static
21
+SX1276.c:297:6:SX1276_clearLoRaIrq	0	static
22
+SX1276.c:301:5:SX1276_LoRaEntryRx	16	static
23
+SX1276.c:336:9:SX1276_LoRaRxPacket	16	static
24
+SX1276.c:362:5:SX1276_LoRaEntryTx	16	static
25
+SX1276.c:396:5:SX1276_LoRaTxPacket	16	static
26
+SX1276.c:422:6:SX1276_begin	40	static
27
+SX1276.c:435:5:SX1276_transmit	24	static
28
+SX1276.c:443:5:SX1276_receive	0	static
29
+SX1276.c:447:9:SX1276_available	0	static
30
+SX1276.c:451:9:SX1276_read	16	static
31
+SX1276.c:460:9:SX1276_RSSI_LoRa	8	static
32
+SX1276.c:467:9:SX1276_RSSI	8	static

BIN
Debug/Src/main.o


+ 25 - 21
Debug/Src/main.su

@@ -1,21 +1,25 @@
1
-main.c:144:6:HAL_UART_RxCpltCallback	4	static
2
-main.c:189:6:HAL_TIM_PeriodElapsedCallback	0	static
3
-main.c:199:6:LoraDataSendSet	0	static
4
-main.c:202:9:LoraDataSendGet	0	static
5
-main.c:206:6:UartDataRecvSet	0	static
6
-main.c:209:9:UartDataRecvGet	0	static
7
-main.c:212:6:RGB_SensorIDAutoSet	0	static
8
-main.c:215:9:RGB_SensorIDAutoGet	0	static
9
-main.c:219:6:Uart2_Data_Send	0	static
10
-main.c:222:6:Uart1_Data_Send	0	static
11
-main.c:226:5:_write	8	static
12
-main.c:262:6:Uart_dataCheck	24	static
13
-main.c:294:6:RGB_Sensor_PowerOnOff	40	static
14
-main.c:452:6:test_read	24	static
15
-main.c:471:6:Flash_RGB_Data_Write	16	static
16
-main.c:484:6:Flash_write	24	static
17
-main.c:537:6:Flash_InitRead	12	static
18
-main.c:581:6:Lora_Initialize	32	static
19
-main.c:761:6:SystemClock_Config	72	static
20
-main.c:613:5:main	304	static
21
-main.c:1048:6:Error_Handler	0	static
1
+main.c:161:6:HAL_UART_RxCpltCallback	8	static
2
+main.c:174:6:HAL_TIM_PeriodElapsedCallback	0	static
3
+main.c:185:6:LoraDataSendSet	0	static
4
+main.c:188:9:LoraDataSendGet	0	static
5
+main.c:192:6:UartDataRecvSet	0	static
6
+main.c:195:9:UartDataRecvGet	0	static
7
+main.c:198:6:RGB_SensorIDAutoSet	0	static
8
+main.c:201:9:RGB_SensorIDAutoGet	0	static
9
+main.c:205:6:Uart2_Data_Send	0	static
10
+main.c:208:6:Uart1_Data_Send	0	static
11
+main.c:212:5:_write	8	static
12
+main.c:248:6:Uart_dataCheck	24	static
13
+main.c:280:6:RGB_Sensor_PowerOnOff	16	static
14
+main.c:437:6:test_read	24	static
15
+main.c:456:6:Flash_RGB_Data_Write	16	static
16
+main.c:469:6:Flash_write	24	static
17
+main.c:522:6:Flash_InitRead	12	static
18
+main.c:556:6:Lora_Initialize	32	static
19
+main.c:581:6:Lora_Operate	24	static
20
+main.c:611:6:Usart_Data_RecvCheck	16	static
21
+main.c:643:6:RGB_Sensor_DataRequest	48	static
22
+main.c:669:6:WDOG_Check_Flag	0	static
23
+main.c:767:6:SystemClock_Config	72	static
24
+main.c:683:5:main	64	static
25
+main.c:1095:6:Error_Handler	0	static

BIN
Debug/Src/stm32f1xx_hal_msp.o


+ 7 - 7
Debug/Src/stm32f1xx_hal_msp.su

@@ -1,7 +1,7 @@
1
-stm32f1xx_hal_msp.c:85:6:HAL_MspInit	8	static
2
-stm32f1xx_hal_msp.c:111:6:HAL_I2C_MspInit	32	static
3
-stm32f1xx_hal_msp.c:147:6:HAL_I2C_MspDeInit	0	static
4
-stm32f1xx_hal_msp.c:177:6:HAL_TIM_Base_MspInit	8	static
5
-stm32f1xx_hal_msp.c:201:6:HAL_TIM_Base_MspDeInit	0	static
6
-stm32f1xx_hal_msp.c:227:6:HAL_UART_MspInit	48	static
7
-stm32f1xx_hal_msp.c:312:6:HAL_UART_MspDeInit	8	static
1
+stm32f1xx_hal_msp.c:87:6:HAL_MspInit	8	static
2
+stm32f1xx_hal_msp.c:113:6:HAL_I2C_MspInit	32	static
3
+stm32f1xx_hal_msp.c:149:6:HAL_I2C_MspDeInit	0	static
4
+stm32f1xx_hal_msp.c:179:6:HAL_TIM_Base_MspInit	8	static
5
+stm32f1xx_hal_msp.c:203:6:HAL_TIM_Base_MspDeInit	0	static
6
+stm32f1xx_hal_msp.c:229:6:HAL_UART_MspInit	48	static
7
+stm32f1xx_hal_msp.c:331:6:HAL_UART_MspDeInit	8	static

BIN
Debug/Src/stm32f1xx_it.o


+ 15 - 13
Debug/Src/stm32f1xx_it.su

@@ -1,13 +1,15 @@
1
-stm32f1xx_it.c:88:6:NMI_Handler	0	static
2
-stm32f1xx_it.c:101:6:HardFault_Handler	0	static
3
-stm32f1xx_it.c:116:6:MemManage_Handler	0	static
4
-stm32f1xx_it.c:131:6:BusFault_Handler	0	static
5
-stm32f1xx_it.c:146:6:UsageFault_Handler	0	static
6
-stm32f1xx_it.c:161:6:SVC_Handler	0	static
7
-stm32f1xx_it.c:174:6:DebugMon_Handler	0	static
8
-stm32f1xx_it.c:187:6:PendSV_Handler	0	static
9
-stm32f1xx_it.c:200:6:SysTick_Handler	0	static
10
-stm32f1xx_it.c:221:6:DMA1_Channel5_IRQHandler	0	static
11
-stm32f1xx_it.c:235:6:USART1_IRQHandler	0	static
12
-stm32f1xx_it.c:249:6:USART2_IRQHandler	0	static
13
-stm32f1xx_it.c:263:6:TIM6_IRQHandler	0	static
1
+stm32f1xx_it.c:89:6:NMI_Handler	0	static
2
+stm32f1xx_it.c:102:6:HardFault_Handler	0	static
3
+stm32f1xx_it.c:117:6:MemManage_Handler	0	static
4
+stm32f1xx_it.c:132:6:BusFault_Handler	0	static
5
+stm32f1xx_it.c:147:6:UsageFault_Handler	0	static
6
+stm32f1xx_it.c:162:6:SVC_Handler	0	static
7
+stm32f1xx_it.c:175:6:DebugMon_Handler	0	static
8
+stm32f1xx_it.c:188:6:PendSV_Handler	0	static
9
+stm32f1xx_it.c:201:6:SysTick_Handler	0	static
10
+stm32f1xx_it.c:222:6:EXTI0_IRQHandler	0	static
11
+stm32f1xx_it.c:236:6:DMA1_Channel5_IRQHandler	0	static
12
+stm32f1xx_it.c:250:6:DMA1_Channel6_IRQHandler	0	static
13
+stm32f1xx_it.c:264:6:USART1_IRQHandler	0	static
14
+stm32f1xx_it.c:278:6:USART2_IRQHandler	0	static
15
+stm32f1xx_it.c:292:6:TIM6_IRQHandler	0	static

+ 238 - 0
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_iwdg.h

@@ -0,0 +1,238 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_iwdg.h
4
+  * @author  MCD Application Team
5
+  * @brief   Header file of IWDG 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_IWDG_H
38
+#define __STM32F1xx_HAL_IWDG_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 IWDG
52
+  * @{
53
+  */
54
+
55
+/* Exported types ------------------------------------------------------------*/
56
+/** @defgroup IWDG_Exported_Types IWDG Exported Types
57
+  * @{
58
+  */
59
+
60
+/**
61
+  * @brief  IWDG Init structure definition
62
+  */
63
+typedef struct
64
+{
65
+  uint32_t Prescaler;  /*!< Select the prescaler of the IWDG.
66
+                            This parameter can be a value of @ref IWDG_Prescaler */
67
+
68
+  uint32_t Reload;     /*!< Specifies the IWDG down-counter reload value.
69
+                            This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
70
+
71
+} IWDG_InitTypeDef;
72
+
73
+/**
74
+  * @brief  IWDG Handle Structure definition
75
+  */
76
+typedef struct
77
+{
78
+  IWDG_TypeDef                 *Instance;  /*!< Register base address    */
79
+
80
+  IWDG_InitTypeDef             Init;       /*!< IWDG required parameters */
81
+
82
+} IWDG_HandleTypeDef;
83
+
84
+/**
85
+  * @}
86
+  */
87
+
88
+/* Exported constants --------------------------------------------------------*/
89
+/** @defgroup IWDG_Exported_Constants IWDG Exported Constants
90
+  * @{
91
+  */
92
+
93
+/** @defgroup IWDG_Prescaler IWDG Prescaler
94
+  * @{
95
+  */
96
+#define IWDG_PRESCALER_4                0x00000000U                   /*!< IWDG prescaler set to 4   */
97
+#define IWDG_PRESCALER_8                IWDG_PR_PR_0                  /*!< IWDG prescaler set to 8   */
98
+#define IWDG_PRESCALER_16               IWDG_PR_PR_1                  /*!< IWDG prescaler set to 16  */
99
+#define IWDG_PRESCALER_32               (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 32  */
100
+#define IWDG_PRESCALER_64               IWDG_PR_PR_2                  /*!< IWDG prescaler set to 64  */
101
+#define IWDG_PRESCALER_128              (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 128 */
102
+#define IWDG_PRESCALER_256              (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< IWDG prescaler set to 256 */
103
+/**
104
+  * @}
105
+  */
106
+
107
+/**
108
+  * @}
109
+  */
110
+
111
+
112
+/* Exported macros -----------------------------------------------------------*/
113
+/** @defgroup IWDG_Exported_Macros IWDG Exported Macros
114
+  * @{
115
+  */
116
+
117
+/**
118
+  * @brief  Enable the IWDG peripheral.
119
+  * @param  __HANDLE__  IWDG handle
120
+  * @retval None
121
+  */
122
+#define __HAL_IWDG_START(__HANDLE__)                WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE)
123
+
124
+/**
125
+  * @brief  Reload IWDG counter with value defined in the reload register
126
+  *         (write access to IWDG_PR & IWDG_RLR registers disabled).
127
+  * @param  __HANDLE__  IWDG handle
128
+  * @retval None
129
+  */
130
+#define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__)       WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD)
131
+
132
+/**
133
+  * @}
134
+  */
135
+
136
+/* Exported functions --------------------------------------------------------*/
137
+/** @defgroup IWDG_Exported_Functions  IWDG Exported Functions
138
+  * @{
139
+  */
140
+
141
+/** @defgroup IWDG_Exported_Functions_Group1 Initialization and Start functions
142
+  * @{
143
+  */
144
+/* Initialization/Start functions  ********************************************/
145
+HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
146
+/**
147
+  * @}
148
+  */
149
+
150
+/** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
151
+  * @{
152
+  */
153
+/* I/O operation functions ****************************************************/
154
+HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
155
+/**
156
+  * @}
157
+  */
158
+
159
+/**
160
+  * @}
161
+  */
162
+
163
+/* Private constants ---------------------------------------------------------*/
164
+/** @defgroup IWDG_Private_Constants IWDG Private Constants
165
+  * @{
166
+  */
167
+
168
+/**
169
+  * @brief  IWDG Key Register BitMask
170
+  */
171
+#define IWDG_KEY_RELOAD                 0x0000AAAAU  /*!< IWDG Reload Counter Enable   */
172
+#define IWDG_KEY_ENABLE                 0x0000CCCCU  /*!< IWDG Peripheral Enable       */
173
+#define IWDG_KEY_WRITE_ACCESS_ENABLE    0x00005555U  /*!< IWDG KR Write Access Enable  */
174
+#define IWDG_KEY_WRITE_ACCESS_DISABLE   0x00000000U  /*!< IWDG KR Write Access Disable */
175
+
176
+/**
177
+  * @}
178
+  */
179
+
180
+/* Private macros ------------------------------------------------------------*/
181
+/** @defgroup IWDG_Private_Macros IWDG Private Macros
182
+  * @{
183
+  */
184
+
185
+/**
186
+  * @brief  Enable write access to IWDG_PR and IWDG_RLR registers.
187
+  * @param  __HANDLE__  IWDG handle
188
+  * @retval None
189
+  */
190
+#define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__)  WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE)
191
+
192
+/**
193
+  * @brief  Disable write access to IWDG_PR and IWDG_RLR registers.
194
+  * @param  __HANDLE__  IWDG handle
195
+  * @retval None
196
+  */
197
+#define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE)
198
+
199
+/**
200
+  * @brief  Check IWDG prescaler value.
201
+  * @param  __PRESCALER__  IWDG prescaler value
202
+  * @retval None
203
+  */
204
+#define IS_IWDG_PRESCALER(__PRESCALER__)      (((__PRESCALER__) == IWDG_PRESCALER_4)  || \
205
+                                               ((__PRESCALER__) == IWDG_PRESCALER_8)  || \
206
+                                               ((__PRESCALER__) == IWDG_PRESCALER_16) || \
207
+                                               ((__PRESCALER__) == IWDG_PRESCALER_32) || \
208
+                                               ((__PRESCALER__) == IWDG_PRESCALER_64) || \
209
+                                               ((__PRESCALER__) == IWDG_PRESCALER_128)|| \
210
+                                               ((__PRESCALER__) == IWDG_PRESCALER_256))
211
+
212
+/**
213
+  * @brief  Check IWDG reload value.
214
+  * @param  __RELOAD__  IWDG reload value
215
+  * @retval None
216
+  */
217
+#define IS_IWDG_RELOAD(__RELOAD__)            ((__RELOAD__) <= IWDG_RLR_RL)
218
+
219
+/**
220
+  * @}
221
+  */
222
+
223
+/**
224
+  * @}
225
+  */
226
+
227
+/**
228
+  * @}
229
+  */
230
+
231
+
232
+#ifdef __cplusplus
233
+}
234
+#endif
235
+
236
+#endif /* __STM32F1xx_HAL_IWDG_H */
237
+
238
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 256 - 0
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c

@@ -0,0 +1,256 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    stm32f1xx_hal_iwdg.c
4
+  * @author  MCD Application Team
5
+  * @brief   IWDG HAL module driver.
6
+  *          This file provides firmware functions to manage the following
7
+  *          functionalities of the Independent Watchdog (IWDG) peripheral:
8
+  *           + Initialization and Start functions
9
+  *           + IO operation functions
10
+  *
11
+  @verbatim
12
+  ==============================================================================
13
+                    ##### IWDG Generic features #####
14
+  ==============================================================================
15
+  [..]
16
+    (+) The IWDG can be started by either software or hardware (configurable
17
+        through option byte).
18
+
19
+    (+) The IWDG is clocked by Low-Speed clock (LSI) and thus stays active even
20
+        if the main clock fails.
21
+
22
+    (+) Once the IWDG is started, the LSI is forced ON and both can not be
23
+        disabled. The counter starts counting down from the reset value (0xFFF).
24
+        When it reaches the end of count value (0x000) a reset signal is
25
+        generated (IWDG reset).
26
+
27
+    (+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register,
28
+        the IWDG_RLR value is reloaded in the counter and the watchdog reset is
29
+        prevented.
30
+
31
+    (+) The IWDG is implemented in the VDD voltage domain that is still functional
32
+        in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
33
+        IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
34
+        reset occurs.
35
+
36
+    (+) Debug mode : When the microcontroller enters debug mode (core halted),
37
+        the IWDG counter either continues to work normally or stops, depending
38
+        on DBG_IWDG_STOP configuration bit in DBG module, accessible through
39
+        __HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros
40
+
41
+    [..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s
42
+         The IWDG timeout may vary due to LSI frequency dispersion. STM32F1xx
43
+         devices provide the capability to measure the LSI frequency (LSI clock
44
+         connected internally to TIM5 CH4 input capture). The measured value
45
+         can be used to have an IWDG timeout with an acceptable accuracy.
46
+
47
+                     ##### How to use this driver #####
48
+  ==============================================================================
49
+  [..]
50
+    (#) Use IWDG using HAL_IWDG_Init() function to :
51
+      (++) Enable instance by writing Start keyword in IWDG_KEY register. LSI
52
+           clock is forced ON and IWDG counter starts downcounting.
53
+      (++) Enable write access to configuration register: IWDG_PR & IWDG_RLR.
54
+      (++) Configure the IWDG prescaler and counter reload value. This reload
55
+           value will be loaded in the IWDG counter each time the watchdog is
56
+           reloaded, then the IWDG will start counting down from this value.
57
+      (++) wait for status flags to be reset"
58
+
59
+    (#) Then the application program must refresh the IWDG counter at regular
60
+        intervals during normal operation to prevent an MCU reset, using
61
+        HAL_IWDG_Refresh() function.
62
+
63
+     *** IWDG HAL driver macros list ***
64
+     ====================================
65
+     [..]
66
+       Below the list of most used macros in IWDG HAL driver:
67
+      (+) __HAL_IWDG_START: Enable the IWDG peripheral
68
+      (+) __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in
69
+          the reload register
70
+
71
+  @endverbatim
72
+  ******************************************************************************
73
+  * @attention
74
+  *
75
+  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
76
+  *
77
+  * Redistribution and use in source and binary forms, with or without modification,
78
+  * are permitted provided that the following conditions are met:
79
+  *   1. Redistributions of source code must retain the above copyright notice,
80
+  *      this list of conditions and the following disclaimer.
81
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
82
+  *      this list of conditions and the following disclaimer in the documentation
83
+  *      and/or other materials provided with the distribution
84
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
85
+  *      may be used to endorse or promote products derived from this software
86
+  *      without specific prior written permission.
87
+  *
88
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
89
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
90
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
91
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
92
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
93
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
94
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
95
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
96
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
97
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98
+  *
99
+  ******************************************************************************
100
+  */
101
+
102
+/* Includes ------------------------------------------------------------------*/
103
+#include "stm32f1xx_hal.h"
104
+
105
+/** @addtogroup STM32F1xx_HAL_Driver
106
+  * @{
107
+  */
108
+
109
+#ifdef HAL_IWDG_MODULE_ENABLED
110
+/** @defgroup IWDG IWDG
111
+  * @brief IWDG HAL module driver.
112
+  * @{
113
+  */
114
+
115
+/* Private typedef -----------------------------------------------------------*/
116
+/* Private define ------------------------------------------------------------*/
117
+/** @defgroup IWDG_Private_Defines IWDG Private Defines
118
+  * @{
119
+  */
120
+/* Status register need 5 RC LSI divided by prescaler clock to be updated. With
121
+   higher prescaler (256), and according to HSI variation, we need to wait at
122
+   least 6 cycles so 48 ms. */
123
+#define HAL_IWDG_DEFAULT_TIMEOUT            48U
124
+/**
125
+  * @}
126
+  */
127
+
128
+/* Private macro -------------------------------------------------------------*/
129
+/* Private variables ---------------------------------------------------------*/
130
+/* Private function prototypes -----------------------------------------------*/
131
+/* Exported functions --------------------------------------------------------*/
132
+
133
+/** @addtogroup IWDG_Exported_Functions
134
+  * @{
135
+  */
136
+
137
+/** @addtogroup IWDG_Exported_Functions_Group1
138
+  *  @brief    Initialization and Start functions.
139
+  *
140
+@verbatim
141
+ ===============================================================================
142
+          ##### Initialization and Start functions #####
143
+ ===============================================================================
144
+ [..]  This section provides functions allowing to:
145
+      (+) Initialize the IWDG according to the specified parameters in the
146
+          IWDG_InitTypeDef of associated handle.
147
+      (+) Once initialization is performed in HAL_IWDG_Init function, Watchdog
148
+          is reloaded in order to exit function with correct time base.
149
+
150
+@endverbatim
151
+  * @{
152
+  */
153
+
154
+/**
155
+  * @brief  Initialize the IWDG according to the specified parameters in the
156
+  *         IWDG_InitTypeDef and start watchdog. Before exiting function,
157
+  *         watchdog is refreshed in order to have correct time base.
158
+  * @param  hiwdg  pointer to a IWDG_HandleTypeDef structure that contains
159
+  *                the configuration information for the specified IWDG module.
160
+  * @retval HAL status
161
+  */
162
+HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
163
+{
164
+  uint32_t tickstart;
165
+
166
+  /* Check the IWDG handle allocation */
167
+  if (hiwdg == NULL)
168
+  {
169
+    return HAL_ERROR;
170
+  }
171
+
172
+  /* Check the parameters */
173
+  assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
174
+  assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
175
+  assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
176
+
177
+  /* Enable IWDG. LSI is turned on automaticaly */
178
+  __HAL_IWDG_START(hiwdg);
179
+
180
+  /* Enable write access to IWDG_PR and IWDG_RLR registers by writing 0x5555 in KR */
181
+  IWDG_ENABLE_WRITE_ACCESS(hiwdg);
182
+
183
+  /* Write to IWDG registers the Prescaler & Reload values to work with */
184
+  hiwdg->Instance->PR = hiwdg->Init.Prescaler;
185
+  hiwdg->Instance->RLR = hiwdg->Init.Reload;
186
+
187
+  /* Check pending flag, if previous update not done, return timeout */
188
+  tickstart = HAL_GetTick();
189
+
190
+  /* Wait for register to be updated */
191
+  while (hiwdg->Instance->SR != RESET)
192
+  {
193
+    if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
194
+    {
195
+      return HAL_TIMEOUT;
196
+    }
197
+  }
198
+
199
+  /* Reload IWDG counter with value defined in the reload register */
200
+  __HAL_IWDG_RELOAD_COUNTER(hiwdg);
201
+
202
+  /* Return function status */
203
+  return HAL_OK;
204
+}
205
+
206
+/**
207
+  * @}
208
+  */
209
+
210
+/** @addtogroup IWDG_Exported_Functions_Group2
211
+  *  @brief   IO operation functions
212
+  *
213
+@verbatim
214
+ ===============================================================================
215
+                      ##### IO operation functions #####
216
+ ===============================================================================
217
+ [..]  This section provides functions allowing to:
218
+      (+) Refresh the IWDG.
219
+
220
+@endverbatim
221
+  * @{
222
+  */
223
+
224
+/**
225
+  * @brief  Refresh the IWDG.
226
+  * @param  hiwdg  pointer to a IWDG_HandleTypeDef structure that contains
227
+  *                the configuration information for the specified IWDG module.
228
+  * @retval HAL status
229
+  */
230
+HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
231
+{
232
+  /* Reload IWDG counter with value defined in the reload register */
233
+  __HAL_IWDG_RELOAD_COUNTER(hiwdg);
234
+
235
+  /* Return function status */
236
+  return HAL_OK;
237
+}
238
+
239
+/**
240
+  * @}
241
+  */
242
+
243
+/**
244
+  * @}
245
+  */
246
+
247
+#endif /* HAL_IWDG_MODULE_ENABLED */
248
+/**
249
+  * @}
250
+  */
251
+
252
+/**
253
+  * @}
254
+  */
255
+
256
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 1 - 0
Inc/RGB_Controller.h

@@ -20,6 +20,7 @@ uint16_t RGB_SensorGreenLimit_Buf[9];
20 20
 uint16_t RGB_SensorBlueLimit_Buf[9];
21 21
 
22 22
 extern uint8_t Lora_Buf[100];
23
+extern uint8_t datalosscnt[9];
23 24
 
24 25
 
25 26
 

+ 6 - 1
Inc/main.h

@@ -115,6 +115,7 @@ extern uint8_t MyControllerID;
115 115
 extern uint8_t  SensorID;
116 116
 extern uint8_t Lora_Buf[100];
117 117
 extern I2C_HandleTypeDef hi2c2;
118
+extern volatile uint32_t LedTimerCnt;
118 119
 
119 120
 
120 121
 
@@ -145,6 +146,7 @@ typedef enum{
145 146
     RGB_Lora_ConfigGet,             //24
146 147
     RGB_Controller_Init_Start        ,  // = 25;
147 148
     RGB_Controller_Init_End           ,   //= 26;    
149
+    RGB_GUI_SensorDataRequest,      //27
148 150
 }RGB_CMD_T;
149 151
 typedef struct{
150 152
     uint8_t Request_stx;
@@ -241,7 +243,7 @@ typedef struct{
241 243
 #define RGB_LORA_BANDWIDTH_ADDRESS   RGB_LORA_SF_ADDRESS        + 1
242 244
 #define RGB_LORA_LNA_ADDRESS         RGB_LORA_BANDWIDTH_ADDRESS + 1
243 245
 
244
-#define Reserved_ADDRESS             RGB_LORA_LNA_ADDRESS       + 1
246
+#define Reserved_ADDRESS             RGB_LORA_PABOOST_ADDRESS   + 1
245 247
 
246 248
 
247 249
 
@@ -274,6 +276,9 @@ typedef struct{
274 276
 /* Private defines -----------------------------------------------------------*/
275 277
 #define BOOT_LED_Pin GPIO_PIN_15
276 278
 #define BOOT_LED_GPIO_Port GPIOC
279
+#define IWDG_RESET_Pin GPIO_PIN_0
280
+#define IWDG_RESET_GPIO_Port GPIOC
281
+#define IWDG_RESET_EXTI_IRQn EXTI0_IRQn
277 282
 #define SX1276_DIO0_Pin GPIO_PIN_4
278 283
 #define SX1276_DIO0_GPIO_Port GPIOA
279 284
 #define SX1276_DIO1_Pin GPIO_PIN_5

+ 1 - 1
Inc/stm32f1xx_hal_conf.h

@@ -63,7 +63,7 @@
63 63
 #define HAL_I2C_MODULE_ENABLED
64 64
 /*#define HAL_I2S_MODULE_ENABLED   */
65 65
 /*#define HAL_IRDA_MODULE_ENABLED   */
66
-/*#define HAL_IWDG_MODULE_ENABLED   */
66
+#define HAL_IWDG_MODULE_ENABLED
67 67
 /*#define HAL_NOR_MODULE_ENABLED   */
68 68
 /*#define HAL_NAND_MODULE_ENABLED   */
69 69
 /*#define HAL_PCCARD_MODULE_ENABLED   */

+ 2 - 0
Inc/stm32f1xx_it.h

@@ -71,7 +71,9 @@ void SVC_Handler(void);
71 71
 void DebugMon_Handler(void);
72 72
 void PendSV_Handler(void);
73 73
 void SysTick_Handler(void);
74
+void EXTI0_IRQHandler(void);
74 75
 void DMA1_Channel5_IRQHandler(void);
76
+void DMA1_Channel6_IRQHandler(void);
75 77
 void USART1_IRQHandler(void);
76 78
 void USART2_IRQHandler(void);
77 79
 void TIM6_IRQHandler(void);

+ 74 - 49
STM32F103_RGBController.ioc

@@ -1,6 +1,7 @@
1 1
 #MicroXplorer Configuration settings - do not modify
2 2
 Dma.Request0=USART1_RX
3
-Dma.RequestsNb=1
3
+Dma.Request1=USART2_RX
4
+Dma.RequestsNb=2
4 5
 Dma.USART1_RX.0.Direction=DMA_PERIPH_TO_MEMORY
5 6
 Dma.USART1_RX.0.Instance=DMA1_Channel5
6 7
 Dma.USART1_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE
@@ -10,63 +11,77 @@ Dma.USART1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
10 11
 Dma.USART1_RX.0.PeriphInc=DMA_PINC_DISABLE
11 12
 Dma.USART1_RX.0.Priority=DMA_PRIORITY_LOW
12 13
 Dma.USART1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
14
+Dma.USART2_RX.1.Direction=DMA_PERIPH_TO_MEMORY
15
+Dma.USART2_RX.1.Instance=DMA1_Channel6
16
+Dma.USART2_RX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE
17
+Dma.USART2_RX.1.MemInc=DMA_MINC_ENABLE
18
+Dma.USART2_RX.1.Mode=DMA_CIRCULAR
19
+Dma.USART2_RX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
20
+Dma.USART2_RX.1.PeriphInc=DMA_PINC_DISABLE
21
+Dma.USART2_RX.1.Priority=DMA_PRIORITY_LOW
22
+Dma.USART2_RX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
13 23
 File.Version=6
24
+IWDG.IPParameters=Reload
25
+IWDG.Reload=1000
14 26
 KeepUserPlacement=false
15 27
 Mcu.Family=STM32F1
16 28
 Mcu.IP0=DMA
17 29
 Mcu.IP1=I2C2
18
-Mcu.IP2=NVIC
19
-Mcu.IP3=RCC
20
-Mcu.IP4=SYS
21
-Mcu.IP5=TIM6
22
-Mcu.IP6=USART1
23
-Mcu.IP7=USART2
24
-Mcu.IPNb=8
30
+Mcu.IP2=IWDG
31
+Mcu.IP3=NVIC
32
+Mcu.IP4=RCC
33
+Mcu.IP5=SYS
34
+Mcu.IP6=TIM6
35
+Mcu.IP7=USART1
36
+Mcu.IP8=USART2
37
+Mcu.IPNb=9
25 38
 Mcu.Name=STM32F103R(C-D-E)Tx
26 39
 Mcu.Package=LQFP64
27 40
 Mcu.Pin0=PC15-OSC32_OUT
28 41
 Mcu.Pin1=PD0-OSC_IN
29
-Mcu.Pin10=PC5
30
-Mcu.Pin11=PB0
31
-Mcu.Pin12=PB10
32
-Mcu.Pin13=PB11
33
-Mcu.Pin14=PB12
34
-Mcu.Pin15=PB13
35
-Mcu.Pin16=PB14
36
-Mcu.Pin17=PB15
37
-Mcu.Pin18=PC6
38
-Mcu.Pin19=PC7
42
+Mcu.Pin10=PC4
43
+Mcu.Pin11=PC5
44
+Mcu.Pin12=PB0
45
+Mcu.Pin13=PB10
46
+Mcu.Pin14=PB11
47
+Mcu.Pin15=PB12
48
+Mcu.Pin16=PB13
49
+Mcu.Pin17=PB14
50
+Mcu.Pin18=PB15
51
+Mcu.Pin19=PC6
39 52
 Mcu.Pin2=PD1-OSC_OUT
40
-Mcu.Pin20=PC8
41
-Mcu.Pin21=PC9
42
-Mcu.Pin22=PA8
43
-Mcu.Pin23=PA9
44
-Mcu.Pin24=PA10
45
-Mcu.Pin25=PA13
46
-Mcu.Pin26=PA14
47
-Mcu.Pin27=PA15
48
-Mcu.Pin28=PC10
49
-Mcu.Pin29=PC11
50
-Mcu.Pin3=PA2
51
-Mcu.Pin30=PC12
52
-Mcu.Pin31=PD2
53
-Mcu.Pin32=PB3
54
-Mcu.Pin33=PB4
55
-Mcu.Pin34=PB5
56
-Mcu.Pin35=PB6
57
-Mcu.Pin36=PB7
58
-Mcu.Pin37=PB8
59
-Mcu.Pin38=PB9
60
-Mcu.Pin39=VP_SYS_VS_ND
61
-Mcu.Pin4=PA3
62
-Mcu.Pin40=VP_SYS_VS_Systick
63
-Mcu.Pin41=VP_TIM6_VS_ClockSourceINT
64
-Mcu.Pin5=PA4
65
-Mcu.Pin6=PA5
66
-Mcu.Pin7=PA6
67
-Mcu.Pin8=PA7
68
-Mcu.Pin9=PC4
69
-Mcu.PinsNb=42
53
+Mcu.Pin20=PC7
54
+Mcu.Pin21=PC8
55
+Mcu.Pin22=PC9
56
+Mcu.Pin23=PA8
57
+Mcu.Pin24=PA9
58
+Mcu.Pin25=PA10
59
+Mcu.Pin26=PA13
60
+Mcu.Pin27=PA14
61
+Mcu.Pin28=PA15
62
+Mcu.Pin29=PC10
63
+Mcu.Pin3=PC0
64
+Mcu.Pin30=PC11
65
+Mcu.Pin31=PC12
66
+Mcu.Pin32=PD2
67
+Mcu.Pin33=PB3
68
+Mcu.Pin34=PB4
69
+Mcu.Pin35=PB5
70
+Mcu.Pin36=PB6
71
+Mcu.Pin37=PB7
72
+Mcu.Pin38=PB8
73
+Mcu.Pin39=PB9
74
+Mcu.Pin4=PA2
75
+Mcu.Pin40=VP_IWDG_VS_IWDG
76
+Mcu.Pin41=VP_SYS_VS_ND
77
+Mcu.Pin42=VP_SYS_VS_Systick
78
+Mcu.Pin43=VP_TIM6_VS_ClockSourceINT
79
+Mcu.Pin5=PA3
80
+Mcu.Pin6=PA4
81
+Mcu.Pin7=PA5
82
+Mcu.Pin8=PA6
83
+Mcu.Pin9=PA7
84
+Mcu.PinsNb=44
70 85
 Mcu.ThirdPartyNb=0
71 86
 Mcu.UserConstants=
72 87
 Mcu.UserName=STM32F103RCTx
@@ -74,7 +89,9 @@ MxCube.Version=5.0.1
74 89
 MxDb.Version=DB.5.0.1
75 90
 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false
76 91
 NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:true\:true\:1\:false
92
+NVIC.DMA1_Channel6_IRQn=true\:0\:0\:false\:true\:true\:5\:false
77 93
 NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false
94
+NVIC.EXTI0_IRQn=true\:0\:0\:false\:true\:true\:6\:true
78 95
 NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false
79 96
 NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false
80 97
 NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false
@@ -175,6 +192,10 @@ PB9.GPIOParameters=GPIO_Label
175 192
 PB9.GPIO_Label=LED_CH8
176 193
 PB9.Locked=true
177 194
 PB9.Signal=GPIO_Output
195
+PC0.GPIOParameters=GPIO_Label
196
+PC0.GPIO_Label=IWDG_RESET
197
+PC0.Locked=true
198
+PC0.Signal=GPXTI0
178 199
 PC10.GPIOParameters=GPIO_Label
179 200
 PC10.GPIO_Label=LED_CH1
180 201
 PC10.Locked=true
@@ -258,7 +279,7 @@ ProjectManager.StackSize=0x400
258 279
 ProjectManager.TargetToolchain=TrueSTUDIO
259 280
 ProjectManager.ToolChainLocation=
260 281
 ProjectManager.UnderRoot=true
261
-ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_TIM6_Init-TIM6-false-HAL-true,5-MX_USART1_UART_Init-USART1-false-HAL-true,6-MX_USART2_UART_Init-USART2-false-HAL-true,7-MX_I2C2_Init-I2C2-false-HAL-true
282
+ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_TIM6_Init-TIM6-false-HAL-true,5-MX_USART1_UART_Init-USART1-false-HAL-true,6-MX_USART2_UART_Init-USART2-false-HAL-true,7-MX_I2C2_Init-I2C2-false-HAL-true,8-MX_IWDG_Init-IWDG-false-HAL-true
262 283
 RCC.ADCFreqValue=8000000
263 284
 RCC.AHBFreq_Value=16000000
264 285
 RCC.APB1CLKDivider=RCC_HCLK_DIV2
@@ -283,6 +304,8 @@ RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
283 304
 RCC.TimSysFreq_Value=16000000
284 305
 RCC.USBFreq_Value=16000000
285 306
 RCC.VCOOutput2Freq_Value=8000000
307
+SH.GPXTI0.0=GPIO_EXTI0
308
+SH.GPXTI0.ConfNb=1
286 309
 TIM6.IPParameters=Prescaler,Period
287 310
 TIM6.Period=10-1
288 311
 TIM6.Prescaler=1600-1
@@ -290,6 +313,8 @@ USART1.IPParameters=VirtualMode
290 313
 USART1.VirtualMode=VM_ASYNC
291 314
 USART2.IPParameters=VirtualMode
292 315
 USART2.VirtualMode=VM_ASYNC
316
+VP_IWDG_VS_IWDG.Mode=IWDG_Activate
317
+VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG
293 318
 VP_SYS_VS_ND.Mode=No_Debug
294 319
 VP_SYS_VS_ND.Signal=SYS_VS_ND
295 320
 VP_SYS_VS_Systick.Mode=SysTick

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 41 - 0
STM32F103_RGB_Controller.elf.launch


+ 74 - 27
Src/RGB_Controller.c

@@ -13,12 +13,13 @@ uint16_t RGB_Location_Address_Check(uint8_t id);
13 13
 
14 14
 uint8_t SensorID_Cnt = 0;
15 15
 uint8_t SensorID_buf[8] = {0,};
16
+
16 17
 uint16_t RGB_SensorRedLimit_Buf[9]={0,};
17 18
 uint16_t RGB_SensorGreenLimit_Buf[9]={0,};
18 19
 uint16_t RGB_SensorBlueLimit_Buf[9]={0,};
19 20
 uint8_t LED_Alarm[9] = {0,};
20 21
 uint8_t RGB_Location_Buf[9][50] = {0};
21
-
22
+uint8_t RGB_SensorDataBuf[9][20] = {0,};
22 23
 
23 24
 void RGB_Data_Init(void){
24 25
     MyControllerID = M24C32_Data_Read(&hi2c2,MY_ID_ADDRESS);
@@ -48,11 +49,16 @@ void RGB_Data_Init(void){
48 49
     if(M24C32_Data_Read(&hi2c2,RGB_LORA_FREQ_ADDRESS) == 0xFF){
49 50
         /*NOP*/
50 51
     }else{
51
-        Default_SX1276.frequency = M24C32_Data_Read(&hi2c2,RGB_LORA_FREQ_ADDRESS);
52
-        Default_SX1276.power     = M24C32_Data_Read(&hi2c2,RGB_LORA_PABOOST_ADDRESS);
53
-        Default_SX1276.LoRa_Rate = M24C32_Data_Read(&hi2c2,RGB_LORA_SF_ADDRESS);
54
-        Default_SX1276.LoRa_BW   = M24C32_Data_Read(&hi2c2,RGB_LORA_BANDWIDTH_ADDRESS);
55
-        Default_SX1276.LoRa_Lna  = M24C32_Data_Read(&hi2c2,RGB_LORA_LNA_ADDRESS);
52
+        Default_SX1276.frequency     = M24C32_Data_Read(&hi2c2,RGB_LORA_FREQ_ADDRESS);
53
+        Default_SX1276.LoRa_Pa_boost = M24C32_Data_Read(&hi2c2,RGB_LORA_PABOOST_ADDRESS);
54
+        Default_SX1276.LoRa_Rate     = M24C32_Data_Read(&hi2c2,RGB_LORA_SF_ADDRESS);
55
+        Default_SX1276.LoRa_BW       = M24C32_Data_Read(&hi2c2,RGB_LORA_BANDWIDTH_ADDRESS);
56
+        Default_SX1276.LoRa_Lna      = M24C32_Data_Read(&hi2c2,RGB_LORA_LNA_ADDRESS);
57
+        printf("Lora frequency     : %d \n",Default_SX1276.frequency);
58
+        printf("Lora LoRa_Pa_boost : %d \n",Default_SX1276.LoRa_Pa_boost);
59
+        printf("Lora LoRa_Rate     : %d \n",Default_SX1276.LoRa_Rate);
60
+        printf("Lora LoRa_BW       : %d \n",Default_SX1276.LoRa_BW);
61
+        printf("Lora LoRa_Lna      : %d \n",Default_SX1276.LoRa_Lna);        
56 62
     }
57 63
 
58 64
 }
@@ -84,6 +90,13 @@ uint16_t RGB_Location_Address_Check(uint8_t id){
84 90
     }
85 91
     return ret;
86 92
 }
93
+uint8_t DatasendSetVal;
94
+void DataSendStop_Set(uint8_t set){
95
+    DatasendSetVal = set;
96
+}
97
+void DataSendStop_Get(uint8_t set){
98
+    return DatasendSetVal;
99
+}
87 100
 
88 101
 void RGB_Response_Func(uint8_t* data){

89 102
 	RGB_CMD_T type = data[bluecell_type];
@@ -106,6 +119,7 @@ for(uint8_t i = 0; i < 10; i++){
106 119
             Uart2_Data_Send(data,RGB_SensorIDAutoSetRequest_Length);
107 120
             break;        
108 121
         case RGB_Status_Data_Response:
122
+            memcpy(&RGB_SensorDataBuf[data[bluecell_srcid]][bluecell_stx],&data[bluecell_stx],data[bluecell_length] + 3);
109 123
             Uart1_Data_Send(data,data[bluecell_length] + 3);
110 124
             break;
111 125
         case RGB_ControllerLimitSet:
@@ -156,14 +170,28 @@ for(uint8_t i = 0; i < 10; i++){
156 170
             Default_SX1276.LoRa_Pa_boost = data[4];
157 171
             Default_SX1276.LoRa_Rate     = data[5];
158 172
             Default_SX1276.LoRa_BW       = data[6];    
159
-            Default_SX1276.LoRa_Lna      = data[7];        
160
-            Lora_Initialize();
173
+            Default_SX1276.LoRa_Lna      = data[7];     
174
+            printf("Lora frequency     : %d \n",Default_SX1276.frequency);
175
+            printf("Lora LoRa_Pa_boost : %d \n",Default_SX1276.LoRa_Pa_boost);
176
+            printf("Lora LoRa_Rate     : %d \n",Default_SX1276.LoRa_Rate);
177
+            printf("Lora LoRa_BW       : %d \n",Default_SX1276.LoRa_BW);
178
+            printf("Lora LoRa_Lna      : %d \n",Default_SX1276.LoRa_Lna);             
161 179
             M24C32_Data_Write(&hi2c2,&data[bluecell_srcid],RGB_LORA_FREQ_ADDRESS,data[bluecell_length] - 2); // EEPROM Controller ID Save 
180
+            NVIC_SystemReset();
162 181
         case RGB_Lora_ConfigGet:
163 182
             Uart1_Data_Send(data,data[bluecell_length] + 3);
164 183
             break;             
184
+        case RGB_GUI_SensorDataRequest:
185
+            
186
+//            printf("I will give Data :   ");
187
+//            for(uint8_t i =0; i <data[bluecell_length] + 3; i++ )
188
+//                printf("%02x ",data[i]);
189
+//            printf("\n");
190
+//            Uart1_Data_Send(data,data[bluecell_length] + 3);
191
+            break;        
165 192
          default:break;
166 193
     }
194
+     LedTimerCnt = 0;
167 195
 }
168 196
 
169 197
 void RGB_Sensor_LED_Alarm_ON(uint8_t id ){
@@ -245,7 +273,7 @@ void RGB_Sensor_LED_Alarm_OFF(uint8_t id ){
245 273
 
246 274
 void RGB_Alarm_Operate(void){
247 275
     uint8_t temp_warning = 0;
248
-    for(uint8_t i = 1; i <= (SensorID_Cnt); i++){
276
+    for(uint8_t i = 0; i <= (SensorID_Cnt); i++){ /*SensorID_Cnt : Current Sensor Device Count */
249 277
         if(LED_Alarm[SensorID_buf[i]] == 1){
250 278
             HAL_GPIO_WritePin(LED_ALARM_GPIO_Port, LED_ALARM_Pin, GPIO_PIN_SET); //표지 LED
251 279
             RGB_Sensor_LED_Alarm_ON(SensorID_buf[i]);
@@ -269,10 +297,10 @@ void RGB_Alarm_Check(uint8_t* data){
269 297
     Sensor_green[data[bluecell_srcid]] = ((data[bluecell_green_H + 2] << 8)| data[bluecell_green_L + 2]);
270 298
     Sensor_blue[data[bluecell_srcid]] = ((data[bluecell_blue_H + 2] << 8)| data[bluecell_blue_L + 2]);  
271 299
 
272
-    for(uint8_t i = 1; i <= (SensorID_Cnt); i++){
273
-        if(RGB_SensorRedLimit_Buf[SensorID_buf[i]]  >= Sensor_red[SensorID_buf[i]]
274
-            || RGB_SensorGreenLimit_Buf[SensorID_buf[i]]  >= Sensor_green[SensorID_buf[i]]
275
-            || RGB_SensorBlueLimit_Buf[SensorID_buf[i]]  >= Sensor_blue[SensorID_buf[i]]) {
300
+    for(uint8_t i = 0; i <= (SensorID_Cnt); i++){
301
+        if(RGB_SensorRedLimit_Buf[SensorID_buf[i]]  > Sensor_red[SensorID_buf[i]]
302
+            || RGB_SensorGreenLimit_Buf[SensorID_buf[i]]  > Sensor_green[SensorID_buf[i]]
303
+            || RGB_SensorBlueLimit_Buf[SensorID_buf[i]]  > Sensor_blue[SensorID_buf[i]]) {
276 304
             LED_Alarm[SensorID_buf[i]] = 1;
277 305
             Alarm_occur = 1;
278 306
         }else{
@@ -288,10 +316,13 @@ void RGB_Alarm_Check(uint8_t* data){
288 316
 
289 317
 uint8_t RGB_DeviceStatusCheck(void){
290 318
     uint8_t ret = 0;
291
-    for(uint8_t i = 1; i <= SensorID_Cnt; i++){
319
+//    printf("SensorID_Cnt : %d ",SensorID_Cnt);
320
+    for(uint8_t i = 0; i < SensorID_Cnt; i++){
321
+//        printf("\n SensorID_buf[%d] : %02x ",i,SensorID_buf[i]);
292 322
         if(SensorID_buf[i] > 0){
293
-            ret += 0x01 << (SensorID_buf[i] - 1); 
323
+            ret |= 0x01 << (SensorID_buf[i] - 1); 
294 324
         }
325
+//        printf("\n ret %02x \n",ret);
295 326
     }
296 327
     return ret;
297 328
 }
@@ -342,16 +373,19 @@ void RGB_Data_Stack(uint8_t* rgb_buf){
342 373
     Lora_Buf[bluecell_length]      = Lora_Max_Amount;// RGB Data 5byte
343 374
     Lora_Buf[bluecell_srcid]       = MyControllerID;
344 375
     /*********************FIX DATA*************************************/
345
-    if(RGB_BufCal(SensorID_buf[1]) == 0){//아무런 Device가 존재 하지않을 때
376
+    if(RGB_BufCal(SensorID_buf[0]) == 0){//아무런 Device가 존재 하지않을 때
346 377
         printf("Not Exist Device \n");
347 378
         return;
348 379
     }
349
-    for(uint8_t i = 1; i <= (SensorID_Cnt); i++){
380
+//    printf("SensorID_Cnt : %d   SensorID_buf[0] : %d \n",SensorID_Cnt,SensorID_buf[0]);
381
+    for(uint8_t i = 0; i <= (SensorID_Cnt); i++){
350 382
         Lora_Buf[bluecell_srcid + 1] |= 0x01  << (SensorID_buf[i] - 1);
351 383
     }
384
+//    printf("Lora_Buf[bluecell_srcid + 1] : %02x\n",Lora_Buf[bluecell_srcid + 1]);
352 385
     for(uint8_t i = 0; i < 8; i++){
353 386
         Lora_Buf[bluecell_srcid + 2] |= rgb_buf[i] << i ;
354 387
     }
388
+//    printf("Lora_Buf[bluecell_srcid + 2] : %02x\n",Lora_Buf[bluecell_srcid + 2]);
355 389
     Lora_Buf[bluecell_srcid + 3]= STH30_CreateCrc(&Lora_Buf[bluecell_type],Lora_Buf[bluecell_length]);
356 390
    
357 391
 }
@@ -387,10 +421,12 @@ uint8_t datalosscnt[9] = {0,};
387 421
 
388 422
 
389 423
 static uint8_t temp_sensorid;
424
+static uint8_t gui_Sensorid;
390 425
 void RGB_Controller_Func(uint8_t* data){
391 426
 	RGB_CMD_T type = data[bluecell_type];
392 427
    // static uint8_t temp_sensorid;
393 428
     uint8_t Result_buf[100] = {0,};
429
+   uint8_t temp_gui_Sensorid = 0;
394 430
     uint8_t i = 0;
395 431
     switch(type){
396 432
         case RGB_Status_Data_Request:          
@@ -398,11 +434,11 @@ void RGB_Controller_Func(uint8_t* data){
398 434
             if(temp_sensorid > (SensorID_Cnt)){
399 435
                 temp_sensorid = 0;
400 436
             }    
401
-            datalosscnt[data[bluecell_srcid + 1]]++;
402
-            if(datalosscnt[data[bluecell_srcid + 1]] > 3 && data[bluecell_srcid + 1] != 0){
403
-                RGB_SensorIDAutoSet(1);
404
-                memset(&SensorID_buf[0],0x00,8);
405
-            }
437
+//            datalosscnt[data[bluecell_srcid + 1]]++;
438
+//            if(datalosscnt[data[bluecell_srcid + 1]] > 5 && data[bluecell_srcid + 1] != 0){
439
+//                RGB_SensorIDAutoSet(1);
440
+//                memset(&SensorID_buf[0],0x00,8);
441
+//            }
406 442
             data[5]   = STH30_CreateCrc(&data[bluecell_type],data[bluecell_length]);
407 443
             memcpy(&Result_buf[bluecell_stx],&data[bluecell_stx],RGB_SensorDataRequest_Length);
408 444
             break;
@@ -416,9 +452,10 @@ void RGB_Controller_Func(uint8_t* data){
416 452
             Result_buf[5]  = STH30_CreateCrc(&Result_buf[bluecell_type],Result_buf[bluecell_length]);
417 453
             break;
418 454
         case RGB_SensorID_SET_Success:
455
+            if(data[bluecell_length + 1] == 0)
456
+                return;
419 457
             printf("Recognize %d Sensor\n",data[bluecell_length + 1]);
420
-            SensorID_Cnt++;
421
-            SensorID_buf[SensorID_Cnt] = data[bluecell_length + 1];
458
+            SensorID_buf[SensorID_Cnt++] = data[bluecell_length + 1];
422 459
             break;
423 460
         case RGB_Status_Data_Response:
424 461
             datalosscnt[data[bluecell_srcid]] = 0;
@@ -476,7 +513,6 @@ void RGB_Controller_Func(uint8_t* data){
476 513
             Result_buf[bluecell_type] = RGB_Lora_DataResponse;
477 514
             break;
478 515
         case RGB_Lora_ConfigSet:
479
-            SX1276_hw_Reset(&SX1276_hw);
480 516
             memcpy(&Result_buf[bluecell_stx],&data[bluecell_stx],data[bluecell_length] + 3);
481 517
             data[(data[bluecell_length] + 3)]=STH30_CreateCrc(&Result_buf[bluecell_type],Result_buf[bluecell_length]);
482 518
             break;
@@ -486,12 +522,23 @@ void RGB_Controller_Func(uint8_t* data){
486 522
             Result_buf[bluecell_length]      = 7;
487 523
             Result_buf[bluecell_srcid + 0]   = SX1276.frequency;
488 524
             Result_buf[bluecell_srcid + 1]   = SX1276.LoRa_Pa_boost;            
489
-            Result_buf[bluecell_srcid + 2]   = SX1276.LoRa_BW;
490
-            Result_buf[bluecell_srcid + 3]   = SX1276.LoRa_Rate;
525
+            Result_buf[bluecell_srcid + 2]   = SX1276.LoRa_Rate; //SF
526
+            Result_buf[bluecell_srcid + 3]   = SX1276.LoRa_BW;
491 527
             Result_buf[bluecell_srcid + 4]   = SX1276.LoRa_Lna;
492 528
             Result_buf[bluecell_srcid + 5]   = STH30_CreateCrc(&Result_buf[bluecell_type],Result_buf[bluecell_length]);
493 529
             Result_buf[bluecell_srcid + 6]   = 0xeb;
494 530
             break;
531
+        case RGB_GUI_SensorDataRequest:
532
+//            printf("%s ",__func__);
533
+//            temp_gui_Sensorid = gui_Sensorid++;
534
+//            memcpy(&Result_buf[bluecell_stx],&RGB_SensorDataBuf[SensorID_buf[temp_gui_Sensorid]][bluecell_stx],RGB_SensorDataBuf[SensorID_buf[temp_gui_Sensorid]][bluecell_length] + 3);
535
+//            if(gui_Sensorid > (SensorID_Cnt)){
536
+//                gui_Sensorid = 0;
537
+//            }   
538
+//            
539
+//            Result_buf[bluecell_type] = RGB_GUI_SensorDataRequest;
540
+//            Result_buf[Result_buf[bluecell_length] + 1]  = STH30_CreateCrc(&Result_buf[bluecell_type],Result_buf[bluecell_length]);
541
+            break;
495 542
         default:
496 543
             break;
497 544
     }

+ 470 - 460
Src/SX1276.c

@@ -1,460 +1,470 @@
1
-/**
2
- * Author Wojciech Domski <Wojciech.Domski@gmail.com>
3
- * www: www.Domski.pl
4
- *
5
- * work based on DORJI.COM sample code and
6
- * https://github.com/realspinner/SX1276_LoRa
7
- */
8
-
9
-#include "SX1276.h"
10
-#include <string.h>
11
-
12
-
13
-//////////////////////////////////
14
-// logic
15
-//////////////////////////////////
16
-
17
-__weak void SX1276_hw_init(SX1276_hw_t * hw) {
18
-	SX1276_hw_SetNSS(hw, 1);
19
-	HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_SET);
20
-}
21
-
22
-__weak void SX1276_hw_SetNSS(SX1276_hw_t * hw, int value) {
23
-	HAL_GPIO_WritePin(hw->nss.port, hw->nss.pin,
24
-			(value == 1) ? GPIO_PIN_SET : GPIO_PIN_RESET);
25
-}
26
-
27
-__weak void SX1276_hw_Reset(SX1276_hw_t * hw) {
28
-	SX1276_hw_SetNSS(hw, 1);
29
-	HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_RESET);
30
-
31
-	SX1276_hw_DelayMs(1);
32
-
33
-	HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_SET);
34
-
35
-	SX1276_hw_DelayMs(100);
36
-}
37
-
38
-#if 0 // PYJ.2019.04.01_BEGIN -- 
39
-__weak void SX1276_hw_SPICommand(SX1276_hw_t * hw, uint8_t cmd) {
40
-	SX1276_hw_SetNSS(hw, 0);
41
-	HAL_SPI_Transmit(hw->spi, &cmd, 1, 1000);
42
-	while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY)
43
-		;
44
-}
45
-#endif // PYJ.2019.04.01_END -- 
46
-void SX1276_hw_SPICommand(SX1276_hw_t * hw, uint8_t cmd) {
47
-	SX1276_hw_SetNSS(hw, 0);
48
-	BLUECELL_SPI_Transmit(cmd);
49
-}
50
-
51
-#if 0 // PYJ.2019.04.01_BEGIN -- 
52
-__weak uint8_t SX1276_hw_SPIReadByte(SX1276_hw_t * hw) {
53
-	uint8_t txByte = 0x00;
54
-	uint8_t rxByte = 0x00;
55
-
56
-	SX1276_hw_SetNSS(hw, 0);
57
-	HAL_SPI_TransmitReceive(hw->spi, &txByte, &rxByte, 1, 1000);
58
-	return rxByte;
59
-}
60
-#endif // PYJ.2019.04.01_END -- 
61
-uint8_t SX1276_hw_SPIReadByte(SX1276_hw_t * hw) {
62
-	//uint8_t txByte = 0x00;
63
-	uint8_t rxByte = 0x00;
64
-
65
-	SX1276_hw_SetNSS(hw, 0);
66
-//	HAL_SPI_TransmitReceive(hw->spi, &txByte, &rxByte, 1, 1000);
67
-    rxByte = SpiRead();
68
-	return rxByte;
69
-}
70
-
71
-__weak void SX1276_hw_DelayMs(uint32_t msec) {
72
-	HAL_Delay(msec);
73
-}
74
-
75
-__weak int SX1276_hw_GetDIO0(SX1276_hw_t * hw) {
76
-	return (HAL_GPIO_ReadPin(hw->dio0.port, hw->dio0.pin) == GPIO_PIN_SET);
77
-}
78
-
79
-//////////////////////////////////
80
-// logic
81
-//////////////////////////////////
82
-
83
-uint8_t SX1276_SPIRead(SX1276_t * module, uint8_t addr) {
84
-	uint8_t tmp;
85
-	SX1276_hw_SPICommand(module->hw, addr);
86
-	tmp = SX1276_hw_SPIReadByte(module->hw);
87
-	SX1276_hw_SetNSS(module->hw, 1);
88
-	return tmp;
89
-}
90
-uint8_t SX1276_SPIIDRead(SX1276_t * module, uint8_t addr) {
91
-	uint8_t tmp;
92
-	SX1276_hw_SPICommand(module->hw, addr);
93
-	tmp = SX1276_hw_SPIReadByte(module->hw);
94
-	SX1276_hw_SetNSS(module->hw, 1);
95
-	return tmp;
96
-}
97
-
98
-void SX1276_SPIWrite(SX1276_t * module, uint8_t addr, uint8_t cmd) {
99
-	SX1276_hw_SetNSS(module->hw, 0);
100
-	SX1276_hw_SPICommand(module->hw, addr | 0x80);
101
-	SX1276_hw_SPICommand(module->hw, cmd);
102
-//    SPIGPIOTxRx(addr | 0x80,cmd);
103
-
104
-	SX1276_hw_SetNSS(module->hw, 1);
105
-}
106
-
107
-void SX1276_SPIBurstRead(SX1276_t * module, uint8_t addr, uint8_t* rxBuf,
108
-		uint8_t length) {
109
-	uint8_t i;
110
-	if (length <= 1) {
111
-		return;
112
-	} else {
113
-		SX1276_hw_SetNSS(module->hw, 0);
114
-		SX1276_hw_SPICommand(module->hw, addr);
115
-		//printf("Test Data:");
116
-		for (i = 0; i < length; i++) {
117
-			rxBuf[i] = SX1276_hw_SPIReadByte(module->hw);
118
-			//printf("%02x ",rxBuf[i]);
119
-		}
120
-		//printf("\n");
121
-		SX1276_hw_SetNSS(module->hw, 1);
122
-	}
123
-}
124
-
125
-void SX1276_SPIBurstWrite(SX1276_t * module, uint8_t addr, uint8_t* txBuf,
126
-		uint8_t length) {
127
-	uint8_t i;
128
-	if (length <= 1) {
129
-		return;
130
-	} else {
131
-		SX1276_hw_SetNSS(module->hw, 0);
132
-		SX1276_hw_SPICommand(module->hw, addr | 0x80);
133
-//        printf("Test Data:");
134
-		for (i = 0; i < length; i++) {
135
-			SX1276_hw_SPICommand(module->hw, txBuf[i]);
136
-//            printf("%02x ",txBuf[i]);
137
-		}
138
-//        printf("\n");
139
-		SX1276_hw_SetNSS(module->hw, 1);
140
-	}
141
-}
142
-        /*
143
-  RegPaConfig - 0x09
144
-  PaSelect    Mode                                  Power Range     Pout Formula
145
-  0           PA_HF or PA_LF on RFO_HF or RFO_LF    -4 to +15dBm    Pout=Pmax-(15-OutputPower), Pmax=10.8+0.6*MaxPower [dBm]
146
-  1           PA_HP on PA_BOOST, any frequency      +2 to +17dBm    Pout=17-(15-OutputPower) [dBm]
147
-  PA_LF option doesn't seem to transmit anything. Not connected on these boards, perhaps?
148
-  Use only PA_BOOST mode.
149
-  
150
-  PA_LF   Pmax              
151
-  Pout    0     1     2     3     4     5     6     7
152
-  0       -4.2  -3.6  -3    -2.4  -1.8  -1.2  -0.6  0
153
-  1       -3.2  -2.6  -2    -1.4  -0.8  -0.2  0.4   1
154
-  2       -2.2  -1.6  -1    -0.4  0.2   0.8   1.4   2
155
-  3       -1.2  -0.6  0     0.6   1.2   1.8   2.4   3
156
-  4       -0.2  0.4   1     1.6   2.2   2.8   3.4   4
157
-  5       0.8   1.4   2     2.6   3.2   3.8   4.4   5
158
-  6       1.8   2.4   3     3.6   4.2   4.8   5.4   6
159
-  7       2.8   3.4   4     4.6   5.2   5.8   6.4   7
160
-  8       3.8   4.4   5     5.6   6.2   6.8   7.4   8
161
-  9       4.8   5.4   6     6.6   7.2   7.8   8.4   9
162
-  10      5.8   6.4   7     7.6   8.2   8.8   9.4   10
163
-  11      6.8   7.4   8     8.6   9.2   9.8   10.4  11
164
-  12      7.8   8.4   9     9.6   10.2  10.8  11.4  12
165
-  13      8.8   9.4   10    10.6  11.2  11.8  12.4  13
166
-  14      9.8   10.4  11    11.6  12.2  12.8  13.4  14
167
-  15      10.8  11.4  12    12.6  13.2  13.8  14.4  15  [dBm]
168
-  
169
-  PA_BOOST 
170
-  Pout  OutputPower
171
-  0     2 dBm
172
-  1     3 dBm
173
-  2     4 dBm
174
-  3     5 dBm
175
-  4     6 dBm
176
-  5     7 dBm
177
-  6     8 dBm
178
-  7     9 dBm
179
-  8     10 dBm
180
-  9     11 dBm
181
-  10    12 dBm
182
-  11    13 dBm
183
-  12    14 dBm
184
-  13    15 dBm
185
-  14    16 dBm
186
-  15    17 dBm
187
-  
188
-  PaSelect
189
-    0 RFO pin. Maximum power of +14 dBm 
190
-    1 PA_BOOST pin. Maximum power of +20 dBm
191
-  MaxPower
192
-    Select max output power: Pmax=10.8+0.6*MaxPower [dBm]
193
-  OutputPower
194
-    Pout=Pmax-(15-OutputPower) if PaSelect = 0 (RFO pins) 
195
-    Pout=17-(15-OutputPower) if PaSelect = 1 (PA_BOOST pin)
196
-  PA_HF and PA_LF are high efficiency amplifiers capable of yielding RF power programmable in 1 dB steps
197
-  from -4 to +14dBm directly into a 50 ohm load with low current consumption. PA_LF covers the lower bands
198
-  (up to 525 MHz), whilst PA_HF will cover the upper bands (from 860 MHz).
199
-  PA_HP (High Power), connected to the PA_BOOST pin, covers all frequency bands that the chip addresses.
200
-  It permits continuous operation at up to +17 dBm and duty cycled operation at up to +20dBm.
201
-  RegOcp - 0x0B
202
-  OcpTrim   IMAX            Imax Formula
203
-  0 to 15   45 to 120 mA    45 + 5*OcpTrim [mA]
204
-  16 to 27  130 to 240 mA   -30 + 10*OcpTrim [mA]
205
-  27+       240 mA          240 mA
206
-  
207
-  The power amplifiers of RFM95/96/97/98(W) are protected against current over supply in adverse RF load
208
-  conditions by the over current protection block. The current limiter value is controlled by the OcpTrim 
209
-  bits in RegOcp.
210
-  Imax sets a limit on the current drain of the Power Amplifier only, hence the maximum current drain of the 
211
-  RFM96/77/78 is equal to Imax + IFS.
212
-  Default 100mA changed to 240mA.
213
-*/
214
-
215
-void SX1276_set_power(SX1276_t * module)
216
-{
217
-//    SX1276_SPIWrite(LR_RegPaConfig, (PaSelect << 7) | ((MaxPower & 0x07) << 4) | (OutputPower & 0x0F));
218
-    SX1276_SPIWrite(module,LR_RegPaConfig, (module->LoRa_Pa_boost << 7) | ((0x07) << 4) | (module->power & 0x0F));
219
-    //RFO -> 0 ~ 15 / PA_BOOST -> 2 ~ 17
220
-}
221
-void SX1276_defaultConfig(SX1276_t * module) {
222
-	SX1276_config(module, module->frequency, module->power, module->LoRa_Rate,
223
-			module->LoRa_BW,module->LoRa_Lna,module->LoRa_Pa_boost);
224
-}
225
-
226
-void SX1276_config(SX1276_t * module, uint8_t frequency, uint8_t power,
227
-		uint8_t LoRa_Rate, uint8_t LoRa_BW,uint8_t LoRa_Lna,uint8_t LoRa_PaBoost) {
228
-	SX1276_sleep(module); //Change modem mode Must in Sleep mode
229
-	SX1276_hw_DelayMs(15);
230
-
231
-	SX1276_entryLoRa(module);
232
-	//SX1276_SPIWrite(module, 0x5904); //?? Change digital regulator form 1.6V to 1.47V: see errata note
233
-
234
-	SX1276_SPIBurstWrite(module, LR_RegFrMsb,
235
-			(uint8_t*) SX1276_Frequency[frequency], 3); //setting  frequency parameter
236
-
237
-	//setting base parameter
238
-	SX1276_SPIWrite(module, LR_RegPaConfig, SX1276_Power[power]); //Setting output power parameter
239
-
240
-	SX1276_SPIWrite(module, LR_RegOcp, 0x0B);			//RegOcp,Close Ocp
241
-//	SX1276_SPIWrite(module, LR_RegLna, 0x20);		//RegLNA,High & LNA Enable
242
-    SX1276_set_power(module);
243
-
244
-    SX1276_SPIWrite(module, LR_RegLna, LoRa_Lna);       //RegLNA,High & LNA Enable
245
-
246
-	if (SX1276_SpreadFactor[LoRa_Rate] == 6) {	//SFactor=6
247
-		uint8_t tmp;
248
-		SX1276_SPIWrite(module,
249
-		LR_RegModemConfig1,
250
-				((SX1276_LoRaBandwidth[LoRa_BW] << 4) + (SX1276_CR << 1) + 0x01)); //Implicit Enable CRC Enable(0x02) & Error Coding rate 4/5(0x01), 4/6(0x02), 4/7(0x03), 4/8(0x04)
251
-
252
-		SX1276_SPIWrite(module,
253
-		LR_RegModemConfig2,
254
-				((SX1276_SpreadFactor[LoRa_Rate] << 4) + (SX1276_CRC << 2)
255
-						+ 0x03));
256
-
257
-		tmp = SX1276_SPIRead(module, 0x31);
258
-		tmp &= 0xF8;
259
-		tmp |= 0x05;
260
-		SX1276_SPIWrite(module, 0x31, tmp);
261
-		SX1276_SPIWrite(module, 0x37, 0x0C);
262
-	} else {
263
-		SX1276_SPIWrite(module,
264
-		LR_RegModemConfig1,
265
-				((SX1276_LoRaBandwidth[LoRa_BW] << 4) + (SX1276_CR << 1) + 0x00)); //Explicit Enable CRC Enable(0x02) & Error Coding rate 4/5(0x01), 4/6(0x02), 4/7(0x03), 4/8(0x04)
266
-
267
-		SX1276_SPIWrite(module,
268
-		LR_RegModemConfig2,
269
-				((SX1276_SpreadFactor[LoRa_Rate] << 4) + (SX1276_CRC << 2)
270
-						+ 0x03)); //SFactor &  LNA gain set by the internal AGC loop
271
-	}
272
-
273
-	SX1276_SPIWrite(module, LR_RegSymbTimeoutLsb, 0xFF); //RegSymbTimeoutLsb Timeout = 0x3FF(Max)
274
-	SX1276_SPIWrite(module, LR_RegPreambleMsb, 0x00); //RegPreambleMsb
275
-	SX1276_SPIWrite(module, LR_RegPreambleLsb, 12); //RegPreambleLsb 8+4=12byte Preamble
276
-	SX1276_SPIWrite(module, REG_LR_DIOMAPPING2, 0x01); //RegDioMapping2 DIO5=00, DIO4=01
277
-	module->readBytes = 0;
278
-	SX1276_standby(module); //Entry standby mode
279
-}
280
-
281
-void SX1276_standby(SX1276_t * module) {
282
-	SX1276_SPIWrite(module, LR_RegOpMode, 0x09);
283
-	module->status = STANDBY;
284
-}
285
-
286
-void SX1276_sleep(SX1276_t * module) {
287
-	SX1276_SPIWrite(module, LR_RegOpMode, 0x08);
288
-	module->status = SLEEP;
289
-}
290
-
291
-void SX1276_entryLoRa(SX1276_t * module) {
292
-	SX1276_SPIWrite(module, LR_RegOpMode, 0x88);
293
-}
294
-
295
-void SX1276_clearLoRaIrq(SX1276_t * module) {
296
-	SX1276_SPIWrite(module, LR_RegIrqFlags, 0xFF);
297
-}
298
-
299
-int SX1276_LoRaEntryRx(SX1276_t * module, uint8_t length, uint32_t timeout) {
300
-	uint8_t addr;
301
-
302
-	module->packetLength = length;
303
-
304
-	SX1276_defaultConfig(module);		//Setting base parameter
305
-	SX1276_SPIWrite(module, REG_LR_PADAC, 0x84);	//Normal and RX
306
-	SX1276_SPIWrite(module, LR_RegHopPeriod, 0xFF); //No FHSS
307
-	SX1276_SPIWrite(module, REG_LR_DIOMAPPING1, 0x01);//DIO=00,DIO1=00,DIO2=00, DIO3=01
308
-	SX1276_SPIWrite(module, LR_RegIrqFlagsMask, 0x3F);//Open RxDone interrupt & Timeout
309
-	SX1276_clearLoRaIrq(module);
310
-	SX1276_SPIWrite(module, LR_RegPayloadLength, length);//Payload Length 21byte(this register must difine when the data long of one byte in SF is 6)
311
-	addr = SX1276_SPIRead(module, LR_RegFifoRxBaseAddr); //Read RxBaseAddr
312
-	SX1276_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RxBaseAddr->FiFoAddrPtr
313
-	SX1276_SPIWrite(module, LR_RegOpMode, 0x85);	//Mode//Low Frequency Mode
314
-	//SX1276_SPIWrite(module, LR_RegOpMode,0x05);	//Continuous Rx Mode //High Frequency Mode
315
-	module->readBytes = 0;
316
-
317
-	while (1) {
318
-		if ((SX1276_SPIRead(module, LR_RegModemStat) & 0x04) == 0x04) { //Rx-on going RegModemStat
319
-			module->status = RX;
320
-			return 1;
321
-		}
322
-		if (--timeout == 0) {
323
-			SX1276_hw_Reset(module->hw);
324
-			SX1276_defaultConfig(module);
325
-			return 0;
326
-		}
327
-		SX1276_hw_DelayMs(1);
328
-	}
329
-}
330
-
331
-uint8_t SX1276_LoRaRxPacket(SX1276_t * module) {
332
-	unsigned char addr;
333
-	unsigned char packet_size;
334
-
335
-	if (SX1276_hw_GetDIO0(module->hw)) {
336
-		memset(module->rxBuffer, 0x00, SX1276_MAX_PACKET);
337
-
338
-		addr = SX1276_SPIRead(module, LR_RegFifoRxCurrentaddr); //last packet addr
339
-		SX1276_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RxBaseAddr -> FiFoAddrPtr
340
-
341
-		if (module->LoRa_Rate == SX1276_LORA_SF_6) { //When SpreadFactor is six,will used Implicit Header mode(Excluding internal packet length)
342
-			packet_size = module->packetLength;
343
-		} else {
344
-			packet_size = SX1276_SPIRead(module, LR_RegRxNbBytes); //Number for received bytes
345
-		}
346
-
347
-		SX1276_SPIBurstRead(module, 0x00, module->rxBuffer, packet_size);
348
-		module->readBytes = packet_size;
349
-		SX1276_clearLoRaIrq(module);
350
-	}
351
-	return module->readBytes;
352
-}
353
-
354
-
355
-
356
-
357
-int SX1276_LoRaEntryTx(SX1276_t * module, uint8_t length, uint32_t timeout) {
358
-	uint8_t addr;
359
-	uint8_t temp;
360
-
361
-	module->packetLength = length;
362
-
363
-	SX1276_defaultConfig(module); //setting base parameter
364
-	SX1276_SPIWrite(module, REG_LR_PADAC, 0x87);	//Tx for 20dBm
365
-	SX1276_SPIWrite(module, LR_RegHopPeriod, 0x00); //RegHopPeriod NO FHSS
366
-	SX1276_SPIWrite(module, REG_LR_DIOMAPPING1, 0x41); //DIO0=01, DIO1=00,DIO2=00, DIO3=01
367
-	SX1276_clearLoRaIrq(module);
368
-	SX1276_SPIWrite(module, LR_RegIrqFlagsMask, 0xF7); //Open TxDone interrupt
369
-	SX1276_SPIWrite(module, LR_RegPayloadLength, length); //RegPayloadLength 21byte
370
-	addr = SX1276_SPIRead(module, LR_RegFifoTxBaseAddr); //RegFiFoTxBaseAddr
371
-	SX1276_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RegFifoAddrPtr
372
-
373
-	while (1) {
374
-		temp = SX1276_SPIRead(module, LR_RegPayloadLength);
375
-		if (temp == length) {
376
-			module->status = TX;
377
-			return 1;
378
-		}
379
-
380
-		if (--timeout == 0) {
381
-			SX1276_hw_Reset(module->hw);
382
-			SX1276_defaultConfig(module);
383
-			return 0;
384
-		}
385
-	}
386
-}
387
-
388
-int SX1276_LoRaTxPacket(SX1276_t * module, uint8_t* txBuffer, uint8_t length,
389
-		uint32_t timeout) {
390
-	SX1276_SPIBurstWrite(module, 0x00, txBuffer, length);
391
-	SX1276_SPIWrite(module, LR_RegOpMode, 0x8b);	//Tx Mode
392
-	while (1) {
393
-		if (SX1276_hw_GetDIO0(module->hw)) { //if(Get_NIRQ()) //Packet send over
394
-			SX1276_SPIRead(module, LR_RegIrqFlags);
395
-			SX1276_clearLoRaIrq(module); //Clear irq
396
-			SX1276_standby(module); //Entry Standby mode
397
-			return 1;
398
-		}
399
-
400
-		if (--timeout == 0) {
401
-			SX1276_hw_Reset(module->hw);
402
-			SX1276_defaultConfig(module);
403
-			return 0;
404
-		}
405
-		SX1276_hw_DelayMs(1);
406
-	}
407
-}
408
-
409
-void SX1276_begin(SX1276_t * module, uint8_t frequency, uint8_t power,
410
-		uint8_t LoRa_Rate, uint8_t LoRa_BW, uint8_t packetLength,uint8_t LoRa_Lna,uint8_t LoRa_PaBoost) {
411
-	SX1276_hw_init(module->hw);
412
-	module->frequency       = frequency;
413
-	module->power           = power;
414
-	module->LoRa_Rate       = LoRa_Rate;
415
-	module->LoRa_BW         = LoRa_BW;
416
-	module->packetLength    = packetLength;
417
-    module->LoRa_Lna        = LoRa_Lna;
418
-    module->LoRa_Pa_boost   = LoRa_PaBoost;
419
-	SX1276_defaultConfig(module);
420
-}
421
-
422
-int SX1276_transmit(SX1276_t * module, uint8_t* txBuf, uint8_t length,
423
-		uint32_t timeout) {
424
-	if (SX1276_LoRaEntryTx(module, length, timeout)) {
425
-		return SX1276_LoRaTxPacket(module, txBuf, length, timeout);
426
-	}
427
-	return 0;
428
-}
429
-
430
-int SX1276_receive(SX1276_t * module, uint8_t length, uint32_t timeout) {
431
-	return SX1276_LoRaEntryRx(module, length, timeout);
432
-}
433
-
434
-uint8_t SX1276_available(SX1276_t * module) {
435
-	return SX1276_LoRaRxPacket(module);
436
-}
437
-
438
-uint8_t SX1276_read(SX1276_t * module, uint8_t* rxBuf, uint8_t length) {
439
-	if (length != module->readBytes)
440
-		length = module->readBytes;
441
-	memcpy(rxBuf, module->rxBuffer, length);
442
-	rxBuf[length] = '\0';
443
-	module->readBytes = 0;
444
-	return length;
445
-}
446
-
447
-uint8_t SX1276_RSSI_LoRa(SX1276_t * module) {
448
-	uint32_t temp = 10;
449
-	temp = SX1276_SPIRead(module, LR_RegRssiValue); //Read RegRssiValue, Rssi value
450
-	temp = temp + 127 - 137; //127:Max RSSI, 137:RSSI offset
451
-	return (uint8_t) temp;
452
-}
453
-
454
-uint8_t SX1276_RSSI(SX1276_t * module) {
455
-	uint8_t temp = 0xff;
456
-	temp = SX1276_SPIRead(module, 0x11);
457
-	temp = 127 - (temp >> 1);	//127:Max RSSI
458
-	return temp;
459
-}
460
-
1
+/**
2
+ * Author Wojciech Domski <Wojciech.Domski@gmail.com>
3
+ * www: www.Domski.pl
4
+ *
5
+ * work based on DORJI.COM sample code and
6
+ * https://github.com/realspinner/SX1276_LoRa
7
+ */
8
+
9
+#include "SX1276.h"
10
+#include <string.h>
11
+
12
+
13
+//////////////////////////////////
14
+// logic
15
+//////////////////////////////////
16
+
17
+__weak void SX1276_hw_init(SX1276_hw_t * hw) {
18
+	SX1276_hw_SetNSS(hw, 1);
19
+	HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_SET);
20
+}
21
+
22
+__weak void SX1276_hw_SetNSS(SX1276_hw_t * hw, int value) {
23
+	HAL_GPIO_WritePin(hw->nss.port, hw->nss.pin,
24
+			(value == 1) ? GPIO_PIN_SET : GPIO_PIN_RESET);
25
+}
26
+
27
+__weak void SX1276_hw_Reset(SX1276_hw_t * hw) {
28
+	SX1276_hw_SetNSS(hw, 1);
29
+	HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_RESET);
30
+
31
+	SX1276_hw_DelayMs(1);
32
+
33
+	HAL_GPIO_WritePin(hw->reset.port, hw->reset.pin, GPIO_PIN_SET);
34
+
35
+	SX1276_hw_DelayMs(100);
36
+}
37
+
38
+#if 0 // PYJ.2019.04.01_BEGIN -- 
39
+__weak void SX1276_hw_SPICommand(SX1276_hw_t * hw, uint8_t cmd) {
40
+	SX1276_hw_SetNSS(hw, 0);
41
+	HAL_SPI_Transmit(hw->spi, &cmd, 1, 1000);
42
+	while (HAL_SPI_GetState(hw->spi) != HAL_SPI_STATE_READY)
43
+		;
44
+}
45
+#endif // PYJ.2019.04.01_END -- 
46
+void SX1276_hw_SPICommand(SX1276_hw_t * hw, uint8_t cmd) {
47
+	SX1276_hw_SetNSS(hw, 0);
48
+	BLUECELL_SPI_Transmit(cmd);
49
+}
50
+
51
+#if 0 // PYJ.2019.04.01_BEGIN -- 
52
+__weak uint8_t SX1276_hw_SPIReadByte(SX1276_hw_t * hw) {
53
+	uint8_t txByte = 0x00;
54
+	uint8_t rxByte = 0x00;
55
+
56
+	SX1276_hw_SetNSS(hw, 0);
57
+	HAL_SPI_TransmitReceive(hw->spi, &txByte, &rxByte, 1, 1000);
58
+	return rxByte;
59
+}
60
+#endif // PYJ.2019.04.01_END -- 
61
+uint8_t SX1276_hw_SPIReadByte(SX1276_hw_t * hw) {
62
+	//uint8_t txByte = 0x00;
63
+	uint8_t rxByte = 0x00;
64
+
65
+	SX1276_hw_SetNSS(hw, 0);
66
+//	HAL_SPI_TransmitReceive(hw->spi, &txByte, &rxByte, 1, 1000);
67
+    rxByte = SpiRead();
68
+	return rxByte;
69
+}
70
+
71
+__weak void SX1276_hw_DelayMs(uint32_t msec) {
72
+	HAL_Delay(msec);
73
+}
74
+
75
+__weak int SX1276_hw_GetDIO0(SX1276_hw_t * hw) {
76
+	return (HAL_GPIO_ReadPin(hw->dio0.port, hw->dio0.pin) == GPIO_PIN_SET);
77
+}
78
+
79
+//////////////////////////////////
80
+// logic
81
+//////////////////////////////////
82
+
83
+uint8_t SX1276_SPIRead(SX1276_t * module, uint8_t addr) {
84
+	uint8_t tmp;
85
+	SX1276_hw_SPICommand(module->hw, addr);
86
+	tmp = SX1276_hw_SPIReadByte(module->hw);
87
+	SX1276_hw_SetNSS(module->hw, 1);
88
+	return tmp;
89
+}
90
+uint8_t SX1276_SPIIDRead(SX1276_t * module, uint8_t addr) {
91
+	uint8_t tmp;
92
+	SX1276_hw_SPICommand(module->hw, addr);
93
+	tmp = SX1276_hw_SPIReadByte(module->hw);
94
+	SX1276_hw_SetNSS(module->hw, 1);
95
+	return tmp;
96
+}
97
+
98
+void SX1276_SPIWrite(SX1276_t * module, uint8_t addr, uint8_t cmd) {
99
+	SX1276_hw_SetNSS(module->hw, 0);
100
+	SX1276_hw_SPICommand(module->hw, addr | 0x80);
101
+	SX1276_hw_SPICommand(module->hw, cmd);
102
+//    SPIGPIOTxRx(addr | 0x80,cmd);
103
+
104
+	SX1276_hw_SetNSS(module->hw, 1);
105
+}
106
+
107
+void SX1276_SPIBurstRead(SX1276_t * module, uint8_t addr, uint8_t* rxBuf,
108
+		uint8_t length) {
109
+	uint8_t i;
110
+	if (length <= 1) {
111
+		return;
112
+	} else {
113
+		SX1276_hw_SetNSS(module->hw, 0);
114
+		SX1276_hw_SPICommand(module->hw, addr);
115
+		//printf("Test Data:");
116
+		for (i = 0; i < length; i++) {
117
+			rxBuf[i] = SX1276_hw_SPIReadByte(module->hw);
118
+			//printf("%02x ",rxBuf[i]);
119
+		}
120
+		//printf("\n");
121
+		SX1276_hw_SetNSS(module->hw, 1);
122
+	}
123
+}
124
+
125
+void SX1276_SPIBurstWrite(SX1276_t * module, uint8_t addr, uint8_t* txBuf,
126
+		uint8_t length) {
127
+	uint8_t i;
128
+	if (length <= 1) {
129
+		return;
130
+	} else {
131
+		SX1276_hw_SetNSS(module->hw, 0);
132
+		SX1276_hw_SPICommand(module->hw, addr | 0x80);
133
+//        printf("Test Data:");
134
+		for (i = 0; i < length; i++) {
135
+			SX1276_hw_SPICommand(module->hw, txBuf[i]);
136
+//            printf("%02x ",txBuf[i]);
137
+		}
138
+//        printf("\n");
139
+		SX1276_hw_SetNSS(module->hw, 1);
140
+	}
141
+}
142
+        /*
143
+  RegPaConfig - 0x09
144
+  PaSelect    Mode                                  Power Range     Pout Formula
145
+  0           PA_HF or PA_LF on RFO_HF or RFO_LF    -4 to +15dBm    Pout=Pmax-(15-OutputPower), Pmax=10.8+0.6*MaxPower [dBm]
146
+  1           PA_HP on PA_BOOST, any frequency      +2 to +17dBm    Pout=17-(15-OutputPower) [dBm]
147
+  PA_LF option doesn't seem to transmit anything. Not connected on these boards, perhaps?
148
+  Use only PA_BOOST mode.
149
+  
150
+  PA_LF   Pmax              
151
+  Pout    0     1     2     3     4     5     6     7
152
+  0       -4.2  -3.6  -3    -2.4  -1.8  -1.2  -0.6  0
153
+  1       -3.2  -2.6  -2    -1.4  -0.8  -0.2  0.4   1
154
+  2       -2.2  -1.6  -1    -0.4  0.2   0.8   1.4   2
155
+  3       -1.2  -0.6  0     0.6   1.2   1.8   2.4   3
156
+  4       -0.2  0.4   1     1.6   2.2   2.8   3.4   4
157
+  5       0.8   1.4   2     2.6   3.2   3.8   4.4   5
158
+  6       1.8   2.4   3     3.6   4.2   4.8   5.4   6
159
+  7       2.8   3.4   4     4.6   5.2   5.8   6.4   7
160
+  8       3.8   4.4   5     5.6   6.2   6.8   7.4   8
161
+  9       4.8   5.4   6     6.6   7.2   7.8   8.4   9
162
+  10      5.8   6.4   7     7.6   8.2   8.8   9.4   10
163
+  11      6.8   7.4   8     8.6   9.2   9.8   10.4  11
164
+  12      7.8   8.4   9     9.6   10.2  10.8  11.4  12
165
+  13      8.8   9.4   10    10.6  11.2  11.8  12.4  13
166
+  14      9.8   10.4  11    11.6  12.2  12.8  13.4  14
167
+  15      10.8  11.4  12    12.6  13.2  13.8  14.4  15  [dBm]
168
+  
169
+  PA_BOOST 
170
+  Pout  OutputPower
171
+  0     2 dBm
172
+  1     3 dBm
173
+  2     4 dBm
174
+  3     5 dBm
175
+  4     6 dBm
176
+  5     7 dBm
177
+  6     8 dBm
178
+  7     9 dBm
179
+  8     10 dBm
180
+  9     11 dBm
181
+  10    12 dBm
182
+  11    13 dBm
183
+  12    14 dBm
184
+  13    15 dBm
185
+  14    16 dBm
186
+  15    17 dBm
187
+  
188
+  PaSelect
189
+    0 RFO pin. Maximum power of +14 dBm 
190
+    1 PA_BOOST pin. Maximum power of +20 dBm
191
+  MaxPower
192
+    Select max output power: Pmax=10.8+0.6*MaxPower [dBm]
193
+  OutputPower
194
+    Pout=Pmax-(15-OutputPower) if PaSelect = 0 (RFO pins) 
195
+    Pout=17-(15-OutputPower) if PaSelect = 1 (PA_BOOST pin)
196
+  PA_HF and PA_LF are high efficiency amplifiers capable of yielding RF power programmable in 1 dB steps
197
+  from -4 to +14dBm directly into a 50 ohm load with low current consumption. PA_LF covers the lower bands
198
+  (up to 525 MHz), whilst PA_HF will cover the upper bands (from 860 MHz).
199
+  PA_HP (High Power), connected to the PA_BOOST pin, covers all frequency bands that the chip addresses.
200
+  It permits continuous operation at up to +17 dBm and duty cycled operation at up to +20dBm.
201
+  RegOcp - 0x0B
202
+  OcpTrim   IMAX            Imax Formula
203
+  0 to 15   45 to 120 mA    45 + 5*OcpTrim [mA]
204
+  16 to 27  130 to 240 mA   -30 + 10*OcpTrim [mA]
205
+  27+       240 mA          240 mA
206
+  
207
+  The power amplifiers of RFM95/96/97/98(W) are protected against current over supply in adverse RF load
208
+  conditions by the over current protection block. The current limiter value is controlled by the OcpTrim 
209
+  bits in RegOcp.
210
+  Imax sets a limit on the current drain of the Power Amplifier only, hence the maximum current drain of the 
211
+  RFM96/77/78 is equal to Imax + IFS.
212
+  Default 100mA changed to 240mA.
213
+*/
214
+
215
+void SX1276_set_power(SX1276_t * module)
216
+{
217
+//    SX1276_SPIWrite(LR_RegPaConfig, (PaSelect << 7) | ((MaxPower & 0x07) << 4) | (OutputPower & 0x0F));
218
+    SX1276_SPIWrite(module,LR_RegPaConfig, (module->LoRa_Pa_boost << 7) | ((0x07) << 4) | (module->power & 0x0F));
219
+    //RFO -> 0 ~ 15 / PA_BOOST -> 2 ~ 17
220
+}
221
+void SX1276_defaultConfig(SX1276_t * module) {
222
+	SX1276_config(module, module->frequency, module->power, module->LoRa_Rate,
223
+			module->LoRa_BW,module->LoRa_Lna,module->LoRa_Pa_boost);
224
+}
225
+
226
+void SX1276_config(SX1276_t * module, uint8_t frequency, uint8_t power,
227
+		uint8_t LoRa_Rate, uint8_t LoRa_BW,uint8_t LoRa_Lna,uint8_t LoRa_PaBoost) {
228
+	SX1276_sleep(module); //Change modem mode Must in Sleep mode
229
+	SX1276_hw_DelayMs(15);
230
+
231
+	SX1276_entryLoRa(module);
232
+	//SX1276_SPIWrite(module, 0x5904); //?? Change digital regulator form 1.6V to 1.47V: see errata note
233
+
234
+	SX1276_SPIBurstWrite(module, LR_RegFrMsb,
235
+			(uint8_t*) SX1276_Frequency[frequency], 3); //setting  frequency parameter
236
+
237
+	//setting base parameter
238
+	SX1276_SPIWrite(module, LR_RegPaConfig, SX1276_Power[power]); //Setting output power parameter
239
+
240
+	SX1276_SPIWrite(module, LR_RegOcp, 0x0B);			//RegOcp,Close Ocp
241
+//	SX1276_SPIWrite(module, LR_RegLna, 0x20);		//RegLNA,High & LNA Enable
242
+    SX1276_set_power(module);
243
+
244
+    SX1276_SPIWrite(module, LR_RegLna, LoRa_Lna);       //RegLNA,High & LNA Enable
245
+
246
+	if (SX1276_SpreadFactor[LoRa_Rate] == 6) {	//SFactor=6
247
+		uint8_t tmp;
248
+		SX1276_SPIWrite(module,
249
+		LR_RegModemConfig1,
250
+				((SX1276_LoRaBandwidth[LoRa_BW] << 4) + (SX1276_CR << 1) + 0x01)); //Implicit Enable CRC Enable(0x02) & Error Coding rate 4/5(0x01), 4/6(0x02), 4/7(0x03), 4/8(0x04)
251
+
252
+		SX1276_SPIWrite(module,LR_RegModemConfig2,((SX1276_SpreadFactor[LoRa_Rate] << 4) + (SX1276_CRC << 2)	+ 0x03));
253
+
254
+		tmp = SX1276_SPIRead(module, 0x31);
255
+		tmp &= 0xF8;
256
+		tmp |= 0x05;
257
+		SX1276_SPIWrite(module, 0x31, tmp);
258
+		SX1276_SPIWrite(module, 0x37, 0x0C);
259
+	} else {
260
+		SX1276_SPIWrite(module,
261
+		LR_RegModemConfig1,
262
+				((SX1276_LoRaBandwidth[LoRa_BW] << 4) + (SX1276_CR << 1) + 0x00)); //Explicit Enable CRC Enable(0x02) & Error Coding rate 4/5(0x01), 4/6(0x02), 4/7(0x03), 4/8(0x04)
263
+
264
+		SX1276_SPIWrite(module,
265
+		LR_RegModemConfig2,
266
+				((SX1276_SpreadFactor[LoRa_Rate] << 4) + (SX1276_CRC << 2)
267
+						+ 0x03)); //SFactor &  LNA gain set by the internal AGC loop
268
+	}
269
+
270
+	SX1276_SPIWrite(module, LR_RegSymbTimeoutLsb, 0xFF); //RegSymbTimeoutLsb Timeout = 0x3FF(Max)
271
+	SX1276_SPIWrite(module, LR_RegPreambleMsb, 0x00); //RegPreambleMsb
272
+	SX1276_SPIWrite(module, LR_RegPreambleLsb, 12); //RegPreambleLsb 8+4=12byte Preamble
273
+	SX1276_SPIWrite(module, REG_LR_DIOMAPPING2, 0x01); //RegDioMapping2 DIO5=00, DIO4=01
274
+	module->readBytes = 0;
275
+	SX1276_standby(module); //Entry standby mode
276
+}
277
+
278
+void SX1276_standby(SX1276_t * module) {
279
+//	SX1276_SPIWrite(module, LR_RegOpMode, 0x09);
280
+	SX1276_SPIWrite(module, LR_RegOpMode, 0x01);
281
+
282
+	module->status = STANDBY;
283
+}
284
+
285
+void SX1276_sleep(SX1276_t * module) {
286
+//	SX1276_SPIWrite(module, LR_RegOpMode, 0x08);
287
+    SX1276_SPIWrite(module, LR_RegOpMode, 0x80);
288
+
289
+	module->status = SLEEP;
290
+}
291
+
292
+void SX1276_entryLoRa(SX1276_t * module) {
293
+//	SX1276_SPIWrite(module, LR_RegOpMode, 0x88);
294
+	SX1276_SPIWrite(module, LR_RegOpMode, 0x80);
295
+}
296
+
297
+void SX1276_clearLoRaIrq(SX1276_t * module) {
298
+	SX1276_SPIWrite(module, LR_RegIrqFlags, 0xFF);
299
+}
300
+
301
+int SX1276_LoRaEntryRx(SX1276_t * module, uint8_t length, uint32_t timeout) {
302
+	uint8_t addr;
303
+
304
+	module->packetLength = length;
305
+
306
+	SX1276_defaultConfig(module);		//Setting base parameter
307
+	SX1276_SPIWrite(module, REG_LR_PADAC, 0x84);	//Normal and RX
308
+	SX1276_SPIWrite(module, LR_RegHopPeriod, 0xFF); //No FHSS
309
+	SX1276_SPIWrite(module, REG_LR_DIOMAPPING1, 0x01);//DIO=00,DIO1=00,DIO2=00, DIO3=01
310
+	SX1276_SPIWrite(module, LR_RegIrqFlagsMask, 0x3F);//Open RxDone interrupt & Timeout
311
+	SX1276_clearLoRaIrq(module);
312
+	SX1276_SPIWrite(module, LR_RegPayloadLength, length);//Payload Length 21byte(this register must difine when the data long of one byte in SF is 6)
313
+	addr = SX1276_SPIRead(module, LR_RegFifoRxBaseAddr); //Read RxBaseAddr
314
+	SX1276_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RxBaseAddr->FiFoAddrPtr
315
+	SX1276_SPIWrite(module, LR_RegOpMode, 0x85);	//Mode//Low Frequency Mode
316
+	//SX1276_SPIWrite(module, LR_RegOpMode,0x05);	//Continuous Rx Mode //High Frequency Mode
317
+	module->readBytes = 0;
318
+
319
+	while (1) {
320
+		if ((SX1276_SPIRead(module, LR_RegModemStat) & 0x04) == 0x04) { //Rx-on going RegModemStat
321
+			module->status = RX;
322
+			return 1;
323
+		}
324
+		if (--timeout == 0) {
325
+            printf(
"Function : %s    Line : %d \n",__func__,__LINE__);
326
+            NVIC_SystemReset();            
327
+			SX1276_hw_Reset(module->hw);
328
+			SX1276_defaultConfig(module);
329
+			return 0;
330
+		}
331
+		SX1276_hw_DelayMs(1);
332
+	}
333
+}
334
+
335
+uint8_t SX1276_LoRaRxPacket(SX1276_t * module) {
336
+	unsigned char addr;
337
+	unsigned char packet_size;
338
+
339
+	if (SX1276_hw_GetDIO0(module->hw)) {
340
+		memset(module->rxBuffer, 0x00, SX1276_MAX_PACKET);
341
+
342
+		addr = SX1276_SPIRead(module, LR_RegFifoRxCurrentaddr); //last packet addr
343
+		SX1276_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RxBaseAddr -> FiFoAddrPtr
344
+
345
+		if (module->LoRa_Rate == SX1276_LORA_SF_6) { //When SpreadFactor is six,will used Implicit Header mode(Excluding internal packet length)
346
+			packet_size = module->packetLength;
347
+		} else {
348
+			packet_size = SX1276_SPIRead(module, LR_RegRxNbBytes); //Number for received bytes
349
+		}
350
+
351
+		SX1276_SPIBurstRead(module, 0x00, module->rxBuffer, packet_size);
352
+		module->readBytes = packet_size;
353
+		SX1276_clearLoRaIrq(module);
354
+	}
355
+	return module->readBytes;
356
+}
357
+
358
+
359
+
360
+
361
+int SX1276_LoRaEntryTx(SX1276_t * module, uint8_t length, uint32_t timeout) {
362
+	uint8_t addr;
363
+	uint8_t temp;
364
+
365
+	module->packetLength = length;
366
+
367
+	SX1276_defaultConfig(module); //setting base parameter
368
+	SX1276_SPIWrite(module, REG_LR_PADAC, 0x87);	//Tx for 20dBm
369
+	SX1276_SPIWrite(module, LR_RegHopPeriod, 0x00); //RegHopPeriod NO FHSS
370
+	SX1276_SPIWrite(module, REG_LR_DIOMAPPING1, 0x41); //DIO0=01, DIO1=00,DIO2=00, DIO3=01
371
+	SX1276_clearLoRaIrq(module);
372
+	SX1276_SPIWrite(module, LR_RegIrqFlagsMask, 0xF7); //Open TxDone interrupt
373
+	SX1276_SPIWrite(module, LR_RegPayloadLength, length); //RegPayloadLength 21byte
374
+	addr = SX1276_SPIRead(module, LR_RegFifoTxBaseAddr); //RegFiFoTxBaseAddr
375
+	SX1276_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RegFifoAddrPtr
376
+
377
+	while (1) {
378
+		temp = SX1276_SPIRead(module, LR_RegPayloadLength);
379
+		if (temp == length) {
380
+			module->status = TX;
381
+			return 1;
382
+		}
383
+
384
+		if (--timeout == 0) {
385
+            printf(
"Function : %s    Line : %d \n",__func__,__LINE__);
386
+            NVIC_SystemReset();
387
+			SX1276_hw_Reset(module->hw);
388
+			SX1276_defaultConfig(module);
389
+			return 0;
390
+		}
391
+	}
392
+}
393
+
394
+int SX1276_LoRaTxPacket(SX1276_t * module, uint8_t* txBuffer, uint8_t length,
395
+		uint32_t timeout) {
396
+	SX1276_SPIBurstWrite(module, 0x00, txBuffer, length);
397
+//	SX1276_SPIWrite(module, LR_RegOpMode, 0x8b);	//Tx Mode
398
+	SX1276_SPIWrite(module, LR_RegOpMode, 0x83);	//Tx Mode
399
+
400
+	while (1) {
401
+		if (SX1276_hw_GetDIO0(module->hw)) { //if(Get_NIRQ()) //Packet send over
402
+			SX1276_SPIRead(module, LR_RegIrqFlags);
403
+			SX1276_clearLoRaIrq(module); //Clear irq
404
+			SX1276_standby(module); //Entry Standby mode
405
+			return 1;
406
+		}
407
+
408
+		if (--timeout == 0) {
409
+            printf(
"Function : %s    Line : %d \n",__func__,__LINE__);
410
+            NVIC_SystemReset();
411
+			SX1276_hw_Reset(module->hw);
412
+			SX1276_defaultConfig(module);
413
+			return 0;
414
+		}
415
+		SX1276_hw_DelayMs(1);
416
+	}
417
+}
418
+
419
+void SX1276_begin(SX1276_t * module, uint8_t frequency, uint8_t power,
420
+		uint8_t LoRa_Rate, uint8_t LoRa_BW, uint8_t packetLength,uint8_t LoRa_Lna,uint8_t LoRa_PaBoost) {
421
+	SX1276_hw_init(module->hw);
422
+	module->frequency       = frequency;
423
+	module->power           = power;
424
+	module->LoRa_Rate       = LoRa_Rate;
425
+	module->LoRa_BW         = LoRa_BW;
426
+	module->packetLength    = packetLength;
427
+    module->LoRa_Lna        = LoRa_Lna;
428
+    module->LoRa_Pa_boost   = LoRa_PaBoost;
429
+	SX1276_defaultConfig(module);
430
+}
431
+
432
+int SX1276_transmit(SX1276_t * module, uint8_t* txBuf, uint8_t length,
433
+		uint32_t timeout) {
434
+	if (SX1276_LoRaEntryTx(module, length, timeout)) {
435
+		return SX1276_LoRaTxPacket(module, txBuf, length, timeout);
436
+	}
437
+	return 0;
438
+}
439
+
440
+int SX1276_receive(SX1276_t * module, uint8_t length, uint32_t timeout) {
441
+	return SX1276_LoRaEntryRx(module, length, timeout);
442
+}
443
+
444
+uint8_t SX1276_available(SX1276_t * module) {
445
+	return SX1276_LoRaRxPacket(module);
446
+}
447
+
448
+uint8_t SX1276_read(SX1276_t * module, uint8_t* rxBuf, uint8_t length) {
449
+	if (length != module->readBytes)
450
+		length = module->readBytes;
451
+	memcpy(rxBuf, module->rxBuffer, length);
452
+	rxBuf[length] = '\0';
453
+	module->readBytes = 0;
454
+	return length;
455
+}
456
+
457
+uint8_t SX1276_RSSI_LoRa(SX1276_t * module) {
458
+	uint32_t temp = 10;
459
+	temp = SX1276_SPIRead(module, LR_RegRssiValue); //Read RegRssiValue, Rssi value
460
+	temp = temp + 127 - 137; //127:Max RSSI, 137:RSSI offset
461
+	return (uint8_t) temp;
462
+}
463
+
464
+uint8_t SX1276_RSSI(SX1276_t * module) {
465
+	uint8_t temp = 0xff;
466
+	temp = SX1276_SPIRead(module, 0x11);
467
+	temp = 127 - (temp >> 1);	//127:Max RSSI
468
+	return temp;
469
+}
470
+

+ 178 - 131
Src/main.c

@@ -64,11 +64,14 @@
64 64
 /* Private variables ---------------------------------------------------------*/
65 65
 I2C_HandleTypeDef hi2c2;
66 66
 
67
+IWDG_HandleTypeDef hiwdg;
68
+
67 69
 TIM_HandleTypeDef htim6;
68 70
 
69 71
 UART_HandleTypeDef huart1;
70 72
 UART_HandleTypeDef huart2;
71 73
 DMA_HandleTypeDef hdma_usart1_rx;
74
+DMA_HandleTypeDef hdma_usart2_rx;
72 75
 
73 76
 /* USER CODE BEGIN PV */
74 77
 uint8_t rx1_data[buf_size];
@@ -86,7 +89,9 @@ uint8_t LoraDataSend;
86 89
 
87 90
 uint8_t RGB_SensorIDAutoset = 0;
88 91
 
89
-volatile uint32_t UartTimerCnt = 0;
92
+volatile uint32_t Uart1TimerCnt = 0;
93
+volatile uint32_t Uart2TimerCnt = 0;
94
+
90 95
 volatile uint32_t LedTimerCnt = 0;
91 96
 volatile uint32_t LoraTxTimerCnt = 0;
92 97
 volatile uint32_t LoraAckTimerCnt = 0;
@@ -97,7 +102,18 @@ uint8_t buf[buf_size] = {0,};
97 102
 uint8_t buf1[buf_size] = {0,};
98 103
 uint8_t buf2[buf_size] = {0,};
99 104
 
100
-Default_SX1276_t Default_SX1276;
105
+//Default_SX1276_t Default_SX1276;
106
+Default_SX1276_t Default_SX1276 = 
107
+{
108
+    SX1276_917MHZ,
109
+    SX1276_POWER_17DBM,
110
+    SX1276_LORA_SF_8,
111
+    SX1276_LORA_BW_20_8KHZ,
112
+    10,
113
+    SX1276_LORA_G1,
114
+    SX1276_15dBm,
115
+};
116
+
101 117
 SX1276_hw_t SX1276_hw;
102 118
 SX1276_t SX1276;
103 119
 
@@ -121,6 +137,7 @@ static void MX_TIM6_Init(void);
121 137
 static void MX_USART1_UART_Init(void);
122 138
 static void MX_USART2_UART_Init(void);
123 139
 static void MX_I2C2_Init(void);
140
+static void MX_IWDG_Init(void);
124 141
 static void MX_NVIC_Init(void);
125 142
 /* USER CODE BEGIN PFP */
126 143
 void RGB_SensorIDAutoSet(uint8_t set);
@@ -147,50 +164,19 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
147 164
     {
148 165
         buf1[count_in1] = rx1_data[0];//(uint8_t)USART2->DR;
149 166
          if(++count_in1>=buf_size){ count_in1 = 0; }
150
-//        printf("data %02x \r\n",rx1_data[0]);
151
-#if 0 // PYJ.2019.04.19_BEGIN -- 
152
-        if(buf[count_in1++] == 0xEB){
153
-            if(buf[bluecell_length] == (count_in1 - 3))
154
-                UartDataRecvSet(1);
155
-            else
156
-                count_in1 = 0;
157
-        }
158
-#endif // PYJ.2019.04.19_END -- 
159
-//        HAL_UART_Receive_IT(&huart1,&rx1_data[0],1);
160 167
     }
161 168
     if(huart->Instance == USART2) // Lora?? ?? Â???¹Â???¢Ë??Å ?? ?Â�¬?Џ
162 169
     {
163 170
         buf2[count_in2] = rx2_data[0];//(uint8_t)USART2->DR;
164 171
         if(++count_in2>=buf_size){ count_in2 = 0; }
165
-//      if(buf[count_in++] == 0xEB)UartDataRecvSet(1);
166
-#if 0 // PYJ.2019.04.19_BEGIN -- 
167
-        if(buf[count_in2++] == 0xEB){
168
-            if(buf[bluecell_length] == (count_in2 - 3))
169
-                UartDataRecvSet(2);
170
-            else
171
-                count_in1 = 0;
172
-//                printf("UART 2 %d",((count_in2 -1) - 3));
173
-        }
174
-#endif // PYJ.2019.04.19_END -- 
175
-        HAL_UART_Receive_IT(&huart2,&rx2_data[0],1);
176 172
     }
177
-#if 0 // PYJ.2019.04.13_BEGIN -- 
178
-    if(huart->Instance == USART3) //GUI ?? ?? Â???¹Â???¢Ë??Å ?? Port
179
-    {
180
-        buf[count_in3] = rx3_data[0];//(uint8_t)USART2->DR;
181
-        if(buf[count_in3++] == 0xEB)UartDataRecvSet(3);
182
-        /*ring_buf[count_in] = rx2_data[0];//(uint8_t)USART2->DR;
183
-        if(++count_in>=buf_size) count_in=0;*/
184
-        HAL_UART_Receive_IT(&huart3,&rx3_data[0],1);
185
-    }
186
-#endif // PYJ.2019.04.13_END -- 
187
-    
188 173
 }
189 174
 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
190 175
 {
191 176
 
192 177
     if(htim->Instance == TIM6){
193
-        UartTimerCnt++;
178
+        Uart1TimerCnt++;
179
+        Uart2TimerCnt++;
194 180
         LedTimerCnt++;
195 181
         LoraTxTimerCnt++;
196 182
         LoraAckTimerCnt++;
@@ -293,7 +279,7 @@ void Uart_dataCheck(uint8_t* Que_Buf,uint8_t* cnt){
293 279
 #endif // PYJ.2019.04.19_END -- 
294 280
 void RGB_Sensor_PowerOnOff(uint8_t id){
295 281
     uint8_t SensorSerchStart_cmd[5] = {0xbe,RGB_Controller_Init_Start,2,STH30_CreateCrc(&SensorSerchStart_cmd[bluecell_type],SensorSerchStart_cmd[bluecell_length]),0xeb};
296
-    uint8_t SensorSerchEnd_cmd[5] = {0xbe,RGB_Controller_Init_End,2,STH30_CreateCrc(&SensorSerchEnd_cmd[bluecell_type],SensorSerchEnd_cmd[bluecell_length]),0xeb};
282
+      
297 283
 //    printf("%d Power ON \r\n",id);
298 284
 
299 285
     switch(id){
@@ -310,7 +296,7 @@ void RGB_Sensor_PowerOnOff(uint8_t id){
310 296
         case 1:
311 297
             Uart1_Data_Send(&SensorSerchStart_cmd[bluecell_stx], SensorSerchStart_cmd[bluecell_length] + 3);
312 298
             HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_RESET);
313
-            HAL_Delay(50);
299
+            HAL_Delay(100);
314 300
             HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
315 301
             HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_RESET);            
316 302
             HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_RESET);            
@@ -391,7 +377,6 @@ void RGB_Sensor_PowerOnOff(uint8_t id){
391 377
 
392 378
             break;
393 379
         case 8:
394
-            Uart1_Data_Send(&SensorSerchEnd_cmd[bluecell_stx], SensorSerchEnd_cmd[bluecell_length] + 3);
395 380
             HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
396 381
             HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);        
397 382
             HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);   
@@ -400,7 +385,7 @@ void RGB_Sensor_PowerOnOff(uint8_t id){
400 385
             HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
401 386
             HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_SET);
402 387
             HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_SET);
403
-
388
+            
404 389
             break;
405 390
     }
406 391
 }
@@ -557,16 +542,6 @@ void Flash_InitRead(void) // ?
557 542
 
558 543
 
559 544
 
560
-Default_SX1276_t Default_SX1276 = 
561
-{
562
-    SX1276_917MHZ,
563
-    SX1276_POWER_17DBM,
564
-    SX1276_LORA_SF_8,
565
-    SX1276_LORA_BW_20_8KHZ,
566
-    10,
567
-    SX1276_LORA_G1,
568
-    SX1276_15dBm,
569
-};
570 545
 
571 546
 
572 547
 int master;
@@ -589,8 +564,11 @@ void Lora_Initialize(void){
589 564
     // SX1276_hw.spi = &hspi3;
590 565
     SX1276.hw = &SX1276_hw;
591 566
 //    printf("Configuring LoRa module\r\n");
567
+//    SX1276_begin(&SX1276, SX1276_917MHZ, SX1276_POWER_17DBM, SX1276_LORA_SF_8,
568
+//            SX1276_LORA_BW_20_8KHZ, 10);
569
+
592 570
     SX1276_begin(&SX1276, Default_SX1276.frequency, Default_SX1276.power,
593
-    Default_SX1276.LoRa_Rate,Default_SX1276.LoRa_BW, 10,Default_SX1276.LoRa_Lna,Default_SX1276.LoRa_Pa_boost);
571
+        Default_SX1276.LoRa_Rate,Default_SX1276.LoRa_BW, 10,Default_SX1276.LoRa_Lna,Default_SX1276.LoRa_Pa_boost);
594 572
 
595 573
 //    printf("Done configuring LoRaModule\r\n");
596 574
     master = 0;
@@ -600,10 +578,102 @@ void Lora_Initialize(void){
600 578
         ret = SX1276_LoRaEntryRx(&SX1276, LORA_MAX_DATA_CNT, 2000);
601 579
     }
602 580
 }
581
+void Lora_Operate(void){
582
+    if(RGB_SensorIDAutoGet() == 0){/*ID allocate if sentence Condition */
583
+        if(LoraDataSendGet() == LoraTx_mode && Lora_Buf[0] == 0xbe){
584
+            //        LoraDataSendSet(LoraRx_mode);
585
+            memcpy(&buffer[0],&Lora_Buf[0],LORA_MAX_DATA_CNT);
586
+            message_length = Lora_Buf[bluecell_length] + 3;////RGB Data 60byte + stx + etx + crc
587
+            ret = SX1276_LoRaEntryTx(&SX1276, message_length, 2000);
588
+            ret = SX1276_LoRaTxPacket(&SX1276, &buffer[0], message_length, 2000);
589
+//            printf("Tx buffer : ");
590
+//            for(uint8_t i = 0; i < sizeof(LoraDataRequest_t); i++)
591
+//                printf("%02x ",buffer[i]);
592
+//            printf("\n");
593
+            LoraDataSendSet(LoraRx_mode);
594
+            ret = SX1276_LoRaEntryRx(&SX1276, LORA_MAX_DATA_CNT, 2000);
595
+        }else{
596
+            ret = SX1276_LoRaRxPacket(&SX1276);
597
+            if (ret > 0) {
598
+                SX1276_read(&SX1276, &buffer[0], ret);
599
+//                printf("Received Data : ");
600
+//                for(uint8_t i = 0; i < ret; i++)
601
+//                printf("%02x ",  buffer[i]);
602
+//                printf("\n");
603
+                Uart_dataCheck(&buffer[bluecell_stx],&ret);
604
+            }
605
+        }
606
+    }
603 607
 
604 608
 
605 609
 
610
+}
611
+void Usart_Data_RecvCheck(void){
612
+    static uint8_t cnt1 = 0,cnt2=0,uartdatarecv = 0;
613
+    static uint8_t data1[100]= {0,};
614
+    static uint8_t data2[100]= {0,};
615
+
616
+    if(count_in1 != count_out1){ // <------- 
617
+           data1[cnt1++] = buf1[count_out1++];
618
+           if(count_out1 >= 100){ count_out1 = 0; }
619
+           Uart1TimerCnt = 0;
620
+           UartDataRecvSet(1);
621
+       }
622
+       if(count_in2 != count_out2){ // <------- 
623
+            data2[cnt2++] = buf2[count_out2++];
624
+            if(count_out2 >= 100){ count_out2 = 0; }
625
+            Uart2TimerCnt = 0;
626
+            UartDataRecvSet(2);
627
+       }
628
+       uartdatarecv = UartDataRecvGet(); 
629
+       if(uartdatarecv == 1 && Uart1TimerCnt > 100){
630
+           cnt1 = 0;
631
+           Uart_dataCheck(&data1[0],&count_in1);
632
+           memset(&data1[0],0,100);
633
+           UartDataRecvSet(0);
634
+       }
635
+       if(uartdatarecv == 2 && Uart2TimerCnt > 100){
636
+           cnt2 = 0;
637
+           Uart_dataCheck(&data2[0],&count_in2);
638
+           memset(&data2[0],0,100);
639
+           UartDataRecvSet(0);
640
+       }
606 641
 
642
+}
643
+void RGB_Sensor_DataRequest(void){
644
+    uint8_t IDAutoSetRequest_data[RGB_SensorIDAutoSetRequest_Length] = {0xbe,RGB_SensorID_SET,RGB_SensorIDAutoSetRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&IDAutoSetRequest_data[bluecell_type],IDAutoSetRequest_data[bluecell_length]),0xeb};  
645
+    uint8_t SensorSerchEnd_cmd[5] = {0xbe,RGB_Controller_Init_End,2,STH30_CreateCrc(&SensorSerchEnd_cmd[bluecell_type],SensorSerchEnd_cmd[bluecell_length]),0xeb};
646
+    uint8_t StatusRequest_data[RGB_SensorDataRequest_Length]         = {0xbe,RGB_Status_Data_Request,RGB_SensorDataRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&StatusRequest_data[bluecell_type],StatusRequest_data[bluecell_length]),0xeb};
647
+      if(LedTimerCnt > 500){
648
+        if(RGB_SensorIDAutoGet() == 1){/*ID allocate if sentence Condition */
649
+            if(SensorID == 0){memset(&SensorID_buf[0],0x00,8);SensorID_Cnt = 0;}
650
+            IDAutoSetRequest_data[bluecell_srcid + 1] = ++SensorID;//DST ID
651
+            if(IDAutoSetRequest_data[bluecell_srcid + 1] > 8){ /*Only 8 IDs are allowed.*/
652
+                RGB_SensorIDAutoSet(0);
653
+                RGB_Sensor_PowerOnOff(0);
654
+                SensorID = 0;
655
+                Uart1_Data_Send(&SensorSerchEnd_cmd[bluecell_stx], SensorSerchEnd_cmd[bluecell_length] + 3);
656
+            }else{
657
+                RGB_Sensor_PowerOnOff(IDAutoSetRequest_data[4]);
658
+                HAL_Delay(100);
659
+                RGB_Controller_Func(&IDAutoSetRequest_data[bluecell_stx]);
660
+            }
661
+        }
662
+        else{ /* Request data after completing ID setup */
663
+            RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
664
+        }
665
+        __HAL_IWDG_RELOAD_COUNTER(&hiwdg);
666
+        HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
667
+      }
668
+}
669
+void WDOG_Check_Flag(void){
670
+    if(RESET != __HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST))
671
+    {
672
+      __HAL_RCC_CLEAR_RESET_FLAGS();
673
+      printf("I am Reset Flag Clear\n");
674
+    }
675
+      
676
+}
607 677
 /* USER CODE END 0 */
608 678
 
609 679
 /**
@@ -614,11 +684,11 @@ int main(void)
614 684
 {
615 685
   /* USER CODE BEGIN 1 */
616 686
     uint8_t SensorSerchStart_cmd[5] = {0xbe,RGB_Controller_Init_Start,2,STH30_CreateCrc(&SensorSerchStart_cmd[bluecell_type],SensorSerchStart_cmd[bluecell_length]),0xeb};
617
-    uint8_t StatusRequest_data[RGB_SensorDataRequest_Length]         = {0xbe,RGB_Status_Data_Request,RGB_SensorDataRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&StatusRequest_data[bluecell_type],StatusRequest_data[bluecell_length]),0xeb};
618
-    uint8_t IDAutoSetRequest_data[RGB_SensorIDAutoSetRequest_Length] = {0xbe,RGB_SensorID_SET,RGB_SensorIDAutoSetRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&IDAutoSetRequest_data[bluecell_type],IDAutoSetRequest_data[bluecell_length]),0xeb};  
619
-    uint8_t cnt1 = 0,cnt2=0,uartdatarecv = 0;
620
-    uint8_t data1[100]= {0,};
621
-    uint8_t data2[100]= {0,};
687
+
688
+    
689
+   
690
+    
691
+    
622 692
   /* USER CODE END 1 */
623 693
 
624 694
   /* MCU Configuration--------------------------------------------------------*/
@@ -644,6 +714,7 @@ int main(void)
644 714
   MX_USART1_UART_Init();
645 715
   MX_USART2_UART_Init();
646 716
   MX_I2C2_Init();
717
+  MX_IWDG_Init();
647 718
 
648 719
   /* Initialize interrupts */
649 720
   MX_NVIC_Init();
@@ -651,9 +722,14 @@ int main(void)
651 722
   HAL_TIM_Base_Start_IT(&htim6);
652 723
   RGB_SensorIDAutoSet(1);
653 724
   HAL_UART_Receive_DMA(&huart1, rx1_data, 1);
654
-  HAL_UART_Receive_IT(&huart2, &rx2_data[0],1);
725
+  HAL_UART_Receive_DMA(&huart2, rx2_data, 1);  
726
+//  HAL_UART_Receive_IT(&huart2, &rx2_data[0],1);
655 727
   setbuf(stdout, NULL); // \n ?�„ ? �?�„ ?–„ë§? 
656 728
    Uart1_Data_Send(&SensorSerchStart_cmd[bluecell_stx], SensorSerchStart_cmd[bluecell_length] + 3);
729
+   WDOG_Check_Flag();
730
+
731
+    
732
+   __HAL_IWDG_START(&hiwdg);
657 733
 #if 0 // PYJ.2019.03.04_BEGIN -- 
658 734
       printf("****************************************\r\n");
659 735
       printf("RGB Project\r\n");
@@ -661,14 +737,12 @@ int main(void)
661 737
       printf("Copyright (c) 2019. BLUECELL\r\n");
662 738
       printf("****************************************\r\n");
663 739
 #endif // PYJ.2019.03.04_END -- 
664
-  Flash_InitRead();
740
+//  Flash_InitRead();
665 741
   RGB_Data_Init();
666 742
   Lora_Initialize();
667 743
   /* USER CODE END 2 */
668
-
669 744
   /* Infinite loop */
670 745
   /* USER CODE BEGIN WHILE */
671
-
672 746
   while (1)
673 747
   {
674 748
      if(LoraTxTimerCnt > LORA_TIMER_CNT){
@@ -676,77 +750,9 @@ int main(void)
676 750
 //        LoraDataSendSet(1);
677 751
     }
678 752
     RGB_Alarm_Operate();//LED ALARM CHECK
679
-    if(LoraDataSendGet() == LoraTx_mode){
680
-//        LoraDataSendSet(LoraRx_mode);
681
-        memcpy(&buffer[0],&Lora_Buf[0],LORA_MAX_DATA_CNT);
682
-        message_length = Lora_Max_Amount + 3;////RGB Data 60byte + stx + etx + crc
683
-        ret = SX1276_LoRaEntryTx(&SX1276, message_length, 2000);
684
-        ret = SX1276_LoRaTxPacket(&SX1276, &buffer[0], message_length, 2000);
685
-//        printf("Tx buffer : ");
686
-//        for(uint8_t i = 0; i < sizeof(LoraDataRequest_t); i++)
687
-//            printf("%02x ",buffer[i]);
688
-//        printf("\n");
689
-        LoraDataSendSet(LoraRx_mode);
690
-        ret = SX1276_LoRaEntryRx(&SX1276, LORA_MAX_DATA_CNT, 2000);
691
-    }else{
692
-           ret = SX1276_LoRaRxPacket(&SX1276);
693
-           if (ret > 0) {
694
-               SX1276_read(&SX1276, &buffer[0], ret);
695
-               Uart_dataCheck(&buffer[bluecell_stx],&ret);
696
-//               printf("Received Data : ");
697
-//               for(uint8_t i = 0; i < ret; i++)
698
-//               printf("%02x ",  buffer[i]);
699
-//               printf("\n");
700
-           }
701
-       }
702
-    
703
-     if(count_in1 != count_out1){ // <------- 
704
-        data1[cnt1++] = buf1[count_out1++];
705
-        if(count_out1 >= 100){ count_out1 = 0; }
706
-        UartTimerCnt = 0;
707
-        UartDataRecvSet(1);
708
-    }
709
-    if(count_in2 != count_out2){ // <------- 
710
-         data2[cnt2++] = buf2[count_out2++];
711
-         if(count_out2 >= 100){ count_out2 = 0; }
712
-         UartTimerCnt = 0;
713
-         UartDataRecvSet(2);
714
-    }
715
-        uartdatarecv = UartDataRecvGet(); 
716
-        if(uartdatarecv == 1 && UartTimerCnt > 100){
717
-            cnt1 = 0;
718
-            UartDataRecvSet(0);
719
-            Uart_dataCheck(&data1[0],&count_in1);
720
-            memset(&data1[0],0,100);
721
-        }
722
-        if(uartdatarecv == 2 && UartTimerCnt > 100){
723
-            cnt2 = 0;
724
-            UartDataRecvSet(0);
725
-            Uart_dataCheck(&data2[0],&count_in2);
726
-            memset(&data2[0],0,100);
727
-        }
728
-    
729
-    if(LedTimerCnt > 500){
730
-        if(RGB_SensorIDAutoGet() == 1){
731
-            if(SensorID == 0){memset(&SensorID_buf[0],0x00,8);SensorID_Cnt = 0;}
732
-            IDAutoSetRequest_data[bluecell_srcid + 1] = ++SensorID;//DST ID
733
-            if(IDAutoSetRequest_data[bluecell_srcid + 1] > 8){
734
-                RGB_SensorIDAutoSet(0);
735
-                RGB_Sensor_PowerOnOff(0);
736
-                SensorID = 0;
737
-            }else{
738
-                RGB_Sensor_PowerOnOff(IDAutoSetRequest_data[4]);
739
-                HAL_Delay(100);
740
-                RGB_Controller_Func(&IDAutoSetRequest_data[bluecell_stx]);
741
-            }
742
-        }
743
-       /* else{
744
-
745
-//            RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
746
-        }*/
747
-        HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
748
-        LedTimerCnt = 0;
749
-    }
753
+    Lora_Operate();
754
+    Usart_Data_RecvCheck();
755
+    RGB_Sensor_DataRequest();
750 756
     /* USER CODE END WHILE */
751 757
 
752 758
     /* USER CODE BEGIN 3 */
@@ -765,10 +771,11 @@ void SystemClock_Config(void)
765 771
 
766 772
   /**Initializes the CPU, AHB and APB busses clocks 
767 773
   */
768
-  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
774
+  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
769 775
   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
770 776
   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
771 777
   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
778
+  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
772 779
   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
773 780
   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
774 781
   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2;
@@ -809,6 +816,12 @@ static void MX_NVIC_Init(void)
809 816
   /* TIM6_IRQn interrupt configuration */
810 817
   HAL_NVIC_SetPriority(TIM6_IRQn, 0, 0);
811 818
   HAL_NVIC_EnableIRQ(TIM6_IRQn);
819
+  /* DMA1_Channel6_IRQn interrupt configuration */
820
+  HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0);
821
+  HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
822
+  /* EXTI0_IRQn interrupt configuration */
823
+  HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
824
+  HAL_NVIC_EnableIRQ(EXTI0_IRQn);
812 825
 }
813 826
 
814 827
 /**
@@ -845,6 +858,34 @@ static void MX_I2C2_Init(void)
845 858
 
846 859
 }
847 860
 
861
+/**
862
+  * @brief IWDG Initialization Function
863
+  * @param None
864
+  * @retval None
865
+  */
866
+static void MX_IWDG_Init(void)
867
+{
868
+
869
+  /* USER CODE BEGIN IWDG_Init 0 */
870
+
871
+  /* USER CODE END IWDG_Init 0 */
872
+
873
+  /* USER CODE BEGIN IWDG_Init 1 */
874
+
875
+  /* USER CODE END IWDG_Init 1 */
876
+  hiwdg.Instance = IWDG;
877
+  hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
878
+  hiwdg.Init.Reload = 1000;
879
+  if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
880
+  {
881
+    Error_Handler();
882
+  }
883
+  /* USER CODE BEGIN IWDG_Init 2 */
884
+
885
+  /* USER CODE END IWDG_Init 2 */
886
+
887
+}
888
+
848 889
 /**
849 890
   * @brief TIM6 Initialization Function
850 891
   * @param None
@@ -1002,6 +1043,12 @@ static void MX_GPIO_Init(void)
1002 1043
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1003 1044
   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
1004 1045
 
1046
+  /*Configure GPIO pin : IWDG_RESET_Pin */
1047
+  GPIO_InitStruct.Pin = IWDG_RESET_Pin;
1048
+  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
1049
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
1050
+  HAL_GPIO_Init(IWDG_RESET_GPIO_Port, &GPIO_InitStruct);
1051
+
1005 1052
   /*Configure GPIO pins : SX1276_DIO0_Pin SX1276_DIO1_Pin SX1276_DIO2_Pin SX1276_DIO3_Pin 
1006 1053
                            SENSOR_EN8_Pin SX1276_NSS_Pin */
1007 1054
   GPIO_InitStruct.Pin = SX1276_DIO0_Pin|SX1276_DIO1_Pin|SX1276_DIO2_Pin|SX1276_DIO3_Pin 

+ 22 - 0
Src/stm32f1xx_hal_msp.c

@@ -46,6 +46,8 @@
46 46
 /* USER CODE END Includes */
47 47
 extern DMA_HandleTypeDef hdma_usart1_rx;
48 48
 
49
+extern DMA_HandleTypeDef hdma_usart2_rx;
50
+
49 51
 /* Private typedef -----------------------------------------------------------*/
50 52
 /* USER CODE BEGIN TD */
51 53
 
@@ -295,6 +297,23 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
295 297
     GPIO_InitStruct.Pull = GPIO_NOPULL;
296 298
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
297 299
 
300
+    /* USART2 DMA Init */
301
+    /* USART2_RX Init */
302
+    hdma_usart2_rx.Instance = DMA1_Channel6;
303
+    hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
304
+    hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE;
305
+    hdma_usart2_rx.Init.MemInc = DMA_MINC_ENABLE;
306
+    hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
307
+    hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
308
+    hdma_usart2_rx.Init.Mode = DMA_CIRCULAR;
309
+    hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW;
310
+    if (HAL_DMA_Init(&hdma_usart2_rx) != HAL_OK)
311
+    {
312
+      Error_Handler();
313
+    }
314
+
315
+    __HAL_LINKDMA(huart,hdmarx,hdma_usart2_rx);
316
+
298 317
   /* USER CODE BEGIN USART2_MspInit 1 */
299 318
 
300 319
   /* USER CODE END USART2_MspInit 1 */
@@ -349,6 +368,9 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
349 368
     */
350 369
     HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
351 370
 
371
+    /* USART2 DMA DeInit */
372
+    HAL_DMA_DeInit(huart->hdmarx);
373
+
352 374
     /* USART2 interrupt DeInit */
353 375
     HAL_NVIC_DisableIRQ(USART2_IRQn);
354 376
   /* USER CODE BEGIN USART2_MspDeInit 1 */

+ 29 - 0
Src/stm32f1xx_it.c

@@ -73,6 +73,7 @@
73 73
 /* External variables --------------------------------------------------------*/
74 74
 extern TIM_HandleTypeDef htim6;
75 75
 extern DMA_HandleTypeDef hdma_usart1_rx;
76
+extern DMA_HandleTypeDef hdma_usart2_rx;
76 77
 extern UART_HandleTypeDef huart1;
77 78
 extern UART_HandleTypeDef huart2;
78 79
 /* USER CODE BEGIN EV */
@@ -215,6 +216,20 @@ void SysTick_Handler(void)
215 216
 /* please refer to the startup file (startup_stm32f1xx.s).                    */
216 217
 /******************************************************************************/
217 218
 
219
+/**
220
+  * @brief This function handles EXTI line0 interrupt.
221
+  */
222
+void EXTI0_IRQHandler(void)
223
+{
224
+  /* USER CODE BEGIN EXTI0_IRQn 0 */
225
+
226
+  /* USER CODE END EXTI0_IRQn 0 */
227
+  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
228
+  /* USER CODE BEGIN EXTI0_IRQn 1 */
229
+
230
+  /* USER CODE END EXTI0_IRQn 1 */
231
+}
232
+
218 233
 /**
219 234
   * @brief This function handles DMA1 channel5 global interrupt.
220 235
   */
@@ -229,6 +244,20 @@ void DMA1_Channel5_IRQHandler(void)
229 244
   /* USER CODE END DMA1_Channel5_IRQn 1 */
230 245
 }
231 246
 
247
+/**
248
+  * @brief This function handles DMA1 channel6 global interrupt.
249
+  */
250
+void DMA1_Channel6_IRQHandler(void)
251
+{
252
+  /* USER CODE BEGIN DMA1_Channel6_IRQn 0 */
253
+
254
+  /* USER CODE END DMA1_Channel6_IRQn 0 */
255
+  HAL_DMA_IRQHandler(&hdma_usart2_rx);
256
+  /* USER CODE BEGIN DMA1_Channel6_IRQn 1 */
257
+
258
+  /* USER CODE END DMA1_Channel6_IRQn 1 */
259
+}
260
+
232 261
 /**
233 262
   * @brief This function handles USART1 global interrupt.
234 263
   */