main.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. ** This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * COPYRIGHT(c) 2019 STMicroelectronics
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,p THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* USER CODE END Header */
  40. /* Includes ------------------------------------------------------------------*/
  41. #include "main.h"
  42. /* Private includes ----------------------------------------------------------*/
  43. /* USER CODE BEGIN Includes */
  44. /* USER CODE END Includes */
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* USER CODE BEGIN PTD */
  47. /* USER CODE END PTD */
  48. /* Private define ------------------------------------------------------------*/
  49. /* USER CODE BEGIN PD */
  50. #define LORA_TIMER_CNT 600000 / 2
  51. /* USER CODE END PD */
  52. /* Private macro -------------------------------------------------------------*/
  53. /* USER CODE BEGIN PM */
  54. /* USER CODE END PM */
  55. /* Private variables ---------------------------------------------------------*/
  56. I2C_HandleTypeDef hi2c2;
  57. TIM_HandleTypeDef htim6;
  58. UART_HandleTypeDef huart1;
  59. UART_HandleTypeDef huart2;
  60. /* USER CODE BEGIN PV */
  61. uint8_t rx1_data[1];
  62. uint8_t rx2_data[1];
  63. uint8_t ring_buf[buf_size];
  64. uint8_t count_in1 = 0, count_out1 = 0;
  65. uint8_t count_in2 = 0, count_out2 = 0;
  66. //uint8_t count_in3 = 0, count_out = 0;
  67. uint8_t UartDataisReved;
  68. uint8_t LoraDataSend;
  69. uint8_t RGB_SensorIDAutoset = 0;
  70. volatile uint32_t UartTimerCnt = 0;
  71. volatile uint32_t LedTimerCnt = 0;
  72. volatile uint32_t LoraTxTimerCnt = 0;
  73. volatile uint32_t LoraAckTimerCnt = 0;
  74. uint8_t buf[buf_size] = {0,};
  75. uint8_t buf1[buf_size] = {0,};
  76. uint8_t buf2[buf_size] = {0,};
  77. uint8_t MyControllerID = 0;
  78. uint8_t SensorID = 0;
  79. typedef enum{
  80. LoraRx_mode = 0,
  81. LoraTx_mode ,
  82. };
  83. /* USER CODE END PV */
  84. /* Private function prototypes -----------------------------------------------*/
  85. void SystemClock_Config(void);
  86. static void MX_GPIO_Init(void);
  87. static void MX_TIM6_Init(void);
  88. static void MX_USART1_UART_Init(void);
  89. static void MX_USART2_UART_Init(void);
  90. static void MX_I2C2_Init(void);
  91. static void MX_NVIC_Init(void);
  92. /* USER CODE BEGIN PFP */
  93. void RGB_SensorIDAutoSet(uint8_t set);
  94. uint8_t RGB_SensorIDAutoGet(void);
  95. void UartDataRecvSet(uint8_t val);
  96. #if 0 // PYJ.2019.04.19_BEGIN --
  97. void Uart_dataCheck(uint8_t* cnt);
  98. #else
  99. void Uart_dataCheck(uint8_t*,uint8_t* cnt);
  100. #endif // PYJ.2019.04.19_END --
  101. void Uart1_Data_Send(uint8_t* data,uint8_t size);
  102. /* USER CODE END PFP */
  103. /* Private user code ---------------------------------------------------------*/
  104. /* USER CODE BEGIN 0 */
  105. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  106. {
  107. if(huart->Instance == USART1)//RGB Comunication
  108. {
  109. buf1[count_in1] = rx1_data[0];//(uint8_t)USART2->DR;
  110. if(++count_in1>=buf_size){ count_in1 = 0; }
  111. // printf("data %02x \r\n",rx1_data[0]);
  112. #if 0 // PYJ.2019.04.19_BEGIN --
  113. if(buf[count_in1++] == 0xEB){
  114. if(buf[bluecell_length] == (count_in1 - 3))
  115. UartDataRecvSet(1);
  116. else
  117. count_in1 = 0;
  118. }
  119. #endif // PYJ.2019.04.19_END --
  120. HAL_UART_Receive_IT(&huart1,&rx1_data[0],1);
  121. }
  122. if(huart->Instance == USART2) // Lora?? ?†µ?‹ ?•˜?Š” ?¬?Џ
  123. {
  124. buf2[count_in2] = rx2_data[0];//(uint8_t)USART2->DR;
  125. if(++count_in2>=buf_size){ count_in2 = 0; }
  126. // if(buf[count_in++] == 0xEB)UartDataRecvSet(1);
  127. #if 0 // PYJ.2019.04.19_BEGIN --
  128. if(buf[count_in2++] == 0xEB){
  129. if(buf[bluecell_length] == (count_in2 - 3))
  130. UartDataRecvSet(2);
  131. else
  132. count_in1 = 0;
  133. // printf("UART 2 %d",((count_in2 -1) - 3));
  134. }
  135. #endif // PYJ.2019.04.19_END --
  136. HAL_UART_Receive_IT(&huart2,&rx2_data[0],1);
  137. }
  138. #if 0 // PYJ.2019.04.13_BEGIN --
  139. if(huart->Instance == USART3) //GUI ?? ?†µ?‹ ?•˜?Š” Port
  140. {
  141. buf[count_in3] = rx3_data[0];//(uint8_t)USART2->DR;
  142. if(buf[count_in3++] == 0xEB)UartDataRecvSet(3);
  143. /*ring_buf[count_in] = rx2_data[0];//(uint8_t)USART2->DR;
  144. if(++count_in>=buf_size) count_in=0;*/
  145. HAL_UART_Receive_IT(&huart3,&rx3_data[0],1);
  146. }
  147. #endif // PYJ.2019.04.13_END --
  148. }
  149. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  150. {
  151. if(htim->Instance == TIM6){
  152. UartTimerCnt++;
  153. LedTimerCnt++;
  154. LoraTxTimerCnt++;
  155. LoraAckTimerCnt++;
  156. }
  157. }
  158. void LoraDataSendSet(uint8_t val){
  159. LoraDataSend = val;
  160. }
  161. uint8_t LoraDataSendGet(void){
  162. return LoraDataSend;
  163. }
  164. void UartDataRecvSet(uint8_t val){
  165. UartDataisReved = val;
  166. }
  167. uint8_t UartDataRecvGet(void){
  168. return UartDataisReved;
  169. }
  170. void RGB_SensorIDAutoSet(uint8_t set){
  171. RGB_SensorIDAutoset = set;
  172. }
  173. uint8_t RGB_SensorIDAutoGet(void){
  174. return RGB_SensorIDAutoset;
  175. }
  176. void Uart2_Data_Send(uint8_t* data,uint8_t size){
  177. HAL_UART_Transmit(&huart2, data,size, 10);
  178. }
  179. void Uart1_Data_Send(uint8_t* data,uint8_t size){
  180. HAL_UART_Transmit(&huart1, data,size, 10);
  181. }
  182. int _write (int file, uint8_t *ptr, uint16_t len)
  183. {
  184. HAL_UART_Transmit (&huart1, ptr, len, 10);
  185. return len;
  186. }
  187. #if 0 // PYJ.2019.04.19_BEGIN --
  188. void Uart_dataCheck(uint8_t* cnt){
  189. etError crccheck = 0;
  190. #if 0
  191. for(uint8_t i = 0; i < (* cnt); i++){
  192. printf("%02x ",buf[i]);
  193. }
  194. printf("\r\n");
  195. #endif
  196. crccheck = STH30_CheckCrc(&buf[bluecell_type],buf[bluecell_length],buf[buf[bluecell_length] + 1]);
  197. if(crccheck == CHECKSUM_ERROR){
  198. for(uint8_t i = 0; i < (*cnt); i++){
  199. printf("%02x ",buf[i]);
  200. }
  201. printf("Original CRC : %02x RecvCRC : %02x \r\n",crccheck,buf[buf[bluecell_length] + 1]);
  202. }
  203. else if(crccheck == NO_ERROR){
  204. RGB_Controller_Func(&buf[bluecell_stx]);
  205. }
  206. else{
  207. printf("What Happen?\r\n");
  208. /*NOP*/
  209. }
  210. *cnt = 0;
  211. memset(buf,0x00,buf_size);
  212. }
  213. #else
  214. void Uart_dataCheck(uint8_t* Que_Buf,uint8_t* cnt){
  215. etError crccheck = 0;
  216. #if 0
  217. for(uint8_t i = 0; i < (* cnt); i++){
  218. printf("%02x ",buf[i]);
  219. }
  220. printf("\r\n");
  221. #endif
  222. crccheck = STH30_CheckCrc(&Que_Buf[bluecell_type],Que_Buf[bluecell_length],Que_Buf[Que_Buf[bluecell_length] + 1]);
  223. if(crccheck == CHECKSUM_ERROR){
  224. for(uint8_t i = 0; i < (*cnt); i++){
  225. printf("%02x ",Que_Buf[i]);
  226. }
  227. printf("Original CRC : %02x RecvCRC : %02x \r\n",crccheck,Que_Buf[Que_Buf[bluecell_length] + 1]);
  228. }
  229. else if(crccheck == NO_ERROR){
  230. RGB_Controller_Func(&Que_Buf[bluecell_stx]);
  231. }
  232. else{
  233. printf("What Happen?\r\n");
  234. /*NOP*/
  235. }
  236. //*cnt = 0;
  237. memset(Que_Buf,0x00,buf_size);
  238. }
  239. #endif // PYJ.2019.04.19_END --
  240. void RGB_Sensor_PowerOnOff(uint8_t id){
  241. printf("%d Power ON \r\n",id);
  242. switch(id){
  243. case 0:
  244. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  245. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
  246. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);
  247. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
  248. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
  249. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
  250. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_SET);
  251. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_SET);
  252. break;
  253. case 1:
  254. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_RESET);
  255. HAL_Delay(50);
  256. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  257. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_RESET);
  258. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_RESET);
  259. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_RESET);
  260. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_RESET);
  261. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
  262. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
  263. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
  264. break;
  265. case 2:
  266. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  267. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
  268. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_RESET);
  269. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_RESET);
  270. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_RESET);
  271. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
  272. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
  273. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
  274. break;
  275. case 3:
  276. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  277. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
  278. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);
  279. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_RESET);
  280. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_RESET);
  281. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
  282. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
  283. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
  284. break;
  285. case 4:
  286. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  287. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
  288. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);
  289. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
  290. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_RESET);
  291. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
  292. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
  293. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
  294. break;
  295. case 5:
  296. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  297. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
  298. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);
  299. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
  300. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
  301. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_RESET);
  302. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
  303. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
  304. break;
  305. case 6:
  306. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  307. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
  308. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);
  309. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
  310. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
  311. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
  312. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_RESET);
  313. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
  314. break;
  315. case 7:
  316. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  317. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
  318. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);
  319. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
  320. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
  321. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
  322. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_SET);
  323. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_RESET);
  324. break;
  325. case 8:
  326. HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
  327. HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
  328. HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);
  329. HAL_GPIO_WritePin(SENSOR_EN4_GPIO_Port,SENSOR_EN4_Pin,GPIO_PIN_SET);
  330. HAL_GPIO_WritePin(SENSOR_EN5_GPIO_Port,SENSOR_EN5_Pin,GPIO_PIN_SET);
  331. HAL_GPIO_WritePin(SENSOR_EN6_GPIO_Port,SENSOR_EN6_Pin,GPIO_PIN_SET);
  332. HAL_GPIO_WritePin(SENSOR_EN7_GPIO_Port,SENSOR_EN7_Pin,GPIO_PIN_SET);
  333. HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_SET);
  334. break;
  335. }
  336. }
  337. #define StartAddr ((uint32_t)0x08030000)
  338. #if 1 // PYJ.2019.03.19_BEGIN --
  339. //----------------------------------------------------
  340. #define FLASH_USER StartAddr
  341. #define START_ADDR FLASH_USER
  342. #define END_ADDR FLASH_USER + 262144 // 256K
  343. //----------------------------------------------------
  344. #if 0 // PYJ.2019.03.20_BEGIN --
  345. void test_write() // 쓰기함수
  346. {
  347. __HAL_RCC_TIM7_CLK_DISABLE(); // 매인타이머를 정지합니다
  348. uint32_t Address = 0;
  349. Address = StartAddr;
  350. // printf("================First============ \r\n");
  351. // for(uint8_t i=0;i<16;i++)
  352. // {
  353. // printf("%08x: %X\r\n", Address, *(uint32_t*)Address);
  354. // Address += 4;
  355. // }
  356. // HAL_FLASH_Unlock(); // lock 풀기
  357. // HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, START_ADDR, (uint32_t)0x12345678); //test
  358. // HAL_FLASH_Lock(); // lock 잠그기
  359. // __HAL_RCC_TIM7_CLK_ENABLE(); // 매인타이머를 재시작합니다
  360. Address = StartAddr;
  361. printf("================Second============ \r\n");
  362. //while(Address < 0x0803FFFF)
  363. for(uint16_t i = 0; i<37273 ; i++)
  364. {
  365. printf("%02X", *(uint8_t*)Address);
  366. Address ++;
  367. }
  368. printf("%08x:",Address);
  369. }
  370. #endif // PYJ.2019.03.20_END --
  371. #define DATA_16_1 ((uint32_t)0x1234)
  372. #define DATA_16_2 ((uint32_t)0x5678)
  373. #if 1 // PYJ.2019.03.20_BEGIN --
  374. void test_read(void) // 쓰기함수
  375. {
  376. uint32_t Address = 0x08000000;
  377. uint8_t aa = 0;
  378. for(uint32_t i = Address; i <= Address + 0x35d8; i++ ){
  379. printf("%02X ",*(uint8_t*)i);
  380. aa++;
  381. if(aa > 15){
  382. printf("\n");
  383. aa= 0;
  384. }
  385. }
  386. }
  387. #endif // PYJ.2019.03.20_END --
  388. #define ADDR_FLASH_PAGE_TEST ((uint32_t)0x08030000) /* Base @ of Page 127, 1 Kbytes */
  389. #define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_TEST /* Start @ of user Flash area */
  390. #define FLASH_USER_END_ADDR ADDR_FLASH_PAGE_TEST + ((uint32_t)0x0000FFFF) /* End @ of user Flash area */
  391. void Flash_RGB_Data_Write(uint32_t Addr,uint8_t* data){
  392. uint16_t temp_Red = 0,temp_Green = 0,temp_Blue = 0;
  393. temp_Red = ((data[bluecell_red_H] << 8) |data[bluecell_red_L]); //R
  394. temp_Green= ((data[bluecell_green_H] << 8) |data[bluecell_green_L]); //G
  395. temp_Blue = ((data[bluecell_blue_H] << 8) |data[bluecell_blue_L]); //B
  396. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,Addr + 0 , (uint16_t)temp_Red);
  397. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,Addr + 2 , (uint16_t)temp_Green);
  398. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,Addr + 4 , (uint16_t)temp_Blue);
  399. }
  400. void Flash_write(uint8_t* data) // 쓰기함수
  401. {
  402. /*Variable used for Erase procedure*/
  403. // static FLASH_EraseInitTypeDef EraseInitStruct;
  404. uint32_t Address = 0;//, PAGEError = 0;
  405. /* Fill EraseInit structure*/
  406. // EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
  407. // EraseInitStruct.PageAddress = FLASH_USER_START_ADDR;
  408. // EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE;
  409. Address = START_ADDR;
  410. __HAL_RCC_TIM7_CLK_DISABLE(); // 매인타이머를 정지합니다
  411. HAL_FLASH_Unlock(); // lock 풀기
  412. // if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK){
  413. // printf("Erase Failed \r\n");
  414. // }else{
  415. // printf("Erase Success \r\n");
  416. // }
  417. switch(data[bluecell_dstid]){
  418. case 1:
  419. Address += 0;
  420. break;
  421. case 2:
  422. Address += 6;
  423. break;
  424. case 3:
  425. Address += 12;
  426. break;
  427. case 4:
  428. Address += 18;
  429. break;
  430. case 5:
  431. Address += 24;
  432. break;
  433. case 6:
  434. Address += 30;
  435. break;
  436. case 7:
  437. Address += 36;
  438. break;
  439. case 8:
  440. Address += 42;
  441. break;
  442. }
  443. Flash_RGB_Data_Write(Address,&data[bluecell_stx]);
  444. HAL_FLASH_Lock(); // lock 잠그기
  445. __HAL_RCC_TIM7_CLK_ENABLE(); // 매인타이머를 재시작합니다
  446. }
  447. void Flash_InitRead(void) // 쓰기함수
  448. {
  449. uint32_t Address = 0;
  450. Address = StartAddr;
  451. for(uint8_t i = 1; i <= 8; i++ ){
  452. RGB_SensorRedLimit_Buf[i] = (*(uint16_t*)Address);
  453. // printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
  454. Address += 2;
  455. RGB_SensorGreenLimit_Buf[i] = (*(uint16_t*)Address);
  456. // printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
  457. Address += 2;
  458. RGB_SensorBlueLimit_Buf[i] = (*(uint16_t*)Address);
  459. // printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
  460. Address += 2;
  461. }
  462. }
  463. #endif // PYJ.2019.03.19_END --
  464. SX1276_hw_t SX1276_hw;
  465. SX1276_t SX1276;
  466. int master;
  467. int ret;
  468. char buffer[100];
  469. int message_length;
  470. int message;
  471. /* USER CODE END 0 */
  472. /**
  473. * @brief The application entry point.
  474. * @retval int
  475. */
  476. int main(void)
  477. {
  478. /* USER CODE BEGIN 1 */
  479. 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};
  480. 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};
  481. uint8_t temp_sensorid = 0;
  482. uint8_t uartdatarecv= 0;
  483. /* USER CODE END 1 */
  484. /* MCU Configuration--------------------------------------------------------*/
  485. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  486. HAL_Init();
  487. /* USER CODE BEGIN Init */
  488. /* USER CODE END Init */
  489. /* Configure the system clock */
  490. SystemClock_Config();
  491. /* USER CODE BEGIN SysInit */
  492. /* USER CODE END SysInit */
  493. /* Initialize all configured peripherals */
  494. MX_GPIO_Init();
  495. MX_TIM6_Init();
  496. MX_USART1_UART_Init();
  497. MX_USART2_UART_Init();
  498. MX_I2C2_Init();
  499. /* Initialize interrupts */
  500. MX_NVIC_Init();
  501. /* USER CODE BEGIN 2 */
  502. HAL_TIM_Base_Start_IT(&htim6);
  503. HAL_UART_Receive_IT(&huart1, &rx1_data[0],1);
  504. HAL_UART_Receive_IT(&huart2, &rx2_data[0],1);
  505. setbuf(stdout, NULL); // \n 을 적을 떄만
  506. #if 1 // PYJ.2019.03.04_BEGIN --
  507. printf("****************************************\r\n");
  508. printf("RGB Project\r\n");
  509. printf("Build at %s %s\r\n", __DATE__, __TIME__);
  510. printf("Copyright (c) 2019. BLUECELL\r\n");
  511. printf("****************************************\r\n");
  512. #endif // PYJ.2019.03.04_END --
  513. RGB_SensorIDAutoSet(1);
  514. Flash_InitRead();
  515. RGB_Data_Init();
  516. /* USER CODE END 2 */
  517. /* Infinite loop */
  518. /* USER CODE BEGIN WHILE */
  519. //initialize LoRa module
  520. SX1276_hw.dio0.port = SX1276_DIO0_GPIO_Port;
  521. SX1276_hw.dio0.pin = SX1276_DIO0_Pin;
  522. SX1276_hw.nss.port = GPIOA;
  523. SX1276_hw.nss.pin = GPIO_PIN_15;
  524. SX1276_hw.reset.port = SX1276_RESET_GPIO_Port;
  525. SX1276_hw.reset.pin = SX1276_RESET_Pin;
  526. // SX1276_hw.spi = &hspi3;
  527. SX1276.hw = &SX1276_hw;
  528. printf("Configuring LoRa module\r\n");
  529. SX1276_begin(&SX1276, SX1276_917MHZ, SX1276_POWER_17DBM, SX1276_LORA_SF_8,
  530. SX1276_LORA_BW_20_8KHZ, 10);
  531. printf("Done configuring LoRaModule\r\n");
  532. master = 0;
  533. if (master == 1) {
  534. ret = SX1276_LoRaEntryTx(&SX1276, LORA_MAX_DATA_CNT, 2000);
  535. } else {
  536. ret = SX1276_LoRaEntryRx(&SX1276, LORA_MAX_DATA_CNT, 2000);
  537. }
  538. #if 0 // PYJ.2019.04.16_BEGIN --
  539. for(uint8_t i = 0; i < 100; i++){
  540. Test_data[i] = i;
  541. M24C32_Data_Write(&hi2c2,&Test_data[i],(uint16_t)i,1);
  542. }
  543. for(uint8_t i = 0; i < 100; i++){
  544. printf("%d \n",M24C32_Data_Read(&hi2c2,(uint16_t)i));
  545. }
  546. #endif // PYJ.2019.04.16_END --
  547. uint8_t data1[100]= {0,};
  548. uint8_t data2[100]= {0,};
  549. uint8_t uartrecv1=0,uartrecv2=0,cnt1 = 0,cnt2=0;
  550. while (1)
  551. {
  552. if(LoraTxTimerCnt > LORA_TIMER_CNT){
  553. LoraTxTimerCnt = 0;
  554. // LoraDataSendSet(1);
  555. }
  556. RGB_Alarm_Operate();//LED ALARM CHECK
  557. if(LoraDataSendGet() == LoraTx_mode){
  558. // LoraDataSendSet(0);
  559. memcpy(&buffer[0],&Lora_Buf[0],LORA_MAX_DATA_CNT);
  560. message_length = Lora_Max_Amount + 3;////RGB Data 60byte + stx + etx + crc
  561. ret = SX1276_LoRaEntryTx(&SX1276, message_length, 2000);
  562. ret = SX1276_LoRaTxPacket(&SX1276, &buffer[0], message_length, 2000);
  563. LoraDataSendSet(0);
  564. ret = SX1276_LoRaEntryRx(&SX1276, LORA_MAX_DATA_CNT, 2000);
  565. }else {
  566. ret = SX1276_LoRaRxPacket(&SX1276);
  567. if (ret > 0) {
  568. SX1276_read(&SX1276, &buffer[0], ret);
  569. #if 1 // PYJ.2019.04.22_BEGIN --
  570. printf("Received Data : ");
  571. for(uint8_t i = 0; i < ret; i++)
  572. printf("%02x ", buffer[i]);
  573. printf("\n");
  574. #endif // PYJ.2019.04.22_END --
  575. Uart_dataCheck(&buffer[bluecell_stx],&ret);
  576. }
  577. }
  578. if(count_in1 != count_out1){ // <-------
  579. data1[cnt1++] = buf1[count_out1++];
  580. if(count_out1 >= 100){ count_out1 = 0; }
  581. UartTimerCnt = 0;
  582. // uartrecv1 = 1;
  583. UartDataRecvSet(1);
  584. }
  585. if(count_in2 != count_out2){ // <-------
  586. data2[cnt2++] = buf2[count_out2++];
  587. if(count_out2 >= 100){ count_out2 = 0; }
  588. UartTimerCnt = 0;
  589. // uartrecv2 = 1;
  590. UartDataRecvSet(2);
  591. }
  592. #if 0 // PYJ.2019.04.19_BEGIN --
  593. uartdatarecv = UartDataRecvGet();
  594. if(uartdatarecv != 0){
  595. if(uartdatarecv == 1){
  596. Uart_dataCheck(data1,&count_in1);
  597. }else if(uartdatarecv == 2){
  598. Uart_dataCheck(data2,&count_in2);
  599. }
  600. UartDataRecvSet(0);
  601. }
  602. #endif // PYJ.2019.04.19_END --
  603. uartdatarecv = UartDataRecvGet();
  604. if(uartdatarecv == 1 && UartTimerCnt > 100){
  605. cnt1 = 0;
  606. UartDataRecvSet(0);
  607. Uart_dataCheck(&data1[0],&count_in1);
  608. memset(&data1[0],0,100);
  609. }
  610. if(uartdatarecv == 2 && UartTimerCnt > 100){
  611. cnt2 = 0;
  612. UartDataRecvSet(0);
  613. Uart_dataCheck(&data2[0],&count_in2);
  614. memset(&data2[0],0,100);
  615. }
  616. else{
  617. if(LedTimerCnt > 500){
  618. if(RGB_SensorIDAutoGet() == 1){
  619. if(SensorID == 0){memset(&SensorID_buf[0],0x00,8);SensorID_Cnt = 0;}
  620. IDAutoSetRequest_data[bluecell_srcid + 1] = ++SensorID;//DST ID
  621. if(IDAutoSetRequest_data[bluecell_srcid + 1] > 8){
  622. RGB_SensorIDAutoSet(0);
  623. RGB_Sensor_PowerOnOff(0);
  624. SensorID = 0;
  625. }else{
  626. RGB_Sensor_PowerOnOff(IDAutoSetRequest_data[4]);
  627. HAL_Delay(500);
  628. RGB_Controller_Func(&IDAutoSetRequest_data[bluecell_stx]);
  629. HAL_Delay(500);
  630. }
  631. }
  632. else{
  633. StatusRequest_data[bluecell_srcid + 1] = SensorID_buf[temp_sensorid++];
  634. if(temp_sensorid > (SensorID_Cnt)){
  635. temp_sensorid = 0;
  636. }
  637. RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
  638. }
  639. HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
  640. LedTimerCnt = 0;
  641. }
  642. }
  643. /* USER CODE END WHILE */
  644. /* USER CODE BEGIN 3 */
  645. }
  646. /* USER CODE END 3 */
  647. }
  648. /**
  649. * @brief System Clock Configuration
  650. * @retval None
  651. */
  652. void SystemClock_Config(void)
  653. {
  654. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  655. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  656. /**Initializes the CPU, AHB and APB busses clocks
  657. */
  658. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  659. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  660. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  661. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  662. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  663. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  664. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2;
  665. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  666. {
  667. Error_Handler();
  668. }
  669. /**Initializes the CPU, AHB and APB busses clocks
  670. */
  671. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  672. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  673. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  674. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  675. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  676. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  677. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  678. {
  679. Error_Handler();
  680. }
  681. }
  682. /**
  683. * @brief NVIC Configuration.
  684. * @retval None
  685. */
  686. static void MX_NVIC_Init(void)
  687. {
  688. /* USART2_IRQn interrupt configuration */
  689. HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  690. HAL_NVIC_EnableIRQ(USART2_IRQn);
  691. /* USART1_IRQn interrupt configuration */
  692. HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
  693. HAL_NVIC_EnableIRQ(USART1_IRQn);
  694. /* TIM6_IRQn interrupt configuration */
  695. HAL_NVIC_SetPriority(TIM6_IRQn, 0, 0);
  696. HAL_NVIC_EnableIRQ(TIM6_IRQn);
  697. }
  698. /**
  699. * @brief I2C2 Initialization Function
  700. * @param None
  701. * @retval None
  702. */
  703. static void MX_I2C2_Init(void)
  704. {
  705. /* USER CODE BEGIN I2C2_Init 0 */
  706. /* USER CODE END I2C2_Init 0 */
  707. /* USER CODE BEGIN I2C2_Init 1 */
  708. /* USER CODE END I2C2_Init 1 */
  709. hi2c2.Instance = I2C2;
  710. hi2c2.Init.ClockSpeed = 100000;
  711. hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
  712. hi2c2.Init.OwnAddress1 = 0;
  713. hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  714. hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  715. hi2c2.Init.OwnAddress2 = 0;
  716. hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  717. hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  718. if (HAL_I2C_Init(&hi2c2) != HAL_OK)
  719. {
  720. Error_Handler();
  721. }
  722. /* USER CODE BEGIN I2C2_Init 2 */
  723. /* USER CODE END I2C2_Init 2 */
  724. }
  725. /**
  726. * @brief TIM6 Initialization Function
  727. * @param None
  728. * @retval None
  729. */
  730. static void MX_TIM6_Init(void)
  731. {
  732. /* USER CODE BEGIN TIM6_Init 0 */
  733. /* USER CODE END TIM6_Init 0 */
  734. TIM_MasterConfigTypeDef sMasterConfig = {0};
  735. /* USER CODE BEGIN TIM6_Init 1 */
  736. /* USER CODE END TIM6_Init 1 */
  737. htim6.Instance = TIM6;
  738. htim6.Init.Prescaler = 1600-1;
  739. htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  740. htim6.Init.Period = 10-1;
  741. htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  742. if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  743. {
  744. Error_Handler();
  745. }
  746. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  747. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  748. if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  749. {
  750. Error_Handler();
  751. }
  752. /* USER CODE BEGIN TIM6_Init 2 */
  753. /* USER CODE END TIM6_Init 2 */
  754. }
  755. /**
  756. * @brief USART1 Initialization Function
  757. * @param None
  758. * @retval None
  759. */
  760. static void MX_USART1_UART_Init(void)
  761. {
  762. /* USER CODE BEGIN USART1_Init 0 */
  763. /* USER CODE END USART1_Init 0 */
  764. /* USER CODE BEGIN USART1_Init 1 */
  765. /* USER CODE END USART1_Init 1 */
  766. huart1.Instance = USART1;
  767. huart1.Init.BaudRate = 115200;
  768. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  769. huart1.Init.StopBits = UART_STOPBITS_1;
  770. huart1.Init.Parity = UART_PARITY_NONE;
  771. huart1.Init.Mode = UART_MODE_TX_RX;
  772. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  773. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  774. if (HAL_UART_Init(&huart1) != HAL_OK)
  775. {
  776. Error_Handler();
  777. }
  778. /* USER CODE BEGIN USART1_Init 2 */
  779. /* USER CODE END USART1_Init 2 */
  780. }
  781. /**
  782. * @brief USART2 Initialization Function
  783. * @param None
  784. * @retval None
  785. */
  786. static void MX_USART2_UART_Init(void)
  787. {
  788. /* USER CODE BEGIN USART2_Init 0 */
  789. /* USER CODE END USART2_Init 0 */
  790. /* USER CODE BEGIN USART2_Init 1 */
  791. /* USER CODE END USART2_Init 1 */
  792. huart2.Instance = USART2;
  793. huart2.Init.BaudRate = 115200;
  794. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  795. huart2.Init.StopBits = UART_STOPBITS_1;
  796. huart2.Init.Parity = UART_PARITY_NONE;
  797. huart2.Init.Mode = UART_MODE_TX_RX;
  798. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  799. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  800. if (HAL_UART_Init(&huart2) != HAL_OK)
  801. {
  802. Error_Handler();
  803. }
  804. /* USER CODE BEGIN USART2_Init 2 */
  805. /* USER CODE END USART2_Init 2 */
  806. }
  807. /**
  808. * @brief GPIO Initialization Function
  809. * @param None
  810. * @retval None
  811. */
  812. static void MX_GPIO_Init(void)
  813. {
  814. GPIO_InitTypeDef GPIO_InitStruct = {0};
  815. /* GPIO Ports Clock Enable */
  816. __HAL_RCC_GPIOC_CLK_ENABLE();
  817. __HAL_RCC_GPIOD_CLK_ENABLE();
  818. __HAL_RCC_GPIOA_CLK_ENABLE();
  819. __HAL_RCC_GPIOB_CLK_ENABLE();
  820. /*Configure GPIO pin Output Level */
  821. HAL_GPIO_WritePin(GPIOC, BOOT_LED_Pin|SX1276_DIO4_Pin|SX1276_DIO5_Pin|SENSOR_EN4_Pin
  822. |SENSOR_EN5_Pin|SENSOR_EN6_Pin|SENSOR_EN7_Pin|LED_CH1_Pin
  823. |LED_CH2_Pin|LED_CH3_Pin, GPIO_PIN_RESET);
  824. /*Configure GPIO pin Output Level */
  825. HAL_GPIO_WritePin(GPIOA, SX1276_DIO0_Pin|SX1276_DIO1_Pin|SX1276_DIO2_Pin|SX1276_DIO3_Pin
  826. |SENSOR_EN8_Pin|SX1276_NSS_Pin, GPIO_PIN_RESET);
  827. /*Configure GPIO pin Output Level */
  828. HAL_GPIO_WritePin(GPIOB, SX1276_RESET_Pin|LED_ALARM_Pin|SENSOR_EN1_Pin|SENSOR_EN2_Pin
  829. |SENSOR_EN3_Pin|SX1276_CLK_Pin|SX1276_MOSI_Pin|LED_CH5_Pin
  830. |LED_CH6_Pin|LED_CH7_Pin|LED_CH8_Pin, GPIO_PIN_RESET);
  831. /*Configure GPIO pin Output Level */
  832. HAL_GPIO_WritePin(LED_CH4_GPIO_Port, LED_CH4_Pin, GPIO_PIN_RESET);
  833. /*Configure GPIO pins : BOOT_LED_Pin SX1276_DIO4_Pin SX1276_DIO5_Pin SENSOR_EN4_Pin
  834. SENSOR_EN5_Pin SENSOR_EN6_Pin SENSOR_EN7_Pin LED_CH1_Pin
  835. LED_CH2_Pin LED_CH3_Pin */
  836. GPIO_InitStruct.Pin = BOOT_LED_Pin|SX1276_DIO4_Pin|SX1276_DIO5_Pin|SENSOR_EN4_Pin
  837. |SENSOR_EN5_Pin|SENSOR_EN6_Pin|SENSOR_EN7_Pin|LED_CH1_Pin
  838. |LED_CH2_Pin|LED_CH3_Pin;
  839. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  840. GPIO_InitStruct.Pull = GPIO_NOPULL;
  841. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  842. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  843. /*Configure GPIO pins : SX1276_DIO0_Pin SX1276_DIO1_Pin SX1276_DIO2_Pin SX1276_DIO3_Pin
  844. SENSOR_EN8_Pin SX1276_NSS_Pin */
  845. GPIO_InitStruct.Pin = SX1276_DIO0_Pin|SX1276_DIO1_Pin|SX1276_DIO2_Pin|SX1276_DIO3_Pin
  846. |SENSOR_EN8_Pin|SX1276_NSS_Pin;
  847. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  848. GPIO_InitStruct.Pull = GPIO_NOPULL;
  849. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  850. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  851. /*Configure GPIO pins : SX1276_RESET_Pin LED_ALARM_Pin SENSOR_EN1_Pin SENSOR_EN2_Pin
  852. SENSOR_EN3_Pin SX1276_CLK_Pin SX1276_MOSI_Pin LED_CH5_Pin
  853. LED_CH6_Pin LED_CH7_Pin LED_CH8_Pin */
  854. GPIO_InitStruct.Pin = SX1276_RESET_Pin|LED_ALARM_Pin|SENSOR_EN1_Pin|SENSOR_EN2_Pin
  855. |SENSOR_EN3_Pin|SX1276_CLK_Pin|SX1276_MOSI_Pin|LED_CH5_Pin
  856. |LED_CH6_Pin|LED_CH7_Pin|LED_CH8_Pin;
  857. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  858. GPIO_InitStruct.Pull = GPIO_NOPULL;
  859. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  860. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  861. /*Configure GPIO pin : LED_CH4_Pin */
  862. GPIO_InitStruct.Pin = LED_CH4_Pin;
  863. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  864. GPIO_InitStruct.Pull = GPIO_NOPULL;
  865. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  866. HAL_GPIO_Init(LED_CH4_GPIO_Port, &GPIO_InitStruct);
  867. /*Configure GPIO pin : SX1276_MISO_Pin */
  868. GPIO_InitStruct.Pin = SX1276_MISO_Pin;
  869. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  870. GPIO_InitStruct.Pull = GPIO_NOPULL;
  871. HAL_GPIO_Init(SX1276_MISO_GPIO_Port, &GPIO_InitStruct);
  872. }
  873. /* USER CODE BEGIN 4 */
  874. /* USER CODE END 4 */
  875. /**
  876. * @brief This function is executed in case of error occurrence.
  877. * @retval None
  878. */
  879. void Error_Handler(void)
  880. {
  881. /* USER CODE BEGIN Error_Handler_Debug */
  882. /* User can add his own implementation to report the HAL error return state */
  883. /* USER CODE END Error_Handler_Debug */
  884. }
  885. #ifdef USE_FULL_ASSERT
  886. /**
  887. * @brief Reports the name of the source file and the source line number
  888. * where the assert_param error has occurred.
  889. * @param file: pointer to the source file name
  890. * @param line: assert_param error line source number
  891. * @retval None
  892. */
  893. void assert_failed(uint8_t *file, uint32_t line)
  894. {
  895. /* USER CODE BEGIN 6 */
  896. /* User can add his own implementation to report the file name and line number,
  897. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  898. /* USER CODE END 6 */
  899. }
  900. #endif /* USE_FULL_ASSERT */
  901. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/