main.c 18 KB

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