2 * Copyright (c) 2020 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * -----------------------------------------------------------------------------
21 * Title: SPI Server hardware specific driver implementation
22 * for STMicroelectronics STM32F407 microcontroller
24 * -----------------------------------------------------------------------------
27 #include "SPI_Server_HW.h"
29 #include "stm32f4xx_hal.h"
32 #define GPIO_PORT_CLOCK_ENABLE() __GPIOI_CLK_ENABLE()
33 #define GPIO_PORT GPIOI
34 #define GPIO_PIN GPIO_PIN_0
37 \fn void SPI_Server_Pin_SS_Initialize (void)
38 \brief Initialize, power up and configure Slave Select pin as GPIO.
41 void SPI_Server_Pin_SS_Initialize (void) {
42 GPIO_InitTypeDef gpio_config;
44 GPIO_PORT_CLOCK_ENABLE();
46 /* Configure pin as GPIO output */
47 gpio_config.Pin = GPIO_PIN;
48 gpio_config.Mode = GPIO_MODE_OUTPUT_PP;
49 gpio_config.Pull = GPIO_NOPULL;
50 gpio_config.Speed = GPIO_SPEED_MEDIUM;
51 gpio_config.Alternate = 0U;
52 HAL_GPIO_Init(GPIO_PORT, &gpio_config);
56 \fn void SPI_Server_Pin_SS_Uninitialize (void)
57 \brief Unconfigure, power down and uninitialize Slave Select pin.
60 void SPI_Server_Pin_SS_Uninitialize (void) {
61 HAL_GPIO_DeInit(GPIO_PORT, GPIO_PIN);
65 \fn void SPI_Server_Pin_SS_SetState (uint32_t state)
66 \brief Set state of Slave Select pin.
67 \param[in] state State to be set
68 - 0: Drive pin to not active state
69 - != 0: Drive pin to active state
72 void SPI_Server_Pin_SS_SetState (uint32_t state) {
73 GPIO_PinState pin_state;
76 pin_state = GPIO_PIN_SET;
78 pin_state = GPIO_PIN_RESET;
81 HAL_GPIO_WritePin(GPIO_PORT, GPIO_PIN, pin_state);