]> begriffs open source - cmsis-driver-validation/blob - Tools/USART_Server/Board/STM32F429I-DISC1/Config/USART_Server_HW.c
Add SPI_Server and USART_Server applications for STM32F429I-DISC1 board
[cmsis-driver-validation] / Tools / USART_Server / Board / STM32F429I-DISC1 / Config / USART_Server_HW.c
1 /*
2  * Copyright (c) 2020-2022 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:     USART Server
21  * Title:       USART Server hardware specific driver implementation
22  *
23  * -----------------------------------------------------------------------------
24  */
25
26 #include "USART_Server_HW.h"
27
28 #include "stm32f4xx_hal.h"
29
30 #define   DCD_CLK_ENABLE()              __GPIOA_CLK_ENABLE()
31 #define   DCD_PORT                      GPIOA
32 #define   DCD_PIN                       GPIO_PIN_13
33
34 #define   RI_CLK_ENABLE()               __GPIOA_CLK_ENABLE()
35 #define   RI_PORT                       GPIOA
36 #define   RI_PIN                        GPIO_PIN_14
37
38 /**
39   \fn            void USART_Server_Pins_Initialize (void)
40   \brief         Initialize, power up and configure GPIO pins used for 
41                  driving DCD and RI lines of the USART Client.
42   \return        none
43 */
44 void USART_Server_Pins_Initialize (void) {
45   GPIO_InitTypeDef gpio_config;
46
47   DCD_CLK_ENABLE();
48
49   gpio_config.Mode  = GPIO_MODE_OUTPUT_PP;
50   gpio_config.Pull  = GPIO_NOPULL;
51   gpio_config.Speed = GPIO_SPEED_LOW;
52
53   /* Configure GPIO pin: DCD as output */
54   gpio_config.Pin   = DCD_PIN;
55   HAL_GPIO_Init(DCD_PORT, &gpio_config);
56
57   /* Configure GPIO pin: RI as output */
58   gpio_config.Pin   = RI_PIN;
59   HAL_GPIO_Init(DCD_PORT, &gpio_config);
60 }
61
62 /**
63   \fn            void USART_Server_Pins_Uninitialize (void)
64   \brief         Unconfigure, power down and uninitialize GPIO pins used for
65                  driving DCD and RI lines of the USART Client.
66   \return        none
67 */
68 void USART_Server_Pins_Uninitialize (void) {
69   HAL_GPIO_DeInit(DCD_PORT, DCD_PIN);
70   HAL_GPIO_DeInit(DCD_PORT, RI_PIN);
71 }
72
73 /**
74   \fn            void USART_Server_Pin_DCD_SetState (uint32_t state)
75   \brief         Set state of GPIO pin used for driving DCD line of the USART Client.
76   \param[in]     state          State to be set
77                    - 0:    Drive pin to not active state
78                    - != 0: Drive pin to active state
79   \return        none
80 */
81 void USART_Server_Pin_DCD_SetState (uint32_t state) {
82
83   // DCD is active low
84   HAL_GPIO_WritePin(DCD_PORT, DCD_PIN, ((state != 0U) ? GPIO_PIN_RESET : GPIO_PIN_SET));
85 }
86
87 /**
88   \fn            void USART_Server_Pin_RI_SetState (uint32_t state)
89   \brief         Set state of GPIO pin used for driving RI line of the USART Client.
90   \param[in]     state          State to be set
91                    - 0:    Drive pin to not active state
92                    - != 0: Drive pin to active state
93   \return        none
94 */
95 void USART_Server_Pin_RI_SetState (uint32_t state) {
96
97   // RI is active low
98   HAL_GPIO_WritePin(RI_PORT, RI_PIN, ((state != 0U) ? GPIO_PIN_RESET : GPIO_PIN_SET));
99 }