-
Notifications
You must be signed in to change notification settings - Fork 2
/
gd32vf103.h
553 lines (537 loc) · 21.8 KB
/
gd32vf103.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
#ifndef GD32VF103xB
#define GD32VF103xB
/*
* GD32VF103CB device header file.
* Written to be as compatible as possible with STM32F1 code.
* These definitions are incomplete and application-specific.
*/
#include <stdint.h>
/**
* Compatibility definitions and RISC-V specific values.
*/
extern volatile uint32_t SystemCoreClock;
/**
* Interrupt handler enumeration.
*/
typedef enum IRQn {
CLIC_INT_RESERVED = 0,
CLIC_INT_SFT = 3,
CLIC_INT_TMR = 7,
CLIC_INT_BWEI = 17,
CLIC_INT_PMOVI = 18,
WWDG_IRQn = 19,
PVD_IRQn = 20,
TAMPER_IRQn = 21,
RTC_IRQn = 22,
FLASH_IRQn = 23,
RCC_IRQn = 24,
EXTI0_IRQn = 25,
EXTI1_IRQn = 26,
EXTI2_IRQn = 27,
EXTI3_IRQn = 28,
EXTI4_IRQn = 29,
DMA1_Channel1_IRQn = 30,
DMA1_Channel2_IRQn = 31,
DMA1_Channel3_IRQn = 32,
DMA1_Channel4_IRQn = 33,
DMA1_Channel5_IRQn = 34,
DMA1_Channel6_IRQn = 35,
DMA1_Channel7_IRQn = 36,
ADC1_2_IRQn = 37,
// These two interrupts aren't connected to the USB peripheral
// on GD32 chips, but names are maintained for STM32F1 compatibility.
USB_HP_CAN1_TX_IRQn = 38,
CAN1_TX_IRQn = 38,
USB_LP_CAN1_RX0_IRQn = 39,
CAN1_RX0_IRQn = 39,
CAN1_RX1_IRQn = 40,
CAN1_SCE_IRQn = 41,
EXTI9_5_IRQn = 42,
TIM1_BRK_IRQn = 43,
TIM1_UP_IRQn = 44,
TIM1_TRG_COM_IRQn = 45,
TIM1_CC_IRQn = 46,
TIM2_IRQn = 47,
TIM3_IRQn = 48,
TIM4_IRQn = 49,
I2C1_EV_IRQn = 50,
I2C1_ER_IRQn = 51,
I2C2_EV_IRQn = 52,
I2C2_ER_IRQn = 53,
SPI1_IRQn = 54,
SPI2_IRQn = 55,
USART1_IRQn = 56,
USART2_IRQn = 57,
USART3_IRQn = 58,
EXTI15_10_IRQn = 59,
RTC_Alarm_IRQn = 60,
USBWakeUp_IRQn = 61,
// Extra interrupts not available on STM32F1 chips:
// (Numbered peripherals are still 1-indexed)
EXMC_IRQn = 67,
TIM5_IRQn = 69,
SPI3_IRQn = 70,
UART4_IRQn = 71,
UART5_IRQn = 72,
TIM6_IRQn = 73,
TIM7_IRQn = 74,
DMA2_Channel1_IRQn = 75,
DMA2_Channel2_IRQn = 76,
DMA2_Channel3_IRQn = 77,
DMA2_Channel4_IRQn = 78,
DMA2_Channel5_IRQn = 79,
CAN2_TX_IRQn = 82,
CAN2_RX0_IRQn = 83,
CAN2_RX1_IRQn = 84,
CAN2_SCE_IRQn = 85,
USBFS_IRQn = 86,
ECLIC_NUM_INTERRUPTS
} IRQn_Type;
/**
* RCC / RCU peripheral struct.
*/
typedef struct
{
volatile uint32_t CR;
volatile uint32_t CFGR;
volatile uint32_t CIR;
volatile uint32_t APB2RSTR;
volatile uint32_t APB1RSTR;
volatile uint32_t AHBENR;
volatile uint32_t APB2ENR;
volatile uint32_t APB1ENR;
volatile uint32_t BDCR;
/* The following registers differ from STM32F1: */
volatile uint32_t RSTSCK;
volatile uint32_t AHBRSTR;
volatile uint32_t CFGR1;
volatile uint32_t DSV;
} RCC_TypeDef;
/**
* GPIO peripheral struct.
*/
typedef struct
{
volatile uint32_t CRL;
volatile uint32_t CRH;
volatile uint32_t IDR;
volatile uint32_t ODR;
volatile uint32_t BSRR;
volatile uint32_t BRR;
volatile uint32_t LCKR;
} GPIO_TypeDef;
/**
* AFIO peripheral struct.
*/
typedef struct
{
volatile uint32_t EVCR;
volatile uint32_t MAPR;
volatile uint32_t EXTICR[ 4 ];
uint32_t RESERVED0;
volatile uint32_t MAPR2;
} AFIO_TypeDef;
/**
* DMA peripheral struct (global).
*/
typedef struct
{
volatile uint32_t ISR;
volatile uint32_t IFCR;
} DMA_TypeDef;
/**
* DMA peripheral struct (per-channel).
*/
typedef struct
{
volatile uint32_t CCR;
volatile uint32_t CNDTR;
volatile uint32_t CPAR;
volatile uint32_t CMAR;
} DMA_Channel_TypeDef;
/**
* SPI peripheral struct.
*/
typedef struct
{
volatile uint32_t CR1;
volatile uint32_t CR2;
volatile uint32_t SR;
volatile uint32_t DR;
volatile uint32_t CRCPR;
volatile uint32_t RXCRCR;
volatile uint32_t TXCRCR;
volatile uint32_t I2SCFGR;
volatile uint32_t I2SPR;
} SPI_TypeDef;
/* Global register block address definitions. */
#define RCC ( ( RCC_TypeDef * ) 0x40021000 )
#define GPIOA ( ( GPIO_TypeDef * ) 0x40010800 )
#define GPIOB ( ( GPIO_TypeDef * ) 0x40010C00 )
#define GPIOC ( ( GPIO_TypeDef * ) 0x40011000 )
#define GPIOD ( ( GPIO_TypeDef * ) 0x40011400 )
#define GPIOE ( ( GPIO_TypeDef * ) 0x40011800 )
#define AFIO ( ( AFIO_TypeDef * ) 0x40010000 )
#define DMA1 ( ( DMA_TypeDef * ) 0x40020000 )
#define DMA2 ( ( DMA_TypeDef * ) 0x40020400 )
#define DMA1_Channel1 ( ( DMA_Channel_TypeDef * ) 0x40020008 )
#define DMA1_Channel2 ( ( DMA_Channel_TypeDef * ) 0x4002001C )
#define DMA1_Channel3 ( ( DMA_Channel_TypeDef * ) 0x40020030 )
#define DMA1_Channel4 ( ( DMA_Channel_TypeDef * ) 0x40020044 )
#define DMA1_Channel5 ( ( DMA_Channel_TypeDef * ) 0x40020058 )
#define DMA1_Channel6 ( ( DMA_Channel_TypeDef * ) 0x4002006C )
#define DMA1_Channel7 ( ( DMA_Channel_TypeDef * ) 0x40020080 )
#define DMA2_Channel1 ( ( DMA_Channel_TypeDef * ) 0x40020408 )
#define DMA2_Channel2 ( ( DMA_Channel_TypeDef * ) 0x4002041C )
#define DMA2_Channel3 ( ( DMA_Channel_TypeDef * ) 0x40020430 )
#define DMA2_Channel4 ( ( DMA_Channel_TypeDef * ) 0x40020444 )
#define DMA2_Channel5 ( ( DMA_Channel_TypeDef * ) 0x40020458 )
#define SPI1 ( ( SPI_TypeDef * ) 0x40013000 )
#define SPI2 ( ( SPI_TypeDef * ) 0x40003800 )
#define SPI3 ( ( SPI_TypeDef * ) 0x40003C00 )
/* RCC register bit definitions. */
/* APB2RSTR */
#define RCC_APB2RSTR_AFIORST_Pos ( 0U )
#define RCC_APB2RSTR_AFIORST_Msk ( 0x1UL << RCC_APB2RSTR_AFIORST_Pos )
#define RCC_APB2RSTR_AFIORST ( RCC_APB2RSTR_AFIORST_Msk )
#define RCC_APB2RSTR_IOPARST_Pos ( 2U )
#define RCC_APB2RSTR_IOPARST_Msk ( 0x1UL << RCC_APB2RSTR_IOPARST_Pos )
#define RCC_APB2RSTR_IOPARST ( RCC_APB2RSTR_IOPARST_Msk )
#define RCC_APB2RSTR_IOPBRST_Pos ( 3U )
#define RCC_APB2RSTR_IOPBRST_Msk ( 0x1UL << RCC_APB2RSTR_IOPBRST_Pos )
#define RCC_APB2RSTR_IOPBRST ( RCC_APB2RSTR_IOPBRST_Msk )
#define RCC_APB2RSTR_IOPCRST_Pos ( 4U )
#define RCC_APB2RSTR_IOPCRST_Msk ( 0x1UL << RCC_APB2RSTR_IOPCRST_Pos )
#define RCC_APB2RSTR_IOPCRST ( RCC_APB2RSTR_IOPCRST_Msk )
#define RCC_APB2RSTR_IOPDRST_Pos ( 5U )
#define RCC_APB2RSTR_IOPDRST_Msk ( 0x1UL << RCC_APB2RSTR_IOPDRST_Pos )
#define RCC_APB2RSTR_IOPDRST ( RCC_APB2RSTR_IOPDRST_Msk )
#define RCC_APB2RSTR_IOPERST_Pos ( 6U )
#define RCC_APB2RSTR_IOPERST_Msk ( 0x1UL << RCC_APB2RSTR_IOPERST_Pos )
#define RCC_APB2RSTR_IOPERST ( RCC_APB2RSTR_IOPERST_Msk )
#define RCC_APB2RSTR_ADC1RST_Pos ( 9U )
#define RCC_APB2RSTR_ADC1RST_Msk ( 0x1UL << RCC_APB2RSTR_ADC1RST_Pos )
#define RCC_APB2RSTR_ADC1RST ( RCC_APB2RSTR_ADC1RST_Msk )
#define RCC_APB2RSTR_ADC2RST_Pos ( 10U )
#define RCC_APB2RSTR_ADC2RST_Msk ( 0x1UL << RCC_APB2RSTR_ADC2RST_Pos )
#define RCC_APB2RSTR_ADC2RST ( RCC_APB2RSTR_ADC2RST_Msk )
#define RCC_APB2RSTR_TIM1RST_Pos ( 11U )
#define RCC_APB2RSTR_TIM1RST_Msk ( 0x1UL << RCC_APB2RSTR_TIM1RST_Pos )
#define RCC_APB2RSTR_TIM1RST ( RCC_APB2RSTR_TIM1RST_Msk )
#define RCC_APB2RSTR_SPI1RST_Pos ( 12U )
#define RCC_APB2RSTR_SPI1RST_Msk ( 0x1UL << RCC_APB2RSTR_SPI1RST_Pos )
#define RCC_APB2RSTR_SPI1RST ( RCC_APB2RSTR_SPI1RST_Msk )
#define RCC_APB2RSTR_USART1RST_Pos ( 14U )
#define RCC_APB2RSTR_USART1RST_Msk ( 0x1UL << RCC_APB2RSTR_USART1RST_Pos )
#define RCC_APB2RSTR_USART1RST ( RCC_APB2RSTR_USART1RST_Msk )
/* AHBENR */
#define RCC_AHBENR_DMA1EN_Pos ( 0U )
#define RCC_AHBENR_DMA1EN_Msk ( 0x1UL << RCC_AHBENR_DMA1EN_Pos )
#define RCC_AHBENR_DMA1EN ( RCC_AHBENR_DMA1EN_Msk )
// Note: DMA2 not present on STM32F103 chips.
#define RCC_AHBENR_DMA2EN_Pos ( 1U )
#define RCC_AHBENR_DMA2EN_Msk ( 0x1UL << RCC_AHBENR_DMA2EN_Pos )
#define RCC_AHBENR_DMA2EN ( RCC_AHBENR_DMA2EN_Msk )
#define RCC_AHBENR_SRAMEN_Pos ( 2U )
#define RCC_AHBENR_SRAMEN_Msk ( 0x1UL << RCC_AHBENR_SRAMEN_Pos )
#define RCC_AHBENR_SRAMEN ( RCC_AHBENR_SRAMEN_Msk )
#define RCC_AHBENR_FLITFEN_Pos ( 4U )
#define RCC_AHBENR_FLITFEN_Msk ( 0x1UL << RCC_AHBENR_FLITFEN_Pos )
#define RCC_AHBENR_FLITFEN ( RCC_AHBENR_FLITFEN_Msk )
#define RCC_AHBENR_CRCEN_Pos ( 6U )
#define RCC_AHBENR_CRCEN_Msk ( 0x1UL << RCC_AHBENR_CRCENEN_Pos )
#define RCC_AHBENR_CRCEN ( RCC_AHBENR_CRCENEN_Msk )
// Note: EXMC not present on STM32F103 chips.
#define RCC_AHBENR_EXMCEN_Pos ( 8U )
#define RCC_AHBENR_EXMCEN_Msk ( 0x1UL << RCC_AHBENR_EXMCEN_Pos )
#define RCC_AHBENR_EXMCEN ( RCC_AHBENR_EXMCEN_Msk )
// Note: USB handled differently on STM32F103 chips.
#define RCC_AHBENR_USBFSEN_Pos ( 12U )
#define RCC_AHBENR_USBFSEN_Msk ( 0x1UL << RCC_AHBENR_USBFSEN_Pos )
#define RCC_AHBENR_USBFSEN ( RCC_AHBENR_USBFSEN_Msk )
/* APB2ENR */
#define RCC_APB2ENR_AFIOEN_Pos ( 0U )
#define RCC_APB2ENR_AFIOEN_Msk ( 0x1UL << RCC_APB2ENR_AFIOEN_Pos )
#define RCC_APB2ENR_AFIOEN ( RCC_APB2ENR_AFIOEN_Msk )
#define RCC_APB2ENR_IOPAEN_Pos ( 2U )
#define RCC_APB2ENR_IOPAEN_Msk ( 0x1UL << RCC_APB2ENR_IOPAEN_Pos )
#define RCC_APB2ENR_IOPAEN ( RCC_APB2ENR_IOPAEN_Msk )
#define RCC_APB2ENR_IOPBEN_Pos ( 3U )
#define RCC_APB2ENR_IOPBEN_Msk ( 0x1UL << RCC_APB2ENR_IOPBEN_Pos )
#define RCC_APB2ENR_IOPBEN ( RCC_APB2ENR_IOPBEN_Msk )
#define RCC_APB2ENR_IOPCEN_Pos ( 4U )
#define RCC_APB2ENR_IOPCEN_Msk ( 0x1UL << RCC_APB2ENR_IOPCEN_Pos )
#define RCC_APB2ENR_IOPCEN ( RCC_APB2ENR_IOPCEN_Msk )
#define RCC_APB2ENR_IOPDEN_Pos ( 5U )
#define RCC_APB2ENR_IOPDEN_Msk ( 0x1UL << RCC_APB2ENR_IOPDEN_Pos )
#define RCC_APB2ENR_IOPDEN ( RCC_APB2ENR_IOPDEN_Msk )
#define RCC_APB2ENR_IOPEEN_Pos ( 6U )
#define RCC_APB2ENR_IOPEEN_Msk ( 0x1UL << RCC_APB2ENR_IOPEEN_Pos )
#define RCC_APB2ENR_IOPEEN ( RCC_APB2ENR_IOPEEN_Msk )
#define RCC_APB2ENR_ADC1EN_Pos ( 9U )
#define RCC_APB2ENR_ADC1EN_Msk ( 0x1UL << RCC_APB2ENR_ADC1EN_Pos )
#define RCC_APB2ENR_ADC1EN ( RCC_APB2ENR_ADC1EN_Msk )
#define RCC_APB2ENR_ADC2EN_Pos ( 10U )
#define RCC_APB2ENR_ADC2EN_Msk ( 0x1UL << RCC_APB2ENR_ADC2EN_Pos )
#define RCC_APB2ENR_ADC2EN ( RCC_APB2ENR_ADC2EN_Msk )
#define RCC_APB2ENR_TIM1EN_Pos ( 11U )
#define RCC_APB2ENR_TIM1EN_Msk ( 0x1UL << RCC_APB2ENR_TIM1EN_Pos )
#define RCC_APB2ENR_TIM1EN ( RCC_APB2ENR_TIM1EN_Msk )
#define RCC_APB2ENR_SPI1EN_Pos ( 12U )
#define RCC_APB2ENR_SPI1EN_Msk ( 0x1UL << RCC_APB2ENR_SPI1EN_Pos )
#define RCC_APB2ENR_SPI1EN ( RCC_APB2ENR_SPI1EN_Msk )
#define RCC_APB2ENR_USART1EN_Pos ( 14U )
#define RCC_APB2ENR_USART1EN_Msk ( 0x1UL << RCC_APB2ENR_USART1EN_Pos )
#define RCC_APB2ENR_USART1EN ( RCC_APB2ENR_USART1EN_Msk )
/* AFIO register bit definitions. */
/* GPIO register bit definitions. */
/* CRL */
#define GPIO_CRL_MODE_Pos ( 0U )
#define GPIO_CRL_MODE_Msk ( 0x33333333UL << GPIO_CRL_MODE_Pos )
#define GPIO_CRL_MODE ( GPIO_CRL_MODE_Msk )
#define GPIO_CRL_MODE0_Pos ( 0U )
#define GPIO_CRL_MODE0_Msk ( 0x3UL << GPIO_CRL_MODE0_Pos )
#define GPIO_CRL_MODE0 ( GPIO_CRL_MODE0_Msk )
#define GPIO_CRL_MODE1_Pos ( 4U )
#define GPIO_CRL_MODE1_Msk ( 0x3UL << GPIO_CRL_MODE1_Pos )
#define GPIO_CRL_MODE1 ( GPIO_CRL_MODE1_Msk )
#define GPIO_CRL_MODE2_Pos ( 8U )
#define GPIO_CRL_MODE2_Msk ( 0x3UL << GPIO_CRL_MODE2_Pos )
#define GPIO_CRL_MODE2 ( GPIO_CRL_MODE2_Msk )
#define GPIO_CRL_MODE3_Pos ( 12U )
#define GPIO_CRL_MODE3_Msk ( 0x3UL << GPIO_CRL_MODE3_Pos )
#define GPIO_CRL_MODE3 ( GPIO_CRL_MODE3_Msk )
#define GPIO_CRL_MODE4_Pos ( 16U )
#define GPIO_CRL_MODE4_Msk ( 0x3UL << GPIO_CRL_MODE4_Pos )
#define GPIO_CRL_MODE4 ( GPIO_CRL_MODE4_Msk )
#define GPIO_CRL_MODE5_Pos ( 20U )
#define GPIO_CRL_MODE5_Msk ( 0x3UL << GPIO_CRL_MODE5_Pos )
#define GPIO_CRL_MODE5 ( GPIO_CRL_MODE5_Msk )
#define GPIO_CRL_MODE6_Pos ( 24U )
#define GPIO_CRL_MODE6_Msk ( 0x3UL << GPIO_CRL_MODE6_Pos )
#define GPIO_CRL_MODE6 ( GPIO_CRL_MODE6_Msk )
#define GPIO_CRL_MODE7_Pos ( 28U )
#define GPIO_CRL_MODE7_Msk ( 0x3UL << GPIO_CRL_MODE7_Pos )
#define GPIO_CRL_MODE7 ( GPIO_CRL_MODE7_Msk )
#define GPIO_CRL_CNF_Pos ( 2U )
#define GPIO_CRL_CNF_Msk ( 0x33333333UL << GPIO_CRL_CNF_Pos )
#define GPIO_CRL_CNF ( GPIO_CRL_CNF_Msk )
#define GPIO_CRL_CNF0_Pos ( 2U )
#define GPIO_CRL_CNF0_Msk ( 0x3UL << GPIO_CRL_CNF0_Pos )
#define GPIO_CRL_CNF0 ( GPIO_CRL_CNF0_Msk )
#define GPIO_CRL_CNF1_Pos ( 6U )
#define GPIO_CRL_CNF1_Msk ( 0x3UL << GPIO_CRL_CNF1_Pos )
#define GPIO_CRL_CNF1 ( GPIO_CRL_CNF1_Msk )
#define GPIO_CRL_CNF2_Pos ( 10U )
#define GPIO_CRL_CNF2_Msk ( 0x3UL << GPIO_CRL_CNF2_Pos )
#define GPIO_CRL_CNF2 ( GPIO_CRL_CNF2_Msk )
#define GPIO_CRL_CNF3_Pos ( 14U )
#define GPIO_CRL_CNF3_Msk ( 0x3UL << GPIO_CRL_CNF3_Pos )
#define GPIO_CRL_CNF3 ( GPIO_CRL_CNF3_Msk )
#define GPIO_CRL_CNF4_Pos ( 18U )
#define GPIO_CRL_CNF4_Msk ( 0x3UL << GPIO_CRL_CNF4_Pos )
#define GPIO_CRL_CNF4 ( GPIO_CRL_CNF4_Msk )
#define GPIO_CRL_CNF5_Pos ( 22U )
#define GPIO_CRL_CNF5_Msk ( 0x3UL << GPIO_CRL_CNF5_Pos )
#define GPIO_CRL_CNF5 ( GPIO_CRL_CNF5_Msk )
#define GPIO_CRL_CNF6_Pos ( 26U )
#define GPIO_CRL_CNF6_Msk ( 0x3UL << GPIO_CRL_CNF6_Pos )
#define GPIO_CRL_CNF6 ( GPIO_CRL_CNF6_Msk )
#define GPIO_CRL_CNF7_Pos ( 30U )
#define GPIO_CRL_CNF7_Msk ( 0x3UL << GPIO_CRL_CNF7_Pos )
#define GPIO_CRL_CNF7 ( GPIO_CRL_CNF7_Msk )
/* CRH */
#define GPIO_CRH_MODE_Pos ( 0U )
#define GPIO_CRH_MODE_Msk ( 0x33333333UL << GPIO_CRH_MODE_Pos )
#define GPIO_CRH_MODE ( GPIO_CRH_MODE_Msk )
#define GPIO_CRH_MODE8_Pos ( 0U )
#define GPIO_CRH_MODE8_Msk ( 0x3UL << GPIO_CRH_MODE8_Pos )
#define GPIO_CRH_MODE8 ( GPIO_CRH_MODE8_Msk )
#define GPIO_CRH_MODE9_Pos ( 4U )
#define GPIO_CRH_MODE9_Msk ( 0x3UL << GPIO_CRH_MODE9_Pos )
#define GPIO_CRH_MODE9 ( GPIO_CRH_MODE9_Msk )
#define GPIO_CRH_MODE10_Pos ( 8U )
#define GPIO_CRH_MODE10_Msk ( 0x3UL << GPIO_CRH_MODE10_Pos )
#define GPIO_CRH_MODE10 ( GPIO_CRH_MODE10_Msk )
#define GPIO_CRH_MODE11_Pos ( 12U )
#define GPIO_CRH_MODE11_Msk ( 0x11UL << GPIO_CRH_MODE11_Pos )
#define GPIO_CRH_MODE11 ( GPIO_CRH_MODE11_Msk )
#define GPIO_CRH_MODE12_Pos ( 16U )
#define GPIO_CRH_MODE12_Msk ( 0x3UL << GPIO_CRH_MODE12_Pos )
#define GPIO_CRH_MODE12 ( GPIO_CRH_MODE12_Msk )
#define GPIO_CRH_MODE13_Pos ( 20U )
#define GPIO_CRH_MODE13_Msk ( 0x3UL << GPIO_CRH_MODE13_Pos )
#define GPIO_CRH_MODE13 ( GPIO_CRH_MODE13_Msk )
#define GPIO_CRH_MODE14_Pos ( 24U )
#define GPIO_CRH_MODE14_Msk ( 0x3UL << GPIO_CRH_MODE14_Pos )
#define GPIO_CRH_MODE14 ( GPIO_CRH_MODE14_Msk )
#define GPIO_CRH_MODE15_Pos ( 28U )
#define GPIO_CRH_MODE15_Msk ( 0x3UL << GPIO_CRH_MODE15_Pos )
#define GPIO_CRH_MODE15 ( GPIO_CRH_MODE15_Msk )
#define GPIO_CRH_CNF_Pos ( 2U )
#define GPIO_CRH_CNF_Msk ( 0x33333333UL << GPIO_CRH_CNF_Pos )
#define GPIO_CRH_CNF ( GPIO_CRH_CNF_Msk )
#define GPIO_CRH_CNF8_Pos ( 2U )
#define GPIO_CRH_CNF8_Msk ( 0x3UL << GPIO_CRH_CNF8_Pos )
#define GPIO_CRH_CNF8 ( GPIO_CRH_CNF8_Msk )
#define GPIO_CRH_CNF9_Pos ( 6U )
#define GPIO_CRH_CNF9_Msk ( 0x3UL << GPIO_CRH_CNF9_Pos )
#define GPIO_CRH_CNF9 ( GPIO_CRH_CNF9_Msk )
#define GPIO_CRH_CNF10_Pos ( 10U )
#define GPIO_CRH_CNF10_Msk ( 0x3UL << GPIO_CRH_CNF10_Pos )
#define GPIO_CRH_CNF10 ( GPIO_CRH_CNF10_Msk )
#define GPIO_CRH_CNF11_Pos ( 14U )
#define GPIO_CRH_CNF11_Msk ( 0x11UL << GPIO_CRH_CNF11_Pos )
#define GPIO_CRH_CNF11 ( GPIO_CRH_CNF11_Msk )
#define GPIO_CRH_CNF12_Pos ( 18U )
#define GPIO_CRH_CNF12_Msk ( 0x3UL << GPIO_CRH_CNF12_Pos )
#define GPIO_CRH_CNF12 ( GPIO_CRH_CNF12_Msk )
#define GPIO_CRH_CNF13_Pos ( 22U )
#define GPIO_CRH_CNF13_Msk ( 0x3UL << GPIO_CRH_CNF13_Pos )
#define GPIO_CRH_CNF13 ( GPIO_CRH_CNF13_Msk )
#define GPIO_CRH_CNF14_Pos ( 214U )
#define GPIO_CRH_CNF14_Msk ( 0x3UL << GPIO_CRH_CNF14_Pos )
#define GPIO_CRH_CNF14 ( GPIO_CRH_CNF14_Msk )
#define GPIO_CRH_CNF15_Pos ( 30U )
#define GPIO_CRH_CNF15_Msk ( 0x3UL << GPIO_CRH_CNF15_Pos )
#define GPIO_CRH_CNF15 ( GPIO_CRH_CNF15_Msk )
/* Global DMA register bit definitions. */
/* Per-channel DMA register bit definitions. */
/* CCR / CHCTL */
#define DMA_CCR_EN_Pos ( 0U )
#define DMA_CCR_EN_Msk ( 0x1UL << DMA_CCR_EN_Pos )
#define DMA_CCR_EN ( DMA_CCR_EN_Msk )
#define DMA_CCR_TCIE_Pos ( 1U )
#define DMA_CCR_TCIE_Msk ( 0x1UL << DMA_CCR_TCIE_Pos )
#define DMA_CCR_TCIE ( DMA_CCR_TCIE_Msk )
#define DMA_CCR_HTIE_Pos ( 2U )
#define DMA_CCR_HTIE_Msk ( 0x1UL << DMA_CCR_HTIE_Pos )
#define DMA_CCR_HTIE ( DMA_CCR_HTIE_Msk )
#define DMA_CCR_TEIE_Pos ( 3U )
#define DMA_CCR_TEIE_Msk ( 0x1UL << DMA_CCR_TEIE_Pos )
#define DMA_CCR_TEIE ( DMA_CCR_TEIE_Msk )
#define DMA_CCR_DIR_Pos ( 4U )
#define DMA_CCR_DIR_Msk ( 0x1UL << DMA_CCR_DIR_Pos )
#define DMA_CCR_DIR ( DMA_CCR_DIR_Msk )
#define DMA_CCR_CIRC_Pos ( 5U )
#define DMA_CCR_CIRC_Msk ( 0x1UL << DMA_CCR_CIRC_Pos )
#define DMA_CCR_CIRC ( DMA_CCR_CIRC_Msk )
#define DMA_CCR_PINC_Pos ( 6U )
#define DMA_CCR_PINC_Msk ( 0x1UL << DMA_CCR_PINC_Pos )
#define DMA_CCR_PINC ( DMA_CCR_PINC_Msk )
#define DMA_CCR_MINC_Pos ( 7U )
#define DMA_CCR_MINC_Msk ( 0x1UL << DMA_CCR_MINC_Pos )
#define DMA_CCR_MINC ( DMA_CCR_MINC_Msk )
#define DMA_CCR_PSIZE_Pos ( 8U )
#define DMA_CCR_PSIZE_Msk ( 0x3UL << DMA_CCR_PSIZE_Pos )
#define DMA_CCR_PSIZE ( DMA_CCR_PSIZE_Msk )
#define DMA_CCR_MSIZE_Pos ( 10U )
#define DMA_CCR_MSIZE_Msk ( 0x3UL << DMA_CCR_MSIZE_Pos )
#define DMA_CCR_MSIZE ( DMA_CCR_MSIZE_Msk )
#define DMA_CCR_PL_Pos ( 12U )
#define DMA_CCR_PL_Msk ( 0x3UL << DMA_CCR_PL_Pos )
#define DMA_CCR_PL ( DMA_CCR_PL_Msk )
#define DMA_CCR_MEM2MEM_Pos ( 14U )
#define DMA_CCR_MEM2MEM_Msk ( 0x1UL << DMA_CCR_MEM2MEM_Pos )
#define DMA_CCR_MEM2MEM ( DMA_CCR_MEM2MEM_Msk )
/* SPI register bit definitions. */
/* CR1 */
#define SPI_CR1_CPHA_Pos ( 0U )
#define SPI_CR1_CPHA_Msk ( 0x1UL << SPI_CR1_CPHA_Pos )
#define SPI_CR1_CPHA ( SPI_CR1_CPHA_Msk )
#define SPI_CR1_CPOL_Pos ( 1U )
#define SPI_CR1_CPOL_Msk ( 0x1UL << SPI_CR1_CPOL_Pos )
#define SPI_CR1_CPOL ( SPI_CR1_CPOL_Msk )
#define SPI_CR1_MSTR_Pos ( 2U )
#define SPI_CR1_MSTR_Msk ( 0x1UL << SPI_CR1_MSTR_Pos )
#define SPI_CR1_MSTR ( SPI_CR1_MSTR_Msk )
#define SPI_CR1_BR_Pos ( 3U )
#define SPI_CR1_BR_Msk ( 0x7UL << SPI_CR1_BR_Pos )
#define SPI_CR1_BR ( SPI_CR1_BR_Msk )
#define SPI_CR1_SPE_Pos ( 6U )
#define SPI_CR1_SPE_Msk ( 0x1UL << SPI_CR1_SPE_Pos )
#define SPI_CR1_SPE ( SPI_CR1_SPE_Msk )
#define SPI_CR1_LSBFIRST_Pos ( 7U )
#define SPI_CR1_LSBFIRST_Msk ( 0x1UL << SPI_CR1_LSBFIRST_Pos )
#define SPI_CR1_LSBFIRST ( SPI_CR1_LSBFIRST_Msk )
#define SPI_CR1_SSI_Pos ( 8U )
#define SPI_CR1_SSI_Msk ( 0x1UL << SPI_CR1_SSI_Pos )
#define SPI_CR1_SSI ( SPI_CR1_SSI_Msk )
#define SPI_CR1_SSM_Pos ( 9U )
#define SPI_CR1_SSM_Msk ( 0x1UL << SPI_CR1_SSM_Pos )
#define SPI_CR1_SSM ( SPI_CR1_SSM_Msk )
#define SPI_CR1_RXONLY_Pos ( 10U )
#define SPI_CR1_RXONLY_Msk ( 0x1UL << SPI_CR1_RXONLY_Pos )
#define SPI_CR1_RXONLY ( SPI_CR1_RXONLY_Msk )
#define SPI_CR1_DFF_Pos ( 11U )
#define SPI_CR1_DFF_Msk ( 0x1UL << SPI_CR1_DFF_Pos )
#define SPI_CR1_DFF ( SPI_CR1_DFF_Msk )
#define SPI_CR1_CRCNEXT_Pos ( 12U )
#define SPI_CR1_CRCNEXT_Msk ( 0x1UL << SPI_CR1_CRCNEXT_Pos )
#define SPI_CR1_CRCNEXT ( SPI_CR1_CRCNEXT_Msk )
#define SPI_CR1_CRCEN_Pos ( 13U )
#define SPI_CR1_CRCEN_Msk ( 0x1UL << SPI_CR1_CRCEN_Pos )
#define SPI_CR1_CRCEN ( SPI_CR1_CRCEN_Msk )
#define SPI_CR1_BIDIOE_Pos ( 14U )
#define SPI_CR1_BIDIOE_Msk ( 0x1UL << SPI_CR1_BIDIOE_Pos )
#define SPI_CR1_BIDIOE ( SPI_CR1_BIDIOE_Msk )
#define SPI_CR1_BIDIMODE_Pos ( 15U )
#define SPI_CR1_BIDIMODE_Msk ( 0x1UL << SPI_CR1_BIDIMODE_Pos )
#define SPI_CR1_BIDIMODE ( SPI_CR1_BIDIMODE_Msk )
/* CR2 */
#define SPI_CR2_RXDMAEN_Pos ( 0U )
#define SPI_CR2_RXDMAEN_Msk ( 0x1UL << SPI_CR2_RXDMAEN_Pos )
#define SPI_CR2_RXDMAEN ( SPI_CR2_RXDMAEN_Msk )
#define SPI_CR2_TXDMAEN_Pos ( 1U )
#define SPI_CR2_TXDMAEN_Msk ( 0x1UL << SPI_CR2_TXDMAEN_Pos )
#define SPI_CR2_TXDMAEN ( SPI_CR2_TXDMAEN_Msk )
#define SPI_CR2_SSOE_Pos ( 2U )
#define SPI_CR2_SSOE_Msk ( 0x1UL << SPI_CR2_SSOE_Pos )
#define SPI_CR2_SSOE ( SPI_CR2_SSOE_Msk )
// Note: 'NSS pulse mode' and 'TI mode' bits don't show up in
// STM32F103 reference documents.
#define SPI_CR2_NSSP_Pos ( 3U )
#define SPI_CR2_NSSP_Msk ( 0x1UL << SPI_CR2_NSSP_Pos )
#define SPI_CR2_NSSP ( SPI_CR2_NSSP_Msk )
#define SPI_CR2_TIMOD_Pos ( 4U )
#define SPI_CR2_TIMOD_Msk ( 0x1UL << SPI_CR2_TIMOD_Pos )
#define SPI_CR2_TIMOD ( SPI_CR2_TIMOD_Msk )
#define SPI_CR2_ERRIE_Pos ( 5U )
#define SPI_CR2_ERRIE_Msk ( 0x1UL << SPI_CR2_ERRIE_Pos )
#define SPI_CR2_ERRIE ( SPI_CR2_ERRIE_Msk )
#define SPI_CR2_RXNEIE_Pos ( 6U )
#define SPI_CR2_RXNEIE_Msk ( 0x1UL << SPI_CR2_RXNEIE_Pos )
#define SPI_CR2_RXNEIE ( SPI_CR2_RXNEIE_Msk )
#define SPI_CR2_TXEIE_Pos ( 7U )
#define SPI_CR2_TXEIE_Msk ( 0x1UL << SPI_CR2_TXEIE_Pos )
#define SPI_CR2_TXEIE ( SPI_CR2_TXEIE_Msk )
/* SR / STAT */
#define SPI_SR_RXNE_Pos ( 0U )
#define SPI_SR_RXNE_Msk ( 0x1UL << SPI_SR_RXNE_Pos )
#define SPI_SR_RXNE ( SPI_SR_RXNE_Msk )
#define SPI_SR_TXE_Pos ( 1U )
#define SPI_SR_TXE_Msk ( 0x1UL << SPI_SR_TXE_Pos )
#define SPI_SR_TXE ( SPI_SR_TXE_Msk )
#define SPI_SR_CHSIDE_Pos ( 2U )
#define SPI_SR_CHSIDE_Msk ( 0x1UL << SPI_SR_CHSIDE_Pos )
#define SPI_SR_CHSIDE ( SPI_SR_CHSIDE_Msk )
#define SPI_SR_UDR_Pos ( 3U )
#define SPI_SR_UDR_Msk ( 0x1UL << SPI_SR_UDR_Pos )
#define SPI_SR_UDR ( SPI_SR_UDR_Msk )
#define SPI_SR_CRCERR_Pos ( 4U )
#define SPI_SR_CRCERR_Msk ( 0x1UL << SPI_SR_CRCERR_Pos )
#define SPI_SR_CRCERR ( SPI_SR_CRCERR_Msk )
#define SPI_SR_MODF_Pos ( 5U )
#define SPI_SR_MODF_Msk ( 0x1UL << SPI_SR_MODF_Pos )
#define SPI_SR_MODF ( SPI_SR_MODF_Msk )
#define SPI_SR_OVR_Pos ( 6U )
#define SPI_SR_OVR_Msk ( 0x1UL << SPI_SR_OVR_Pos )
#define SPI_SR_OVR ( SPI_SR_OVR_Msk )
#define SPI_SR_BSY_Pos ( 7U )
#define SPI_SR_BSY_Msk ( 0x1UL << SPI_SR_BSY_Pos )
#define SPI_SR_BSY ( SPI_SR_BSY_Msk )
// Note: "Format error" bit doesn't show up in STM32F1 documentation.
#define SPI_SR_FERR_Pos ( 8U )
#define SPI_SR_FERR_Msk ( 0x1UL << SPI_SR_FERR_Pos )
#define SPI_SR_FERR ( SPI_SR_FERR_Msk )
#endif