main(4884).c 26 KB

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