main(917).c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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, 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. /* USER CODE END PD */
  51. /* Private macro -------------------------------------------------------------*/
  52. /* USER CODE BEGIN PM */
  53. /* USER CODE END PM */
  54. /* Private variables ---------------------------------------------------------*/
  55. I2C_HandleTypeDef hi2c3;
  56. TIM_HandleTypeDef htim6;
  57. UART_HandleTypeDef huart1;
  58. UART_HandleTypeDef huart3;
  59. /* USER CODE BEGIN PV */
  60. /* USER CODE END PV */
  61. /* Private function prototypes -----------------------------------------------*/
  62. void SystemClock_Config(void);
  63. static void MX_GPIO_Init(void);
  64. static void MX_USART1_UART_Init(void);
  65. static void MX_TIM6_Init(void);
  66. static void MX_I2C3_Init(void);
  67. static void MX_USART3_UART_Init(void);
  68. static void MX_NVIC_Init(void);
  69. /* USER CODE BEGIN PFP */
  70. /* USER CODE END PFP */
  71. /* Private user code ---------------------------------------------------------*/
  72. /* USER CODE BEGIN 0 */
  73. #define buf_size 64
  74. uint8_t rx2_data[2];
  75. uint8_t ring_buf[buf_size];
  76. uint8_t count_in, count_out;
  77. uint8_t data_complete = 0;
  78. uint32_t Timer10ms;
  79. uint8_t buf[buf_size] = {0,};
  80. volatile uint32_t UartTimerCnt = 0;
  81. volatile uint32_t LedTimerCnt = 0;
  82. volatile uint8_t switchcnt[5] = {0,};
  83. int _write (int file, uint8_t *ptr, uint16_t len)
  84. {
  85. HAL_UART_Transmit (&huart3, ptr, len, 10);
  86. return len;
  87. }
  88. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  89. {
  90. /* Prevent unused argument(s) compilation warning */
  91. if(htim->Instance == TIM6){
  92. UartTimerCnt++;
  93. LedTimerCnt++;
  94. // HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2);
  95. // HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  96. // |GPIO_PIN_6|GPIO_PIN_7);
  97. #if 0 // PYJ.2019.02.20_BEGIN --
  98. if(UartTimerCnt % 1000== 1){
  99. HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2);
  100. HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  101. |GPIO_PIN_6|GPIO_PIN_7);
  102. }
  103. #endif // PYJ.2019.02.20_END --
  104. // HAL_GPIO_TogglePin(LD2_GPIO_Port,GPIO_PIN_15);
  105. }
  106. /* NOTE : This function Should not be modified, when the callback is needed,
  107. the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file
  108. */
  109. }
  110. uint8_t UartDataisReved;
  111. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  112. {
  113. if(huart->Instance == USART3){
  114. ring_buf[count_in] = rx2_data[0];//(uint8_t)USART2->DR;
  115. if(++count_in>=buf_size) count_in=0;
  116. HAL_UART_Receive_IT(&huart3,&rx2_data,1);
  117. }
  118. }
  119. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  120. {
  121. switch(GPIO_Pin){
  122. case GPIO_PIN_8: if(switchcnt[0] == 0){switchcnt[0]++;return;}
  123. case GPIO_PIN_12: if(switchcnt[1] == 0){switchcnt[1]++;return;}
  124. case GPIO_PIN_13: if(switchcnt[2] == 0){switchcnt[2]++;return;}
  125. case GPIO_PIN_14: if(switchcnt[3] == 0){switchcnt[3]++;return;}
  126. case GPIO_PIN_15: if(switchcnt[4] == 0){switchcnt[4]++;return;}
  127. }
  128. if(GPIO_Pin == GPIO_PIN_8){
  129. printf("%d \r\n",HAL_GPIO_ReadPin(GPIOD,GPIO_Pin));
  130. printf("Func : %s LINE = %d \r\n",__func__,__LINE__);
  131. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_10, GPIO_PIN_RESET);
  132. switchcnt[0] = 0;
  133. }
  134. if(GPIO_Pin == GPIO_PIN_12){
  135. printf("%d \r\n",HAL_GPIO_ReadPin(GPIOB,GPIO_Pin));
  136. printf("Func : %s LINE = %d \r\n",__func__,__LINE__);
  137. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_10, GPIO_PIN_SET);
  138. switchcnt[1] = 0;
  139. }
  140. if(GPIO_Pin == GPIO_PIN_13){
  141. printf("%d \r\n",HAL_GPIO_ReadPin(GPIOB,GPIO_Pin));
  142. printf("Func : %s LINE = %d \r\n",__func__,__LINE__);
  143. switchcnt[2] = 0;
  144. }
  145. if(GPIO_Pin == GPIO_PIN_14){
  146. printf("%d \r\n",HAL_GPIO_ReadPin(GPIOB,GPIO_Pin));
  147. printf("Func : %s LINE = %d \r\n",__func__,__LINE__);
  148. switchcnt[3] = 0;
  149. }
  150. if(GPIO_Pin == GPIO_PIN_15){
  151. printf("%d \r\n",HAL_GPIO_ReadPin(GPIOB,GPIO_Pin));
  152. printf("Func : %s LINE = %d \r\n",__func__,__LINE__);
  153. switchcnt[4] = 0;
  154. }
  155. }
  156. void UartDataRecvSet(uint8_t val){
  157. data_complete = val;
  158. }
  159. uint8_t UartDataRecvGet(void){
  160. return data_complete;
  161. }
  162. #define ATTEN_0DB 0
  163. #define ATTEN_0_5DB 0.5
  164. #define ATTEN_1DB 1
  165. #define ATTEN_2DB 2
  166. #define ATTEN_4DB 4
  167. #define ATTEN_8DB 8
  168. #define ATTEN_16DB 16
  169. #define ATTEN_31_5DB 31.5
  170. /* USER CODE END 0 */
  171. /**
  172. * @brief The application entry point.
  173. * @retval int
  174. */
  175. int main(void)
  176. {
  177. /* USER CODE BEGIN 1 */
  178. //uint8_t writetemp[10] = {6,4,2,0,1,2,3,4,5,0xab};
  179. uint8_t tempdata[100] = {0,};
  180. Atten_Alarm_t Alarm_st;
  181. /* USER CODE END 1 */
  182. /* MCU Configuration--------------------------------------------------------*/
  183. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  184. HAL_Init();
  185. /* USER CODE BEGIN Init */
  186. /* USER CODE END Init */
  187. /* Configure the system clock */
  188. SystemClock_Config();
  189. /* USER CODE BEGIN SysInit */
  190. /* USER CODE END SysInit */
  191. /* Initialize all configured peripherals */
  192. MX_GPIO_Init();
  193. MX_USART1_UART_Init();
  194. MX_TIM6_Init();
  195. MX_I2C3_Init();
  196. MX_USART3_UART_Init();
  197. /* Initialize interrupts */
  198. MX_NVIC_Init();
  199. /* USER CODE BEGIN 2 */
  200. HAL_TIM_Base_Start_IT(&htim6);
  201. // TCS34725_enable();
  202. HAL_UART_Receive_IT(&huart3, &rx2_data,1);
  203. setbuf(stdout, NULL); // \n ?��?��?��, printf �????��?���??? ?��?��?��
  204. LCD_16T202DA1EA_Init();
  205. /* USER CODE END 2 */
  206. /* Infinite loop */
  207. /* USER CODE BEGIN WHILE */
  208. //init_queue();
  209. // unsigned short temp_CrcData = 0;
  210. printf("****************************************\r\n");
  211. printf("TEST Project\r\n");
  212. printf("Build at %s %s\r\n", __DATE__, __TIME__);
  213. printf("Copyright (c) 2019. BLUECELL\r\n");
  214. printf("****************************************\r\n");
  215. //memcpy(&ATT_A_EN_150M_Table.Atten_Table_31_5dB_Value,writetemp,10);
  216. //EEPROM_IM24CM01P_write(EEPROM_ATT_A_EN_150M ,&ATT_A_EN_150M_Table.Atten_Table_31_5dB_Value ,sizeof(Atten_Table_Value_t));
  217. // EEPROM_IM24CM01P_Read(EEPROM_ATT_A_EN_150M ,&ATT_A_EN_150M_Table.Atten_Table_31_5dB_Value ,sizeof(Atten_Table_Value_t));
  218. EEPROM_IM24CM01P_Init();
  219. memcpy(tempdata,&ATT_A_EN_30G1_28_28_5Ghz_Table.Atten_Table_31_5dB_Value,sizeof(Atten_Table_Value_t));
  220. Atten_Init();
  221. #if 0
  222. printf("HAL_I2C_Mem_Read : data : ");
  223. for(uint8_t i = 0; i < sizeof(Atten_Table_Value_t); i++){
  224. printf("%02x ",tempdata[i]);
  225. }
  226. printf("\r\n");
  227. memset(tempdata,0,sizeof(Atten_Table_Value_t));
  228. #endif
  229. // HAL_UART_Transmit(&huart1, buf, 1, 10);
  230. uint8_t uartindex = 0;
  231. etError crccheck = 0;
  232. while(1)
  233. {
  234. if(count_in != count_out){
  235. UartDataisReved = 1;
  236. UartTimerCnt = 0;
  237. buf[uartindex++] = ring_buf[count_out];
  238. if(++count_out >= buf_size) count_out=0;
  239. }
  240. if(UartDataisReved == 1 && UartTimerCnt > 10){
  241. #if 0
  242. for(uint8_t i = 0; i < (uartindex); i++){
  243. printf("%02x ",buf[i]);
  244. }
  245. printf("\r\n");
  246. #endif
  247. UartDataisReved =0;
  248. crccheck = STH30_CheckCrc(&buf[Bluecell_Type],buf[Bluecell_Length]+2,buf[3 + buf[Bluecell_Length]]);
  249. if(crccheck == CHECKSUM_ERROR){
  250. printf("CHECKSUM_ERROR RecvCRC : %02x , index %d\r\n",buf[3 + buf[Bluecell_Length]],3 + buf[Bluecell_Length]);
  251. }
  252. else if(crccheck == NO_ERROR){
  253. Atten_Operate_Mem_RW(&buf[Bluecell_STX]);
  254. // printf("NO_ERROR\r\n");
  255. }
  256. else{
  257. printf("What Happen?\r\n");
  258. /*NOP*/
  259. }
  260. memset(buf,0x00,buf_size);
  261. uartindex = 0;
  262. }
  263. else{
  264. //Alarm Timer
  265. if(LedTimerCnt > 500){
  266. Alarm_st = Atten_Alarm_Read();
  267. Alarm_Operate(Alarm_st);
  268. tempdata[Bluecell_STX] = 0xBE;
  269. tempdata[Bluecell_Type] = ATT_AB_ALARM_READ;
  270. tempdata[Bluecell_Length] = sizeof(Atten_Alarm_t) + 2;
  271. memcpy(&tempdata[Bluecell_DATA],&Alarm_st.Atten_Ach_Alarm_150M,sizeof(Atten_Alarm_t));
  272. tempdata[tempdata[Bluecell_Length] + 3] = STH30_CreateCrc(&tempdata[Bluecell_Type],tempdata[Bluecell_Length] + 2);
  273. tempdata[tempdata[Bluecell_Length] + 4] = 0xeb;
  274. Uart_Data_Send(&tempdata[Bluecell_STX],tempdata[Bluecell_Length]+5);
  275. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_15);
  276. LedTimerCnt = 0;
  277. }
  278. }
  279. }
  280. HAL_Delay(1);
  281. /* USER CODE END WHILE */
  282. /* USER CODE BEGIN 3 */
  283. /* USER CODE END 3 */
  284. }
  285. /**
  286. * @brief System Clock Configuration
  287. * @retval None
  288. */
  289. void SystemClock_Config(void)
  290. {
  291. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  292. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  293. /**Initializes the CPU, AHB and APB busses clocks
  294. */
  295. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  296. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  297. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  298. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  299. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  300. {
  301. Error_Handler();
  302. }
  303. /**Initializes the CPU, AHB and APB busses clocks
  304. */
  305. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  306. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  307. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  308. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  309. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  310. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  311. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  312. {
  313. Error_Handler();
  314. }
  315. }
  316. /**
  317. * @brief NVIC Configuration.
  318. * @retval None
  319. */
  320. static void MX_NVIC_Init(void)
  321. {
  322. /* USART1_IRQn interrupt configuration */
  323. HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
  324. HAL_NVIC_EnableIRQ(USART1_IRQn);
  325. /* TIM6_DAC_IRQn interrupt configuration */
  326. HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 0, 0);
  327. HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
  328. /* USART3_IRQn interrupt configuration */
  329. HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
  330. HAL_NVIC_EnableIRQ(USART3_IRQn);
  331. /* EXTI9_5_IRQn interrupt configuration */
  332. HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
  333. HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
  334. /* EXTI15_10_IRQn interrupt configuration */
  335. HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
  336. HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
  337. }
  338. /**
  339. * @brief I2C3 Initialization Function
  340. * @param None
  341. * @retval None
  342. */
  343. static void MX_I2C3_Init(void)
  344. {
  345. /* USER CODE BEGIN I2C3_Init 0 */
  346. /* USER CODE END I2C3_Init 0 */
  347. /* USER CODE BEGIN I2C3_Init 1 */
  348. /* USER CODE END I2C3_Init 1 */
  349. hi2c3.Instance = I2C3;
  350. hi2c3.Init.ClockSpeed = 400000;
  351. hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
  352. hi2c3.Init.OwnAddress1 = 0;
  353. hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  354. hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  355. hi2c3.Init.OwnAddress2 = 0;
  356. hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  357. hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  358. if (HAL_I2C_Init(&hi2c3) != HAL_OK)
  359. {
  360. Error_Handler();
  361. }
  362. /* USER CODE BEGIN I2C3_Init 2 */
  363. /* USER CODE END I2C3_Init 2 */
  364. }
  365. /**
  366. * @brief TIM6 Initialization Function
  367. * @param None
  368. * @retval None
  369. */
  370. static void MX_TIM6_Init(void)
  371. {
  372. /* USER CODE BEGIN TIM6_Init 0 */
  373. /* USER CODE END TIM6_Init 0 */
  374. TIM_MasterConfigTypeDef sMasterConfig = {0};
  375. /* USER CODE BEGIN TIM6_Init 1 */
  376. /* USER CODE END TIM6_Init 1 */
  377. htim6.Instance = TIM6;
  378. htim6.Init.Prescaler = 999;
  379. htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  380. htim6.Init.Period = 15;
  381. htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  382. if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  383. {
  384. Error_Handler();
  385. }
  386. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  387. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  388. if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  389. {
  390. Error_Handler();
  391. }
  392. /* USER CODE BEGIN TIM6_Init 2 */
  393. /* USER CODE END TIM6_Init 2 */
  394. }
  395. /**
  396. * @brief USART1 Initialization Function
  397. * @param None
  398. * @retval None
  399. */
  400. static void MX_USART1_UART_Init(void)
  401. {
  402. /* USER CODE BEGIN USART1_Init 0 */
  403. /* USER CODE END USART1_Init 0 */
  404. /* USER CODE BEGIN USART1_Init 1 */
  405. /* USER CODE END USART1_Init 1 */
  406. huart1.Instance = USART1;
  407. huart1.Init.BaudRate = 115200;
  408. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  409. huart1.Init.StopBits = UART_STOPBITS_1;
  410. huart1.Init.Parity = UART_PARITY_NONE;
  411. huart1.Init.Mode = UART_MODE_TX_RX;
  412. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  413. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  414. if (HAL_UART_Init(&huart1) != HAL_OK)
  415. {
  416. Error_Handler();
  417. }
  418. /* USER CODE BEGIN USART1_Init 2 */
  419. /* USER CODE END USART1_Init 2 */
  420. }
  421. /**
  422. * @brief USART3 Initialization Function
  423. * @param None
  424. * @retval None
  425. */
  426. static void MX_USART3_UART_Init(void)
  427. {
  428. /* USER CODE BEGIN USART3_Init 0 */
  429. /* USER CODE END USART3_Init 0 */
  430. /* USER CODE BEGIN USART3_Init 1 */
  431. /* USER CODE END USART3_Init 1 */
  432. huart3.Instance = USART3;
  433. huart3.Init.BaudRate = 115200;
  434. huart3.Init.WordLength = UART_WORDLENGTH_8B;
  435. huart3.Init.StopBits = UART_STOPBITS_1;
  436. huart3.Init.Parity = UART_PARITY_NONE;
  437. huart3.Init.Mode = UART_MODE_TX_RX;
  438. huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  439. huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  440. if (HAL_UART_Init(&huart3) != HAL_OK)
  441. {
  442. Error_Handler();
  443. }
  444. /* USER CODE BEGIN USART3_Init 2 */
  445. /* USER CODE END USART3_Init 2 */
  446. }
  447. /**
  448. * @brief GPIO Initialization Function
  449. * @param None
  450. * @retval None
  451. */
  452. static void MX_GPIO_Init(void)
  453. {
  454. GPIO_InitTypeDef GPIO_InitStruct = {0};
  455. /* GPIO Ports Clock Enable */
  456. __HAL_RCC_GPIOE_CLK_ENABLE();
  457. __HAL_RCC_GPIOC_CLK_ENABLE();
  458. __HAL_RCC_GPIOF_CLK_ENABLE();
  459. __HAL_RCC_GPIOH_CLK_ENABLE();
  460. __HAL_RCC_GPIOA_CLK_ENABLE();
  461. __HAL_RCC_GPIOB_CLK_ENABLE();
  462. __HAL_RCC_GPIOD_CLK_ENABLE();
  463. __HAL_RCC_GPIOG_CLK_ENABLE();
  464. /*Configure GPIO pin Output Level */
  465. HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  466. |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
  467. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_0, GPIO_PIN_RESET);
  468. /*Configure GPIO pin Output Level */
  469. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_4|GPIO_PIN_5
  470. |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET);
  471. /*Configure GPIO pin Output Level */
  472. HAL_GPIO_WritePin(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_11
  473. |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
  474. /*Configure GPIO pin Output Level */
  475. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
  476. |GPIO_PIN_11, GPIO_PIN_RESET);
  477. /*Configure GPIO pin Output Level */
  478. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
  479. |GPIO_PIN_9, GPIO_PIN_RESET);
  480. /*Configure GPIO pin Output Level */
  481. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13
  482. |GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
  483. |GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
  484. /*Configure GPIO pin Output Level */
  485. HAL_GPIO_WritePin(GPIOG, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  486. |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_9|GPIO_PIN_11
  487. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14, GPIO_PIN_RESET);
  488. /*Configure GPIO pins : PE2 PE3 PE4 PE5
  489. PE8 PE9 PE10 PE11
  490. PE12 PE13 PE14 PE0 */
  491. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  492. |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
  493. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_0;
  494. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  495. GPIO_InitStruct.Pull = GPIO_NOPULL;
  496. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  497. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  498. /*Configure GPIO pins : PC14 PC15 PC4 PC5
  499. PC10 PC11 PC12 */
  500. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_4|GPIO_PIN_5
  501. |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
  502. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  503. GPIO_InitStruct.Pull = GPIO_NOPULL;
  504. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  505. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  506. /*Configure GPIO pins : PF0 PF1 PF2 PF11
  507. PF13 PF14 PF15 */
  508. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_11
  509. |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  510. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  511. GPIO_InitStruct.Pull = GPIO_NOPULL;
  512. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  513. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  514. /*Configure GPIO pins : PF6 PF7 PF8 */
  515. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8;
  516. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  517. GPIO_InitStruct.Pull = GPIO_NOPULL;
  518. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  519. /*Configure GPIO pins : PC1 PC2 PC3 */
  520. GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
  521. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  522. GPIO_InitStruct.Pull = GPIO_NOPULL;
  523. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  524. /*Configure GPIO pins : PA4 PA5 PA6 PA7
  525. PA11 */
  526. GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
  527. |GPIO_PIN_11;
  528. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  529. GPIO_InitStruct.Pull = GPIO_NOPULL;
  530. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  531. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  532. /*Configure GPIO pins : PB0 PB5 PB6 PB7
  533. PB9 */
  534. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
  535. |GPIO_PIN_9;
  536. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  537. GPIO_InitStruct.Pull = GPIO_NOPULL;
  538. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  539. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  540. /*Configure GPIO pins : PB12 PB13 PB14 PB15 */
  541. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  542. GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  543. GPIO_InitStruct.Pull = GPIO_PULLUP;
  544. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  545. /*Configure GPIO pin : PD8 */
  546. GPIO_InitStruct.Pin = GPIO_PIN_8;
  547. GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  548. GPIO_InitStruct.Pull = GPIO_PULLUP;
  549. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  550. /*Configure GPIO pins : PD10 PD11 PD12 PD13
  551. PD14 PD15 PD0 PD1
  552. PD2 PD3 PD6 PD7 */
  553. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13
  554. |GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
  555. |GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7;
  556. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  557. GPIO_InitStruct.Pull = GPIO_NOPULL;
  558. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  559. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  560. /*Configure GPIO pins : PG2 PG3 PG4 PG5
  561. PG6 PG7 PG9 PG11
  562. PG12 PG13 PG14 */
  563. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  564. |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_9|GPIO_PIN_11
  565. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14;
  566. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  567. GPIO_InitStruct.Pull = GPIO_NOPULL;
  568. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  569. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  570. }
  571. /* USER CODE BEGIN 4 */
  572. /* USER CODE END 4 */
  573. /**
  574. * @brief This function is executed in case of error occurrence.
  575. * @retval None
  576. */
  577. void Error_Handler(void)
  578. {
  579. /* USER CODE BEGIN Error_Handler_Debug */
  580. /* User can add his own implementation to report the HAL error return state */
  581. /* USER CODE END Error_Handler_Debug */
  582. }
  583. #ifdef USE_FULL_ASSERT
  584. /**
  585. * @brief Reports the name of the source file and the source line number
  586. * where the assert_param error has occurred.
  587. * @param file: pointer to the source file name
  588. * @param line: assert_param error line source number
  589. * @retval None
  590. */
  591. void assert_failed(uint8_t *file, uint32_t line)
  592. {
  593. /* USER CODE BEGIN 6 */
  594. /* User can add his own implementation to report the file name and line number,
  595. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  596. /* USER CODE END 6 */
  597. }
  598. #endif /* USE_FULL_ASSERT */
  599. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/