Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / STM32F407G-DISC1 / board.h @ e7b5a625

History | View | Annotate | Download (85.793 KB)

1
/*
2
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

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
#ifndef BOARD_H
20
#define BOARD_H
21

    
22
/*===========================================================================*/
23
/* Driver constants.                                                         */
24
/*===========================================================================*/
25

    
26
/*
27
 * Setup for STMicroelectronics STM32F4-Discovery board.
28
 */
29

    
30
/*
31
 * Board identifier.
32
 */
33
#define BOARD_ST_STM32F4_DISCOVERY
34
#define BOARD_NAME                  "STMicroelectronics STM32F4-Discovery"
35

    
36
/*
37
 * Board oscillators-related settings.
38
 * NOTE: LSE not fitted.
39
 */
40
#if !defined(STM32_LSECLK)
41
#define STM32_LSECLK                0U
42
#endif
43

    
44
#if !defined(STM32_HSECLK)
45
#define STM32_HSECLK                8000000U
46
#endif
47

    
48
/*
49
 * Board voltages.
50
 * Required for performance limits calculation.
51
 */
52
#define STM32_VDD                   300U
53

    
54
/*
55
 * MCU type as defined in the ST header.
56
 */
57
#define STM32F407xx
58

    
59
/*
60
 * IO pins assignments.
61
 */
62
#define GPIOA_BUTTON                0U
63
#define GPIOA_PIN1                  1U
64
#define GPIOA_PIN2                  2U
65
#define GPIOA_PIN3                  3U
66
#define GPIOA_LRCK                  4U
67
#define GPIOA_SPC                   5U
68
#define GPIOA_SDO                   6U
69
#define GPIOA_SDI                   7U
70
#define GPIOA_PIN8                  8U
71
#define GPIOA_VBUS_FS               9U
72
#define GPIOA_OTG_FS_ID             10U
73
#define GPIOA_OTG_FS_DM             11U
74
#define GPIOA_OTG_FS_DP             12U
75
#define GPIOA_SWDIO                 13U
76
#define GPIOA_SWCLK                 14U
77
#define GPIOA_PIN15                 15U
78

    
79
#define GPIOB_PIN0                  0U
80
#define GPIOB_PIN1                  1U
81
#define GPIOB_PIN2                  2U
82
#define GPIOB_SWO                   3U
83
#define GPIOB_PIN4                  4U
84
#define GPIOB_PIN5                  5U
85
#define GPIOB_SCL                   6U
86
#define GPIOB_PIN7                  7U
87
#define GPIOB_PIN8                  8U
88
#define GPIOB_SDA                   9U
89
#define GPIOB_CLK_IN                10U
90
#define GPIOB_PIN11                 11U
91
#define GPIOB_PIN12                 12U
92
#define GPIOB_PIN13                 13U
93
#define GPIOB_PIN14                 14U
94
#define GPIOB_PIN15                 15U
95

    
96
#define GPIOC_OTG_FS_POWER_ON       0U
97
#define GPIOC_PIN1                  1U
98
#define GPIOC_PIN2                  2U
99
#define GPIOC_PDM_OUT               3U
100
#define GPIOC_PIN4                  4U
101
#define GPIOC_PIN5                  5U
102
#define GPIOC_PIN6                  6U
103
#define GPIOC_MCLK                  7U
104
#define GPIOC_PIN8                  8U
105
#define GPIOC_PIN9                  9U
106
#define GPIOC_SCLK                  10U
107
#define GPIOC_PIN11                 11U
108
#define GPIOC_SDIN                  12U
109
#define GPIOC_PIN13                 13U
110
#define GPIOC_PIN14                 14U
111
#define GPIOC_PIN15                 15U
112

    
113
#define GPIOD_PIN0                  0U
114
#define GPIOD_PIN1                  1U
115
#define GPIOD_PIN2                  2U
116
#define GPIOD_PIN3                  3U
117
#define GPIOD_RESET                 4U
118
#define GPIOD_OVER_CURRENT          5U
119
#define GPIOD_PIN6                  6U
120
#define GPIOD_PIN7                  7U
121
#define GPIOD_PIN8                  8U
122
#define GPIOD_PIN9                  9U
123
#define GPIOD_PIN10                 10U
124
#define GPIOD_PIN11                 11U
125
#define GPIOD_LED4                  12U
126
#define GPIOD_LED3                  13U
127
#define GPIOD_LED5                  14U
128
#define GPIOD_LED6                  15U
129

    
130
#define GPIOE_INT1                  0U
131
#define GPIOE_INT2                  1U
132
#define GPIOE_PIN2                  2U
133
#define GPIOE_CS_SPI                3U
134
#define GPIOE_PIN4                  4U
135
#define GPIOE_PIN5                  5U
136
#define GPIOE_PIN6                  6U
137
#define GPIOE_PIN7                  7U
138
#define GPIOE_PIN8                  8U
139
#define GPIOE_PIN9                  9U
140
#define GPIOE_PIN10                 10U
141
#define GPIOE_PIN11                 11U
142
#define GPIOE_PIN12                 12U
143
#define GPIOE_PIN13                 13U
144
#define GPIOE_PIN14                 14U
145
#define GPIOE_PIN15                 15U
146

    
147
#define GPIOF_PIN0                  0U
148
#define GPIOF_PIN1                  1U
149
#define GPIOF_PIN2                  2U
150
#define GPIOF_PIN3                  3U
151
#define GPIOF_PIN4                  4U
152
#define GPIOF_PIN5                  5U
153
#define GPIOF_PIN6                  6U
154
#define GPIOF_PIN7                  7U
155
#define GPIOF_PIN8                  8U
156
#define GPIOF_PIN9                  9U
157
#define GPIOF_PIN10                 10U
158
#define GPIOF_PIN11                 11U
159
#define GPIOF_PIN12                 12U
160
#define GPIOF_PIN13                 13U
161
#define GPIOF_PIN14                 14U
162
#define GPIOF_PIN15                 15U
163

    
164
#define GPIOG_PIN0                  0U
165
#define GPIOG_PIN1                  1U
166
#define GPIOG_PIN2                  2U
167
#define GPIOG_PIN3                  3U
168
#define GPIOG_PIN4                  4U
169
#define GPIOG_PIN5                  5U
170
#define GPIOG_PIN6                  6U
171
#define GPIOG_PIN7                  7U
172
#define GPIOG_PIN8                  8U
173
#define GPIOG_PIN9                  9U
174
#define GPIOG_PIN10                 10U
175
#define GPIOG_PIN11                 11U
176
#define GPIOG_PIN12                 12U
177
#define GPIOG_PIN13                 13U
178
#define GPIOG_PIN14                 14U
179
#define GPIOG_PIN15                 15U
180

    
181
#define GPIOH_OSC_IN                0U
182
#define GPIOH_OSC_OUT               1U
183
#define GPIOH_PIN2                  2U
184
#define GPIOH_PIN3                  3U
185
#define GPIOH_PIN4                  4U
186
#define GPIOH_PIN5                  5U
187
#define GPIOH_PIN6                  6U
188
#define GPIOH_PIN7                  7U
189
#define GPIOH_PIN8                  8U
190
#define GPIOH_PIN9                  9U
191
#define GPIOH_PIN10                 10U
192
#define GPIOH_PIN11                 11U
193
#define GPIOH_PIN12                 12U
194
#define GPIOH_PIN13                 13U
195
#define GPIOH_PIN14                 14U
196
#define GPIOH_PIN15                 15U
197

    
198
#define GPIOI_PIN0                  0U
199
#define GPIOI_PIN1                  1U
200
#define GPIOI_PIN2                  2U
201
#define GPIOI_PIN3                  3U
202
#define GPIOI_PIN4                  4U
203
#define GPIOI_PIN5                  5U
204
#define GPIOI_PIN6                  6U
205
#define GPIOI_PIN7                  7U
206
#define GPIOI_PIN8                  8U
207
#define GPIOI_PIN9                  9U
208
#define GPIOI_PIN10                 10U
209
#define GPIOI_PIN11                 11U
210
#define GPIOI_PIN12                 12U
211
#define GPIOI_PIN13                 13U
212
#define GPIOI_PIN14                 14U
213
#define GPIOI_PIN15                 15U
214

    
215
/*
216
 * IO lines assignments.
217
 */
218
#define LINE_BUTTON                 PAL_LINE(GPIOA, GPIOA_BUTTON)
219
#define LINE_LRCK                   PAL_LINE(GPIOA, GPIOA_LRCK)
220
#define LINE_SPC                    PAL_LINE(GPIOA, GPIOA_SPC)
221
#define LINE_SDO                    PAL_LINE(GPIOA, GPIOA_SDO)
222
#define LINE_SDI                    PAL_LINE(GPIOA, GPIOA_SDI)
223
#define LINE_VBUS_FS                PAL_LINE(GPIOA, GPIOA_VBUS_FS)
224
#define LINE_OTG_FS_ID              PAL_LINE(GPIOA, GPIOA_OTG_FS_ID)
225
#define LINE_OTG_FS_DM              PAL_LINE(GPIOA, GPIOA_FS_DM)
226
#define LINE_OTG_FS_DP              PAL_LINE(GPIOA, GPIOA_FS_DP)
227
#define LINE_SWDIO                  PAL_LINE(GPIOA, GPIOA_SWDIO)
228
#define LINE_SWCLK                  PAL_LINE(GPIOA, GPIOA_SWCLK)
229

    
230
#define LINE_SWO                    PAL_LINE(GPIOB, GPIOB_SWO)
231
#define LINE_SCL                    PAL_LINE(GPIOB, GPIOA_SCL)
232
#define LINE_SDA                    PAL_LINE(GPIOB, GPIOA_SDA)
233
#define LINE_CLK_IN                 PAL_LINE(GPIOB, GPIOA_CLK_IN)
234

    
235
#define LINE_OTG_FS_POWER_ON        PAL_LINE(GPIOC, GPIOC_OTG_FS_POWER_ON)
236
#define LINE_PDM_OUT                PAL_LINE(GPIOC, GPIOC_PDM_OUT)
237
#define LINE_MCLK                   PAL_LINE(GPIOC, GPIOC_MCLK)
238
#define LINE_SCLK                   PAL_LINE(GPIOC, GPIOC_SCLK)
239
#define LINE_SDIN                   PAL_LINE(GPIOC, GPIOC_SDIN)
240

    
241
#define LINE_RESET                  PAL_LINE(GPIOD, GPIOD_RESET)
242
#define LINE_OVER_CURRENT           PAL_LINE(GPIOD, GPIOD_OVER_CURRENT)
243
#define LINE_LED4                   PAL_LINE(GPIOD, GPIOD_LED4)
244
#define LINE_LED3                   PAL_LINE(GPIOD, GPIOD_LED3)
245
#define LINE_LED5                   PAL_LINE(GPIOD, GPIOD_LED5)
246
#define LINE_LED6                   PAL_LINE(GPIOD, GPIOD_LED6)
247

    
248
#define LINE_INT1                   PAL_LINE(GPIOE, GPIOE_INT1)
249
#define LINE_INT2                   PAL_LINE(GPIOE, GPIOE_INT2)
250
#define LINE_CS_SPI                 PAL_LINE(GPIOE, GPIOE_VS_SPI)
251

    
252
#define LINE_OSC_IN                 PAL_LINE(GPIOH, GPIOH_OSC_IN)
253
#define LINE_OSC_OUT                PAL_LINE(GPIOH, GPIOE_OSC_OUT)
254

    
255
/*===========================================================================*/
256
/* Driver pre-compile time settings.                                         */
257
/*===========================================================================*/
258

    
259
/*===========================================================================*/
260
/* Derived constants and error checks.                                       */
261
/*===========================================================================*/
262

    
263
/*===========================================================================*/
264
/* Driver data structures and types.                                         */
265
/*===========================================================================*/
266

    
267
/*===========================================================================*/
268
/* Driver macros.                                                            */
269
/*===========================================================================*/
270

    
271
/*
272
 * I/O ports initial setup, this configuration is established soon after reset
273
 * in the initialization code.
274
 * Please refer to the STM32 Reference Manual for details.
275
 */
276
#define PIN_MODE_INPUT(n)           (0U << ((n) * 2U))
277
#define PIN_MODE_OUTPUT(n)          (1U << ((n) * 2U))
278
#define PIN_MODE_ALTERNATE(n)       (2U << ((n) * 2U))
279
#define PIN_MODE_ANALOG(n)          (3U << ((n) * 2U))
280
#define PIN_ODR_LOW(n)              (0U << (n))
281
#define PIN_ODR_HIGH(n)             (1U << (n))
282
#define PIN_OTYPE_PUSHPULL(n)       (0U << (n))
283
#define PIN_OTYPE_OPENDRAIN(n)      (1U << (n))
284
#define PIN_OSPEED_VERYLOW(n)       (0U << ((n) * 2U))
285
#define PIN_OSPEED_LOW(n)           (1U << ((n) * 2U))
286
#define PIN_OSPEED_MEDIUM(n)        (2U << ((n) * 2U))
287
#define PIN_OSPEED_HIGH(n)          (3U << ((n) * 2U))
288
#define PIN_PUPDR_FLOATING(n)       (0U << ((n) * 2U))
289
#define PIN_PUPDR_PULLUP(n)         (1U << ((n) * 2U))
290
#define PIN_PUPDR_PULLDOWN(n)       (2U << ((n) * 2U))
291
#define PIN_AFIO_AF(n, v)           ((v) << (((n) % 8U) * 4U))
292

    
293
/*
294
 * GPIOA setup:
295
 *
296
 * PA0  - BUTTON                    (input floating).
297
 * PA1  - PIN1                      (input pullup).
298
 * PA2  - PIN2                      (input pullup).
299
 * PA3  - PIN3                      (input pullup).
300
 * PA4  - LRCK                      (alternate 6).
301
 * PA5  - SPC                       (alternate 5).
302
 * PA6  - SDO                       (alternate 5).
303
 * PA7  - SDI                       (alternate 5).
304
 * PA8  - PIN8                      (input pullup).
305
 * PA9  - VBUS_FS                   (input floating).
306
 * PA10 - OTG_FS_ID                 (alternate 10).
307
 * PA11 - OTG_FS_DM                 (alternate 10).
308
 * PA12 - OTG_FS_DP                 (alternate 10).
309
 * PA13 - SWDIO                     (alternate 0).
310
 * PA14 - SWCLK                     (alternate 0).
311
 * PA15 - PIN15                     (input pullup).
312
 */
313
#define VAL_GPIOA_MODER             (PIN_MODE_INPUT(GPIOA_BUTTON) |         \
314
                                     PIN_MODE_INPUT(GPIOA_PIN1) |           \
315
                                     PIN_MODE_ALTERNATE(GPIOA_PIN2) |       \
316
                                     PIN_MODE_ALTERNATE(GPIOA_PIN3) |       \
317
                                     PIN_MODE_ALTERNATE(GPIOA_LRCK) |       \
318
                                     PIN_MODE_ALTERNATE(GPIOA_SPC) |        \
319
                                     PIN_MODE_ALTERNATE(GPIOA_SDO) |        \
320
                                     PIN_MODE_ALTERNATE(GPIOA_SDI) |        \
321
                                     PIN_MODE_INPUT(GPIOA_PIN8) |           \
322
                                     PIN_MODE_INPUT(GPIOA_VBUS_FS) |        \
323
                                     PIN_MODE_ALTERNATE(GPIOA_OTG_FS_ID) |  \
324
                                     PIN_MODE_ALTERNATE(GPIOA_OTG_FS_DM) |  \
325
                                     PIN_MODE_ALTERNATE(GPIOA_OTG_FS_DP) |  \
326 <