]> begriffs open source - cmsis-driver-validation/blob - Tools/SPI_Server/Board/MCBSTM32F400/Config/SPI_Server_HW.c
Minor update to SPI Driver testing
[cmsis-driver-validation] / Tools / SPI_Server / Board / MCBSTM32F400 / Config / SPI_Server_HW.c
1 /*
2  * Copyright (c) 2020 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
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
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * -----------------------------------------------------------------------------
19  *
20  * Project:     SPI Server
21  * Title:       SPI Server hardware specific driver implementation
22  *              for STMicroelectronics STM32F407 microcontroller
23  *
24  * -----------------------------------------------------------------------------
25  */
26
27 #include "SPI_Server_HW.h"
28
29 #include "stm32f4xx_hal.h"
30
31
32 #define  GPIO_PORT_CLOCK_ENABLE()       __GPIOI_CLK_ENABLE()
33 #define  GPIO_PORT                      GPIOI
34 #define  GPIO_PIN                       GPIO_PIN_0
35
36 /**
37   \fn            void SPI_Server_Pin_SS_Initialize (void)
38   \brief         Initialize, power up and configure Slave Select pin as GPIO.
39   \return        none
40 */
41 void SPI_Server_Pin_SS_Initialize (void) {
42   GPIO_InitTypeDef gpio_config;
43
44   GPIO_PORT_CLOCK_ENABLE();
45
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);
53 }
54
55 /**
56   \fn            void SPI_Server_Pin_SS_Uninitialize (void)
57   \brief         Unconfigure, power down and uninitialize Slave Select pin.
58   \return        none
59 */
60 void SPI_Server_Pin_SS_Uninitialize (void) {
61   HAL_GPIO_DeInit(GPIO_PORT, GPIO_PIN);
62 }
63
64 /**
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
70   \return        none
71 */
72 void SPI_Server_Pin_SS_SetState (uint32_t state) {
73   GPIO_PinState pin_state;
74
75   if (state == 0U) {
76     pin_state = GPIO_PIN_SET;
77   } else {
78     pin_state = GPIO_PIN_RESET;
79   }
80
81   HAL_GPIO_WritePin(GPIO_PORT, GPIO_PIN, pin_state);
82 }