Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / STM32F407G-DISC1 / board.c @ 0f60c8ad

History | View | Annotate | Download (8.01 KB)

1 07ff44a7 Thomas Schöpping
/*
2 0f60c8ad Thomas Schöpping
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 07ff44a7 Thomas Schöpping

5 0f60c8ad Thomas Schöpping
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 07ff44a7 Thomas Schöpping

10 0f60c8ad Thomas Schöpping
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 07ff44a7 Thomas Schöpping

15 0f60c8ad Thomas Schöpping
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 07ff44a7 Thomas Schöpping
*/
18
19
#include "hal.h"
20
#include "stm32_gpio.h"
21
22
/*===========================================================================*/
23
/* Driver local definitions.                                                 */
24
/*===========================================================================*/
25
26
/*===========================================================================*/
27
/* Driver exported variables.                                                */
28
/*===========================================================================*/
29
30
/*===========================================================================*/
31
/* Driver local variables and types.                                         */
32
/*===========================================================================*/
33
34
/**
35
 * @brief   Type of STM32 GPIO port setup.
36
 */
37
typedef struct {
38
  uint32_t              moder;
39
  uint32_t              otyper;
40
  uint32_t              ospeedr;
41
  uint32_t              pupdr;
42
  uint32_t              odr;
43
  uint32_t              afrl;
44
  uint32_t              afrh;
45
} gpio_setup_t;
46
47
/**
48
 * @brief   Type of STM32 GPIO initialization data.
49
 */
50
typedef struct {
51
#if STM32_HAS_GPIOA || defined(__DOXYGEN__)
52
  gpio_setup_t          PAData;
53
#endif
54
#if STM32_HAS_GPIOB || defined(__DOXYGEN__)
55
  gpio_setup_t          PBData;
56
#endif
57
#if STM32_HAS_GPIOC || defined(__DOXYGEN__)
58
  gpio_setup_t          PCData;
59
#endif
60
#if STM32_HAS_GPIOD || defined(__DOXYGEN__)
61
  gpio_setup_t          PDData;
62
#endif
63
#if STM32_HAS_GPIOE || defined(__DOXYGEN__)
64
  gpio_setup_t          PEData;
65
#endif
66
#if STM32_HAS_GPIOF || defined(__DOXYGEN__)
67
  gpio_setup_t          PFData;
68
#endif
69
#if STM32_HAS_GPIOG || defined(__DOXYGEN__)
70
  gpio_setup_t          PGData;
71
#endif
72
#if STM32_HAS_GPIOH || defined(__DOXYGEN__)
73
  gpio_setup_t          PHData;
74
#endif
75
#if STM32_HAS_GPIOI || defined(__DOXYGEN__)
76
  gpio_setup_t          PIData;
77
#endif
78
#if STM32_HAS_GPIOJ || defined(__DOXYGEN__)
79
  gpio_setup_t          PJData;
80
#endif
81
#if STM32_HAS_GPIOK || defined(__DOXYGEN__)
82
  gpio_setup_t          PKData;
83
#endif
84
} gpio_config_t;
85
86
/**
87
 * @brief   STM32 GPIO static initialization data.
88
 */
89
static const gpio_config_t gpio_default_config = {
90
#if STM32_HAS_GPIOA
91
  {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR,
92
   VAL_GPIOA_ODR,   VAL_GPIOA_AFRL,   VAL_GPIOA_AFRH},
93
#endif
94
#if STM32_HAS_GPIOB
95
  {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR,
96
   VAL_GPIOB_ODR,   VAL_GPIOB_AFRL,   VAL_GPIOB_AFRH},
97
#endif
98
#if STM32_HAS_GPIOC
99
  {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR,
100
   VAL_GPIOC_ODR,   VAL_GPIOC_AFRL,   VAL_GPIOC_AFRH},
101
#endif
102
#if STM32_HAS_GPIOD
103
  {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR,
104
   VAL_GPIOD_ODR,   VAL_GPIOD_AFRL,   VAL_GPIOD_AFRH},
105
#endif
106
#if STM32_HAS_GPIOE
107
  {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR,
108
   VAL_GPIOE_ODR,   VAL_GPIOE_AFRL,   VAL_GPIOE_AFRH},
109
#endif
110
#if STM32_HAS_GPIOF
111
  {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR,
112
   VAL_GPIOF_ODR,   VAL_GPIOF_AFRL,   VAL_GPIOF_AFRH},
113
#endif
114
#if STM32_HAS_GPIOG
115
  {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR,
116
   VAL_GPIOG_ODR,   VAL_GPIOG_AFRL,   VAL_GPIOG_AFRH},
117
#endif
118
#if STM32_HAS_GPIOH
119
  {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR,
120
   VAL_GPIOH_ODR,   VAL_GPIOH_AFRL,   VAL_GPIOH_AFRH},
121
#endif
122
#if STM32_HAS_GPIOI
123
  {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR,
124
   VAL_GPIOI_ODR,   VAL_GPIOI_AFRL,   VAL_GPIOI_AFRH},
125
#endif
126
#if STM32_HAS_GPIOJ
127
  {VAL_GPIOJ_MODER, VAL_GPIOJ_OTYPER, VAL_GPIOJ_OSPEEDR, VAL_GPIOJ_PUPDR,
128
   VAL_GPIOJ_ODR,   VAL_GPIOJ_AFRL,   VAL_GPIOJ_AFRH},
129
#endif
130
#if STM32_HAS_GPIOK
131
  {VAL_GPIOK_MODER, VAL_GPIOK_OTYPER, VAL_GPIOK_OSPEEDR, VAL_GPIOK_PUPDR,
132
   VAL_GPIOK_ODR,   VAL_GPIOK_AFRL,   VAL_GPIOK_AFRH}
133
#endif
134
};
135
136
/*===========================================================================*/
137
/* Driver local functions.                                                   */
138
/*===========================================================================*/
139
140
static void gpio_init(stm32_gpio_t *gpiop, const gpio_setup_t *config) {
141
142
  gpiop->OTYPER  = config->otyper;
143
  gpiop->OSPEEDR = config->ospeedr;
144
  gpiop->PUPDR   = config->pupdr;
145
  gpiop->ODR     = config->odr;
146
  gpiop->AFRL    = config->afrl;
147
  gpiop->AFRH    = config->afrh;
148
  gpiop->MODER   = config->moder;
149
}
150
151
static void stm32_gpio_init(void) {
152
153
  /* Enabling GPIO-related clocks, the mask comes from the
154
     registry header file.*/
155
  rccResetAHB1(STM32_GPIO_EN_MASK);
156
  rccEnableAHB1(STM32_GPIO_EN_MASK, true);
157
158
  /* Initializing all the defined GPIO ports.*/
159
#if STM32_HAS_GPIOA
160
  gpio_init(GPIOA, &gpio_default_config.PAData);
161
#endif
162
#if STM32_HAS_GPIOB
163
  gpio_init(GPIOB, &gpio_default_config.PBData);
164
#endif
165
#if STM32_HAS_GPIOC
166
  gpio_init(GPIOC, &gpio_default_config.PCData);
167
#endif
168
#if STM32_HAS_GPIOD
169
  gpio_init(GPIOD, &gpio_default_config.PDData);
170
#endif
171
#if STM32_HAS_GPIOE
172
  gpio_init(GPIOE, &gpio_default_config.PEData);
173
#endif
174
#if STM32_HAS_GPIOF
175
  gpio_init(GPIOF, &gpio_default_config.PFData);
176
#endif
177
#if STM32_HAS_GPIOG
178
  gpio_init(GPIOG, &gpio_default_config.PGData);
179
#endif
180
#if STM32_HAS_GPIOH
181
  gpio_init(GPIOH, &gpio_default_config.PHData);
182
#endif
183
#if STM32_HAS_GPIOI
184
  gpio_init(GPIOI, &gpio_default_config.PIData);
185
#endif
186
#if STM32_HAS_GPIOJ
187
  gpio_init(GPIOJ, &gpio_default_config.PJData);
188
#endif
189
#if STM32_HAS_GPIOK
190
  gpio_init(GPIOK, &gpio_default_config.PKData);
191
#endif
192
}
193
194
/*===========================================================================*/
195
/* Driver interrupt handlers.                                                */
196
/*===========================================================================*/
197
198
/*===========================================================================*/
199
/* Driver exported functions.                                                */
200
/*===========================================================================*/
201
202
/**
203
 * @brief   Early initialization code.
204
 * @details GPIO ports and system clocks are initialized before everything
205
 *          else.
206
 */
207
void __early_init(void) {
208
209
  stm32_gpio_init();
210
  stm32_clock_init();
211
}
212
213
#if HAL_USE_SDC || defined(__DOXYGEN__)
214
/**
215
 * @brief   SDC card detection.
216
 */
217
bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
218
219
  (void)sdcp;
220
  /* TODO: Fill the implementation.*/
221
  return true;
222
}
223
224
/**
225
 * @brief   SDC card write protection detection.
226
 */
227
bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
228
229
  (void)sdcp;
230
  /* TODO: Fill the implementation.*/
231
  return false;
232
}
233
#endif /* HAL_USE_SDC */
234
235
#if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
236
/**
237
 * @brief   MMC_SPI card detection.
238
 */
239
bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
240
241
  (void)mmcp;
242
  /* TODO: Fill the implementation.*/
243
  return true;
244
}
245
246
/**
247
 * @brief   MMC_SPI card write protection detection.
248
 */
249
bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
250
251
  (void)mmcp;
252
  /* TODO: Fill the implementation.*/
253
  return false;
254
}
255
#endif
256
257
/**
258
 * @brief   Board-specific initialization code.
259
 * @todo    Add your board-specific code, if any.
260
 */
261
void boardInit(void) {
262
263
}