amiro-os / modules / PowerManagement_1-1 / board.c @ 6df420be
History | View | Annotate | Download (5.769 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
#include <hal.h> |
20 |
#include <stm32_gpio.h> |
21 |
|
22 |
/**
|
23 |
* @brief Type of STM32 GPIO port setup.
|
24 |
*/
|
25 |
typedef struct { |
26 |
uint32_t moder; |
27 |
uint32_t otyper; |
28 |
uint32_t ospeedr; |
29 |
uint32_t pupdr; |
30 |
uint32_t odr; |
31 |
uint32_t afrl; |
32 |
uint32_t afrh; |
33 |
} gpio_setup_t; |
34 |
|
35 |
/**
|
36 |
* @brief Type of STM32 GPIO initialization data.
|
37 |
*/
|
38 |
typedef struct { |
39 |
#if STM32_HAS_GPIOA || defined(__DOXYGEN__)
|
40 |
gpio_setup_t PAData; |
41 |
#endif
|
42 |
#if STM32_HAS_GPIOB || defined(__DOXYGEN__)
|
43 |
gpio_setup_t PBData; |
44 |
#endif
|
45 |
#if STM32_HAS_GPIOC || defined(__DOXYGEN__)
|
46 |
gpio_setup_t PCData; |
47 |
#endif
|
48 |
#if STM32_HAS_GPIOD || defined(__DOXYGEN__)
|
49 |
gpio_setup_t PDData; |
50 |
#endif
|
51 |
#if STM32_HAS_GPIOE || defined(__DOXYGEN__)
|
52 |
gpio_setup_t PEData; |
53 |
#endif
|
54 |
#if STM32_HAS_GPIOF || defined(__DOXYGEN__)
|
55 |
gpio_setup_t PFData; |
56 |
#endif
|
57 |
#if STM32_HAS_GPIOG || defined(__DOXYGEN__)
|
58 |
gpio_setup_t PGData; |
59 |
#endif
|
60 |
#if STM32_HAS_GPIOH || defined(__DOXYGEN__)
|
61 |
gpio_setup_t PHData; |
62 |
#endif
|
63 |
#if STM32_HAS_GPIOI || defined(__DOXYGEN__)
|
64 |
gpio_setup_t PIData; |
65 |
#endif
|
66 |
#if STM32_HAS_GPIOJ || defined(__DOXYGEN__)
|
67 |
gpio_setup_t PJData; |
68 |
#endif
|
69 |
#if STM32_HAS_GPIOK || defined(__DOXYGEN__)
|
70 |
gpio_setup_t PKData; |
71 |
#endif
|
72 |
} gpio_config_t; |
73 |
|
74 |
/**
|
75 |
* @brief STM32 GPIO static initialization data.
|
76 |
*/
|
77 |
static const gpio_config_t gpio_default_config = { |
78 |
#if STM32_HAS_GPIOA
|
79 |
{VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR, |
80 |
VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH}, |
81 |
#endif
|
82 |
#if STM32_HAS_GPIOB
|
83 |
{VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, |
84 |
VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH}, |
85 |
#endif
|
86 |
#if STM32_HAS_GPIOC
|
87 |
{VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR, |
88 |
VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH}, |
89 |
#endif
|
90 |
#if STM32_HAS_GPIOD
|
91 |
{VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR, |
92 |
VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH}, |
93 |
#endif
|
94 |
#if STM32_HAS_GPIOE
|
95 |
{VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR, |
96 |
VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH}, |
97 |
#endif
|
98 |
#if STM32_HAS_GPIOF
|
99 |
{VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR, |
100 |
VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH}, |
101 |
#endif
|
102 |
#if STM32_HAS_GPIOG
|
103 |
{VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR, |
104 |
VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH}, |
105 |
#endif
|
106 |
#if STM32_HAS_GPIOH
|
107 |
{VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR, |
108 |
VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH}, |
109 |
#endif
|
110 |
#if STM32_HAS_GPIOI
|
111 |
{VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR, |
112 |
VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH}, |
113 |
#endif
|
114 |
#if STM32_HAS_GPIOJ
|
115 |
{VAL_GPIOJ_MODER, VAL_GPIOJ_OTYPER, VAL_GPIOJ_OSPEEDR, VAL_GPIOJ_PUPDR, |
116 |
VAL_GPIOJ_ODR, VAL_GPIOJ_AFRL, VAL_GPIOJ_AFRH}, |
117 |
#endif
|
118 |
#if STM32_HAS_GPIOK
|
119 |
{VAL_GPIOK_MODER, VAL_GPIOK_OTYPER, VAL_GPIOK_OSPEEDR, VAL_GPIOK_PUPDR, |
120 |
VAL_GPIOK_ODR, VAL_GPIOK_AFRL, VAL_GPIOK_AFRH} |
121 |
#endif
|
122 |
}; |
123 |
|
124 |
/**
|
125 |
* @brief GPIO initialization.
|
126 |
*
|
127 |
* @param[in] gpiop GPIO register block.
|
128 |
* @param[in] config GPIO configuration.
|
129 |
*/
|
130 |
static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config) { |
131 |
|
132 |
gpiop->OTYPER = config->otyper; |
133 |
gpiop->OSPEEDR = config->ospeedr; |
134 |
gpiop->PUPDR = config->pupdr; |
135 |
gpiop->ODR = config->odr; |
136 |
gpiop->AFRL = config->afrl; |
137 |
gpiop->AFRH = config->afrh; |
138 |
gpiop->MODER = config->moder; |
139 |
} |
140 |
|
141 |
/**
|
142 |
* @brief GPIO initilization for all ports.
|
143 |
*/
|
144 |
static void stm32_gpio_init(void) { |
145 |
|
146 |
/* Enabling GPIO-related clocks, the mask comes from the
|
147 |
registry header file.*/
|
148 |
rccResetAHB1(STM32_GPIO_EN_MASK); |
149 |
rccEnableAHB1(STM32_GPIO_EN_MASK, true);
|
150 |
|
151 |
/* Initializing all the defined GPIO ports.*/
|
152 |
#if STM32_HAS_GPIOA
|
153 |
gpio_init(GPIOA, &gpio_default_config.PAData); |
154 |
#endif
|
155 |
#if STM32_HAS_GPIOB
|
156 |
gpio_init(GPIOB, &gpio_default_config.PBData); |
157 |
#endif
|
158 |
#if STM32_HAS_GPIOC
|
159 |
gpio_init(GPIOC, &gpio_default_config.PCData); |
160 |
#endif
|
161 |
#if STM32_HAS_GPIOD
|
162 |
gpio_init(GPIOD, &gpio_default_config.PDData); |
163 |
#endif
|
164 |
#if STM32_HAS_GPIOE
|
165 |
gpio_init(GPIOE, &gpio_default_config.PEData); |
166 |
#endif
|
167 |
#if STM32_HAS_GPIOF
|
168 |
gpio_init(GPIOF, &gpio_default_config.PFData); |
169 |
#endif
|
170 |
#if STM32_HAS_GPIOG
|
171 |
gpio_init(GPIOG, &gpio_default_config.PGData); |
172 |
#endif
|
173 |
#if STM32_HAS_GPIOH
|
174 |
gpio_init(GPIOH, &gpio_default_config.PHData); |
175 |
#endif
|
176 |
#if STM32_HAS_GPIOI
|
177 |
gpio_init(GPIOI, &gpio_default_config.PIData); |
178 |
#endif
|
179 |
#if STM32_HAS_GPIOJ
|
180 |
gpio_init(GPIOJ, &gpio_default_config.PJData); |
181 |
#endif
|
182 |
#if STM32_HAS_GPIOK
|
183 |
gpio_init(GPIOK, &gpio_default_config.PKData); |
184 |
#endif
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* @brief Early initialization code.
|
189 |
* @details This initialization must be performed just after stack setup
|
190 |
* and before any other initialization.
|
191 |
*/
|
192 |
void __early_init(void) { |
193 |
|
194 |
stm32_gpio_init(); |
195 |
stm32_clock_init(); |
196 |
} |
197 |
|
198 |
/**
|
199 |
* @brief Board-specific initialization code.
|
200 |
* @todo Add your board-specific code, if any.
|
201 |
*/
|
202 |
void boardInit(void) { |
203 |
} |