amiro-os / modules / PowerManagement_1-1 / board.c @ e05848a6
History | View | Annotate | Download (5.909 KB)
1 | e545e620 | Thomas Schöpping | /*
|
---|---|---|---|
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 | 53710ca3 | Marc Rothmann | /**
|
20 | * @file
|
||
21 | * @brief PowerManagement v1.1 Board specific initializations.
|
||
22 | *
|
||
23 | * @addtogroup powermanagement_board
|
||
24 | * @{
|
||
25 | */
|
||
26 | |||
27 | e545e620 | Thomas Schöpping | #include <hal.h> |
28 | 0128be0f | Marc Rothmann | #include <stm32_gpio.h> |
29 | e545e620 | Thomas Schöpping | |
30 | /**
|
||
31 | 0128be0f | Marc Rothmann | * @brief Type of STM32 GPIO port setup.
|
32 | e545e620 | Thomas Schöpping | */
|
33 | 0128be0f | Marc Rothmann | typedef struct { |
34 | uint32_t moder; |
||
35 | uint32_t otyper; |
||
36 | uint32_t ospeedr; |
||
37 | uint32_t pupdr; |
||
38 | uint32_t odr; |
||
39 | uint32_t afrl; |
||
40 | uint32_t afrh; |
||
41 | } gpio_setup_t; |
||
42 | |||
43 | /**
|
||
44 | * @brief Type of STM32 GPIO initialization data.
|
||
45 | */
|
||
46 | typedef struct { |
||
47 | #if STM32_HAS_GPIOA || defined(__DOXYGEN__)
|
||
48 | gpio_setup_t PAData; |
||
49 | #endif
|
||
50 | #if STM32_HAS_GPIOB || defined(__DOXYGEN__)
|
||
51 | gpio_setup_t PBData; |
||
52 | #endif
|
||
53 | #if STM32_HAS_GPIOC || defined(__DOXYGEN__)
|
||
54 | gpio_setup_t PCData; |
||
55 | #endif
|
||
56 | #if STM32_HAS_GPIOD || defined(__DOXYGEN__)
|
||
57 | gpio_setup_t PDData; |
||
58 | #endif
|
||
59 | #if STM32_HAS_GPIOE || defined(__DOXYGEN__)
|
||
60 | gpio_setup_t PEData; |
||
61 | #endif
|
||
62 | #if STM32_HAS_GPIOF || defined(__DOXYGEN__)
|
||
63 | gpio_setup_t PFData; |
||
64 | #endif
|
||
65 | #if STM32_HAS_GPIOG || defined(__DOXYGEN__)
|
||
66 | gpio_setup_t PGData; |
||
67 | #endif
|
||
68 | #if STM32_HAS_GPIOH || defined(__DOXYGEN__)
|
||
69 | gpio_setup_t PHData; |
||
70 | #endif
|
||
71 | #if STM32_HAS_GPIOI || defined(__DOXYGEN__)
|
||
72 | gpio_setup_t PIData; |
||
73 | #endif
|
||
74 | #if STM32_HAS_GPIOJ || defined(__DOXYGEN__)
|
||
75 | gpio_setup_t PJData; |
||
76 | #endif
|
||
77 | #if STM32_HAS_GPIOK || defined(__DOXYGEN__)
|
||
78 | gpio_setup_t PKData; |
||
79 | #endif
|
||
80 | } gpio_config_t; |
||
81 | |||
82 | /**
|
||
83 | * @brief STM32 GPIO static initialization data.
|
||
84 | */
|
||
85 | static const gpio_config_t gpio_default_config = { |
||
86 | e545e620 | Thomas Schöpping | #if STM32_HAS_GPIOA
|
87 | {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR, |
||
88 | VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH}, |
||
89 | #endif
|
||
90 | #if STM32_HAS_GPIOB
|
||
91 | {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, |
||
92 | VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH}, |
||
93 | #endif
|
||
94 | #if STM32_HAS_GPIOC
|
||
95 | {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR, |
||
96 | VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH}, |
||
97 | #endif
|
||
98 | #if STM32_HAS_GPIOD
|
||
99 | {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR, |
||
100 | VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH}, |
||
101 | #endif
|
||
102 | #if STM32_HAS_GPIOE
|
||
103 | {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR, |
||
104 | VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH}, |
||
105 | #endif
|
||
106 | #if STM32_HAS_GPIOF
|
||
107 | {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR, |
||
108 | VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH}, |
||
109 | #endif
|
||
110 | #if STM32_HAS_GPIOG
|
||
111 | {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR, |
||
112 | VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH}, |
||
113 | #endif
|
||
114 | #if STM32_HAS_GPIOH
|
||
115 | {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR, |
||
116 | VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH}, |
||
117 | #endif
|
||
118 | #if STM32_HAS_GPIOI
|
||
119 | {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR, |
||
120 | 0128be0f | Marc Rothmann | VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH}, |
121 | #endif
|
||
122 | #if STM32_HAS_GPIOJ
|
||
123 | {VAL_GPIOJ_MODER, VAL_GPIOJ_OTYPER, VAL_GPIOJ_OSPEEDR, VAL_GPIOJ_PUPDR, |
||
124 | VAL_GPIOJ_ODR, VAL_GPIOJ_AFRL, VAL_GPIOJ_AFRH}, |
||
125 | #endif
|
||
126 | #if STM32_HAS_GPIOK
|
||
127 | {VAL_GPIOK_MODER, VAL_GPIOK_OTYPER, VAL_GPIOK_OSPEEDR, VAL_GPIOK_PUPDR, |
||
128 | VAL_GPIOK_ODR, VAL_GPIOK_AFRL, VAL_GPIOK_AFRH} |
||
129 | e545e620 | Thomas Schöpping | #endif
|
130 | }; |
||
131 | 0128be0f | Marc Rothmann | |
132 | /**
|
||
133 | * @brief GPIO initialization.
|
||
134 | *
|
||
135 | * @param[in] gpiop GPIO register block.
|
||
136 | * @param[in] config GPIO configuration.
|
||
137 | */
|
||
138 | static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config) { |
||
139 | |||
140 | gpiop->OTYPER = config->otyper; |
||
141 | gpiop->OSPEEDR = config->ospeedr; |
||
142 | gpiop->PUPDR = config->pupdr; |
||
143 | gpiop->ODR = config->odr; |
||
144 | gpiop->AFRL = config->afrl; |
||
145 | gpiop->AFRH = config->afrh; |
||
146 | gpiop->MODER = config->moder; |
||
147 | } |
||
148 | |||
149 | /**
|
||
150 | * @brief GPIO initilization for all ports.
|
||
151 | */
|
||
152 | static void stm32_gpio_init(void) { |
||
153 | |||
154 | /* Enabling GPIO-related clocks, the mask comes from the
|
||
155 | registry header file.*/
|
||
156 | rccResetAHB1(STM32_GPIO_EN_MASK); |
||
157 | rccEnableAHB1(STM32_GPIO_EN_MASK, true);
|
||
158 | |||
159 | /* Initializing all the defined GPIO ports.*/
|
||
160 | #if STM32_HAS_GPIOA
|
||
161 | gpio_init(GPIOA, &gpio_default_config.PAData); |
||
162 | #endif
|
||
163 | #if STM32_HAS_GPIOB
|
||
164 | gpio_init(GPIOB, &gpio_default_config.PBData); |
||
165 | #endif
|
||
166 | #if STM32_HAS_GPIOC
|
||
167 | gpio_init(GPIOC, &gpio_default_config.PCData); |
||
168 | #endif
|
||
169 | #if STM32_HAS_GPIOD
|
||
170 | gpio_init(GPIOD, &gpio_default_config.PDData); |
||
171 | #endif
|
||
172 | #if STM32_HAS_GPIOE
|
||
173 | gpio_init(GPIOE, &gpio_default_config.PEData); |
||
174 | #endif
|
||
175 | #if STM32_HAS_GPIOF
|
||
176 | gpio_init(GPIOF, &gpio_default_config.PFData); |
||
177 | #endif
|
||
178 | #if STM32_HAS_GPIOG
|
||
179 | gpio_init(GPIOG, &gpio_default_config.PGData); |
||
180 | #endif
|
||
181 | #if STM32_HAS_GPIOH
|
||
182 | gpio_init(GPIOH, &gpio_default_config.PHData); |
||
183 | #endif
|
||
184 | #if STM32_HAS_GPIOI
|
||
185 | gpio_init(GPIOI, &gpio_default_config.PIData); |
||
186 | e545e620 | Thomas Schöpping | #endif
|
187 | 0128be0f | Marc Rothmann | #if STM32_HAS_GPIOJ
|
188 | gpio_init(GPIOJ, &gpio_default_config.PJData); |
||
189 | #endif
|
||
190 | #if STM32_HAS_GPIOK
|
||
191 | gpio_init(GPIOK, &gpio_default_config.PKData); |
||
192 | #endif
|
||
193 | } |
||
194 | e545e620 | Thomas Schöpping | |
195 | /**
|
||
196 | * @brief Early initialization code.
|
||
197 | * @details This initialization must be performed just after stack setup
|
||
198 | * and before any other initialization.
|
||
199 | */
|
||
200 | void __early_init(void) { |
||
201 | |||
202 | 0128be0f | Marc Rothmann | stm32_gpio_init(); |
203 | e545e620 | Thomas Schöpping | stm32_clock_init(); |
204 | } |
||
205 | |||
206 | /**
|
||
207 | * @brief Board-specific initialization code.
|
||
208 | * @todo Add your board-specific code, if any.
|
||
209 | */
|
||
210 | void boardInit(void) { |
||
211 | } |
||
212 | 53710ca3 | Marc Rothmann | |
213 | /** @} */ |