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.hPath: Project/Drivers/Inc/
xxxxxxxxxx6551/*******************************************************************************2 * File : stm32f407xx.h3 * Brief : Device header file for stm32f407xx MCU4 * Author ; Kyungjae Lee5 * Date : May 18, 20236 *7 * Note : This code includes only the features that are necessary for my8 * personal projects.9 * ****************************************************************************/10
111213
1415/* NULL */16
17/* I/O registers are highly volatile */1819
20/********************* START: Processor Specific Details **********************/21
22/**23 * ARM Cortex-Mx processor NVIC_ISERx register addresses24 * Interrupt Set-enable Registers25 * Note: Since ARM Cortex-Mx process implements only 82 interrupts, ISER3-7 will26 * not be used.27 * NVIC could be defined as a structure, but just the necessary registers28 * are defined separately here since there is too much space in between29 * each group of registers.30 */313233343536373839
40/**41 * ARM Cortex-Mx processor NVIC_ICERx register addresses42 * Interrupt Clear-enable Registers43 * Note: Since ARM Cortex-Mx process implements only 82 interrupts, ISER3-7 will44 * not be used.45 * NVIC could be defined as a structure, but just the necessary registers46 * are defined separately here since there is too much space in between47 * each group of registers.48 */495051525354555657
58/**59 * ARM Cortex-Mx processor NVIC_IPRx register addresses60 * Interrupt Priority Registers61 * Note: NVIC could be defined as a structure, but just the necessary registers62 * are defined separately here since there is too much space in between63 * each group of registers.64 */6566
6768
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 */8182838485
86/* Base addresses of AHB1 peripherals */8788899091929394959697
98/* Base addresses of APB1 peripherals */99100101102103104105106107108
109/* Base addresses of APB2 peripherals */110111112113114115116
117
118/**119 * Peripheral registers structures120 *121 * Note: Number of registers of each peripheral may defer from MCU family to MCU122 * family. Check the reference manual!123 */124
125/* General Purpose I/O */126typedef struct127{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 struct141{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 struct176{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 struct187{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 struct197{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 struct211{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 struct226{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 to239 * (x_TypeDef *))240 */241
242/* GPIOs */243244245246247248249250251252
253/* RCC */254255
256/* EXTI */257258
259/* SYSCFG */260261
262/* SPIx */263264265266267
268/* I2Cx */269270271272
273/* USARTx */274275276277278279280
281
282/**283 * Clock enable macros for peripherals284 */285
286/* GPIOx */287288289290291292293294295296
297/* I2Cx */298299300301
302/* SPIx */303304305306307
308/* USARTx */309310311312313314315
316/* SYSCFG */317318
319
320/**321 * Clock enable macros for peripherals322 */323
324/* GPIOx */325326327328329330331332333334
335/* I2Cx */336337338339
340/* SPIx */341342343344345
346/* USARTx */347348349350351352353
354/* SYSCFG */355356
357
358/**359 * Reset peripherals (set the corresponding bit, and then clear)360 */361
362/* GPIO */363364365366367368369370371372
373/* SPI */374375376377378
379
380/**381 * Macro function to return port code for the given GPIO base address382 */383384 385 386 387 388 389 390 391 392
393
394/**395 * Interrupt Request (IRQ) numbers of STM32F407xx MCU396 * Note: This information is specific to MCU family397 */398
399/* GPIO interrupts */400401402403404405406407
408/* SPI interrupts */409410411412
413/* I2C interrupts */414415416417418419420
421/* USART interrupts */422423424425426427428
429
430/**431 * Possible NVIC IRQ priority levels432 */433434435436437438439440441442443444445446447448449
450
451/**452 * SPI peripheral bit position definitions453 */454
455/* SPI_CR1 */456457458459460461462463464465466467468469470
471/* SPI_CR2 */472473474475476477478479
480/* SPI_SR */481482483484485486487488489490
491
492/**493 * I2C peripheral bit position definitions494 */495
496/* I2C_CR1 */497498499500501502503504505506507508509510511
512/* I2C_CR2 */513514515516517518519
520/* I2C_OAR1 */521522523524525
526/* I2C_SR1 */527528529530531532533534535536537538539540541
542/* I2C_SR2 */543544545546547548549550551
552/* I2C_CCR */553554555556
557
558/**559 * USART peripheral bit position definitions560 */561
562/* USART_SR */563564565566567568569570571572573
574/* USART_BRR */575576577
578/* USART_CR1 */579580581582583584585586587588589590591592593594
595/* USART_CR2 */596597598599600601602603604605
606/* USART_CR3 */607608609610611612613614615616617618619
620/* USART_GTPR */621622623
624
625/**626 * RCC peripheral bit position definitions627 * (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 macros637 */638639640641642643644645646
647
648649650651652653
654
655/* STM32F407XX_H */