main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2023 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. /* Private includes ----------------------------------------------------------*/
  22. /* USER CODE BEGIN Includes */
  23. #include "nbus_app.h"
  24. #if MODULE == MODULE_FSR
  25. #include "app_adc.h"
  26. #endif
  27. #if MODULE == MODULE_DUMMY
  28. #include "app_dummy.h"
  29. #endif
  30. #include "app_interface.h"
  31. /* USER CODE END Includes */
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* USER CODE BEGIN PTD */
  34. /* USER CODE END PTD */
  35. /* Private define ------------------------------------------------------------*/
  36. /* USER CODE BEGIN PD */
  37. /* USER CODE END PD */
  38. /* Private macro -------------------------------------------------------------*/
  39. /* USER CODE BEGIN PM */
  40. /* USER CODE END PM */
  41. /* Private variables ---------------------------------------------------------*/
  42. ADC_HandleTypeDef hadc;
  43. DMA_HandleTypeDef hdma_adc;
  44. TIM_HandleTypeDef htim21;
  45. TIM_HandleTypeDef htim22;
  46. UART_HandleTypeDef huart2;
  47. DMA_HandleTypeDef hdma_usart2_tx;
  48. /* USER CODE BEGIN PV */
  49. /* USER CODE END PV */
  50. /* Private function prototypes -----------------------------------------------*/
  51. void SystemClock_Config(void);
  52. static void MX_GPIO_Init(void);
  53. static void MX_DMA_Init(void);
  54. static void MX_USART2_UART_Init(void);
  55. static void MX_TIM22_Init(void);
  56. static void MX_TIM21_Init(void);
  57. static void MX_ADC_Init(void);
  58. /* USER CODE BEGIN PFP */
  59. /* USER CODE END PFP */
  60. /* Private user code ---------------------------------------------------------*/
  61. /* USER CODE BEGIN 0 */
  62. inline void uart_send(uint8_t *data, int n)
  63. {
  64. #if USE_USART_DMA_TX == 1
  65. HAL_UART_Transmit_DMA(&huart2, data, n);
  66. #else
  67. HAL_UART_Transmit(&huart2, data, n, 10);
  68. #endif
  69. }
  70. inline void led_on(){
  71. HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
  72. }
  73. inline void led_off(){
  74. HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
  75. }
  76. inline void led_toggle(){
  77. HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
  78. }
  79. inline void uart_receive_it(uint8_t *data, int n)
  80. {
  81. HAL_UART_Receive_IT(&huart2, data, n);
  82. }
  83. inline void uart_abort_receive(){
  84. HAL_UART_AbortReceive_IT(&huart2);
  85. }
  86. inline void timer_uart_start(int n){
  87. htim22.Instance->CNT = 1;
  88. htim22.Instance->ARR = 40*n + 400; // (10*n + 100)us
  89. HAL_TIM_Base_Start_IT(&htim22);
  90. }
  91. inline void timer_uart_stop(){
  92. HAL_TIM_Base_Stop_IT(&htim22);
  93. }
  94. static inline void nbus_app_UART_RX(UART_HandleTypeDef *huart){
  95. nbus_cb_UART_RX();
  96. }
  97. static inline void nbus_app_TIM_periodElapsed(TIM_HandleTypeDef *htim){
  98. nbus_cb_TIM_periodElapsed();
  99. }
  100. /* USER CODE END 0 */
  101. /**
  102. * @brief The application entry point.
  103. * @retval int
  104. */
  105. int main(void)
  106. {
  107. /* USER CODE BEGIN 1 */
  108. /* USER CODE END 1 */
  109. /* MCU Configuration--------------------------------------------------------*/
  110. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  111. HAL_Init();
  112. /* USER CODE BEGIN Init */
  113. /* USER CODE END Init */
  114. /* Configure the system clock */
  115. SystemClock_Config();
  116. /* USER CODE BEGIN SysInit */
  117. /* USER CODE END SysInit */
  118. /* Initialize all configured peripherals */
  119. MX_GPIO_Init();
  120. MX_DMA_Init();
  121. MX_USART2_UART_Init();
  122. MX_TIM22_Init();
  123. MX_TIM21_Init();
  124. /* USER CODE BEGIN 2 */
  125. #ifdef MODULE_INIT_IP_ADC
  126. MX_ADC_Init();
  127. #endif
  128. #ifdef MODULE_INIT_IP_SPI
  129. MX_SPI_Init();
  130. #endif
  131. #if MODULE_MASTER == 1
  132. MX_RTC_Init();
  133. #endif
  134. nBusPlatformInterface_t hw_platform ={
  135. uart_receive_it,
  136. uart_send,
  137. uart_abort_receive,
  138. led_on,
  139. led_off,
  140. led_toggle,
  141. timer_uart_start,
  142. timer_uart_stop
  143. };
  144. #if MODULE_MASTER == 1
  145. periph.rtc = &hrtc;
  146. #endif
  147. #if MODULE == MODULE_DUMMY
  148. nbus_init(getDummyDriver(), &hw_platform);
  149. nbus_init_app(NULL, NULL);
  150. #endif
  151. #if MODULE == MODULE_FSR
  152. nbus_init(getMcuAdcDriver(), &hw_platform);
  153. nbus_init_app(&hadc, NULL);
  154. #endif
  155. #if MODULE == MODULE_IMU
  156. nbus_init(getImuDriver(), &hw_platform);
  157. nbus_init_app(&hspi, NULL);
  158. #endif
  159. HAL_UART_RegisterCallback(&huart2, HAL_UART_RX_COMPLETE_CB_ID, nbus_app_UART_RX);
  160. HAL_TIM_RegisterCallback(&htim22, HAL_TIM_PERIOD_ELAPSED_CB_ID, nbus_app_TIM_periodElapsed);
  161. nBus_MemoryDriver memory_ec20 = {
  162. DS28EC20_init,
  163. DS28EC20_readData4B,
  164. DS28EC20_readData2B,
  165. DS28EC20_writeData4B,
  166. DS28EC20_writeData2B,
  167. DS28EC20_getId
  168. };
  169. memory_ec20.init(ONE_WIRE_GPIO_Port, ONE_WIRE_Pin);
  170. nbus_init_memory_driver(&memory_ec20,16);
  171. nbus_stack();
  172. /* USER CODE END 2 */
  173. /* Infinite loop */
  174. /* USER CODE BEGIN WHILE */
  175. while (1)
  176. {
  177. /* USER CODE END WHILE */
  178. /* USER CODE BEGIN 3 */
  179. }
  180. /* USER CODE END 3 */
  181. }
  182. /**
  183. * @brief System Clock Configuration
  184. * @retval None
  185. */
  186. void SystemClock_Config(void)
  187. {
  188. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  189. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  190. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  191. /** Configure the main internal regulator output voltage
  192. */
  193. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  194. /** Initializes the RCC Oscillators according to the specified parameters
  195. * in the RCC_OscInitTypeDef structure.
  196. */
  197. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  198. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  199. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  200. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  201. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  202. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6;
  203. RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3;
  204. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  205. {
  206. Error_Handler();
  207. }
  208. /** Initializes the CPU, AHB and APB buses clocks
  209. */
  210. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  211. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  212. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  213. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  214. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  215. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  216. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  217. {
  218. Error_Handler();
  219. }
  220. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
  221. PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  222. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  223. {
  224. Error_Handler();
  225. }
  226. }
  227. /**
  228. * @brief ADC Initialization Function
  229. * @param None
  230. * @retval None
  231. */
  232. static void MX_ADC_Init(void)
  233. {
  234. /* USER CODE BEGIN ADC_Init 0 */
  235. /* USER CODE END ADC_Init 0 */
  236. ADC_ChannelConfTypeDef sConfig = {0};
  237. /* USER CODE BEGIN ADC_Init 1 */
  238. /* USER CODE END ADC_Init 1 */
  239. /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  240. */
  241. hadc.Instance = ADC1;
  242. hadc.Init.OversamplingMode = DISABLE;
  243. hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
  244. hadc.Init.Resolution = ADC_RESOLUTION_12B;
  245. hadc.Init.SamplingTime = ADC_SAMPLETIME_79CYCLES_5;
  246. hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  247. hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  248. hadc.Init.ContinuousConvMode = ENABLE;
  249. hadc.Init.DiscontinuousConvMode = DISABLE;
  250. hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  251. hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  252. hadc.Init.DMAContinuousRequests = ENABLE;
  253. hadc.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  254. hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  255. hadc.Init.LowPowerAutoWait = DISABLE;
  256. hadc.Init.LowPowerFrequencyMode = DISABLE;
  257. hadc.Init.LowPowerAutoPowerOff = DISABLE;
  258. if (HAL_ADC_Init(&hadc) != HAL_OK)
  259. {
  260. Error_Handler();
  261. }
  262. /** Configure for the selected ADC regular channel to be converted.
  263. */
  264. sConfig.Channel = ADC_CHANNEL_0;
  265. sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  266. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  267. {
  268. Error_Handler();
  269. }
  270. /** Configure for the selected ADC regular channel to be converted.
  271. */
  272. sConfig.Channel = ADC_CHANNEL_1;
  273. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  274. {
  275. Error_Handler();
  276. }
  277. /** Configure for the selected ADC regular channel to be converted.
  278. */
  279. sConfig.Channel = ADC_CHANNEL_2;
  280. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  281. {
  282. Error_Handler();
  283. }
  284. /** Configure for the selected ADC regular channel to be converted.
  285. */
  286. sConfig.Channel = ADC_CHANNEL_3;
  287. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  288. {
  289. Error_Handler();
  290. }
  291. /** Configure for the selected ADC regular channel to be converted.
  292. */
  293. sConfig.Channel = ADC_CHANNEL_4;
  294. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  295. {
  296. Error_Handler();
  297. }
  298. /** Configure for the selected ADC regular channel to be converted.
  299. */
  300. sConfig.Channel = ADC_CHANNEL_6;
  301. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  302. {
  303. Error_Handler();
  304. }
  305. /** Configure for the selected ADC regular channel to be converted.
  306. */
  307. sConfig.Channel = ADC_CHANNEL_7;
  308. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  309. {
  310. Error_Handler();
  311. }
  312. /** Configure for the selected ADC regular channel to be converted.
  313. */
  314. sConfig.Channel = ADC_CHANNEL_8;
  315. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  316. {
  317. Error_Handler();
  318. }
  319. /* USER CODE BEGIN ADC_Init 2 */
  320. /* USER CODE END ADC_Init 2 */
  321. }
  322. /**
  323. * @brief TIM21 Initialization Function
  324. * @param None
  325. * @retval None
  326. */
  327. static void MX_TIM21_Init(void)
  328. {
  329. /* USER CODE BEGIN TIM21_Init 0 */
  330. /* USER CODE END TIM21_Init 0 */
  331. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  332. TIM_MasterConfigTypeDef sMasterConfig = {0};
  333. /* USER CODE BEGIN TIM21_Init 1 */
  334. /* USER CODE END TIM21_Init 1 */
  335. htim21.Instance = TIM21;
  336. htim21.Init.Prescaler = 32000;
  337. htim21.Init.CounterMode = TIM_COUNTERMODE_UP;
  338. htim21.Init.Period = 100;
  339. htim21.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  340. htim21.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  341. if (HAL_TIM_Base_Init(&htim21) != HAL_OK)
  342. {
  343. Error_Handler();
  344. }
  345. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  346. if (HAL_TIM_ConfigClockSource(&htim21, &sClockSourceConfig) != HAL_OK)
  347. {
  348. Error_Handler();
  349. }
  350. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  351. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  352. if (HAL_TIMEx_MasterConfigSynchronization(&htim21, &sMasterConfig) != HAL_OK)
  353. {
  354. Error_Handler();
  355. }
  356. /* USER CODE BEGIN TIM21_Init 2 */
  357. /* USER CODE END TIM21_Init 2 */
  358. }
  359. /**
  360. * @brief TIM22 Initialization Function
  361. * @param None
  362. * @retval None
  363. */
  364. static void MX_TIM22_Init(void)
  365. {
  366. /* USER CODE BEGIN TIM22_Init 0 */
  367. /* USER CODE END TIM22_Init 0 */
  368. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  369. TIM_MasterConfigTypeDef sMasterConfig = {0};
  370. /* USER CODE BEGIN TIM22_Init 1 */
  371. /* USER CODE END TIM22_Init 1 */
  372. htim22.Instance = TIM22;
  373. htim22.Init.Prescaler = UART_TIMER_PRESCALER;
  374. htim22.Init.CounterMode = TIM_COUNTERMODE_UP;
  375. htim22.Init.Period = 65535;
  376. htim22.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  377. htim22.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  378. if (HAL_TIM_Base_Init(&htim22) != HAL_OK)
  379. {
  380. Error_Handler();
  381. }
  382. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  383. if (HAL_TIM_ConfigClockSource(&htim22, &sClockSourceConfig) != HAL_OK)
  384. {
  385. Error_Handler();
  386. }
  387. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  388. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  389. if (HAL_TIMEx_MasterConfigSynchronization(&htim22, &sMasterConfig) != HAL_OK)
  390. {
  391. Error_Handler();
  392. }
  393. /* USER CODE BEGIN TIM22_Init 2 */
  394. /* USER CODE END TIM22_Init 2 */
  395. }
  396. /**
  397. * @brief USART2 Initialization Function
  398. * @param None
  399. * @retval None
  400. */
  401. static void MX_USART2_UART_Init(void)
  402. {
  403. /* USER CODE BEGIN USART2_Init 0 */
  404. /* USER CODE END USART2_Init 0 */
  405. /* USER CODE BEGIN USART2_Init 1 */
  406. /* USER CODE END USART2_Init 1 */
  407. huart2.Instance = USART2;
  408. huart2.Init.BaudRate = UART_BAUDRATE;
  409. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  410. huart2.Init.StopBits = UART_STOPBITS_1;
  411. huart2.Init.Parity = UART_PARITY_NONE;
  412. huart2.Init.Mode = UART_MODE_TX_RX;
  413. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  414. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  415. huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  416. huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  417. if (HAL_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
  418. {
  419. Error_Handler();
  420. }
  421. /* USER CODE BEGIN USART2_Init 2 */
  422. /* USER CODE END USART2_Init 2 */
  423. }
  424. /**
  425. * Enable DMA controller clock
  426. */
  427. static void MX_DMA_Init(void)
  428. {
  429. /* DMA controller clock enable */
  430. __HAL_RCC_DMA1_CLK_ENABLE();
  431. /* DMA interrupt init */
  432. /* DMA1_Channel1_IRQn interrupt configuration */
  433. HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  434. HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  435. /* DMA1_Channel4_5_6_7_IRQn interrupt configuration */
  436. HAL_NVIC_SetPriority(DMA1_Channel4_5_6_7_IRQn, 0, 0);
  437. HAL_NVIC_EnableIRQ(DMA1_Channel4_5_6_7_IRQn);
  438. }
  439. /**
  440. * @brief GPIO Initialization Function
  441. * @param None
  442. * @retval None
  443. */
  444. static void MX_GPIO_Init(void)
  445. {
  446. GPIO_InitTypeDef GPIO_InitStruct = {0};
  447. /* USER CODE BEGIN MX_GPIO_Init_1 */
  448. /* USER CODE END MX_GPIO_Init_1 */
  449. /* GPIO Ports Clock Enable */
  450. __HAL_RCC_GPIOC_CLK_ENABLE();
  451. __HAL_RCC_GPIOA_CLK_ENABLE();
  452. __HAL_RCC_GPIOB_CLK_ENABLE();
  453. /*Configure GPIO pin Output Level */
  454. HAL_GPIO_WritePin(SPI_SS_GPIO_Port, SPI_SS_Pin, GPIO_PIN_SET);
  455. /*Configure GPIO pin Output Level */
  456. HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
  457. /*Configure GPIO pin Output Level */
  458. HAL_GPIO_WritePin(ONE_WIRE_GPIO_Port, ONE_WIRE_Pin, GPIO_PIN_SET);
  459. /*Configure GPIO pins : PA5 PA11 */
  460. GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_11;
  461. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  462. GPIO_InitStruct.Pull = GPIO_NOPULL;
  463. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  464. GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
  465. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  466. /*Configure GPIO pin : PB1 */
  467. GPIO_InitStruct.Pin = GPIO_PIN_1;
  468. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  469. GPIO_InitStruct.Pull = GPIO_NOPULL;
  470. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  471. GPIO_InitStruct.Alternate = GPIO_AF1_SPI1;
  472. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  473. /*Configure GPIO pin : SPI_SS_Pin */
  474. GPIO_InitStruct.Pin = SPI_SS_Pin;
  475. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  476. GPIO_InitStruct.Pull = GPIO_PULLUP;
  477. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  478. HAL_GPIO_Init(SPI_SS_GPIO_Port, &GPIO_InitStruct);
  479. /*Configure GPIO pin : LD3_Pin */
  480. GPIO_InitStruct.Pin = LD3_Pin;
  481. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  482. GPIO_InitStruct.Pull = GPIO_NOPULL;
  483. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  484. HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct);
  485. /*Configure GPIO pin : ONE_WIRE_Pin */
  486. GPIO_InitStruct.Pin = ONE_WIRE_Pin;
  487. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  488. GPIO_InitStruct.Pull = GPIO_PULLUP;
  489. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
  490. HAL_GPIO_Init(ONE_WIRE_GPIO_Port, &GPIO_InitStruct);
  491. /*Configure GPIO pins : PB6 PB7 */
  492. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  493. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  494. GPIO_InitStruct.Pull = GPIO_NOPULL;
  495. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  496. GPIO_InitStruct.Alternate = GPIO_AF1_I2C1;
  497. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  498. /* USER CODE BEGIN MX_GPIO_Init_2 */
  499. /* USER CODE END MX_GPIO_Init_2 */
  500. }
  501. /* USER CODE BEGIN 4 */
  502. /* USER CODE END 4 */
  503. /**
  504. * @brief This function is executed in case of error occurrence.
  505. * @retval None
  506. */
  507. void Error_Handler(void)
  508. {
  509. /* USER CODE BEGIN Error_Handler_Debug */
  510. /* User can add his own implementation to report the HAL error return state */
  511. __disable_irq();
  512. while (1)
  513. {
  514. }
  515. /* USER CODE END Error_Handler_Debug */
  516. }
  517. #ifdef USE_FULL_ASSERT
  518. /**
  519. * @brief Reports the name of the source file and the source line number
  520. * where the assert_param error has occurred.
  521. * @param file: pointer to the source file name
  522. * @param line: assert_param error line source number
  523. * @retval None
  524. */
  525. void assert_failed(uint8_t *file, uint32_t line)
  526. {
  527. /* USER CODE BEGIN 6 */
  528. /* User can add his own implementation to report the file name and line number,
  529. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  530. /* USER CODE END 6 */
  531. }
  532. #endif /* USE_FULL_ASSERT */