main.c 35 KB

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