main(4241).c 24 KB

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