HWA
Bare metal programming with style
stm32f411.h
Go to the documentation of this file.
1 
2 /* This file is part of the HWA project.
3  * Copyright (c) 2021 Christophe Duparquet.
4  * All rights reserved. Read LICENSE.TXT for details.
5  */
6 
20 #include "../hwa_1.h"
21 
62 #define HW_DEVICE_STM32F411
63 
67 #define HW_DEVICE_STM32F4
68 
72 #define HW_DEVICE_HSIHZ 16000000
73 
77 #define HW_DEVICE_LSIHZ 32000
78 
83 /*******************************************************************************
84  * *
85  * Exception & interrupt vectors *
86  * *
87  *******************************************************************************/
88 
89 #define _hw_isr_nmi_ _isr, , hw_esr_nmi
90 #define _hw_isr_hardfault_ _isr, , hw_esr_hardfault
91 #define _hw_isr_systick_ _isr, , hw_esr_systick
92 #define _hw_isr_systick_alarm _isr, , hw_esr_systick
93 
94 #define _hw_isr_counter2_ _isr, 28, hw_isr_counter2
95 #define _hw_isr_counter3_ _isr, 29, hw_isr_counter3
96 #define _hw_isr_counter4_ _isr, 30, hw_isr_counter4
97 #define _hw_isr_counter5_ _isr, 50, hw_isr_counter5
98 
99 
100 /*******************************************************************************
101  * *
102  * Objects *
103  * *
104  * Object class, address *
105  * *
106  *******************************************************************************/
107 
108 /* NVIC
109  */
110 #include "../classes/nvica_1.h"
111 
112 #define hw_nvic _nvica, 0xE000E100
113 
114 
115 /* SysTick
116  *
117  * FIXME: stm32f4 systick does not have `skew` or `noref`
118  */
119 #include "../classes/stka_1.h"
120 
121 #define hw_systick _stka, 0xE000E010
122 
123 
124 /* RCC
125  */
126 #include "../classes/rccb_1.h"
127 
128 #define hw_rcc _rccb, 0x40023800
129 
130 
131 /* GPIO
132  */
133 #include "../classes/gpb_1.h"
134 
135 #define hw_porta _gpb, 0x40020000
136 #define hw_portb _gpb, 0x40020400
137 #define hw_portc _gpb, 0x40020800
138 #define hw_portd _gpb, 0x40020C00
139 #define hw_porte _gpb, 0x40021000
140 #define hw_porth _gpb, 0x40021C00
141 
142 
143 /* AFIO , AFR
144  */
145 #define _hw_af_porta_1_0 (gpio,(counter2,channel1),(counter2,etr),(counter5,channel1),(usart2,cts),eventout))
146 #define _hw_af_porta_1_0_counter2_channel1 , 1
147 #define _hw_af_porta_1_0_counter2_etr , 1
148 #define _hw_af_porta_1_0_counter5_channel1 , 2
149 #define _hw_af_porta_1_0_usart2_cts , 7
150 #define _hw_af_porta_1_0_eventout , 15
151 #define _hw_af_porta_1_1_usart2_rts , 7
152 #define _hw_af_porta_1_2_usart2_tx , 7
153 
154 #define _hw_af_porta_1_3 (gpio,(counter2,channel4),(counter5,channel4),(counter9,channel2),(i2s2,mck),(usart2,rx),eventout))
155 #define _hw_af_porta_1_3_usart2_rx , 7
156 #define _hw_af_porta_1_4_usart2_ck , 7
157 #define _hw_af_porta_1_8_usart1_ck , 7
158 #define _hw_af_porta_1_9_usart1_tx , 7
159 #define _hw_af_porta_1_10_usart1_rx , 7
160 #define _hw_af_porta_1_11_usart1_cts , 7
161 #define _hw_af_porta_1_11_usart6_tx , 8
162 #define _hw_af_porta_1_12_usart1_rts , 7
163 #define _hw_af_porta_1_12_usart6_rx , 8
164 #define _hw_af_porta_1_15_usart1_tx , 7
165 
166 #define _hw_af_portb_1_3_usart1_rx , 7
167 #define _hw_af_portb_1_6_usart1_tx , 7
168 #define _hw_af_portb_1_7_usart1_rx , 7
169 
170 #define _hw_af_portc_1_6_usart6_tx , 8
171 #define _hw_af_portc_1_7_usart6_rx , 8
172 #define _hw_af_portc_1_8_usart6_ck , 8
173 
174 #define _hw_af_portd_1_3_usart2_cts , 7
175 #define _hw_af_portd_1_4_usart2_rts , 7
176 #define _hw_af_portd_1_5_usart2_tx , 7
177 #define _hw_af_portd_1_6_usart2_rx , 7
178 #define _hw_af_portd_1_7_usart2_ck , 7
179 
180 #define _hw_af_portd_1_13 (gpio,(counter4,channel2),eventout))
181 #define _hw_af_portd_1_13_counter4_channel2 , 2
182 #define _hw_af_portd_1_13_eventout , 15
183 
184 
185 /* Counters
186  */
187 #include "../classes/cta_1.h"
188 
189 #define hw_counter3 _cta, 0x40000400
190 #define hw_counter4 _cta, 0x40000800
191 
192 #include "../classes/ctb_1.h"
193 
194 #define hw_counter2 _ctb, 0x40000000
195 #define hw_counter5 _ctb, 0x40000C00
196 
197 
198 /* USART
199  */
200 #include "../classes/sab_1.h"
201 
202 #define hw_usart2 _sab, 0x40004400
203 #define hw_usart1 _sab, 0x40011000
204 #define hw_usart6 _sab, 0x40011400
205 
206 
207 /*******************************************************************************
208  * *
209  * HWA context *
210  * *
211  *******************************************************************************/
212 
213 #if !defined __ASSEMBLER__
214 
215 /* This structure is instanciated by hwa( begin ) or hwa( begin, reset ) and
216  * used by all hwa(...) instructions to bufferize hardware accesses.
217  */
218 typedef struct {
219  uint8_t commit ;
221  hwa_nvica_t nvic ;
222  hwa_stka_t systick ;
223  hwa_rccb_t rcc ;
224 
225  hwa_gpb_t porta ;
226  hwa_gpb_t portb ;
227  hwa_gpb_t portc ;
228  hwa_gpb_t portd ;
229  hwa_gpb_t porte ;
230  hwa_gpb_t porth ;
231 
232  hwa_ctb_t counter2 ;
233  hwa_cta_t counter3 ;
234  hwa_cta_t counter4 ;
235  hwa_ctb_t counter5 ;
236 
237  hwa_sab_t usart1 ;
238  hwa_sab_t usart2 ;
239  hwa_sab_t usart6 ;
240 } hwa_t ;
241 
242 #include "../hwa_2.h"
243 #include "../classes/nvica_2.h"
244 #include "../classes/stka_2.h"
245 #include "../classes/rccb_2.h"
246 #include "../classes/gpb_2.h"
247 #include "../classes/cta_2.h"
248 #include "../classes/ctb_2.h"
249 #include "../classes/sab_2.h"
250 
251 
252 HW_INLINE void _hwa_setup_context( hwa_t *hwa )
253 {
254  _hwa_setup_o( nvic );
255  _hwa_setup_o( systick );
256  _hwa_setup_o( rcc );
257  _hwa_setup_o( porta );
258  _hwa_setup_o( portb );
259  _hwa_setup_o( portc );
260  _hwa_setup_o( portd );
261  _hwa_setup_o( porte );
262  _hwa_setup_o( porth );
263  _hwa_setup_o( counter2 );
264  _hwa_setup_o( counter3 );
265  _hwa_setup_o( counter4 );
266  _hwa_setup_o( counter5 );
267  _hwa_setup_o( usart1 );
268  _hwa_setup_o( usart2 );
269  _hwa_setup_o( usart6 );
270 }
271 
272 
273 HW_INLINE void _hwa_init_context( hwa_t *hwa )
274 {
275  _hwa_init_o( nvic );
276  _hwa_init_o( systick );
277  _hwa_init_o( rcc );
278  _hwa_init_o( porta );
279  _hwa_init_o( portb );
280  _hwa_init_o( portc );
281  _hwa_init_o( portd );
282  _hwa_init_o( porte );
283  _hwa_init_o( porth );
284  _hwa_init_o( counter2 );
285  _hwa_init_o( counter3 );
286  _hwa_init_o( counter4 );
287  _hwa_init_o( counter5 );
288  _hwa_init_o( usart1 );
289  _hwa_init_o( usart2 );
290  _hwa_init_o( usart6 );
291 }
292 
293 
294 HW_INLINE void _hwa_commit_context( hwa_t *hwa )
295 {
296  _hwa_commit_o( nvic );
297  _hwa_commit_o( systick );
298  _hwa_commit_o( rcc );
299  _hwa_commit_o( porta );
300  _hwa_commit_o( portb );
301  _hwa_commit_o( portc );
302  _hwa_commit_o( portd );
303  _hwa_commit_o( porte );
304  _hwa_commit_o( porth );
305  _hwa_commit_o( counter2 );
306  _hwa_commit_o( counter3 );
307  _hwa_commit_o( counter4 );
308  _hwa_commit_o( counter5 );
309  _hwa_commit_o( usart1 );
310  _hwa_commit_o( usart2 );
311  _hwa_commit_o( usart6 );
312 }
313 
314 #endif /* !defined __ASSEMBLER__ */
_hwa_init_o
#define _hwa_init_o(o)
Initialize the HWA context registers of an object with their reset value.
Definition: hwa_2.h:331
hwa
#define hwa(...)
hwa( action, object [,...] ) stores an action for an object into a HWA context.
Definition: hwa_macros.h:552
_hwa_commit_o
#define _hwa_commit_o(o)
Commit the registers of an object.
Definition: hwa_2.h:349
_hwa_setup_o
#define _hwa_setup_o(o)
Initialize the HWA context registers addresses of an object.
Definition: hwa_2.h:322