aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/STM32F1xx/hal_lld.h
blob: 44e179f4942e9e61cbf6de779a3d5d9e19542c7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
/*
    ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
                 2011 Giovanni Di Sirio.

    This file is part of ChibiOS/RT.

    ChibiOS/RT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    ChibiOS/RT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file    STM32/hal_lld.h
 * @brief   STM32 HAL subsystem low level driver header.
 * @pre     This module requires the following macros to be defined in the
 *          @p board.h file:
 *          - STM32_LSECLK.
 *          - STM32_HSECLK.
 *          .
 *          One of the following macros must also be defined:
 *          - STM32F10X_LD_VL for Value Line Low Density devices.
 *          - STM32F10X_MD_VL for Value Line Medium Density devices.
 *          - STM32F10X_LD for Performance Low Density devices.
 *          - STM32F10X_MD for Performance Medium Density devices.
 *          - STM32F10X_HD for Performance High Density devices.
 *          - STM32F10X_XL for Performance eXtra Density devices.
 *          - STM32F10X_CL for Connectivity Line devices.
 *          .
 *
 * @addtogroup HAL
 * @{
 */

#ifndef _HAL_LLD_H_
#define _HAL_LLD_H_

/*===========================================================================*/
/* Driver constants.                                                         */
/*===========================================================================*/

/*===========================================================================*/
/* Driver pre-compile time settings.                                         */
/*===========================================================================*/

/*===========================================================================*/
/* Derived constants and error checks.                                       */
/*===========================================================================*/

/**
 * @brief   Platform name.
 */
#if defined(__DOXYGEN__)
#define PLATFORM_NAME           "STM32"

#elif defined(STM32F10X_LD_VL)
/*
 * Capability flags for Value Line Low Density devices.
 */
#define PLATFORM_NAME           "STM32 Value Line Low Density"
#include "hal_lld_f100.h"

#define STM32_HAS_ADC1          TRUE
#define STM32_HAS_ADC2          FALSE
#define STM32_HAS_ADC3          FALSE

#define STM32_HAS_CAN1          FALSE
#define STM32_HAS_CAN2          FALSE

#define STM32_HAS_DAC           TRUE

#define STM32_HAS_DMA1          TRUE
#define STM32_HAS_DMA2          FALSE

#define STM32_HAS_ETH           FALSE

#define STM32_HAS_GPIOA         TRUE
#define STM32_HAS_GPIOB         TRUE
#define STM32_HAS_GPIOC         TRUE
#define STM32_HAS_GPIOD         TRUE
#define STM32_HAS_GPIOE         TRUE
#define STM32_HAS_GPIOF         FALSE
#define STM32_HAS_GPIOG         FALSE
#define STM32_HAS_GPIOH         FALSE

#define STM32_HAS_I2C1          TRUE
#define STM32_HAS_I2C2          FALSE

#define STM32_HAS_RTC           TRUE

#define STM32_HAS_SDIO          FALSE

#define STM32_HAS_SPI1          TRUE
#define STM32_HAS_SPI2          FALSE
#define STM32_HAS_SPI3          FALSE

#define STM32_HAS_TIM1          TRUE
#define STM32_HAS_TIM2          TRUE
#define STM32_HAS_TIM3          TRUE
#define STM32_HAS_TIM4          FALSE
#define STM32_HAS_TIM5          FALSE
#define STM32_HAS_TIM6          TRUE
#define STM32_HAS_TIM7          TRUE
#define STM32_HAS_TIM8          FALSE
#define STM32_HAS_TIM9          FALSE
#define STM32_HAS_TIM10         FALSE
#define STM32_HAS_TIM11         FALSE
#define STM32_HAS_TIM12         FALSE
#define STM32_HAS_TIM13         FALSE
#define STM32_HAS_TIM14         FALSE
#define STM32_HAS_TIM15         TRUE
#define STM32_HAS_TIM16         TRUE
#define STM32_HAS_TIM17         TRUE

#define STM32_HAS_USART1        TRUE
#define STM32_HAS_USART2        TRUE
#define STM32_HAS_USART3        FALSE
#define STM32_HAS_UART3         FALSE
#define STM32_HAS_UART4         FALSE

#define STM32_HAS_USB           FALSE
#define STM32_HAS_OTG1          FALSE

#elif defined(STM32F10X_MD_VL)
/*
 * Capability flags for Value Line Medium Density devices.
 */
#define PLATFORM_NAME           "STM32 Value Line Medium Density"
#include "hal_lld_f100.h"

#define STM32_HAS_ADC1          TRUE
#define STM32_HAS_ADC2          FALSE
#define STM32_HAS_ADC3          FALSE

#define STM32_HAS_CAN1          FALSE
#define STM32_HAS_CAN2          FALSE

#define STM32_HAS_DAC           TRUE

#define STM32_HAS_DMA1          TRUE
#define STM32_HAS_DMA2          FALSE

#define STM32_HAS_ETH           FALSE

#define STM32_HAS_GPIOA         TRUE
#define STM32_HAS_GPIOB         TRUE
#define STM32_HAS_GPIOC         TRUE
#define STM32_HAS_GPIOD         TRUE
#define STM32_HAS_GPIOE         TRUE
#define STM32_HAS_GPIOF         FALSE
#define STM32_HAS_GPIOG         FALSE
#define STM32_HAS_GPIOH         FALSE

#define STM32_HAS_I2C1          TRUE
#define STM32_HAS_I2C2          TRUE

#define STM32_HAS_RTC           TRUE

#define STM32_HAS_SDIO          FALSE

#define STM32_HAS_SPI1          TRUE
#define STM32_HAS_SPI2          TRUE
#define STM32_HAS_SPI3          FALSE

#define STM32_HAS_TIM1          TRUE
#define STM32_HAS_TIM2          TRUE
#define STM32_HAS_TIM3          TRUE
#define STM32_HAS_TIM4          TRUE
#define STM32_HAS_TIM5          FALSE
#define STM32_HAS_TIM6          TRUE
#define STM32_HAS_TIM7          TRUE
#define STM32_HAS_TIM8          FALSE
#define STM32_HAS_TIM9          FALSE
#define STM32_HAS_TIM10         FALSE
#define STM32_HAS_TIM11         FALSE
#define STM32_HAS_TIM12         FALSE
#define STM32_HAS_TIM13         FALSE
#define STM32_HAS_TIM14         FALSE
#define STM32_HAS_TIM15         TRUE
#define STM32_HAS_TIM16         TRUE
#define STM32_HAS_TIM17         TRUE

#define STM32_HAS_USART1        TRUE
#define STM32_HAS_USART2        TRUE
#define STM32_HAS_USART3        TRUE
#define STM32_HAS_UART3         FALSE
#define STM32_HAS_UART4         FALSE

#define STM32_HAS_USB           FALSE
#define STM32_HAS_OTG1          FALSE

#elif defined(STM32F10X_LD)
/*
 * Capability flags for Performance Line Low Density devices.
 */
#define PLATFORM_NAME           "STM32 Performance Line Low Density"
#include "hal_lld_f103.h"

#define STM32_HAS_ADC1          TRUE
#define STM32_HAS_ADC2          TRUE
#define STM32_HAS_ADC3          FALSE

#define STM32_HAS_CAN1          TRUE
#define STM32_HAS_CAN2          FALSE

#define STM32_HAS_DAC           FALSE

#define STM32_HAS_DMA1          TRUE
#define STM32_HAS_DMA2          FALSE

#define STM32_HAS_ETH           FALSE

#define STM32_HAS_GPIOA         TRUE
#define STM32_HAS_GPIOB         TRUE
#define STM32_HAS_GPIOC         TRUE
#define STM32_HAS_GPIOD         TRUE
#define STM32_HAS_GPIOE         FALSE
#define STM32_HAS_GPIOF         FALSE
#define STM32_HAS_GPIOG         FALSE
#define STM32_HAS_GPIOH         FALSE

#define STM32_HAS_I2C1          TRUE
#define STM32_HAS_I2C2          FALSE

#define STM32_HAS_RTC           TRUE

#define STM32_HAS_SDIO          FALSE

#define STM32_HAS_SPI1          TRUE
#define STM32_HAS_SPI2          FALSE
#define STM32_HAS_SPI3          FALSE

#define STM32_HAS_TIM1          TRUE
#define STM32_HAS_TIM2          TRUE
#define STM32_HAS_TIM3          TRUE
#define STM32_HAS_TIM4          FALSE
#define STM32_HAS_TIM5          FALSE
#define STM32_HAS_TIM6          FALSE
#define STM32_HAS_TIM7          FALSE
#define STM32_HAS_TIM8          FALSE
#define STM32_HAS_TIM9          FALSE
#define STM32_HAS_TIM10         FALSE
#define STM32_HAS_TIM11         FALSE
#define STM32_HAS_TIM12         FALSE
#define STM32_HAS_TIM13         FALSE
#define STM32_HAS_TIM14         FALSE
#define STM32_HAS_TIM15         FALSE
#define STM32_HAS_TIM16         FALSE
#define STM32_HAS_TIM17         FALSE

#define STM32_HAS_USART1        TRUE
#define STM32_HAS_USART2        TRUE
#define STM32_HAS_USART3        FALSE
#define STM32_HAS_UART3         FALSE
#define STM32_HAS_UART4         FALSE

#define STM32_HAS_USB           FALSE
#define STM32_HAS_OTG1          FALSE

#elif defined(STM32F10X_MD)
/*
 * Capability flags for Performance Line Medium Density devices.
 */
#define PLATFORM_NAME           "STM32 Performance Line Medium Density"
#include "hal_lld_f103.h"

#define STM32_HAS_ADC1          TRUE
#define STM32_HAS_ADC2          TRUE
#define STM32_HAS_ADC3          FALSE

#define STM32_HAS_CAN1          TRUE
#define STM32_HAS_CAN2          FALSE

#define STM32_HAS_DAC           FALSE

#define STM32_HAS_DMA1          TRUE
#define STM32_HAS_DMA2          FALSE

#define STM32_HAS_ETH           FALSE

#define STM32_HAS_GPIOA         TRUE
#define STM32_HAS_GPIOB         TRUE
#define STM32_HAS_GPIOC         TRUE
#define STM32_HAS_GPIOD         TRUE
#define STM32_HAS_GPIOE         TRUE
#define STM32_HAS_GPIOF         FALSE
#define STM32_HAS_GPIOG         FALSE
#define STM32_HAS_GPIOH         FALSE

#define STM32_HAS_I2C1          TRUE
#define STM32_HAS_I2C2          TRUE

#define STM32_HAS_RTC           TRUE

#define STM32_HAS_SDIO          FALSE

#define STM32_HAS_SPI1          TRUE
#define STM32_HAS_SPI2          TRUE
#define STM32_HAS_SPI3          FALSE

#define STM32_HAS_TIM1          TRUE
#define STM32_HAS_TIM2          TRUE
#define STM32_HAS_TIM3          TRUE
#define STM32_HAS_TIM4          TRUE
#define STM32_HAS_TIM5          FALSE
#define STM32_HAS_TIM6          FALSE
#define STM32_HAS_TIM7          FALSE
#define STM32_HAS_TIM8          FALSE
#define STM32_HAS_TIM9          FALSE
#define STM32_HAS_TIM10         FALSE
#define STM32_HAS_TIM11         FALSE
#define STM32_HAS_TIM12         FALSE
#define STM32_HAS_TIM13         FALSE
#define STM32_HAS_TIM14         FALSE
#define STM32_HAS_TIM15         FALSE
#define STM32_HAS_TIM16         FALSE
#define STM32_HAS_TIM17         FALSE

#define STM32_HAS_USART1        TRUE
#define STM32_HAS_USART2        TRUE
#define STM32_HAS_USART3        TRUE
#define STM32_HAS_UART3         FALSE
#define STM32_HAS_UART4         FALSE

#define STM32_HAS_USB           TRUE
#define STM32_HAS_OTG1          FALSE

#elif defined(STM32F10X_HD)
/*
 * Capability flags for Performance Line High Density devices.
 */
#define PLATFORM_NAME           "STM32 Performance Line High Density"
#include "hal_lld_f103.h"

#define STM32_HAS_ADC1          TRUE
#define STM32_HAS_ADC2          TRUE
#define STM32_HAS_ADC3          TRUE

#define STM32_HAS_CAN1          TRUE
#define STM32_HAS_CAN2          FALSE

#define STM32_HAS_DAC           TRUE

#define STM32_HAS_DMA1          TRUE
#define STM32_HAS_DMA2          TRUE

#define STM32_HAS_ETH           FALSE

#define STM32_HAS_GPIOA         TRUE
#define STM32_HAS_GPIOB         TRUE
#define STM32_HAS_GPIOC         TRUE
#define STM32_HAS_GPIOD         TRUE
#define STM32_HAS_GPIOE         TRUE
#define STM32_HAS_GPIOF         TRUE
#define STM32_HAS_GPIOG         TRUE
#define STM32_HAS_GPIOH         FALSE

#define STM32_HAS_I2C1          TRUE
#define STM32_HAS_I2C2          TRUE

#define STM32_HAS_RTC           TRUE

#define STM32_HAS_SDIO          TRUE

#define STM32_HAS_SPI1          TRUE
#define STM32_HAS_SPI2          TRUE
#define STM32_HAS_SPI3          TRUE

#define STM32_HAS_TIM1          TRUE
#define STM32_HAS_TIM2          TRUE
#define STM32_HAS_TIM3          TRUE
#define STM32_HAS_TIM4          TRUE
#define STM32_HAS_TIM5          TRUE
#define STM32_HAS_TIM6          TRUE
#define STM32_HAS_TIM7          TRUE
#define STM32_HAS_TIM8          TRUE
#define STM32_HAS_TIM9          TRUE
#define STM32_HAS_TIM10         TRUE
#define STM32_HAS_TIM11         TRUE
#define STM32_HAS_TIM12         TRUE
#define STM32_HAS_TIM13         TRUE
#define STM32_HAS_TIM14         TRUE
#define STM32_HAS_TIM15         FALSE
#define STM32_HAS_TIM16         FALSE
#define STM32_HAS_TIM17         FALSE

#define STM32_HAS_USART1        TRUE
#define STM32_HAS_USART2        TRUE
#define STM32_HAS_USART3        TRUE
#define STM32_HAS_UART3         TRUE
#define STM32_HAS_UART4         TRUE

#define STM32_HAS_USB           TRUE
#define STM32_HAS_OTG1          FALSE

#elif defined(STM32F10X_XL)
/*
 * Capability flags for Performance Line eXtra Density devices.
 */
#define PLATFORM_NAME           "STM32 Performance Line eXtra Density"
#include "hal_lld_f103.h"

#define STM32_HAS_ADC1          TRUE
#define STM32_HAS_ADC2          TRUE
#define STM32_HAS_ADC3          TRUE

#define STM32_HAS_CAN1          TRUE
#define STM32_HAS_CAN2          FALSE

#define STM32_HAS_DAC           TRUE

#define STM32_HAS_DMA1          TRUE
#define STM32_HAS_DMA2          TRUE

#define STM32_HAS_ETH           FALSE

#define STM32_HAS_GPIOA         TRUE
#define STM32_HAS_GPIOB         TRUE
#define STM32_HAS_GPIOC         TRUE
#define STM32_HAS_GPIOD         TRUE
#define STM32_HAS_GPIOE         TRUE
#define STM32_HAS_GPIOF         TRUE
#define STM32_HAS_GPIOG         TRUE
#define STM32_HAS_GPIOH         FALSE

#define STM32_HAS_I2C1          TRUE
#define STM32_HAS_I2C2          TRUE

#define STM32_HAS_RTC           TRUE

#define STM32_HAS_SDIO          TRUE

#define STM32_HAS_SPI1          TRUE
#define STM32_HAS_SPI2          TRUE
#define STM32_HAS_SPI3          TRUE

#define STM32_HAS_TIM1          TRUE
#define STM32_HAS_TIM2          TRUE
#define STM32_HAS_TIM3          TRUE
#define STM32_HAS_TIM4          TRUE
#define STM32_HAS_TIM5          TRUE
#define STM32_HAS_TIM6          TRUE
#define STM32_HAS_TIM7          TRUE
#define STM32_HAS_TIM8          TRUE
#define STM32_HAS_TIM9          FALSE
#define STM32_HAS_TIM10         FALSE
#define STM32_HAS_TIM11         FALSE
#define STM32_HAS_TIM12         FALSE
#define STM32_HAS_TIM13         FALSE
#define STM32_HAS_TIM14         FALSE
#define STM32_HAS_TIM15         FALSE
#define STM32_HAS_TIM16         FALSE
#define STM32_HAS_TIM17         FALSE

#define STM32_HAS_USART1        TRUE
#define STM32_HAS_USART2        TRUE
#define STM32_HAS_USART3        TRUE
#define STM32_HAS_UART3         TRUE
#define STM32_HAS_UART4         TRUE

#define STM32_HAS_USB           TRUE
#define STM32_HAS_OTG1          FALSE

#elif defined(STM32F10X_CL)
/*
 * Capability flags for Connectivity Line devices.
 */
#define PLATFORM_NAME           "STM32 Connectivity Line"
#include "hal_lld_f105_f107.h"

#define STM32_HAS_ADC1          TRUE
#define STM32_HAS_ADC2          TRUE
#define STM32_HAS_ADC3          FALSE

#define STM32_HAS_CAN1          TRUE
#define STM32_HAS_CAN2          TRUE

#define STM32_HAS_DAC           TRUE

#define STM32_HAS_DMA1          TRUE
#define STM32_HAS_DMA2          TRUE

#define STM32_HAS_ETH           TRUE

#define STM32_HAS_GPIOA         TRUE
#define STM32_HAS_GPIOB         TRUE
#define STM32_HAS_GPIOC         TRUE
#define STM32_HAS_GPIOD         TRUE
#define STM32_HAS_GPIOE         TRUE
#define STM32_HAS_GPIOF         FALSE
#define STM32_HAS_GPIOG         FALSE
#define STM32_HAS_GPIOH         FALSE

#define STM32_HAS_I2C1          TRUE
#define STM32_HAS_I2C2          TRUE

#define STM32_HAS_RTC           TRUE

#define STM32_HAS_SDIO          FALSE

#define STM32_HAS_SPI1          TRUE
#define STM32_HAS_SPI2          TRUE
#define STM32_HAS_SPI3          TRUE

#define STM32_HAS_TIM1          TRUE
#define STM32_HAS_TIM2          TRUE
#define STM32_HAS_TIM3          TRUE
#define STM32_HAS_TIM4          TRUE
#define STM32_HAS_TIM5          TRUE
#define STM32_HAS_TIM6          TRUE
#define STM32_HAS_TIM7          TRUE
#define STM32_HAS_TIM8          FALSE
#define STM32_HAS_TIM9          FALSE
#define STM32_HAS_TIM10         FALSE
#define STM32_HAS_TIM11         FALSE
#define STM32_HAS_TIM12         FALSE
#define STM32_HAS_TIM13         FALSE
#define STM32_HAS_TIM14         FALSE
#define STM32_HAS_TIM15         FALSE
#define STM32_HAS_TIM16         FALSE
#define STM32_HAS_TIM17         FALSE

#define STM32_HAS_USART1        TRUE
#define STM32_HAS_USART2        TRUE
#define STM32_HAS_USART3        TRUE
#define STM32_HAS_UART3         TRUE
#define STM32_HAS_UART4         TRUE

#define STM32_HAS_USB           FALSE
#define STM32_HAS_OTG1          TRUE

#else
#error "unspecified, unsupported or invalid STM32 platform"
#endif

/* There are differences in vector names in the various sub-families,
   normalizing.*/
#if defined(STM32F10X_XL)
#define TIM1_BRK_IRQn       TIM1_BRK_TIM9_IRQn
#define TIM1_UP_IRQn        TIM1_UP_TIM10_IRQn
#define TIM1_TRG_COM_IRQn   TIM1_TRG_COM_TIM11_IRQn
#define TIM8_BRK_IRQn       TIM8_BRK_TIM12_IRQn
#define TIM8_UP_IRQn        TIM8_UP_TIM13_IRQn
#define TIM8_TRG_COM_IRQn   TIM8_TRG_COM_TIM14_IRQn

#elif defined(STM32F10X_LD_VL)|| defined(STM32F10X_MD_VL) ||                \
      defined(STM32F10X_HD_VL)
#define TIM1_BRK_IRQn       TIM1_BRK_TIM15_IRQn
#define TIM1_UP_IRQn        TIM1_UP_TIM16_IRQn
#define TIM1_TRG_COM_IRQn   TIM1_TRG_COM_TIM17_IRQn
#endif

/*===========================================================================*/
/* Driver data structures and types.                                         */
/*===========================================================================*/

/*===========================================================================*/
/* Driver macros.                                                            */
/*===========================================================================*/

/*===========================================================================*/
/* External declarations.                                                    */
/*===========================================================================*/

/* Tricks required to make the TRUE/FALSE declaration inside the library
   compatible.*/
#undef FALSE
#undef TRUE
#include "stm32f10x.h"
#define FALSE 0
#define TRUE (!FALSE)

/* STM32 DMA support code.*/
#include "stm32_dma.h"

#ifdef __cplusplus
extern "C" {
#endif
  void hal_lld_init(void);
  void stm32_clock_init(void);
#ifdef __cplusplus
}
#endif

#endif /* _HAL_LLD_H_ */

/** @} */