rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
board.c
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/*
18 * This file has been automatically generated using ChibiStudio board
19 * generator plugin. Do not edit manually.
20 */
21
22#include "hal.h"
23#include "stm32_gpio.h"
24
25/*===========================================================================*/
26/* Driver local definitions. */
27/*===========================================================================*/
28
29/*===========================================================================*/
30/* Driver exported variables. */
31/*===========================================================================*/
32
33/*===========================================================================*/
34/* Driver local variables and types. */
35/*===========================================================================*/
36
37/**
38 * @brief Type of STM32 GPIO port setup.
39 */
40typedef struct {
41 uint32_t moder;
42 uint32_t otyper;
43 uint32_t ospeedr;
44 uint32_t pupdr;
45 uint32_t odr;
46 uint32_t afrl;
47 uint32_t afrh;
48} gpio_setup_t;
49
50/**
51 * @brief Type of STM32 GPIO initialization data.
52 */
53typedef struct {
54#if STM32_HAS_GPIOA || defined(__DOXYGEN__)
55 gpio_setup_t PAData;
56#endif
57#if STM32_HAS_GPIOB || defined(__DOXYGEN__)
58 gpio_setup_t PBData;
59#endif
60#if STM32_HAS_GPIOC || defined(__DOXYGEN__)
61 gpio_setup_t PCData;
62#endif
63#if STM32_HAS_GPIOD || defined(__DOXYGEN__)
64 gpio_setup_t PDData;
65#endif
66#if STM32_HAS_GPIOE || defined(__DOXYGEN__)
67 gpio_setup_t PEData;
68#endif
69#if STM32_HAS_GPIOF || defined(__DOXYGEN__)
70 gpio_setup_t PFData;
71#endif
72#if STM32_HAS_GPIOG || defined(__DOXYGEN__)
73 gpio_setup_t PGData;
74#endif
75#if STM32_HAS_GPIOH || defined(__DOXYGEN__)
76 gpio_setup_t PHData;
77#endif
78} gpio_config_t;
79
80/**
81 * @brief STM32 GPIO static initialization data.
82 */
83static const gpio_config_t gpio_default_config = {
84#if STM32_HAS_GPIOA
85 {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR,
86 VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH},
87#endif
88#if STM32_HAS_GPIOB
89 {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR,
90 VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH},
91#endif
92#if STM32_HAS_GPIOC
93 {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR,
94 VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH},
95#endif
96#if STM32_HAS_GPIOD
97 {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR,
98 VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH},
99#endif
100#if STM32_HAS_GPIOE
101 {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR,
102 VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH},
103#endif
104#if STM32_HAS_GPIOF
105 {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR,
106 VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH},
107#endif
108#if STM32_HAS_GPIOG
109 {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR,
110 VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH},
111#endif
112#if STM32_HAS_GPIOH
113 {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR,
114 VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH},
115#endif
116};
117
118/*===========================================================================*/
119/* Driver local functions. */
120/*===========================================================================*/
121
122static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config) {
123
124 gpiop->OTYPER = config->otyper;
125 gpiop->OSPEEDR = config->ospeedr;
126 gpiop->PUPDR = config->pupdr;
127 gpiop->ODR = config->odr;
128 gpiop->AFRL = config->afrl;
129 gpiop->AFRH = config->afrh;
130 gpiop->MODER = config->moder;
131}
132
133static void stm32_gpio_init(void) {
134
135 /* Enabling GPIO-related clocks, the mask comes from the
136 registry header file.*/
137 rccResetAHB1(STM32_GPIO_EN_MASK);
138 rccEnableAHB1(STM32_GPIO_EN_MASK, true);
139
140 /* Initializing all the defined GPIO ports.*/
141#if STM32_HAS_GPIOA
142 gpio_init(GPIOA, &gpio_default_config.PAData);
143#endif
144#if STM32_HAS_GPIOB
145 gpio_init(GPIOB, &gpio_default_config.PBData);
146#endif
147#if STM32_HAS_GPIOC
148 gpio_init(GPIOC, &gpio_default_config.PCData);
149#endif
150#if STM32_HAS_GPIOD
151 gpio_init(GPIOD, &gpio_default_config.PDData);
152#endif
153#if STM32_HAS_GPIOE
154 gpio_init(GPIOE, &gpio_default_config.PEData);
155#endif
156#if STM32_HAS_GPIOF
157 gpio_init(GPIOF, &gpio_default_config.PFData);
158#endif
159#if STM32_HAS_GPIOG
160 gpio_init(GPIOG, &gpio_default_config.PGData);
161#endif
162#if STM32_HAS_GPIOH
163 gpio_init(GPIOH, &gpio_default_config.PHData);
164#endif
165}
166
167/*===========================================================================*/
168/* Driver interrupt handlers. */
169/*===========================================================================*/
170
171/*===========================================================================*/
172/* Driver exported functions. */
173/*===========================================================================*/
174
175/**
176 * @brief Early initialization code.
177 * @details GPIO ports and system clocks are initialized before everything
178 * else.
179 */
180void __early_init(void) {
181
183 stm32_clock_init();
184}
185
186#if HAL_USE_SDC || defined(__DOXYGEN__)
187/**
188 * @brief SDC card detection.
189 */
190bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
191
192 (void)sdcp;
193 /* CHTODO: Fill the implementation.*/
194 return true;
195}
196
197/**
198 * @brief SDC card write protection detection.
199 */
200bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
201
202 (void)sdcp;
203 /* CHTODO: Fill the implementation.*/
204 return false;
205}
206#endif /* HAL_USE_SDC */
207
208#if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
209/**
210 * @brief MMC_SPI card detection.
211 */
212bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
213
214 (void)mmcp;
215 /* CHTODO: Fill the implementation.*/
216 return true;
217}
218
219/**
220 * @brief MMC_SPI card write protection detection.
221 */
222bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
223
224 (void)mmcp;
225 /* CHTODO: Fill the implementation.*/
226 return false;
227}
228#endif
void __early_init(void)
Definition board.c:21
static constexpr persistent_config_s * config
bool sdc_lld_is_write_protected(SDCDriver *sdcp)
SDC card write protection detection.
Definition board.c:394
bool mmc_lld_is_card_inserted(MMCDriver *mmcp)
MMC_SPI card detection.
Definition board.c:406
bool mmc_lld_is_write_protected(MMCDriver *mmcp)
MMC_SPI card write protection detection.
Definition board.c:416
static void stm32_gpio_init(void)
Definition board.c:181
static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config)
Definition board.c:170
static const gpio_config_t gpio_default_config
STM32 GPIO static initialization data.
Definition board.c:119
bool sdc_lld_is_card_inserted(SDCDriver *sdcp)
SDC card detection.
Definition board.c:384