mastering_embedded_systems_diploma
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 //NVIC register map
30 #define NVIC_Base (0xE000E100UL)
31 #define NVIC_ISER0 *(volatile uint32_t *)(NVIC_Base+0x0)
32 #define NVIC_ISER1 *(volatile uint32_t *)(NVIC_Base+0x4)
33 #define NVIC_ISER2 *(volatile uint32_t *)(NVIC_Base+0x8)
34 #define NVIC_ICER0 *(volatile uint32_t *)(NVIC_Base+0x80)
35 #define NVIC_ICER1 *(volatile uint32_t *)(NVIC_Base+0x84)
36 #define NVIC_ICER2 *(volatile uint32_t *)(NVIC_Base+0x88)
37 /*
38  * base addresses for AHB peripherals
39  */
40 
41 // RCC
42 #define RCC_BASE 0x40021000
43 
44 /*
45  * base addresses for APB2 peripherals
46  */
47 //gpio
48 //A,B fully included in LQFP48 package
49 #define GPIOA_BASE 0x40010800
50 #define GPIOB_BASE 0x40010C00
51 
52 //C,D partial included in LQFP48 package
53 #define GPIOC_BASE 0x40011000
54 #define GPIOD_BASE 0x4001400
55 
56 //E not included in LQFP48 package
57 
58 #define GPIOE_BASE 0x40011800
59 
60 //EXTI
61 
62 #define EXTI_BASE 0x40010400
63 // AFIO
64 #define AFIO_BASE 0x40010400
65 
66 //---------------------------------------------------------------
67 
68 /*
69  * peripherals registers
70  */
71 
72 
73 /*
74  * peripherals registers GPIO
75  */
76 typedef struct{
77  volatile uint32_t CRL;
78  volatile uint32_t CRH;
79  volatile uint32_t IDR;
80  volatile uint32_t ODR;
81  volatile uint32_t BSRR;
82  volatile uint32_t BRR;
83  volatile uint32_t LCKR;
84 
85 
87 /*
88  * peripherals registers RCC
89  */
90 typedef struct{
91  volatile uint32_t CR;
92  volatile uint32_t CFGR;
93  volatile uint32_t CIR;
94  volatile uint32_t APB2RSTR;
95  volatile uint32_t APB1RSTR;
96  volatile uint32_t AHBENR;
97  volatile uint32_t APB2ENR;
98  volatile uint32_t APB1ENR;
99  volatile uint32_t BDCR;
100  volatile uint32_t CSR;
101 
102 
103 }RCC_typedef;
104 /*
105  * peripherals registers AFIO
106  */
107 typedef struct{
108  volatile uint32_t EVCR;
109  volatile uint32_t MAPR;
110  volatile uint32_t EXTICR[4];
111  volatile uint32_t RESERVED;//0x18
112  volatile uint32_t MAPR2;
113 
114 
115 
116 }AFIO_typedef;
117 /*
118  * peripherals registers EXTI
119  */
120 typedef struct{
121  volatile uint32_t IMR;
122  volatile uint32_t EMR;
123  volatile uint32_t RTSR;
124  volatile uint32_t FTSR;
125  volatile uint32_t SWIER;
126  volatile uint32_t PR;
127 
128 }EXTI_typedef;
129 
130 //==============================================================
131 
132 /*
133  * peripherals instants
134  */
135 
136 #define GPIOA ((GPIO_typedef *)GPIOA_BASE)
137 #define GPIOB ((GPIO_typedef *)GPIOB_BASE)
138 #define GPIOC ((GPIO_typedef *)GPIOC_BASE)
139 #define GPIOD ((GPIO_typedef *)GPIOD_BASE)
140 #define GPIOE ((GPIO_typedef *)GPIOE_BASE)
141 
142 #define EXTI ((EXTI_typedef *)EXTI_BASE)
143 
144 #define RCC ((RCC_typedef *)RCC_BASE)
145 
146 #define AFIO ((AFIO_typedef *)AFIO_BASE)
147 
148 
149 //=======================================================
150 
151 /*
152  * clock macros
153  */
154 
155 #define GPIOA_EN_CLK() (RCC->APB2ENR |= (1<<2))
156 #define GPIOB_EN_CLK() (RCC->APB2ENR |= (1<<3))
157 #define GPIOC_EN_CLK() (RCC->APB2ENR |= (1<<4))
158 #define GPIOD_EN_CLK() (RCC->APB2ENR |= (1<<5))
159 #define GPIOE_EN_CLK() (RCC->APB2ENR |= (1<<6))
160 
161 
162 #define AFIO_EN_CLK() (RCC->APB2ENR |= (1<<0))
163 
164 
165 
166 
167 //ivt
168 
169 
170 #define EXTI0_IRQ 6
171 #define EXTI1_IRQ 7
172 #define EXTI2_IRQ 8
173 #define EXTI3_IRQ 9
174 #define EXTI4_IRQ 10
175 #define EXTI5_IRQ 23
176 #define EXTI6_IRQ 23
177 #define EXTI7_IRQ 23
178 #define EXTI8_IRQ 23
179 #define EXTI9_IRQ 23
180 #define EXTI10_IRQ 40
181 #define EXTI11_IRQ 40
182 #define EXTI12_IRQ 40
183 #define EXTI13_IRQ 40
184 #define EXTI14_IRQ 40
185 #define EXTI15_IRQ 40
186 
187 
188 // NVIC IRQ enable /disable macros
189 
190 #define NVIC_IRQ6_EXTI0_Enable (NVIC_ISER0 |= 1<<6)
191 #define NVIC_IRQ7_EXTI1_Enable (NVIC_ISER0 |= 1<<7)
192 #define NVIC_IRQ8_EXTI2_Enable (NVIC_ISER0 |= 1<<8)
193 #define NVIC_IRQ9_EXTI3_Enable (NVIC_ISER0 |= 1<<9)
194 #define NVIC_IRQ10_EXTI4_Enable (NVIC_ISER0 |= 1<<10)
195 #define NVIC_IRQ23_EXTI5_9_Enable (NVIC_ISER0 |= 1<<23)
196 #define NVIC_IRQ40_EXTI10_15_Enable (NVIC_ISER1 |= 1<<8) // 40-32=8
197 
198 
199 #define NVIC_IRQ6_EXTI0_disable (NVIC_ICER0 |= 1<<6)
200 #define NVIC_IRQ7_EXTI1_disable (NVIC_ICER0 |= 1<<7)
201 #define NVIC_IRQ8_EXTI2_disable (NVIC_ICER0 |= 1<<8)
202 #define NVIC_IRQ9_EXTI3_disable (NVIC_ICER0 |= 1<<9)
203 #define NVIC_IRQ10_EXTI4_disable (NVIC_ICER0 |= 1<<10)
204 #define NVIC_IRQ23_EXTI5_9_disable (NVIC_ICER0 |= 1<<23)
205 #define NVIC_IRQ40_EXTI10_15_disable (NVIC_ICER1 |= 1<<8) // 40-32=8
206 
207 
208 
209 
210 #endif /* INC_STM32F103C6_H_ */
Definition: stm32f103c6.h:99
Definition: stm32f103c6.h:68
Definition: stm32f103c6.h:115
Definition: stm32f103c6.h:82