mastering_embedded_systems_diploma
mcu
unit7
lesson3
Driver
stm32f103c6_drivers
inc
stm32f103c6.h
1
/*
2
* stm32f103c6.h
3
*
4
* Created on: Oct 8, 2022
5
* Author: soft
6
*/
7
8
#ifndef INC_STM32F103C6_H_
9
#define INC_STM32F103C6_H_
10
11
/*-------------------------
12
* includes
13
*/
14
#include <stdio.h>
15
#include <stdint.h>
16
#include <stdlib.h>
17
18
/* ------------------------
19
* BASE ADDRESSES for memories
20
*/
21
#define FLASH_mem_BASE 0x08000000
22
#define system_mem_BASE 0x1ffff000
23
24
#define SRAM_mem_BASE 0x20000000
25
#define peripherals_BASE 0x40000000
26
27
#define cortex_m3_internal_peripherals 0xE0000000
28
29
/*
30
* base addresses for AHB peripherals
31
*/
32
33
// RCC
34
#define RCC_BASE 0x40021000
35
36
/*
37
* base addresses for APB2 peripherals
38
*/
39
//gpio
40
//A,B fully included in LQFP48 package
41
#define GPIOA_BASE 0x40010800
42
#define GPIOB_BASE 0x40010C00
43
44
//C,D partial included in LQFP48 package
45
#define GPIOC_BASE 0x40011000
46
#define GPIOD_BASE 0x4001400
47
48
//E not included in LQFP48 package
49
50
#define GPIOE_BASE 0x40011800
51
52
//EXTI
53
54
#define EXTI_BASE 0x40010400
55
// AFIO
56
#define AFIO_BASE 0x40010400
57
58
//---------------------------------------------------------------
59
60
/*
61
* peripherals registers
62
*/
63
64
65
/*
66
* peripherals registers GPIO
67
*/
68
typedef
struct
{
69
volatile
uint32_t CRL;
70
volatile
uint32_t CRH;
71
volatile
uint32_t IDR;
72
volatile
uint32_t ODR;
73
volatile
uint32_t BSRR;
74
volatile
uint32_t BRR;
75
volatile
uint32_t LCKR;
76
77
78
}
GPIO_typedef
;
79
/*
80
* peripherals registers RCC
81
*/
82
typedef
struct
{
83
volatile
uint32_t CR;
84
volatile
uint32_t CFGR;
85
volatile
uint32_t CIR;
86
volatile
uint32_t APB2RSTR;
87
volatile
uint32_t APB1RSTR;
88
volatile
uint32_t AHBENR;
89
volatile
uint32_t APB2ENR;
90
volatile
uint32_t APB1ENR;
91
volatile
uint32_t BDCR;
92
volatile
uint32_t CSR;
93
94
95
}
RCC_typedef
;
96
/*
97
* peripherals registers AFIO
98
*/
99
typedef
struct
{
100
volatile
uint32_t EVCR;
101
volatile
uint32_t MAPR;
102
volatile
uint32_t EXTICR1;
103
volatile
uint32_t EXTICR2;
104
volatile
uint32_t EXTICR3;
105
volatile
uint32_t EXTICR4;
106
volatile
uint32_t RESERVED;
//0x18
107
volatile
uint32_t MAPR2;
108
109
110
111
}
AFIO_typedef
;
112
/*
113
* peripherals registers EXTI
114
*/
115
typedef
struct
{
116
volatile
uint32_t IMR;
117
volatile
uint32_t EMR;
118
volatile
uint32_t RTSR;
119
volatile
uint32_t FTSR;
120
volatile
uint32_t SWIER;
121
volatile
uint32_t PR;
122
123
}
EXTI_typedef
;
124
125
//==============================================================
126
127
/*
128
* peripherals instants
129
*/
130
131
#define GPIOA ((GPIO_typedef *)GPIOA_BASE)
132
#define GPIOB ((GPIO_typedef *)GPIOB_BASE)
133
#define GPIOC ((GPIO_typedef *)GPIOC_BASE)
134
#define GPIOD ((GPIO_typedef *)GPIOD_BASE)
135
#define GPIOE ((GPIO_typedef *)GPIOE_BASE)
136
137
#define EXTI ((EXTI_typedef *)EXTI_BASE)
138
139
#define RCC ((RCC_typedef *)RCC_BASE)
140
141
#define AFIO ((AFIO_typedef *)AFIO_BASE)
142
143
144
//=======================================================
145
146
/*
147
* clock macros
148
*/
149
150
#define GPIOA_EN_CLK() (RCC->APB2ENR |= (1<<2))
151
#define GPIOB_EN_CLK() (RCC->APB2ENR |= (1<<3))
152
#define GPIOC_EN_CLK() (RCC->APB2ENR |= (1<<4))
153
#define GPIOD_EN_CLK() (RCC->APB2ENR |= (1<<5))
154
#define GPIOE_EN_CLK() (RCC->APB2ENR |= (1<<6))
155
156
157
#define AFIO_EN_CLK() (RCC->APB2ENR |= (1<<0))
158
159
160
161
162
163
164
165
166
167
168
169
170
#endif
/* INC_STM32F103C6_H_ */
AFIO_typedef
Definition:
stm32f103c6.h:99
GPIO_typedef
Definition:
stm32f103c6.h:68
EXTI_typedef
Definition:
stm32f103c6.h:115
RCC_typedef
Definition:
stm32f103c6.h:82
Generated by
1.8.13