|
@@ -70,16 +70,23 @@ UART_HandleTypeDef huart1;
|
70
|
70
|
UART_HandleTypeDef huart2;
|
71
|
71
|
|
72
|
72
|
/* USER CODE BEGIN PV */
|
|
73
|
+uint8_t rx1_data[1];
|
|
74
|
+uint8_t rx2_data[1];
|
73
|
75
|
|
74
|
76
|
|
|
77
|
+uint8_t ring_buf[buf_size];
|
|
78
|
+uint8_t count_in1 = 0;//, count_out = 0;
|
|
79
|
+uint8_t count_in2 = 0;//, count_out = 0;
|
|
80
|
+uint8_t count_in3 = 0, count_out = 0;
|
75
|
81
|
|
76
|
82
|
|
|
83
|
+uint8_t UartDataisReved;
|
77
|
84
|
uint8_t RGB_SensorIDAutoset = 0;
|
78
|
85
|
|
79
|
86
|
volatile uint32_t UartTimerCnt = 0;
|
80
|
87
|
volatile uint32_t LedTimerCnt = 0;
|
81
|
88
|
|
82
|
|
-
|
|
89
|
+uint8_t buf[buf_size] = {0,};
|
83
|
90
|
|
84
|
91
|
uint8_t MyControllerID = 0;
|
85
|
92
|
uint8_t SensorID = 0;
|
|
@@ -97,7 +104,9 @@ static void MX_NVIC_Init(void);
|
97
|
104
|
/* USER CODE BEGIN PFP */
|
98
|
105
|
void RGB_SensorIDAutoSet(uint8_t set);
|
99
|
106
|
uint8_t RGB_SensorIDAutoGet(void);
|
100
|
|
-
|
|
107
|
+void UartDataRecvSet(uint8_t val);
|
|
108
|
+void Uart_dataCheck(uint8_t* cnt);
|
|
109
|
+void Uart1_Data_Send(uint8_t* data,uint8_t size);
|
101
|
110
|
/* USER CODE END PFP */
|
102
|
111
|
|
103
|
112
|
/* Private user code ---------------------------------------------------------*/
|
|
@@ -105,7 +114,46 @@ uint8_t RGB_SensorIDAutoGet(void);
|
105
|
114
|
|
106
|
115
|
|
107
|
116
|
|
|
117
|
+void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
|
118
|
+{
|
|
119
|
+ if(huart->Instance == USART1)//RGB Comunication
|
|
120
|
+ {
|
|
121
|
+ buf[count_in1] = rx1_data[0];//(uint8_t)USART2->DR;
|
|
122
|
+// printf("data %02x \r\n",rx1_data[0]);
|
|
123
|
+ if(buf[count_in1++] == 0xEB){
|
|
124
|
+ if(buf[blucell_length] == (count_in1 - 3))
|
|
125
|
+ UartDataRecvSet(1);
|
|
126
|
+ else
|
|
127
|
+ count_in1 = 0;
|
|
128
|
+ }
|
|
129
|
+ HAL_UART_Receive_IT(&huart1,&rx1_data[0],1);
|
|
130
|
+ }
|
|
131
|
+ if(huart->Instance == USART2) // Lora?? ?†µ?‹ ?•˜?Š� ?�¬?Џ
|
|
132
|
+ {
|
|
133
|
+ buf[count_in2] = rx2_data[0];//(uint8_t)USART2->DR;
|
|
134
|
+// if(buf[count_in++] == 0xEB)UartDataRecvSet(1);
|
|
135
|
+ if(buf[count_in2++] == 0xEB){
|
|
136
|
+ if(buf[blucell_length] == (count_in2 - 3))
|
|
137
|
+ UartDataRecvSet(2);
|
|
138
|
+ else
|
|
139
|
+ count_in1 = 0;
|
|
140
|
+// printf("UART 2 %d",((count_in2 -1) - 3));
|
|
141
|
+ }
|
108
|
142
|
|
|
143
|
+ HAL_UART_Receive_IT(&huart2,&rx2_data[0],1);
|
|
144
|
+ }
|
|
145
|
+#if 0 // PYJ.2019.04.13_BEGIN --
|
|
146
|
+ if(huart->Instance == USART3) //GUI ?? ?†µ?‹ ?•˜?Š� Port
|
|
147
|
+ {
|
|
148
|
+ buf[count_in3] = rx3_data[0];//(uint8_t)USART2->DR;
|
|
149
|
+ if(buf[count_in3++] == 0xEB)UartDataRecvSet(3);
|
|
150
|
+ /*ring_buf[count_in] = rx2_data[0];//(uint8_t)USART2->DR;
|
|
151
|
+ if(++count_in>=buf_size) count_in=0;*/
|
|
152
|
+ HAL_UART_Receive_IT(&huart3,&rx3_data[0],1);
|
|
153
|
+ }
|
|
154
|
+#endif // PYJ.2019.04.13_END --
|
|
155
|
+
|
|
156
|
+}
|
109
|
157
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
110
|
158
|
{
|
111
|
159
|
|
|
@@ -116,7 +164,12 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
116
|
164
|
}
|
117
|
165
|
}
|
118
|
166
|
|
119
|
|
-
|
|
167
|
+void UartDataRecvSet(uint8_t val){
|
|
168
|
+ UartDataisReved = val;
|
|
169
|
+}
|
|
170
|
+uint8_t UartDataRecvGet(void){
|
|
171
|
+ return UartDataisReved;
|
|
172
|
+}
|
120
|
173
|
void RGB_SensorIDAutoSet(uint8_t set){
|
121
|
174
|
RGB_SensorIDAutoset = set;
|
122
|
175
|
}
|
|
@@ -124,7 +177,47 @@ uint8_t RGB_SensorIDAutoGet(void){
|
124
|
177
|
return RGB_SensorIDAutoset;
|
125
|
178
|
}
|
126
|
179
|
|
|
180
|
+void Uart2_Data_Send(uint8_t* data,uint8_t size){
|
|
181
|
+ HAL_UART_Transmit(&huart2, data,size, 10);
|
|
182
|
+}
|
|
183
|
+void Uart1_Data_Send(uint8_t* data,uint8_t size){
|
|
184
|
+ HAL_UART_Transmit(&huart1, data,size, 10);
|
|
185
|
+}
|
127
|
186
|
|
|
187
|
+int _write (int file, uint8_t *ptr, uint16_t len)
|
|
188
|
+{
|
|
189
|
+ HAL_UART_Transmit (&huart1, ptr, len, 10);
|
|
190
|
+ return len;
|
|
191
|
+}
|
|
192
|
+void Uart_dataCheck(uint8_t* cnt){
|
|
193
|
+
|
|
194
|
+ etError crccheck = 0;
|
|
195
|
+#if 0
|
|
196
|
+ for(uint8_t i = 0; i < (* cnt); i++){
|
|
197
|
+ printf("%02x ",buf[i]);
|
|
198
|
+ }
|
|
199
|
+ printf("\r\n");
|
|
200
|
+#endif
|
|
201
|
+
|
|
202
|
+ crccheck = STH30_CheckCrc(&buf[blucell_type],buf[blucell_length],buf[buf[blucell_length] + 1]);
|
|
203
|
+ if(crccheck == CHECKSUM_ERROR){
|
|
204
|
+ for(uint8_t i = 0; i < (*cnt); i++){
|
|
205
|
+ printf("%02x ",buf[i]);
|
|
206
|
+ }
|
|
207
|
+ printf("Original CRC : %02x RecvCRC : %02x \r\n",crccheck,buf[buf[blucell_length] + 1]);
|
|
208
|
+ }
|
|
209
|
+ else if(crccheck == NO_ERROR){
|
|
210
|
+ RGB_Controller_Func(&buf[blucell_stx]);
|
|
211
|
+ }
|
|
212
|
+ else{
|
|
213
|
+ printf("What Happen?\r\n");
|
|
214
|
+ /*NOP*/
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ *cnt = 0;
|
|
218
|
+
|
|
219
|
+ memset(buf,0x00,buf_size);
|
|
220
|
+}
|
128
|
221
|
void RGB_Sensor_PowerOnOff(uint8_t id){
|
129
|
222
|
printf("%d Power ON \r\n",id);
|
130
|
223
|
|
|
@@ -243,10 +336,10 @@ void RGB_Sensor_PowerOnOff(uint8_t id){
|
243
|
336
|
#define END_ADDR FLASH_USER + 262144 // 256K
|
244
|
337
|
//----------------------------------------------------
|
245
|
338
|
#if 0 // PYJ.2019.03.20_BEGIN --
|
246
|
|
-void test_write() // ?“°ê¸°í•¨?ˆ˜
|
|
339
|
+void test_write() // 쓰기함수
|
247
|
340
|
{
|
248
|
341
|
|
249
|
|
- __HAL_RCC_TIM7_CLK_DISABLE(); // 매ì�¸???�´ë¨¸ë?? ? •ì§??•©?‹ˆ?‹¤
|
|
342
|
+ __HAL_RCC_TIM7_CLK_DISABLE(); // 매ì�¸íƒ€ì�´ë¨¸ë¥¼ ì •ì§€í•©ë‹ˆë‹¤
|
250
|
343
|
uint32_t Address = 0;
|
251
|
344
|
Address = StartAddr;
|
252
|
345
|
// printf("================First============ \r\n");
|
|
@@ -257,10 +350,10 @@ void test_write() // ?
|
257
|
350
|
// Address += 4;
|
258
|
351
|
// }
|
259
|
352
|
|
260
|
|
-// HAL_FLASH_Unlock(); // lock ??�
|
|
353
|
+// HAL_FLASH_Unlock(); // lock 풀기
|
261
|
354
|
// HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, START_ADDR, (uint32_t)0x12345678); //test
|
262
|
|
-// HAL_FLASH_Lock(); // lock ?ž 그기
|
263
|
|
-// __HAL_RCC_TIM7_CLK_ENABLE(); // 매ì�¸???�´ë¨¸ë?? ?ž¬?‹œ?ž‘?•©?‹ˆ?‹¤
|
|
355
|
+// HAL_FLASH_Lock(); // lock ìž ê·¸ê¸°
|
|
356
|
+// __HAL_RCC_TIM7_CLK_ENABLE(); // 매�타�머를 재시작합니다
|
264
|
357
|
Address = StartAddr;
|
265
|
358
|
printf("================Second============ \r\n");
|
266
|
359
|
|
|
@@ -279,7 +372,7 @@ void test_write() // ?
|
279
|
372
|
|
280
|
373
|
|
281
|
374
|
#if 1 // PYJ.2019.03.20_BEGIN --
|
282
|
|
-void test_read(void) // ?“°ê¸°í•¨?ˆ˜
|
|
375
|
+void test_read(void) // 쓰기함수
|
283
|
376
|
{
|
284
|
377
|
uint32_t Address = 0x08000000;
|
285
|
378
|
uint8_t aa = 0;
|
|
@@ -311,7 +404,7 @@ void Flash_RGB_Data_Write(uint32_t Addr,uint8_t* data){
|
311
|
404
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,Addr + 4 , (uint16_t)temp_Blue);
|
312
|
405
|
|
313
|
406
|
}
|
314
|
|
-void Flash_write(uint8_t* data) // ?“°ê¸°í•¨?ˆ˜
|
|
407
|
+void Flash_write(uint8_t* data) // 쓰기함수
|
315
|
408
|
{
|
316
|
409
|
|
317
|
410
|
/*Variable used for Erase procedure*/
|
|
@@ -324,8 +417,8 @@ void Flash_write(uint8_t* data) // ?
|
324
|
417
|
// EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE;
|
325
|
418
|
Address = START_ADDR;
|
326
|
419
|
|
327
|
|
- __HAL_RCC_TIM7_CLK_DISABLE(); // 매ì�¸???�´ë¨¸ë?? ? •ì§??•©?‹ˆ?‹¤
|
328
|
|
- HAL_FLASH_Unlock(); // lock ??�
|
|
420
|
+ __HAL_RCC_TIM7_CLK_DISABLE(); // 매ì�¸íƒ€ì�´ë¨¸ë¥¼ ì •ì§€í•©ë‹ˆë‹¤
|
|
421
|
+ HAL_FLASH_Unlock(); // lock 풀기
|
329
|
422
|
// if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK){
|
330
|
423
|
// printf("Erase Failed \r\n");
|
331
|
424
|
// }else{
|
|
@@ -360,11 +453,11 @@ void Flash_write(uint8_t* data) // ?
|
360
|
453
|
|
361
|
454
|
}
|
362
|
455
|
Flash_RGB_Data_Write(Address,&data[blucell_stx]);
|
363
|
|
- HAL_FLASH_Lock(); // lock ?ž 그기
|
364
|
|
- __HAL_RCC_TIM7_CLK_ENABLE(); // 매ì�¸???�´ë¨¸ë?? ?ž¬?‹œ?ž‘?•©?‹ˆ?‹¤
|
|
456
|
+ HAL_FLASH_Lock(); // lock ìž ê·¸ê¸°
|
|
457
|
+ __HAL_RCC_TIM7_CLK_ENABLE(); // 매�타�머를 재시작합니다
|
365
|
458
|
|
366
|
459
|
}
|
367
|
|
-void Flash_InitRead(void) // ?“°ê¸°í•¨?ˆ˜
|
|
460
|
+void Flash_InitRead(void) // 쓰기함수
|
368
|
461
|
{
|
369
|
462
|
uint32_t Address = 0;
|
370
|
463
|
Address = StartAddr;
|
|
@@ -439,7 +532,7 @@ int main(void)
|
439
|
532
|
HAL_TIM_Base_Start_IT(&htim6);
|
440
|
533
|
HAL_UART_Receive_IT(&huart1, &rx1_data[0],1);
|
441
|
534
|
HAL_UART_Receive_IT(&huart2, &rx2_data[0],1);
|
442
|
|
- setbuf(stdout, NULL); // \n ?�„ ? �?�„ ?–„ë§?
|
|
535
|
+ setbuf(stdout, NULL); // \n ì�„ ì �ì�„ ë–„ë§Œ
|
443
|
536
|
#if 1 // PYJ.2019.03.04_BEGIN --
|
444
|
537
|
printf("****************************************\r\n");
|
445
|
538
|
printf("RGB Project\r\n");
|
|
@@ -482,10 +575,10 @@ int main(void)
|
482
|
575
|
uartdatarecv = UartDataRecvGet();
|
483
|
576
|
if(uartdatarecv != 0){
|
484
|
577
|
if(uartdatarecv == 1){
|
485
|
|
- Uart_dataCheck(USART1_CNT,&count_in1);
|
|
578
|
+ Uart_dataCheck(&count_in1);
|
486
|
579
|
}else if(uartdatarecv == 2){
|
487
|
|
- Uart_dataCheck(USART2_CNT,&count_in2);
|
488
|
|
- }
|
|
580
|
+ Uart_dataCheck(&count_in2);
|
|
581
|
+ }
|
489
|
582
|
UartDataRecvSet(0);
|
490
|
583
|
}
|
491
|
584
|
#else
|
|
@@ -529,7 +622,7 @@ int main(void)
|
529
|
622
|
SensorID = 0;
|
530
|
623
|
}else{
|
531
|
624
|
RGB_Sensor_PowerOnOff(IDAutoSetRequest_data[4]);
|
532
|
|
- HAL_Delay(5000);
|
|
625
|
+ HAL_Delay(1500);
|
533
|
626
|
RGB_Controller_Func(&IDAutoSetRequest_data[blucell_stx]);
|
534
|
627
|
HAL_Delay(500);
|
535
|
628
|
}
|