2 ******************************************************************************
4 * Description : This file provides code for the configuration
5 * of the SPI instances.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2021 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under Ultimate Liberty license
13 * SLA0044, the "License"; You may not use this file except in compliance with
14 * the License. You may obtain a copy of the License at:
17 ******************************************************************************
20 /* Includes ------------------------------------------------------------------*/
23 /* USER CODE BEGIN 0 */
27 SPI_HandleTypeDef hspi1;
29 /* SPI1 init function */
30 void MX_SPI1_Init(void)
33 hspi1.Instance = SPI1;
34 hspi1.Init.Mode = SPI_MODE_MASTER;
35 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
36 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
37 hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
38 hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
39 hspi1.Init.NSS = SPI_NSS_SOFT;
40 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
41 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
42 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
43 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
44 hspi1.Init.CRCPolynomial = 10;
45 if (HAL_SPI_Init(&hspi1) != HAL_OK)
52 void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
55 GPIO_InitTypeDef GPIO_InitStruct = {0};
56 if(spiHandle->Instance==SPI1)
58 /* USER CODE BEGIN SPI1_MspInit 0 */
60 /* USER CODE END SPI1_MspInit 0 */
61 /* SPI1 clock enable */
62 __HAL_RCC_SPI1_CLK_ENABLE();
64 __HAL_RCC_GPIOA_CLK_ENABLE();
65 __HAL_RCC_GPIOB_CLK_ENABLE();
66 /**SPI1 GPIO Configuration
71 GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
72 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
73 GPIO_InitStruct.Pull = GPIO_NOPULL;
74 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
75 GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
76 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
78 GPIO_InitStruct.Pin = GPIO_PIN_3;
79 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
80 GPIO_InitStruct.Pull = GPIO_NOPULL;
81 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
82 GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
83 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
85 /* USER CODE BEGIN SPI1_MspInit 1 */
87 /* USER CODE END SPI1_MspInit 1 */
91 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
94 if(spiHandle->Instance==SPI1)
96 /* USER CODE BEGIN SPI1_MspDeInit 0 */
98 /* USER CODE END SPI1_MspDeInit 0 */
99 /* Peripheral clock disable */
100 __HAL_RCC_SPI1_CLK_DISABLE();
102 /**SPI1 GPIO Configuration
103 PA6 ------> SPI1_MISO
104 PA7 ------> SPI1_MOSI
107 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6|GPIO_PIN_7);
109 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3);
111 /* USER CODE BEGIN SPI1_MspDeInit 1 */
113 /* USER CODE END SPI1_MspDeInit 1 */
117 /* USER CODE BEGIN 1 */
119 /* USER CODE END 1 */
121 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/