L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
spi.c
Go to the documentation of this file.
1/* USER CODE BEGIN Header */
2/**
3 ******************************************************************************
4 * @file spi.c
5 * @brief This file provides code for the configuration
6 * of the SPI instances.
7 ******************************************************************************
8 * @attention
9 *
10 * Copyright (c) 2025 STMicroelectronics.
11 * All rights reserved.
12 *
13 * This software is licensed under terms that can be found in the LICENSE file
14 * in the root directory of this software component.
15 * If no LICENSE file comes with this software, it is provided AS-IS.
16 *
17 ******************************************************************************
18 */
19/* USER CODE END Header */
20/* Includes ------------------------------------------------------------------*/
21#include "spi.h"
22
23/* USER CODE BEGIN 0 */
24
25/* USER CODE END 0 */
26
27SPI_HandleTypeDef hspi1;
28
29/* SPI1 init function */
30void MX_SPI1_Init(void)
31{
32
33 /* USER CODE BEGIN SPI1_Init 0 */
34
35 /* USER CODE END SPI1_Init 0 */
36
37 /* USER CODE BEGIN SPI1_Init 1 */
38
39 /* USER CODE END SPI1_Init 1 */
40 hspi1.Instance = SPI1;
41 hspi1.Init.Mode = SPI_MODE_MASTER;
42 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
43 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
44 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
45 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
46 hspi1.Init.NSS = SPI_NSS_SOFT;
47 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
48 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
49 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
50 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
51 hspi1.Init.CRCPolynomial = 7;
52 hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
53 hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
54 if (HAL_SPI_Init(&hspi1) != HAL_OK)
55 {
57 }
58 /* USER CODE BEGIN SPI1_Init 2 */
59
60 /* USER CODE END SPI1_Init 2 */
61
62}
63
64void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
65{
66
67 GPIO_InitTypeDef GPIO_InitStruct = {0};
68 if(spiHandle->Instance==SPI1)
69 {
70 /* USER CODE BEGIN SPI1_MspInit 0 */
71
72 /* USER CODE END SPI1_MspInit 0 */
73 /* SPI1 clock enable */
74 __HAL_RCC_SPI1_CLK_ENABLE();
75
76 __HAL_RCC_GPIOA_CLK_ENABLE();
77 /**SPI1 GPIO Configuration
78 PA5 ------> SPI1_SCK
79 PA6 ------> SPI1_MISO
80 PA7 ------> SPI1_MOSI
81 */
82 GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
83 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
84 GPIO_InitStruct.Pull = GPIO_NOPULL;
85 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
86 GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
87 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
88
89 /* USER CODE BEGIN SPI1_MspInit 1 */
90
91 /* USER CODE END SPI1_MspInit 1 */
92 }
93}
94
95void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
96{
97
98 if(spiHandle->Instance==SPI1)
99 {
100 /* USER CODE BEGIN SPI1_MspDeInit 0 */
101
102 /* USER CODE END SPI1_MspDeInit 0 */
103 /* Peripheral clock disable */
104 __HAL_RCC_SPI1_CLK_DISABLE();
105
106 /**SPI1 GPIO Configuration
107 PA5 ------> SPI1_SCK
108 PA6 ------> SPI1_MISO
109 PA7 ------> SPI1_MOSI
110 */
111 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
112
113 /* USER CODE BEGIN SPI1_MspDeInit 1 */
114/*
115 GPIO_InitTypeDef GPIO_InitStruct = { 0 };
116 GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
117 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
118 GPIO_InitStruct.Pull = GPIO_NOPULL;
119 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
120*/
121 /* USER CODE END SPI1_MspDeInit 1 */
122 }
123}
124
125/* USER CODE BEGIN 1 */
126
127/**
128 * @brief Deinitialize SPI1 peripheral for low power mode
129 */
131{
132 HAL_SPI_DeInit(&hspi1);
133}
134
135/* USER CODE END 1 */
void Error_Handler(void)
Default error handler called by HAL on unrecoverable errors. Disables interrupts and enters an infini...
Definition main.c:505
void HAL_SPI_MspInit(SPI_HandleTypeDef *spiHandle)
Definition spi.c:64
void MX_SPI1_DeInit(void)
Deinitialize SPI1 peripheral for low power mode.
Definition spi.c:130
void MX_SPI1_Init(void)
Initialise SPI1 peripheral (hspi1) as configured by STM32CubeMX. Sets clock polarity/phase,...
Definition spi.c:30
void HAL_SPI_MspDeInit(SPI_HandleTypeDef *spiHandle)
Definition spi.c:95
This file contains all the function prototypes for the spi.c file.
SPI_HandleTypeDef hspi1
Definition spi.c:27