main(3516).c 25 KB

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