Home | Projects | Notes > MCU Peripheral Drivers > Device Header File (stm32f407xx.h)
A device header file (C header file in this case) is a header file which contains MCU specific details such as:
Base addresses of various memories present in the MCU such as Flash, SRAM1, SRAM2, ROM, etc.
Base addresses of various bus domains such as AHBx domain, APBx domain, etc.
Base addresses of various peripherals present in different bus domains of the MCU.
Clock management macros (i.e., clock enable/disable macros)
IRQ definitions
Peripheral register definition structures
Peripheral register bit definitions
Other useful MCU configuration macros
The device header file will be used by both the application and the drivers. Therefore, the application and the driver source files may #include
the device specific header file to access MCU specific details.
stm32f407xx.h
Path: Project/Drivers/Inc/
xxxxxxxxxx
6551/*******************************************************************************
2 * File : stm32f407xx.h
3 * Brief : Device header file for stm32f407xx MCU
4 * Author ; Kyungjae Lee
5 * Date : May 18, 2023
6 *
7 * Note : This code includes only the features that are necessary for my
8 * personal projects.
9 * ****************************************************************************/
10
11
12
13
14
15/* NULL */
16
17/* I/O registers are highly volatile */
18
19
20/********************* START: Processor Specific Details **********************/
21
22/**
23 * ARM Cortex-Mx processor NVIC_ISERx register addresses
24 * Interrupt Set-enable Registers
25 * Note: Since ARM Cortex-Mx process implements only 82 interrupts, ISER3-7 will
26 * not be used.
27 * NVIC could be defined as a structure, but just the necessary registers
28 * are defined separately here since there is too much space in between
29 * each group of registers.
30 */
31
32
33
34
35
36
37
38
39
40/**
41 * ARM Cortex-Mx processor NVIC_ICERx register addresses
42 * Interrupt Clear-enable Registers
43 * Note: Since ARM Cortex-Mx process implements only 82 interrupts, ISER3-7 will
44 * not be used.
45 * NVIC could be defined as a structure, but just the necessary registers
46 * are defined separately here since there is too much space in between
47 * each group of registers.
48 */
49
50
51
52
53
54
55
56
57
58/**
59 * ARM Cortex-Mx processor NVIC_IPRx register addresses
60 * Interrupt Priority Registers
61 * Note: NVIC could be defined as a structure, but just the necessary registers
62 * are defined separately here since there is too much space in between
63 * each group of registers.
64 */
65
66
67
68
69/*********************** END: Processor Specific Details **********************/
70
71
72/* Base addresses of memories */
73/* Flash base address in the alias */
74/* SRAM1(112 KB) base address in the alias */
75/* SRAM2(16 KB) base address in the alias */
76/* SRAM base address in the alias */
77/* ROM(system memory) base address in the alias */
78
79/* Base addresses of APBx and AHB bus peripherals */
80/* Peripheral base address in the alias */
81
82
83
84
85
86/* Base addresses of AHB1 peripherals */
87
88
89
90
91
92
93
94
95
96
97
98/* Base addresses of APB1 peripherals */
99
100
101
102
103
104
105
106
107
108
109/* Base addresses of APB2 peripherals */
110
111
112
113
114
115
116
117
118/**
119 * Peripheral registers structures
120 *
121 * Note: Number of registers of each peripheral may defer from MCU family to MCU
122 * family. Check the reference manual!
123 */
124
125/* General Purpose I/O */
126typedef struct
127{
128 __IO uint32_t MODER; /* GPIO port mode register, Address offset: 0x00 */
129 __IO uint32_t OTYPER; /* GPIO port output type register, Address offset: 0x04 */
130 __IO uint32_t OSPEEDR; /* GPIO port output speed register, Address offset: 0x08 */
131 __IO uint32_t PUPDR; /* GPIO port pull-up/pull-down register, Address offset: 0x0C */
132 __IO uint32_t IDR; /* GPIO port input data register, Address offset: 0x10 */
133 __IO uint32_t ODR; /* GPIO port output data register, Address offset: 0x14 */
134 __IO uint32_t BSRR; /* GPIO port bit set/reset register, Address offset: 0x18 */
135 __IO uint32_t LCKR; /* GPIO port configuration lack register, Address offset: 0x1C */
136 __IO uint32_t AFR[2]; /* GPIO port alternate function register, Address offset: 0x20-0x24 */
137} GPIO_TypeDef;
138
139/* Reset and Clock Control */
140typedef struct
141{
142 __IO uint32_t CR; /* RCC clock control register, Address offset: 0x00 */
143 __IO uint32_t PLLCFGR; /* RCC PLL configuration register, Address offset: 0x04 */
144 __IO uint32_t CFGR; /* RCC clock configuration register, Address offset: 0x08 */
145 __IO uint32_t CIR; /* RCC clock interrupt register, Address offset: 0x0C */
146 __IO uint32_t AHB1RSTR; /* RCC AHB1 peripheral reset register, Address offset: 0x10 */
147 __IO uint32_t AHB2RSTR; /* RCC AHB2 peripheral reset register, Address offset: 0x14 */
148 __IO uint32_t AHB3RSTR; /* RCC AHB3 peripheral reset register, Address offset: 0x18 */
149 uint32_t RESERVED0; /* Reserved, Address offset: 0x1C */
150 __IO uint32_t APB1RSTR; /* RCC APB1 peripheral reset register, Address offset: 0x20 */
151 __IO uint32_t APB2RSTR; /* RCC APB2 peripheral reset register, Address offset: 0x24 */
152 uint32_t RESERVED1[2]; /* Reserved, Address offset: 0x28-0x2C */
153 __IO uint32_t AHB1ENR; /* RCC AHB1 peripheral clock enable register, Address offset: 0x30 */
154 __IO uint32_t AHB2ENR; /* RCC AHB2 peripheral clock enable register, Address offset: 0x34 */
155 __IO uint32_t AHB3ENR; /* RCC AHB3 peripheral clock enable register, Address offset: 0x38 */
156 uint32_t RESERVED2; /* Reserved, Address offset: 0x3C */
157 __IO uint32_t APB1ENR; /* RCC APB1 peripheral clock enable register, Address offset: 0x40 */
158 __IO uint32_t APB2ENR; /* RCC APB2 peripheral clock enable register, Address offset: 0x44 */
159 uint32_t RESERVED3[2]; /* Reserved, Address offset: 0x48-0x4C */
160 __IO uint32_t AHB1LPENR; /* RCC AHB1 peripheral clock enable in low power mode register, Address offset: 0x50 */
161 __IO uint32_t AHB2LPENR; /* RCC AHB2 peripheral clock enable in low power mode register, Address offset: 0x54 */
162 __IO uint32_t AHB3LPENR; /* RCC AHB3 peripheral clock enable in low power mode register, Address offset: 0x58 */
163 uint32_t RESERVED4; /* Reserved, Address offset: 0x04 */
164 __IO uint32_t APB1LPENR; /* RCC APB1 peripheral clock enable in low power mode register, Address offset: 0x60 */
165 __IO uint32_t APB2LPENR; /* RCC APB2 peripheral clock enable in low power mode register, Address offset: 0x64 */
166 uint32_t RESERVED5[2]; /* Reserved, Address offset: 0x68-0x6C */
167 __IO uint32_t BDCR; /* RCC Backup domain control register, Address offset: 0x70 */
168 __IO uint32_t CSR; /* RCC clock control & status register, Address offset: 0x74 */
169 uint32_t RESERVED6[2]; /* Reserved, Address offset: 0x78-7C */
170 __IO uint32_t SSCGR; /* RCC spread spectrum clock generation register, Address offset: 0x80 */
171 __IO uint32_t PLLI2SCFGR; /* RCC PLLI2S configuration register, Address offset: 0x84 */
172} RCC_TypeDef;
173
174/* External interrupt/event controller (EXTI) */
175typedef struct
176{
177 __IO uint32_t IMR; /* Interrupt mask register, Address offset: 0x00 */
178 __IO uint32_t EMR; /* Event mask register, Address offset: 0x04 */
179 __IO uint32_t RTSR; /* Rising trigger selection register, Address offset: 0x08 */
180 __IO uint32_t FTSR; /* Falling trigger selection register, Address offset: 0x0C */
181 __IO uint32_t SWIER; /* Software interrupt event register, Address offset: 0x10 */
182 __IO uint32_t PR; /* Pending register, Address offset: 0x14 */
183} EXTI_TypeDef;
184
185/* System configuration controller (SYSCFG) */
186typedef struct
187{
188 __IO uint32_t MEMRMP; /* SYSCFG memory remap register, Address offset: 0x00 */
189 __IO uint32_t PMC; /* SYSCFG peripheral mode configuration register, Address offset: 0x04 */
190 __IO uint32_t EXTICR[4];/* SYSCFG external interrupt configuration register1-4, Address offset: 0x08 */
191 uint32_t RESERVED[2]; /* Reserved, Address offset: 0x18-0x1C */
192 __IO uint32_t CMPCR; /* Compensation cell control register, Address offset: 0x20 */
193} SYSCFG_TypeDef;
194
195/* Serial peripheral interface (SPI) */
196typedef struct
197{
198 __IO uint32_t CR1; /* SPI control register 1, Address offset: 0x00 */
199 __IO uint32_t CR2; /* SPI control register 2, Address offset: 0x04 */
200 __IO uint32_t SR; /* SPI status register, Address offset: 0x08 */
201 __IO uint32_t DR; /* SPI data register, Address offset: 0x0C */
202 __IO uint32_t SRCPR; /* SPI CRC polynomial register, Address offset: 0x10 */
203 __IO uint32_t RXCRCR; /* SPI RX CRC register, Address offset: 0x14 */
204 __IO uint32_t TXCRCR; /* SPI TX CRC register, Address offset: 0x18 */
205 __IO uint32_t I2SCFGR; /* SPI_I2S configuration register, Address offset: 0x1C */
206 __IO uint32_t I2SPR; /* SPI_I2S prescaler register, Address offset: 0x20 */
207} SPI_TypeDef;
208
209/* Inter-integrated circuit (I2C) */
210typedef struct
211{
212 __IO uint32_t CR1; /* I2C control register 1, Address offset: 0x00 */
213 __IO uint32_t CR2; /* I2C control register 2, Address offset: 0x04 */
214 __IO uint32_t OAR1; /* I2C own address register, Address offset: 0x08 */
215 __IO uint32_t OAR2; /* I2C own address register, Address offset: 0x0C */
216 __IO uint32_t DR; /* I2C data register, Address offset: 0x10 */
217 __IO uint32_t SR1; /* I2C status register, Address offset: 0x14 */
218 __IO uint32_t SR2; /* I2C status register, Address offset: 0x18 */
219 __IO uint32_t CCR; /* I2C clock control register, Address offset: 0x1C */
220 __IO uint32_t TRISE; /* I2C TRISE register, Address offset: 0x20 */
221 __IO uint32_t FLTR; /* I2C FLTR register, Address offset: 0x24 */
222} I2C_TypeDef;
223
224/* Universal synchronous asynchronous receiver transmitter (USART) */
225typedef struct
226{
227 __IO uint32_t SR; /* USART status register, Address offset: 0x00 */
228 __IO uint32_t DR; /* USART data register, Address offset: 0x04 */
229 __IO uint32_t BRR; /* USART baud rate register, Address offset: 0x08 */
230 __IO uint32_t CR1; /* USART control register 1, Address offset: 0x0C */
231 __IO uint32_t CR2; /* USART control register 2, Address offset: 0x10 */
232 __IO uint32_t CR3; /* USART control register 3, Address offset: 0x14 */
233 __IO uint32_t GTPR; /* USART guard time and prescalar register, Address offset: 0x18 */
234} USART_TypeDef;
235
236
237/**
238 * Peripheral declarations (Peripheral base addresses typecasted to
239 * (x_TypeDef *))
240 */
241
242/* GPIOs */
243
244
245
246
247
248
249
250
251
252
253/* RCC */
254
255
256/* EXTI */
257
258
259/* SYSCFG */
260
261
262/* SPIx */
263
264
265
266
267
268/* I2Cx */
269
270
271
272
273/* USARTx */
274
275
276
277
278
279
280
281
282/**
283 * Clock enable macros for peripherals
284 */
285
286/* GPIOx */
287
288
289
290
291
292
293
294
295
296
297/* I2Cx */
298
299
300
301
302/* SPIx */
303
304
305
306
307
308/* USARTx */
309
310
311
312
313
314
315
316/* SYSCFG */
317
318
319
320/**
321 * Clock enable macros for peripherals
322 */
323
324/* GPIOx */
325
326
327
328
329
330
331
332
333
334
335/* I2Cx */
336
337
338
339
340/* SPIx */
341
342
343
344
345
346/* USARTx */
347
348
349
350
351
352
353
354/* SYSCFG */
355
356
357
358/**
359 * Reset peripherals (set the corresponding bit, and then clear)
360 */
361
362/* GPIO */
363
364
365
366
367
368
369
370
371
372
373/* SPI */
374
375
376
377
378
379
380/**
381 * Macro function to return port code for the given GPIO base address
382 */
383
384
385
386
387
388
389
390
391
392
393
394/**
395 * Interrupt Request (IRQ) numbers of STM32F407xx MCU
396 * Note: This information is specific to MCU family
397 */
398
399/* GPIO interrupts */
400
401
402
403
404
405
406
407
408/* SPI interrupts */
409
410
411
412
413/* I2C interrupts */
414
415
416
417
418
419
420
421/* USART interrupts */
422
423
424
425
426
427
428
429
430/**
431 * Possible NVIC IRQ priority levels
432 */
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451/**
452 * SPI peripheral bit position definitions
453 */
454
455/* SPI_CR1 */
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471/* SPI_CR2 */
472
473
474
475
476
477
478
479
480/* SPI_SR */
481
482
483
484
485
486
487
488
489
490
491
492/**
493 * I2C peripheral bit position definitions
494 */
495
496/* I2C_CR1 */
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512/* I2C_CR2 */
513
514
515
516
517
518
519
520/* I2C_OAR1 */
521
522
523
524
525
526/* I2C_SR1 */
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542/* I2C_SR2 */
543
544
545
546
547
548
549
550
551
552/* I2C_CCR */
553
554
555
556
557
558/**
559 * USART peripheral bit position definitions
560 */
561
562/* USART_SR */
563
564
565
566
567
568
569
570
571
572
573
574/* USART_BRR */
575
576
577
578/* USART_CR1 */
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595/* USART_CR2 */
596
597
598
599
600
601
602
603
604
605
606/* USART_CR3 */
607
608
609
610
611
612
613
614
615
616
617
618
619
620/* USART_GTPR */
621
622
623
624
625/**
626 * RCC peripheral bit position definitions
627 * (Required bit positions only)
628 */
629/* System clock switch status */
630/* AHB prescalar */
631/* APB low-speed prescalar (APB1) */
632/* APB high-speed prescalar (APB2) */
633
634
635/**
636 * Other generic macros
637 */
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655/* STM32F407XX_H */