main.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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. #include "memory_ec20.h"
  25. #if MODULE == MODULE_FSR
  26. #include "app_adc.h"
  27. #endif
  28. #if MODULE == MODULE_DUMMY
  29. #include "app_dummy.h"
  30. #endif
  31. #if MODULE == MODULE_IMU
  32. #include "app_dummy.h"
  33. #include "app_imu.h"
  34. #endif
  35. #include "app_interface.h"
  36. /* USER CODE END Includes */
  37. /* Private typedef -----------------------------------------------------------*/
  38. /* USER CODE BEGIN PTD */
  39. /* USER CODE END PTD */
  40. /* Private define ------------------------------------------------------------*/
  41. /* USER CODE BEGIN PD */
  42. /* USER CODE END PD */
  43. /* Private macro -------------------------------------------------------------*/
  44. /* USER CODE BEGIN PM */
  45. /* USER CODE END PM */
  46. /* Private variables ---------------------------------------------------------*/
  47. ADC_HandleTypeDef hadc;
  48. DMA_HandleTypeDef hdma_adc;
  49. SPI_HandleTypeDef hspi1;
  50. TIM_HandleTypeDef htim21;
  51. UART_HandleTypeDef huart2;
  52. DMA_HandleTypeDef hdma_usart2_tx;
  53. DMA_HandleTypeDef hdma_usart2_rx;
  54. /* USER CODE BEGIN PV */
  55. /* USER CODE END PV */
  56. /* Private function prototypes -----------------------------------------------*/
  57. void SystemClock_Config(void);
  58. static void MX_GPIO_Init(void);
  59. static void MX_DMA_Init(void);
  60. static void MX_USART2_UART_Init(void);
  61. static void MX_TIM21_Init(void);
  62. static void MX_ADC_Init(void);
  63. static void MX_SPI1_Init(void);
  64. /* USER CODE BEGIN PFP */
  65. /* USER CODE END PFP */
  66. /* Private user code ---------------------------------------------------------*/
  67. /* USER CODE BEGIN 0 */
  68. #define MAX_SYSTICK 0xFFFFFFFF;
  69. uint8_t data[64]; // tmp read buffer
  70. uint8_t *dataUART; // pointee for rx_buffer
  71. volatile uint8_t dataL;
  72. volatile uint8_t dataI;
  73. volatile uint32_t uart_timeout = MAX_SYSTICK;
  74. #if MODULE == MODULE_IMU
  75. volatile uint8_t icm_data_ready = 0;
  76. #endif
  77. inline void uart_send(uint8_t *data, int n)
  78. {
  79. #if USE_USART_DMA_TX == 1
  80. HAL_UART_Transmit_DMA(&huart2, data, n);
  81. #else
  82. HAL_UART_Transmit(&huart2, data, n, 10);
  83. #endif
  84. }
  85. inline void uart_receive(uint8_t *dataNBUS, int n)
  86. {
  87. dataUART = dataNBUS;
  88. dataL = 0;
  89. dataI = 0;
  90. data[0] = 0;
  91. uart_timeout = HAL_GetTick();
  92. HAL_UARTEx_ReceiveToIdle_DMA(&huart2, data, n);
  93. }
  94. inline void led_on(){
  95. HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
  96. }
  97. inline void led_off(){
  98. HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
  99. }
  100. inline void led_toggle(){
  101. HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
  102. }
  103. inline void app_delay(uint8_t ms){
  104. HAL_Delay(ms);
  105. }
  106. static inline uint8_t loop_callback(nBusStateCallbackType_t state_check) {
  107. // traba kontrolovat kazdu stav (state_check) zvmlast. Moznost doplnit dalsie kontroly
  108. if (state_check == CallbackType_SENSOR) {
  109. #if MODULE == MODULE_IMU
  110. if(icm_data_ready == 1){
  111. icm_data_ready = 0;
  112. return 1; // interrupt from external sensor: data ready
  113. }
  114. #endif
  115. return 0;
  116. }
  117. if (state_check == CallbackType_UART) {
  118. // timemout: 1 - 2 ms
  119. if(HAL_GetTick() - 1 > uart_timeout) {
  120. dataL = 0;
  121. dataI = 0;
  122. data[0] = 0;
  123. uart_timeout = MAX_SYSTICK;
  124. led_off();
  125. HAL_UARTEx_ReceiveToIdle_DMA(&huart2, data, 64);
  126. return 1; // UART receive timeout
  127. }
  128. return 0;
  129. }
  130. return 0;
  131. }
  132. // Application callbacks
  133. void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
  134. HAL_UARTEx_ReceiveToIdle_DMA(huart, data, 64);
  135. uint8_t copy_offset = 0;
  136. if (dataL == 0) {
  137. uart_timeout = HAL_GetTick();
  138. dataL = data[0];
  139. dataI = 0;
  140. led_on();
  141. if (Size == 1) {
  142. return;
  143. }
  144. Size--;
  145. copy_offset = 1;
  146. }
  147. memcpy(&dataUART[dataI], &data[copy_offset], Size);
  148. dataI += Size;
  149. if(dataI >= dataL){
  150. led_off();
  151. nbus_cb_UART_RX(dataI);
  152. dataL=0;
  153. dataI=0;
  154. data[0]=0;
  155. uart_timeout = MAX_SYSTICK;
  156. }
  157. }
  158. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
  159. #if MODULE == MODULE_IMU
  160. icm_data_ready = 1;
  161. #endif
  162. }
  163. /* USER CODE END 0 */
  164. /**
  165. * @brief The application entry point.
  166. * @retval int
  167. */
  168. int main(void)
  169. {
  170. /* USER CODE BEGIN 1 */
  171. /* USER CODE END 1 */
  172. /* MCU Configuration--------------------------------------------------------*/
  173. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  174. HAL_Init();
  175. /* USER CODE BEGIN Init */
  176. /* USER CODE END Init */
  177. /* Configure the system clock */
  178. SystemClock_Config();
  179. /* USER CODE BEGIN SysInit */
  180. /* USER CODE END SysInit */
  181. /* Initialize all configured peripherals */
  182. MX_GPIO_Init();
  183. MX_DMA_Init();
  184. MX_USART2_UART_Init();
  185. MX_TIM21_Init();
  186. MX_SPI1_Init();
  187. /* USER CODE BEGIN 2 */
  188. dataI=0;
  189. dataL=0;
  190. #ifdef MODULE_INIT_IP_ADC
  191. MX_ADC_Init();
  192. #endif
  193. #ifdef MODULE_INIT_IP_SPI
  194. MX_SPI1_Init();
  195. #endif
  196. #if MODULE_MASTER == 1
  197. MX_RTC_Init();
  198. #endif
  199. nBusPlatformInterface_t hw_platform = {
  200. uart_receive,
  201. uart_send,
  202. led_on,
  203. led_off,
  204. led_toggle,
  205. app_delay,
  206. loop_callback,
  207. };
  208. #if MODULE_MASTER == 1
  209. periph.rtc = &hrtc;
  210. #endif
  211. //HAL_UARTEx_ReceiveToIdle_DMA(&huart2, data, 64);
  212. #if MODULE == MODULE_DUMMY
  213. nbus_init(getDummyDriver(), &hw_platform);
  214. nbus_init_app(NULL, NULL);
  215. #endif
  216. #if MODULE == MODULE_FSR
  217. nbus_init(getMcuAdcDriver(), &hw_platform);
  218. nbus_init_app(&hadc, NULL);
  219. #endif
  220. #if MODULE == MODULE_IMU
  221. icm20948_Config config;
  222. McuPin_typeDef pinCS;
  223. pinCS.pin = SPI_SS_Pin;
  224. pinCS.port = SPI_SS_GPIO_Port;
  225. config.pinCS = &pinCS;
  226. config.gyro.low_pass_filter = GYRO_lpf_196_6Hz;
  227. config.gyro.sample_rate = GYRO_samplerate_281_3Hz;
  228. config.accel.low_pass_filter = ACCEL_lpf_246Hz;
  229. config.accel.sample_rate = ACCEL_samplerate_281_3Hz;
  230. config.int_source = interrupt_RAW_DATA_0_RDY_EN;
  231. config.mag.mode = mag_mode_power_down;
  232. nbus_init(getImuDriver(), &hw_platform);
  233. nbus_init_app(&hspi1, &config);
  234. #endif
  235. nBus_MemoryDriver memory_ec20 = {
  236. DS28EC20_init,
  237. DS28EC20_readData4B,
  238. DS28EC20_readData2B,
  239. DS28EC20_readData1B,
  240. DS28EC20_writeData,
  241. DS28EC20_getId,
  242. DS28EC20_getCapacity
  243. };
  244. memory_ec20.init(ONE_WIRE_GPIO_Port, ONE_WIRE_Pin);
  245. nbus_init_memory_driver(&memory_ec20);
  246. nbus_stack();
  247. /* USER CODE END 2 */
  248. /* Infinite loop */
  249. /* USER CODE BEGIN WHILE */
  250. while (1)
  251. {
  252. /* USER CODE END WHILE */
  253. /* USER CODE BEGIN 3 */
  254. }
  255. /* USER CODE END 3 */
  256. }
  257. /**
  258. * @brief System Clock Configuration
  259. * @retval None
  260. */
  261. void SystemClock_Config(void)
  262. {
  263. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  264. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  265. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  266. /** Configure the main internal regulator output voltage
  267. */
  268. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  269. /** Initializes the RCC Oscillators according to the specified parameters
  270. * in the RCC_OscInitTypeDef structure.
  271. */
  272. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  273. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  274. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  275. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  276. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  277. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6;
  278. RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3;
  279. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  280. {
  281. Error_Handler();
  282. }
  283. /** Initializes the CPU, AHB and APB buses clocks
  284. */
  285. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  286. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  287. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  288. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  289. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  290. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  291. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  292. {
  293. Error_Handler();
  294. }
  295. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
  296. PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  297. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  298. {
  299. Error_Handler();
  300. }
  301. }
  302. /**
  303. * @brief ADC Initialization Function
  304. * @param None
  305. * @retval None
  306. */
  307. static void MX_ADC_Init(void)
  308. {
  309. /* USER CODE BEGIN ADC_Init 0 */
  310. /* USER CODE END ADC_Init 0 */
  311. ADC_ChannelConfTypeDef sConfig = {0};
  312. /* USER CODE BEGIN ADC_Init 1 */
  313. /* USER CODE END ADC_Init 1 */
  314. /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  315. */
  316. hadc.Instance = ADC1;
  317. hadc.Init.OversamplingMode = DISABLE;
  318. hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
  319. hadc.Init.Resolution = ADC_RESOLUTION_12B;
  320. hadc.Init.SamplingTime = ADC_SAMPLETIME_79CYCLES_5;
  321. hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  322. hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  323. hadc.Init.ContinuousConvMode = ENABLE;
  324. hadc.Init.DiscontinuousConvMode = DISABLE;
  325. hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  326. hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  327. hadc.Init.DMAContinuousRequests = ENABLE;
  328. hadc.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  329. hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  330. hadc.Init.LowPowerAutoWait = DISABLE;
  331. hadc.Init.LowPowerFrequencyMode = DISABLE;
  332. hadc.Init.LowPowerAutoPowerOff = DISABLE;
  333. if (HAL_ADC_Init(&hadc) != HAL_OK)
  334. {
  335. Error_Handler();
  336. }
  337. /** Configure for the selected ADC regular channel to be converted.
  338. */
  339. sConfig.Channel = ADC_CHANNEL_0;
  340. sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  341. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  342. {
  343. Error_Handler();
  344. }
  345. /** Configure for the selected ADC regular channel to be converted.
  346. */
  347. sConfig.Channel = ADC_CHANNEL_1;
  348. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  349. {
  350. Error_Handler();
  351. }
  352. /** Configure for the selected ADC regular channel to be converted.
  353. */
  354. sConfig.Channel = ADC_CHANNEL_2;
  355. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  356. {
  357. Error_Handler();
  358. }
  359. /** Configure for the selected ADC regular channel to be converted.
  360. */
  361. sConfig.Channel = ADC_CHANNEL_3;
  362. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  363. {
  364. Error_Handler();
  365. }
  366. /** Configure for the selected ADC regular channel to be converted.
  367. */
  368. sConfig.Channel = ADC_CHANNEL_4;
  369. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  370. {
  371. Error_Handler();
  372. }
  373. /** Configure for the selected ADC regular channel to be converted.
  374. */
  375. sConfig.Channel = ADC_CHANNEL_6;
  376. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  377. {
  378. Error_Handler();
  379. }
  380. /** Configure for the selected ADC regular channel to be converted.
  381. */
  382. sConfig.Channel = ADC_CHANNEL_7;
  383. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  384. {
  385. Error_Handler();
  386. }
  387. /** Configure for the selected ADC regular channel to be converted.
  388. */
  389. sConfig.Channel = ADC_CHANNEL_8;
  390. if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  391. {
  392. Error_Handler();
  393. }
  394. /* USER CODE BEGIN ADC_Init 2 */
  395. /* USER CODE END ADC_Init 2 */
  396. }
  397. /**
  398. * @brief SPI1 Initialization Function
  399. * @param None
  400. * @retval None
  401. */
  402. static void MX_SPI1_Init(void)
  403. {
  404. /* USER CODE BEGIN SPI1_Init 0 */
  405. /* USER CODE END SPI1_Init 0 */
  406. /* USER CODE BEGIN SPI1_Init 1 */
  407. /* USER CODE END SPI1_Init 1 */
  408. /* SPI1 parameter configuration*/
  409. hspi1.Instance = SPI1;
  410. hspi1.Init.Mode = SPI_MODE_MASTER;
  411. hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  412. hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  413. hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  414. hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  415. hspi1.Init.NSS = SPI_NSS_SOFT;
  416. hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  417. hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  418. hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  419. hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  420. hspi1.Init.CRCPolynomial = 7;
  421. if (HAL_SPI_Init(&hspi1) != HAL_OK)
  422. {
  423. Error_Handler();
  424. }
  425. /* USER CODE BEGIN SPI1_Init 2 */
  426. /* USER CODE END SPI1_Init 2 */
  427. }
  428. /**
  429. * @brief TIM21 Initialization Function
  430. * @param None
  431. * @retval None
  432. */
  433. static void MX_TIM21_Init(void)
  434. {
  435. /* USER CODE BEGIN TIM21_Init 0 */
  436. /* USER CODE END TIM21_Init 0 */
  437. TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  438. TIM_MasterConfigTypeDef sMasterConfig = {0};
  439. /* USER CODE BEGIN TIM21_Init 1 */
  440. /* USER CODE END TIM21_Init 1 */
  441. htim21.Instance = TIM21;
  442. htim21.Init.Prescaler = 32000;
  443. htim21.Init.CounterMode = TIM_COUNTERMODE_UP;
  444. htim21.Init.Period = 100;
  445. htim21.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  446. htim21.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  447. if (HAL_TIM_Base_Init(&htim21) != HAL_OK)
  448. {
  449. Error_Handler();
  450. }
  451. sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  452. if (HAL_TIM_ConfigClockSource(&htim21, &sClockSourceConfig) != HAL_OK)
  453. {
  454. Error_Handler();
  455. }
  456. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  457. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  458. if (HAL_TIMEx_MasterConfigSynchronization(&htim21, &sMasterConfig) != HAL_OK)
  459. {
  460. Error_Handler();
  461. }
  462. /* USER CODE BEGIN TIM21_Init 2 */
  463. /* USER CODE END TIM21_Init 2 */
  464. }
  465. /**
  466. * @brief USART2 Initialization Function
  467. * @param None
  468. * @retval None
  469. */
  470. static void MX_USART2_UART_Init(void)
  471. {
  472. /* USER CODE BEGIN USART2_Init 0 */
  473. /* USER CODE END USART2_Init 0 */
  474. /* USER CODE BEGIN USART2_Init 1 */
  475. /* USER CODE END USART2_Init 1 */
  476. huart2.Instance = USART2;
  477. huart2.Init.BaudRate = UART_BAUDRATE;
  478. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  479. huart2.Init.StopBits = UART_STOPBITS_1;
  480. huart2.Init.Parity = UART_PARITY_NONE;
  481. huart2.Init.Mode = UART_MODE_TX_RX;
  482. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  483. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  484. huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  485. huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  486. if (HAL_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
  487. {
  488. Error_Handler();
  489. }
  490. /* USER CODE BEGIN USART2_Init 2 */
  491. /* USER CODE END USART2_Init 2 */
  492. }
  493. /**
  494. * Enable DMA controller clock
  495. */
  496. static void MX_DMA_Init(void)
  497. {
  498. /* DMA controller clock enable */
  499. __HAL_RCC_DMA1_CLK_ENABLE();
  500. /* DMA interrupt init */
  501. /* DMA1_Channel1_IRQn interrupt configuration */
  502. HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  503. HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  504. /* DMA1_Channel4_5_6_7_IRQn interrupt configuration */
  505. HAL_NVIC_SetPriority(DMA1_Channel4_5_6_7_IRQn, 0, 0);
  506. HAL_NVIC_EnableIRQ(DMA1_Channel4_5_6_7_IRQn);
  507. }
  508. /**
  509. * @brief GPIO Initialization Function
  510. * @param None
  511. * @retval None
  512. */
  513. static void MX_GPIO_Init(void)
  514. {
  515. GPIO_InitTypeDef GPIO_InitStruct = {0};
  516. /* USER CODE BEGIN MX_GPIO_Init_1 */
  517. /* USER CODE END MX_GPIO_Init_1 */
  518. /* GPIO Ports Clock Enable */
  519. __HAL_RCC_GPIOC_CLK_ENABLE();
  520. __HAL_RCC_GPIOA_CLK_ENABLE();
  521. __HAL_RCC_GPIOB_CLK_ENABLE();
  522. /*Configure GPIO pin Output Level */
  523. HAL_GPIO_WritePin(SPI_SS_GPIO_Port, SPI_SS_Pin, GPIO_PIN_SET);
  524. /*Configure GPIO pin Output Level */
  525. HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
  526. /*Configure GPIO pin Output Level */
  527. HAL_GPIO_WritePin(ONE_WIRE_GPIO_Port, ONE_WIRE_Pin, GPIO_PIN_SET);
  528. /*Configure GPIO pin : SPI_SS_Pin */
  529. GPIO_InitStruct.Pin = SPI_SS_Pin;
  530. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  531. GPIO_InitStruct.Pull = GPIO_PULLUP;
  532. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  533. HAL_GPIO_Init(SPI_SS_GPIO_Port, &GPIO_InitStruct);
  534. /*Configure GPIO pin : LD3_Pin */
  535. GPIO_InitStruct.Pin = LD3_Pin;
  536. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  537. GPIO_InitStruct.Pull = GPIO_NOPULL;
  538. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  539. HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct);
  540. /*Configure GPIO pin : ONE_WIRE_Pin */
  541. GPIO_InitStruct.Pin = ONE_WIRE_Pin;
  542. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  543. GPIO_InitStruct.Pull = GPIO_PULLUP;
  544. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
  545. HAL_GPIO_Init(ONE_WIRE_GPIO_Port, &GPIO_InitStruct);
  546. /*Configure GPIO pin : SPI_INT_Pin */
  547. GPIO_InitStruct.Pin = SPI_INT_Pin;
  548. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  549. GPIO_InitStruct.Pull = GPIO_PULLUP;
  550. HAL_GPIO_Init(SPI_INT_GPIO_Port, &GPIO_InitStruct);
  551. /*Configure GPIO pins : PB6 PB7 */
  552. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  553. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  554. GPIO_InitStruct.Pull = GPIO_NOPULL;
  555. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  556. GPIO_InitStruct.Alternate = GPIO_AF1_I2C1;
  557. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  558. /* EXTI interrupt init*/
  559. HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
  560. HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
  561. /* USER CODE BEGIN MX_GPIO_Init_2 */
  562. /* USER CODE END MX_GPIO_Init_2 */
  563. }
  564. /* USER CODE BEGIN 4 */
  565. /* USER CODE END 4 */
  566. /**
  567. * @brief This function is executed in case of error occurrence.
  568. * @retval None
  569. */
  570. void Error_Handler(void)
  571. {
  572. /* USER CODE BEGIN Error_Handler_Debug */
  573. /* User can add his own implementation to report the HAL error return state */
  574. __disable_irq();
  575. while (1)
  576. {
  577. }
  578. /* USER CODE END Error_Handler_Debug */
  579. }
  580. #ifdef USE_FULL_ASSERT
  581. /**
  582. * @brief Reports the name of the source file and the source line number
  583. * where the assert_param error has occurred.
  584. * @param file: pointer to the source file name
  585. * @param line: assert_param error line source number
  586. * @retval None
  587. */
  588. void assert_failed(uint8_t *file, uint32_t line)
  589. {
  590. /* USER CODE BEGIN 6 */
  591. /* User can add his own implementation to report the file name and line number,
  592. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  593. /* USER CODE END 6 */
  594. }
  595. #endif /* USE_FULL_ASSERT */