100 lines
3.1 KiB
C
100 lines
3.1 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file spi.c
|
|
* @brief This file provides code for the configuration
|
|
* of the SPI instances.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2024 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "spi.h"
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
/* SPI1 init function */
|
|
void MX_SPI1_Init(void)
|
|
{
|
|
|
|
/* USER CODE BEGIN SPI1_Init 0 */
|
|
|
|
/* USER CODE END SPI1_Init 0 */
|
|
|
|
LL_SPI_InitTypeDef SPI_InitStruct = {0};
|
|
|
|
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI1;
|
|
PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
|
|
|
|
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOD);
|
|
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOG);
|
|
/**SPI1 GPIO Configuration
|
|
PD7 ------> SPI1_MOSI
|
|
PG9 ------> SPI1_MISO
|
|
PG11 ------> SPI1_SCK
|
|
*/
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
|
|
LL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_11;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
|
|
LL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN SPI1_Init 1 */
|
|
|
|
/* USER CODE END SPI1_Init 1 */
|
|
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
|
|
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
|
|
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
|
|
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
|
|
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
|
|
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
|
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV16;
|
|
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
|
|
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
|
SPI_InitStruct.CRCPoly = 0x0;
|
|
LL_SPI_Init(SPI1, &SPI_InitStruct);
|
|
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
|
|
LL_SPI_EnableNSSPulseMgt(SPI1);
|
|
/* USER CODE BEGIN SPI1_Init 2 */
|
|
|
|
/* USER CODE END SPI1_Init 2 */
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|