2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This file has been automatically generated using ChibiStudio board
19 * generator plugin. Do not edit manually.
23 #include "stm32_gpio.h"
25 /*===========================================================================*/
26 /* Driver local definitions. */
27 /*===========================================================================*/
29 /*===========================================================================*/
30 /* Driver exported variables. */
31 /*===========================================================================*/
33 /*===========================================================================*/
34 /* Driver local variables and types. */
35 /*===========================================================================*/
38 * @brief Type of STM32 GPIO port setup.
51 * @brief Type of STM32 GPIO initialization data.
54 #if STM32_HAS_GPIOA || defined(__DOXYGEN__)
57 #if STM32_HAS_GPIOB || defined(__DOXYGEN__)
60 #if STM32_HAS_GPIOC || defined(__DOXYGEN__)
63 #if STM32_HAS_GPIOD || defined(__DOXYGEN__)
66 #if STM32_HAS_GPIOE || defined(__DOXYGEN__)
69 #if STM32_HAS_GPIOF || defined(__DOXYGEN__)
72 #if STM32_HAS_GPIOG || defined(__DOXYGEN__)
75 #if STM32_HAS_GPIOH || defined(__DOXYGEN__)
78 #if STM32_HAS_GPIOI || defined(__DOXYGEN__)
81 #if STM32_HAS_GPIOJ || defined(__DOXYGEN__)
84 #if STM32_HAS_GPIOK || defined(__DOXYGEN__)
90 * @brief STM32 GPIO static initialization data.
92 static const gpio_config_t gpio_default_config
= {
94 {VAL_GPIOA_MODER
, VAL_GPIOA_OTYPER
, VAL_GPIOA_OSPEEDR
, VAL_GPIOA_PUPDR
,
95 VAL_GPIOA_ODR
, VAL_GPIOA_AFRL
, VAL_GPIOA_AFRH
},
98 {VAL_GPIOB_MODER
, VAL_GPIOB_OTYPER
, VAL_GPIOB_OSPEE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GPIOJ_AFRL
, VAL_GPIOJ_AFRH
},
134 {VAL_GPIOK_MODER
, VAL_GPIOK_OTYPER
, VAL_GPIOK_OSPEEDR
, VAL_GPIOK_PUPDR
,
135 VAL_GPIOK_ODR
, VAL_GPIOK_AFRL
, VAL_GPIOK_AFRH
}
139 /*===========================================================================*/
140 /* Driver local functions. */
141 /*===========================================================================*/
143 static void gpio_init(stm32_gpio_t
*gpiop
, const gpio_setup_t
*config
) {
145 gpiop
->OTYPER
= config
->otyper
;
146 gpiop
->OSPEEDR
= config
->ospeedr
;
147 gpiop
->PUPDR
= config
->pupdr
;
148 gpiop
->ODR
= config
->odr
;
149 gpiop
->AFRL
= config
->afrl
;
150 gpiop
->AFRH
= config
->afrh
;
151 gpiop
->MODER
= config
->moder
;
154 static void stm32_gpio_init(void) {
156 /* Enabling GPIO-related clocks, the mask comes from the
157 registry header file.*/
158 rccResetAHB1(STM32_GPIO_EN_MASK
);
159 rccEnableAHB1(STM32_GPIO_EN_MASK
, true);
161 /* Initializing all the defined GPIO ports.*/
163 gpio_init(GPIOA
, &gpio_default_config
.PAData
);
166 gpio_init(GPIOB
, &gpio_default_config
.PBData
);
169 gpio_init(GPIOC
, &gpio_default_config
.PCData
);
172 gpio_init(GPIOD
, &gpio_default_config
.PDData
);
175 gpio_init(GPIOE
, &gpio_default_config
.PEData
);
178 gpio_init(GPIOF
, &gpio_default_config
.PFData
);
181 gpio_init(GPIOG
, &gpio_default_config
.PGData
);
184 gpio_init(GPIOH
, &gpio_default_config
.PHData
);
187 gpio_init(GPIOI
, &gpio_default_config
.PIData
);
190 gpio_init(GPIOJ
, &gpio_default_config
.PJData
);
193 gpio_init(GPIOK
, &gpio_default_config
.PKData
);
197 /*===========================================================================*/
198 /* Driver interrupt handlers. */
199 /*===========================================================================*/
201 /*===========================================================================*/
202 /* Driver exported functions. */
203 /*===========================================================================*/
206 * @brief Early initialization code.
207 * @details GPIO ports and system clocks are initialized before everything
210 void __early_init(void) {
211 extern void enter_bootloader_mode_if_requested(void);
212 enter_bootloader_mode_if_requested();
218 #if HAL_USE_SDC || defined(__DOXYGEN__)
220 * @brief SDC card detection.
222 bool sdc_lld_is_card_inserted(SDCDriver
*sdcp
) {
225 /* TODO: Fill the implementation.*/
230 * @brief SDC card write protection detection.
232 bool sdc_lld_is_write_protected(SDCDriver
*sdcp
) {
235 /* TODO: Fill the implementation.*/
238 #endif /* HAL_USE_SDC */
240 #if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
242 * @brief MMC_SPI card detection.
244 bool mmc_lld_is_card_inserted(MMCDriver
*mmcp
) {
247 /* TODO: Fill the implementation.*/
252 * @brief MMC_SPI card write protection detection.
254 bool mmc_lld_is_write_protected(MMCDriver
*mmcp
) {
257 /* TODO: Fill the implementation.*/
263 * @brief Board-specific initialization code.
264 * @todo Add your board-specific code, if any.
266 void boardInit(void) {