main(7519).c 23 KB

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