main.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  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. printf("Received Data : ");
  570. for(uint8_t i = 0; i < ret; i++)
  571. printf("%02x ", buffer[i]);
  572. printf("\n");
  573. Uart_dataCheck(&buffer[bluecell_stx],&ret);
  574. }
  575. }
  576. if(count_in1 != count_out1){ // <-------
  577. data1[cnt1++] = buf1[count_out1++];
  578. if(count_out1 >= 100){ count_out1 = 0; }
  579. UartTimerCnt = 0;
  580. // uartrecv1 = 1;
  581. UartDataRecvSet(1);
  582. }
  583. if(count_in2 != count_out2){ // <-------
  584. data2[cnt2++] = buf2[count_out2++];
  585. if(count_out2 >= 100){ count_out2 = 0; }
  586. UartTimerCnt = 0;
  587. // uartrecv2 = 1;
  588. UartDataRecvSet(2);
  589. }
  590. #if 0 // PYJ.2019.04.19_BEGIN --
  591. uartdatarecv = UartDataRecvGet();
  592. if(uartdatarecv != 0){
  593. if(uartdatarecv == 1){
  594. Uart_dataCheck(data1,&count_in1);
  595. }else if(uartdatarecv == 2){
  596. Uart_dataCheck(data2,&count_in2);
  597. }
  598. UartDataRecvSet(0);
  599. }
  600. #endif // PYJ.2019.04.19_END --
  601. uartdatarecv = UartDataRecvGet();
  602. if(uartdatarecv == 1 && UartTimerCnt > 100){
  603. cnt1 = 0;
  604. UartDataRecvSet(0);
  605. Uart_dataCheck(&data1[0],&count_in1);
  606. memset(&data1[0],0,100);
  607. }
  608. if(uartdatarecv == 2 && UartTimerCnt > 100){
  609. cnt2 = 0;
  610. UartDataRecvSet(0);
  611. Uart_dataCheck(&data2[0],&count_in2);
  612. memset(&data2[0],0,100);
  613. }
  614. else{
  615. if(LedTimerCnt > 500){
  616. if(RGB_SensorIDAutoGet() == 1){
  617. if(SensorID == 0){memset(&SensorID_buf[0],0x00,8);SensorID_Cnt = 0;}
  618. IDAutoSetRequest_data[bluecell_srcid + 1] = ++SensorID;//DST ID
  619. if(IDAutoSetRequest_data[bluecell_srcid + 1] > 8){
  620. RGB_SensorIDAutoSet(0);
  621. RGB_Sensor_PowerOnOff(0);
  622. SensorID = 0;
  623. }else{
  624. RGB_Sensor_PowerOnOff(IDAutoSetRequest_data[4]);
  625. HAL_Delay(450);
  626. RGB_Controller_Func(&IDAutoSetRequest_data[bluecell_stx]);
  627. HAL_Delay(450);
  628. }
  629. }
  630. else{
  631. StatusRequest_data[bluecell_srcid + 1] = SensorID_buf[temp_sensorid++];
  632. if(temp_sensorid > (SensorID_Cnt)){
  633. temp_sensorid = 0;
  634. }
  635. RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
  636. }
  637. HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
  638. LedTimerCnt = 0;
  639. }
  640. }
  641. /* USER CODE END WHILE */
  642. /* USER CODE BEGIN 3 */
  643. }
  644. /* USER CODE END 3 */
  645. }
  646. /**
  647. * @brief System Clock Configuration
  648. * @retval None
  649. */
  650. void SystemClock_Config(void)
  651. {
  652. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  653. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  654. /**Initializes the CPU, AHB and APB busses clocks
  655. */
  656. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  657. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  658. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  659. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  660. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  661. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  662. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2;
  663. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  664. {
  665. Error_Handler();
  666. }
  667. /**Initializes the CPU, AHB and APB busses clocks
  668. */
  669. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  670. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  671. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  672. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  673. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  674. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  675. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  676. {
  677. Error_Handler();
  678. }
  679. }
  680. /**
  681. * @brief NVIC Configuration.
  682. * @retval None
  683. */
  684. static void MX_NVIC_Init(void)
  685. {
  686. /* USART2_IRQn interrupt configuration */
  687. HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  688. HAL_NVIC_EnableIRQ(USART2_IRQn);
  689. /* USART1_IRQn interrupt configuration */
  690. HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
  691. HAL_NVIC_EnableIRQ(USART1_IRQn);
  692. /* TIM6_IRQn interrupt configuration */
  693. HAL_NVIC_SetPriority(TIM6_IRQn, 0, 0);
  694. HAL_NVIC_EnableIRQ(TIM6_IRQn);
  695. }
  696. /**
  697. * @brief I2C2 Initialization Function
  698. * @param None
  699. * @retval None
  700. */
  701. static void MX_I2C2_Init(void)
  702. {
  703. /* USER CODE BEGIN I2C2_Init 0 */
  704. /* USER CODE END I2C2_Init 0 */
  705. /* USER CODE BEGIN I2C2_Init 1 */
  706. /* USER CODE END I2C2_Init 1 */
  707. hi2c2.Instance = I2C2;
  708. hi2c2.Init.ClockSpeed = 100000;
  709. hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
  710. hi2c2.Init.OwnAddress1 = 0;
  711. hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  712. hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  713. hi2c2.Init.OwnAddress2 = 0;
  714. hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  715. hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  716. if (HAL_I2C_Init(&hi2c2) != HAL_OK)
  717. {
  718. Error_Handler();
  719. }
  720. /* USER CODE BEGIN I2C2_Init 2 */
  721. /* USER CODE END I2C2_Init 2 */
  722. }
  723. /**
  724. * @brief TIM6 Initialization Function
  725. * @param None
  726. * @retval None
  727. */
  728. static void MX_TIM6_Init(void)
  729. {
  730. /* USER CODE BEGIN TIM6_Init 0 */
  731. /* USER CODE END TIM6_Init 0 */
  732. TIM_MasterConfigTypeDef sMasterConfig = {0};
  733. /* USER CODE BEGIN TIM6_Init 1 */
  734. /* USER CODE END TIM6_Init 1 */
  735. htim6.Instance = TIM6;
  736. htim6.Init.Prescaler = 1600-1;
  737. htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  738. htim6.Init.Period = 10-1;
  739. htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  740. if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  741. {
  742. Error_Handler();
  743. }
  744. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  745. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  746. if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  747. {
  748. Error_Handler();
  749. }
  750. /* USER CODE BEGIN TIM6_Init 2 */
  751. /* USER CODE END TIM6_Init 2 */
  752. }
  753. /**
  754. * @brief USART1 Initialization Function
  755. * @param None
  756. * @retval None
  757. */
  758. static void MX_USART1_UART_Init(void)
  759. {
  760. /* USER CODE BEGIN USART1_Init 0 */
  761. /* USER CODE END USART1_Init 0 */
  762. /* USER CODE BEGIN USART1_Init 1 */
  763. /* USER CODE END USART1_Init 1 */
  764. huart1.Instance = USART1;
  765. huart1.Init.BaudRate = 115200;
  766. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  767. huart1.Init.StopBits = UART_STOPBITS_1;
  768. huart1.Init.Parity = UART_PARITY_NONE;
  769. huart1.Init.Mode = UART_MODE_TX_RX;
  770. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  771. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  772. if (HAL_UART_Init(&huart1) != HAL_OK)
  773. {
  774. Error_Handler();
  775. }
  776. /* USER CODE BEGIN USART1_Init 2 */
  777. /* USER CODE END USART1_Init 2 */
  778. }
  779. /**
  780. * @brief USART2 Initialization Function
  781. * @param None
  782. * @retval None
  783. */
  784. static void MX_USART2_UART_Init(void)
  785. {
  786. /* USER CODE BEGIN USART2_Init 0 */
  787. /* USER CODE END USART2_Init 0 */
  788. /* USER CODE BEGIN USART2_Init 1 */
  789. /* USER CODE END USART2_Init 1 */
  790. huart2.Instance = USART2;
  791. huart2.Init.BaudRate = 115200;
  792. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  793. huart2.Init.StopBits = UART_STOPBITS_1;
  794. huart2.Init.Parity = UART_PARITY_NONE;
  795. huart2.Init.Mode = UART_MODE_TX_RX;
  796. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  797. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  798. if (HAL_UART_Init(&huart2) != HAL_OK)
  799. {
  800. Error_Handler();
  801. }
  802. /* USER CODE BEGIN USART2_Init 2 */
  803. /* USER CODE END USART2_Init 2 */
  804. }
  805. /**
  806. * @brief GPIO Initialization Function
  807. * @param None
  808. * @retval None
  809. */
  810. static void MX_GPIO_Init(void)
  811. {
  812. GPIO_InitTypeDef GPIO_InitStruct = {0};
  813. /* GPIO Ports Clock Enable */
  814. __HAL_RCC_GPIOC_CLK_ENABLE();
  815. __HAL_RCC_GPIOD_CLK_ENABLE();
  816. __HAL_RCC_GPIOA_CLK_ENABLE();
  817. __HAL_RCC_GPIOB_CLK_ENABLE();
  818. /*Configure GPIO pin Output Level */
  819. HAL_GPIO_WritePin(GPIOC, BOOT_LED_Pin|SX1276_DIO4_Pin|SX1276_DIO5_Pin|SENSOR_EN4_Pin
  820. |SENSOR_EN5_Pin|SENSOR_EN6_Pin|SENSOR_EN7_Pin|LED_CH1_Pin
  821. |LED_CH2_Pin|LED_CH3_Pin, GPIO_PIN_RESET);
  822. /*Configure GPIO pin Output Level */
  823. HAL_GPIO_WritePin(GPIOA, SX1276_DIO0_Pin|SX1276_DIO1_Pin|SX1276_DIO2_Pin|SX1276_DIO3_Pin
  824. |SENSOR_EN8_Pin|SX1276_NSS_Pin, GPIO_PIN_RESET);
  825. /*Configure GPIO pin Output Level */
  826. HAL_GPIO_WritePin(GPIOB, SX1276_RESET_Pin|LED_ALARM_Pin|SENSOR_EN1_Pin|SENSOR_EN2_Pin
  827. |SENSOR_EN3_Pin|SX1276_CLK_Pin|SX1276_MOSI_Pin|LED_CH5_Pin
  828. |LED_CH6_Pin|LED_CH7_Pin|LED_CH8_Pin, GPIO_PIN_RESET);
  829. /*Configure GPIO pin Output Level */
  830. HAL_GPIO_WritePin(LED_CH4_GPIO_Port, LED_CH4_Pin, GPIO_PIN_RESET);
  831. /*Configure GPIO pins : BOOT_LED_Pin SX1276_DIO4_Pin SX1276_DIO5_Pin SENSOR_EN4_Pin
  832. SENSOR_EN5_Pin SENSOR_EN6_Pin SENSOR_EN7_Pin LED_CH1_Pin
  833. LED_CH2_Pin LED_CH3_Pin */
  834. GPIO_InitStruct.Pin = BOOT_LED_Pin|SX1276_DIO4_Pin|SX1276_DIO5_Pin|SENSOR_EN4_Pin
  835. |SENSOR_EN5_Pin|SENSOR_EN6_Pin|SENSOR_EN7_Pin|LED_CH1_Pin
  836. |LED_CH2_Pin|LED_CH3_Pin;
  837. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  838. GPIO_InitStruct.Pull = GPIO_NOPULL;
  839. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  840. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  841. /*Configure GPIO pins : SX1276_DIO0_Pin SX1276_DIO1_Pin SX1276_DIO2_Pin SX1276_DIO3_Pin
  842. SENSOR_EN8_Pin SX1276_NSS_Pin */
  843. GPIO_InitStruct.Pin = SX1276_DIO0_Pin|SX1276_DIO1_Pin|SX1276_DIO2_Pin|SX1276_DIO3_Pin
  844. |SENSOR_EN8_Pin|SX1276_NSS_Pin;
  845. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  846. GPIO_InitStruct.Pull = GPIO_NOPULL;
  847. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  848. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  849. /*Configure GPIO pins : SX1276_RESET_Pin LED_ALARM_Pin SENSOR_EN1_Pin SENSOR_EN2_Pin
  850. SENSOR_EN3_Pin SX1276_CLK_Pin SX1276_MOSI_Pin LED_CH5_Pin
  851. LED_CH6_Pin LED_CH7_Pin LED_CH8_Pin */
  852. GPIO_InitStruct.Pin = SX1276_RESET_Pin|LED_ALARM_Pin|SENSOR_EN1_Pin|SENSOR_EN2_Pin
  853. |SENSOR_EN3_Pin|SX1276_CLK_Pin|SX1276_MOSI_Pin|LED_CH5_Pin
  854. |LED_CH6_Pin|LED_CH7_Pin|LED_CH8_Pin;
  855. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  856. GPIO_InitStruct.Pull = GPIO_NOPULL;
  857. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  858. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  859. /*Configure GPIO pin : LED_CH4_Pin */
  860. GPIO_InitStruct.Pin = LED_CH4_Pin;
  861. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  862. GPIO_InitStruct.Pull = GPIO_NOPULL;
  863. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  864. HAL_GPIO_Init(LED_CH4_GPIO_Port, &GPIO_InitStruct);
  865. /*Configure GPIO pin : SX1276_MISO_Pin */
  866. GPIO_InitStruct.Pin = SX1276_MISO_Pin;
  867. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  868. GPIO_InitStruct.Pull = GPIO_NOPULL;
  869. HAL_GPIO_Init(SX1276_MISO_GPIO_Port, &GPIO_InitStruct);
  870. }
  871. /* USER CODE BEGIN 4 */
  872. /* USER CODE END 4 */
  873. /**
  874. * @brief This function is executed in case of error occurrence.
  875. * @retval None
  876. */
  877. void Error_Handler(void)
  878. {
  879. /* USER CODE BEGIN Error_Handler_Debug */
  880. /* User can add his own implementation to report the HAL error return state */
  881. /* USER CODE END Error_Handler_Debug */
  882. }
  883. #ifdef USE_FULL_ASSERT
  884. /**
  885. * @brief Reports the name of the source file and the source line number
  886. * where the assert_param error has occurred.
  887. * @param file: pointer to the source file name
  888. * @param line: assert_param error line source number
  889. * @retval None
  890. */
  891. void assert_failed(uint8_t *file, uint32_t line)
  892. {
  893. /* USER CODE BEGIN 6 */
  894. /* User can add his own implementation to report the file name and line number,
  895. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  896. /* USER CODE END 6 */
  897. }
  898. #endif /* USE_FULL_ASSERT */
  899. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/