main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. #include "usb_device.h"
  23. /* Private includes ----------------------------------------------------------*/
  24. /* USER CODE BEGIN Includes */
  25. /* USER CODE END Includes */
  26. /* Private typedef -----------------------------------------------------------*/
  27. /* USER CODE BEGIN PTD */
  28. /* USER CODE END PTD */
  29. /* Private define ------------------------------------------------------------*/
  30. /* USER CODE BEGIN PD */
  31. /* USER CODE END PD */
  32. /* Private macro -------------------------------------------------------------*/
  33. /* USER CODE BEGIN PM */
  34. /* USER CODE END PM */
  35. /* Private variables ---------------------------------------------------------*/
  36. ADC_HandleTypeDef hadc1;
  37. ADC_HandleTypeDef hadc2;
  38. DAC_HandleTypeDef hdac;
  39. SMBUS_HandleTypeDef hsmbus1;
  40. RTC_HandleTypeDef hrtc;
  41. SPI_HandleTypeDef hspi1;
  42. SPI_HandleTypeDef hspi2;
  43. TIM_HandleTypeDef htim2;
  44. UART_HandleTypeDef huart1;
  45. /* USER CODE BEGIN PV */
  46. /* USER CODE END PV */
  47. /* Private function prototypes -----------------------------------------------*/
  48. void SystemClock_Config(void);
  49. static void MX_GPIO_Init(void);
  50. static void MX_ADC1_Init(void);
  51. static void MX_ADC2_Init(void);
  52. static void MX_DAC_Init(void);
  53. static void MX_I2C1_SMBUS_Init(void);
  54. static void MX_RTC_Init(void);
  55. static void MX_SPI1_Init(void);
  56. static void MX_SPI2_Init(void);
  57. static void MX_USART1_UART_Init(void);
  58. static void MX_TIM2_Init(void);
  59. /* USER CODE BEGIN PFP */
  60. /* USER CODE END PFP */
  61. /* Private user code ---------------------------------------------------------*/
  62. /* USER CODE BEGIN 0 */
  63. /* USER CODE END 0 */
  64. /**
  65. * @brief The application entry point.
  66. * @retval int
  67. */
  68. int main(void)
  69. {
  70. /* USER CODE BEGIN 1 */
  71. /* USER CODE END 1 */
  72. /* MCU Configuration--------------------------------------------------------*/
  73. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  74. HAL_Init();
  75. /* USER CODE BEGIN Init */
  76. /* USER CODE END Init */
  77. /* Configure the system clock */
  78. SystemClock_Config();
  79. /* USER CODE BEGIN SysInit */
  80. /* USER CODE END SysInit */
  81. /* Initialize all configured peripherals */
  82. MX_GPIO_Init();
  83. MX_ADC1_Init();
  84. MX_ADC2_Init();
  85. MX_DAC_Init();
  86. MX_I2C1_SMBUS_Init();
  87. MX_RTC_Init();
  88. MX_SPI1_Init();
  89. MX_SPI2_Init();
  90. MX_USART1_UART_Init();
  91. MX_USB_DEVICE_Init();
  92. MX_TIM2_Init();
  93. /* USER CODE BEGIN 2 */
  94. /* USER CODE END 2 */
  95. /* Infinite loop */
  96. /* USER CODE BEGIN WHILE */
  97. while (1)
  98. {
  99. /* USER CODE END WHILE */
  100. /* USER CODE BEGIN 3 */
  101. }
  102. /* USER CODE END 3 */
  103. }
  104. /**
  105. * @brief System Clock Configuration
  106. * @retval None
  107. */
  108. void SystemClock_Config(void)
  109. {
  110. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  111. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  112. /** Configure the main internal regulator output voltage
  113. */
  114. __HAL_RCC_PWR_CLK_ENABLE();
  115. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  116. /** Initializes the RCC Oscillators according to the specified parameters
  117. * in the RCC_OscInitTypeDef structure.
  118. */
  119. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
  120. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  121. RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  122. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  123. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  124. RCC_OscInitStruct.PLL.PLLM = 4;
  125. RCC_OscInitStruct.PLL.PLLN = 160;
  126. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  127. RCC_OscInitStruct.PLL.PLLQ = 2;
  128. RCC_OscInitStruct.PLL.PLLR = 2;
  129. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  130. {
  131. Error_Handler();
  132. }
  133. /** Initializes the CPU, AHB and APB buses clocks
  134. */
  135. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  136. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  137. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  138. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  139. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  140. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  141. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  142. {
  143. Error_Handler();
  144. }
  145. }
  146. /**
  147. * @brief ADC1 Initialization Function
  148. * @param None
  149. * @retval None
  150. */
  151. static void MX_ADC1_Init(void)
  152. {
  153. /* USER CODE BEGIN ADC1_Init 0 */
  154. /* USER CODE END ADC1_Init 0 */
  155. ADC_ChannelConfTypeDef sConfig = {0};
  156. /* USER CODE BEGIN ADC1_Init 1 */
  157. /* USER CODE END ADC1_Init 1 */
  158. /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  159. */
  160. hadc1.Instance = ADC1;
  161. hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  162. hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  163. hadc1.Init.ScanConvMode = DISABLE;
  164. hadc1.Init.ContinuousConvMode = DISABLE;
  165. hadc1.Init.DiscontinuousConvMode = DISABLE;
  166. hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  167. hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  168. hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  169. hadc1.Init.NbrOfConversion = 1;
  170. hadc1.Init.DMAContinuousRequests = DISABLE;
  171. hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  172. if (HAL_ADC_Init(&hadc1) != HAL_OK)
  173. {
  174. Error_Handler();
  175. }
  176. /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  177. */
  178. sConfig.Channel = ADC_CHANNEL_VREFINT;
  179. sConfig.Rank = 1;
  180. sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  181. if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  182. {
  183. Error_Handler();
  184. }
  185. /* USER CODE BEGIN ADC1_Init 2 */
  186. /* USER CODE END ADC1_Init 2 */
  187. }
  188. /**
  189. * @brief ADC2 Initialization Function
  190. * @param None
  191. * @retval None
  192. */
  193. static void MX_ADC2_Init(void)
  194. {
  195. /* USER CODE BEGIN ADC2_Init 0 */
  196. /* USER CODE END ADC2_Init 0 */
  197. ADC_ChannelConfTypeDef sConfig = {0};
  198. /* USER CODE BEGIN ADC2_Init 1 */
  199. /* USER CODE END ADC2_Init 1 */
  200. /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  201. */
  202. hadc2.Instance = ADC2;
  203. hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  204. hadc2.Init.Resolution = ADC_RESOLUTION_12B;
  205. hadc2.Init.ScanConvMode = DISABLE;
  206. hadc2.Init.ContinuousConvMode = DISABLE;
  207. hadc2.Init.DiscontinuousConvMode = DISABLE;
  208. hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  209. hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  210. hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  211. hadc2.Init.NbrOfConversion = 1;
  212. hadc2.Init.DMAContinuousRequests = DISABLE;
  213. hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  214. if (HAL_ADC_Init(&hadc2) != HAL_OK)
  215. {
  216. Error_Handler();
  217. }
  218. /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  219. */
  220. sConfig.Channel = ADC_CHANNEL_14;
  221. sConfig.Rank = 1;
  222. sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  223. if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
  224. {
  225. Error_Handler();
  226. }
  227. /* USER CODE BEGIN ADC2_Init 2 */
  228. /* USER CODE END ADC2_Init 2 */
  229. }
  230. /**
  231. * @brief DAC Initialization Function
  232. * @param None
  233. * @retval None
  234. */
  235. static void MX_DAC_Init(void)
  236. {
  237. /* USER CODE BEGIN DAC_Init 0 */
  238. /* USER CODE END DAC_Init 0 */
  239. DAC_ChannelConfTypeDef sConfig = {0};
  240. /* USER CODE BEGIN DAC_Init 1 */
  241. /* USER CODE END DAC_Init 1 */
  242. /** DAC Initialization
  243. */
  244. hdac.Instance = DAC;
  245. if (HAL_DAC_Init(&hdac) != HAL_OK)
  246. {
  247. Error_Handler();
  248. }
  249. /** DAC channel OUT1 config
  250. */
  251. sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
  252. sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
  253. if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK)
  254. {
  255. Error_Handler();
  256. }
  257. /** DAC channel OUT2 config
  258. */
  259. if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_2) != HAL_OK)
  260. {
  261. Error_Handler();
  262. }
  263. /* USER CODE BEGIN DAC_Init 2 */
  264. /* USER CODE END DAC_Init 2 */
  265. }
  266. /**
  267. * @brief I2C1 Initialization Function
  268. * @param None
  269. * @retval None
  270. */
  271. static void MX_I2C1_SMBUS_Init(void)
  272. {
  273. /* USER CODE BEGIN I2C1_Init 0 */
  274. /* USER CODE END I2C1_Init 0 */
  275. /* USER CODE BEGIN I2C1_Init 1 */
  276. /* USER CODE END I2C1_Init 1 */
  277. hsmbus1.Instance = I2C1;
  278. hsmbus1.Init.ClockSpeed = 100000;
  279. hsmbus1.Init.OwnAddress1 = 0;
  280. hsmbus1.Init.AddressingMode = SMBUS_ADDRESSINGMODE_7BIT;
  281. hsmbus1.Init.DualAddressMode = SMBUS_DUALADDRESS_DISABLE;
  282. hsmbus1.Init.OwnAddress2 = 0;
  283. hsmbus1.Init.GeneralCallMode = SMBUS_GENERALCALL_DISABLE;
  284. hsmbus1.Init.NoStretchMode = SMBUS_NOSTRETCH_DISABLE;
  285. hsmbus1.Init.PacketErrorCheckMode = SMBUS_PEC_DISABLE;
  286. hsmbus1.Init.PeripheralMode = SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE;
  287. if (HAL_SMBUS_Init(&hsmbus1) != HAL_OK)
  288. {
  289. Error_Handler();
  290. }
  291. /* USER CODE BEGIN I2C1_Init 2 */
  292. /* USER CODE END I2C1_Init 2 */
  293. }
  294. /**
  295. * @brief RTC Initialization Function
  296. * @param None
  297. * @retval None
  298. */
  299. static void MX_RTC_Init(void)
  300. {
  301. /* USER CODE BEGIN RTC_Init 0 */
  302. /* USER CODE END RTC_Init 0 */
  303. RTC_TimeTypeDef sTime = {0};
  304. RTC_DateTypeDef sDate = {0};
  305. /* USER CODE BEGIN RTC_Init 1 */
  306. /* USER CODE END RTC_Init 1 */
  307. /** Initialize RTC Only
  308. */
  309. hrtc.Instance = RTC;
  310. hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  311. hrtc.Init.AsynchPrediv = 127;
  312. hrtc.Init.SynchPrediv = 255;
  313. hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  314. hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  315. hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  316. if (HAL_RTC_Init(&hrtc) != HAL_OK)
  317. {
  318. Error_Handler();
  319. }
  320. /* USER CODE BEGIN Check_RTC_BKUP */
  321. /* USER CODE END Check_RTC_BKUP */
  322. /** Initialize RTC and set the Time and Date
  323. */
  324. sTime.Hours = 0x0;
  325. sTime.Minutes = 0x0;
  326. sTime.Seconds = 0x0;
  327. sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  328. sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  329. if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
  330. {
  331. Error_Handler();
  332. }
  333. sDate.WeekDay = RTC_WEEKDAY_MONDAY;
  334. sDate.Month = RTC_MONTH_JANUARY;
  335. sDate.Date = 0x1;
  336. sDate.Year = 0x0;
  337. if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
  338. {
  339. Error_Handler();
  340. }
  341. /* USER CODE BEGIN RTC_Init 2 */
  342. /* USER CODE END RTC_Init 2 */
  343. }
  344. /**
  345. * @brief SPI1 Initialization Function
  346. * @param None
  347. * @retval None
  348. */
  349. static void MX_SPI1_Init(void)
  350. {
  351. /* USER CODE BEGIN SPI1_Init 0 */
  352. /* USER CODE END SPI1_Init 0 */
  353. /* USER CODE BEGIN SPI1_Init 1 */
  354. /* USER CODE END SPI1_Init 1 */
  355. /* SPI1 parameter configuration*/
  356. hspi1.Instance = SPI1;
  357. hspi1.Init.Mode = SPI_MODE_MASTER;
  358. hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  359. hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  360. hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  361. hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  362. hspi1.Init.NSS = SPI_NSS_SOFT;
  363. hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  364. hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  365. hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  366. hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  367. hspi1.Init.CRCPolynomial = 10;
  368. if (HAL_SPI_Init(&hspi1) != HAL_OK)
  369. {
  370. Error_Handler();
  371. }
  372. /* USER CODE BEGIN SPI1_Init 2 */
  373. /* USER CODE END SPI1_Init 2 */
  374. }
  375. /**
  376. * @brief SPI2 Initialization Function
  377. * @param None
  378. * @retval None
  379. */
  380. static void MX_SPI2_Init(void)
  381. {
  382. /* USER CODE BEGIN SPI2_Init 0 */
  383. /* USER CODE END SPI2_Init 0 */
  384. /* USER CODE BEGIN SPI2_Init 1 */
  385. /* USER CODE END SPI2_Init 1 */
  386. /* SPI2 parameter configuration*/
  387. hspi2.Instance = SPI2;
  388. hspi2.Init.Mode = SPI_MODE_MASTER;
  389. hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  390. hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  391. hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  392. hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  393. hspi2.Init.NSS = SPI_NSS_SOFT;
  394. hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  395. hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  396. hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  397. hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  398. hspi2.Init.CRCPolynomial = 10;
  399. if (HAL_SPI_Init(&hspi2) != HAL_OK)
  400. {
  401. Error_Handler();
  402. }
  403. /* USER CODE BEGIN SPI2_Init 2 */
  404. /* USER CODE END SPI2_Init 2 */
  405. }
  406. /**
  407. * @brief TIM2 Initialization Function
  408. * @param None
  409. * @retval None
  410. */
  411. static void MX_TIM2_Init(void)
  412. {
  413. /* USER CODE BEGIN TIM2_Init 0 */
  414. /* USER CODE END TIM2_Init 0 */
  415. TIM_SlaveConfigTypeDef sSlaveConfig = {0};
  416. TIM_MasterConfigTypeDef sMasterConfig = {0};
  417. /* USER CODE BEGIN TIM2_Init 1 */
  418. /* USER CODE END TIM2_Init 1 */
  419. htim2.Instance = TIM2;
  420. htim2.Init.Prescaler = 0;
  421. htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  422. htim2.Init.Period = 4294967295;
  423. htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  424. htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  425. if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  426. {
  427. Error_Handler();
  428. }
  429. sSlaveConfig.SlaveMode = TIM_SLAVEMODE_EXTERNAL1;
  430. sSlaveConfig.InputTrigger = TIM_TS_ETRF;
  431. sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_NONINVERTED;
  432. sSlaveConfig.TriggerPrescaler = TIM_TRIGGERPRESCALER_DIV1;
  433. sSlaveConfig.TriggerFilter = 0;
  434. if (HAL_TIM_SlaveConfigSynchro(&htim2, &sSlaveConfig) != HAL_OK)
  435. {
  436. Error_Handler();
  437. }
  438. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  439. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  440. if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  441. {
  442. Error_Handler();
  443. }
  444. /* USER CODE BEGIN TIM2_Init 2 */
  445. /* USER CODE END TIM2_Init 2 */
  446. }
  447. /**
  448. * @brief USART1 Initialization Function
  449. * @param None
  450. * @retval None
  451. */
  452. static void MX_USART1_UART_Init(void)
  453. {
  454. /* USER CODE BEGIN USART1_Init 0 */
  455. /* USER CODE END USART1_Init 0 */
  456. /* USER CODE BEGIN USART1_Init 1 */
  457. /* USER CODE END USART1_Init 1 */
  458. huart1.Instance = USART1;
  459. huart1.Init.BaudRate = 115200;
  460. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  461. huart1.Init.StopBits = UART_STOPBITS_1;
  462. huart1.Init.Parity = UART_PARITY_NONE;
  463. huart1.Init.Mode = UART_MODE_TX_RX;
  464. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  465. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  466. if (HAL_UART_Init(&huart1) != HAL_OK)
  467. {
  468. Error_Handler();
  469. }
  470. /* USER CODE BEGIN USART1_Init 2 */
  471. /* USER CODE END USART1_Init 2 */
  472. }
  473. /**
  474. * @brief GPIO Initialization Function
  475. * @param None
  476. * @retval None
  477. */
  478. static void MX_GPIO_Init(void)
  479. {
  480. GPIO_InitTypeDef GPIO_InitStruct = {0};
  481. /* GPIO Ports Clock Enable */
  482. __HAL_RCC_GPIOC_CLK_ENABLE();
  483. __HAL_RCC_GPIOH_CLK_ENABLE();
  484. __HAL_RCC_GPIOA_CLK_ENABLE();
  485. __HAL_RCC_GPIOB_CLK_ENABLE();
  486. __HAL_RCC_GPIOD_CLK_ENABLE();
  487. /*Configure GPIO pin Output Level */
  488. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3
  489. |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET);
  490. /*Configure GPIO pin Output Level */
  491. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10|GPIO_PIN_12
  492. |GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
  493. /*Configure GPIO pin Output Level */
  494. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
  495. /*Configure GPIO pin Output Level */
  496. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
  497. /*Configure GPIO pins : PC13 PC0 PC1 PC3
  498. PC10 PC11 PC12 */
  499. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3
  500. |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
  501. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  502. GPIO_InitStruct.Pull = GPIO_NOPULL;
  503. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  504. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  505. /*Configure GPIO pins : PC2 PC6 PC7 PC8
  506. PC9 */
  507. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
  508. |GPIO_PIN_9;
  509. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  510. GPIO_InitStruct.Pull = GPIO_NOPULL;
  511. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  512. /*Configure GPIO pin : PA1 */
  513. GPIO_InitStruct.Pin = GPIO_PIN_1;
  514. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  515. GPIO_InitStruct.Pull = GPIO_NOPULL;
  516. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  517. /*Configure GPIO pins : PB1 PB2 PB10 PB12
  518. PB6 PB7 */
  519. GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10|GPIO_PIN_12
  520. |GPIO_PIN_6|GPIO_PIN_7;
  521. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  522. GPIO_InitStruct.Pull = GPIO_NOPULL;
  523. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  524. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  525. /*Configure GPIO pin : PA8 */
  526. GPIO_InitStruct.Pin = GPIO_PIN_8;
  527. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  528. GPIO_InitStruct.Pull = GPIO_NOPULL;
  529. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  530. /*Configure GPIO pin : PA15 */
  531. GPIO_InitStruct.Pin = GPIO_PIN_15;
  532. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  533. GPIO_InitStruct.Pull = GPIO_NOPULL;
  534. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  535. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  536. /*Configure GPIO pin : PD2 */
  537. GPIO_InitStruct.Pin = GPIO_PIN_2;
  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(GPIOD, &GPIO_InitStruct);
  542. }
  543. /* USER CODE BEGIN 4 */
  544. /* USER CODE END 4 */
  545. /**
  546. * @brief This function is executed in case of error occurrence.
  547. * @retval None
  548. */
  549. void Error_Handler(void)
  550. {
  551. /* USER CODE BEGIN Error_Handler_Debug */
  552. /* User can add his own implementation to report the HAL error return state */
  553. __disable_irq();
  554. while (1)
  555. {
  556. }
  557. /* USER CODE END Error_Handler_Debug */
  558. }
  559. #ifdef USE_FULL_ASSERT
  560. /**
  561. * @brief Reports the name of the source file and the source line number
  562. * where the assert_param error has occurred.
  563. * @param file: pointer to the source file name
  564. * @param line: assert_param error line source number
  565. * @retval None
  566. */
  567. void assert_failed(uint8_t *file, uint32_t line)
  568. {
  569. /* USER CODE BEGIN 6 */
  570. /* User can add his own implementation to report the file name and line number,
  571. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  572. /* USER CODE END 6 */
  573. }
  574. #endif /* USE_FULL_ASSERT */
  575. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/