stm32f030.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /**
  2. *
  3. * File Name : stm32f030.h
  4. * Author : Pat Beirne
  5. * Version : 12.0
  6. * Date : 01/08/2014
  7. * Copyright : 2014 Pat Beirne
  8. * License : GPL v3
  9. *
  10. */
  11. #ifndef __STM32F030_H
  12. #define __STM32F030_H
  13. /******************************************************************************/
  14. /* Data Types Needed */
  15. /******************************************************************************/
  16. typedef signed long s32;
  17. typedef signed short s16;
  18. typedef signed char s8;
  19. typedef signed long const sc32; /* Read Only */
  20. typedef signed short const sc16; /* Read Only */
  21. typedef signed char const sc8; /* Read Only */
  22. typedef volatile signed long vs32;
  23. typedef volatile signed short vs16;
  24. typedef volatile signed char vs8;
  25. typedef volatile signed long const vsc32; /* Read Only */
  26. typedef volatile signed short const vsc16; /* Read Only */
  27. typedef volatile signed char const vsc8; /* Read Only */
  28. typedef unsigned long u32;
  29. typedef unsigned short u16;
  30. typedef unsigned char u8;
  31. typedef unsigned long const uc32; /* Read Only */
  32. typedef unsigned short const uc16; /* Read Only */
  33. typedef unsigned char const uc8; /* Read Only */
  34. typedef volatile unsigned long vu32;
  35. typedef volatile unsigned short vu16;
  36. typedef volatile unsigned char vu8;
  37. typedef volatile unsigned long const vuc32; /* Read Only */
  38. typedef volatile unsigned short const vuc16; /* Read Only */
  39. typedef volatile unsigned char const vuc8; /* Read Only */
  40. /******************************************************************************/
  41. /* Peripheral registers structures */
  42. /******************************************************************************/
  43. /*------------------------ Analog to Digital Converter -----------------------*/
  44. typedef struct
  45. {
  46. vu32 ISR; //0
  47. vu32 IER;
  48. vu32 CR;
  49. vu32 CFGR1;
  50. vu32 CFGR2; //0x10
  51. vu32 SMPR;
  52. vu32 RESERVED0;
  53. vu32 RESERVED1;
  54. vu32 TR; //0x20
  55. vu32 RESERVED2;
  56. vu32 CHSELR;
  57. vu32 RESERVED4[5];
  58. vu32 DR; //0x40
  59. vu32 CCR;
  60. } ADC_TypeDef;
  61. /*------------------------ DMA Controller ------------------------------------*/
  62. typedef struct
  63. {
  64. vu32 CCR;
  65. vu32 CNDTR;
  66. vu32 CPAR;
  67. vu32 CMAR;
  68. } DMA_Channel_TypeDef;
  69. typedef struct
  70. {
  71. vu32 ISR;
  72. vu32 IFCR;
  73. } DMA_TypeDef;
  74. /*------------------------ External Interrupt/Event Controller ---------------*/
  75. typedef struct
  76. {
  77. vu32 IMR;
  78. vu32 EMR;
  79. vu32 RTSR;
  80. vu32 FTSR;
  81. vu32 SWIER;
  82. vu32 PR;
  83. } EXTI_TypeDef;
  84. /*------------------------ FLASH and Option Bytes Registers ------------------*/
  85. typedef struct
  86. {
  87. vu32 ACR;
  88. vu32 KEYR;
  89. vu32 OPTKEYR;
  90. vu32 SR;
  91. vu32 CR;
  92. vu32 AR;
  93. vu32 RESERVED;
  94. vu32 OBR;
  95. vu32 WRPR;
  96. } FLASH_TypeDef;
  97. typedef struct
  98. {
  99. vu16 RDP;
  100. vu16 USER;
  101. vu16 Data0;
  102. vu16 Data1;
  103. vu16 WRP0;
  104. vu16 WRP1;
  105. } OB_TypeDef;
  106. /*------------------------ General Purpose and Alternate Function IO ---------*/
  107. typedef struct
  108. {
  109. vu32 MODER;
  110. vu32 OTYPER;
  111. vu32 OSPEEDR;
  112. vu32 PUPDR;
  113. vu32 IDR;
  114. vu32 ODR;
  115. vu32 BSRR;
  116. vu32 LCKR;
  117. vu32 AFRL;
  118. vu32 AFRH;
  119. vu32 BRR;
  120. } GPIO_TypeDef;
  121. /*------------------------ Inter-integrated Circuit Interface ----------------*/
  122. typedef struct
  123. {
  124. vu32 CR1;
  125. vu32 CR2;
  126. vu16 OAR1;
  127. u16 RESERVED2;
  128. vu16 OAR2;
  129. u16 RESERVED3;
  130. vu32 TIMINGR; // 0x10
  131. vu32 TIMEOUTR;
  132. vu32 ISR;
  133. vu32 ICR;
  134. vu8 PECR; // 0x20
  135. vu8 RESERVED4[3];
  136. vu8 RXDR;
  137. vu8 RESERVED5[3];
  138. vu8 TXDR;
  139. vu8 RESERVED6[3];
  140. } I2C_TypeDef;
  141. /*------------------------ Independent WATCHDOG ------------------------------*/
  142. typedef struct
  143. {
  144. vu32 KR;
  145. vu32 PR;
  146. vu32 RLR;
  147. vu32 SR;
  148. vu32 WINR;
  149. } IWDG_TypeDef;
  150. /*------------------------ Nested Vectored Interrupt Controller --------------*/
  151. typedef struct
  152. {
  153. vu32 ISER[2];
  154. u32 RESERVED0[30];
  155. vu32 ICER[2];
  156. u32 RSERVED1[30];
  157. vu32 ISPR[2];
  158. u32 RESERVED2[30];
  159. vu32 ICPR[2];
  160. u32 RESERVED3[30];
  161. vu32 IABR[2];
  162. u32 RESERVED4[62];
  163. vu32 IPR[11];
  164. } NVIC_TypeDef;
  165. typedef struct
  166. {
  167. vuc32 CPUID;
  168. vu32 ICSR;
  169. vu32 VTOR;
  170. vu32 AIRCR;
  171. vu32 SCR;
  172. vu32 CCR;
  173. vu32 SHPR[3];
  174. vu32 SHCSR;
  175. vu32 CFSR;
  176. vu32 HFSR;
  177. vu32 DFSR;
  178. vu32 MMFAR;
  179. vu32 BFAR;
  180. vu32 AFSR;
  181. } SCB_TypeDef;
  182. /*------------------------ Power Control -------------------------------------*/
  183. typedef struct
  184. {
  185. vu32 CR;
  186. vu32 CSR;
  187. } PWR_TypeDef;
  188. /*------------------------ Reset and Clock Control ---------------------------*/
  189. typedef struct
  190. {
  191. vu32 CR;
  192. vu32 CFGR;
  193. vu32 CIR;
  194. vu32 APB2RSTR;
  195. vu32 APB1RSTR; // 0x10
  196. vu32 AHBENR;
  197. vu32 APB2ENR;
  198. vu32 APB1ENR;
  199. vu32 BDCR; // 0x20
  200. vu32 CSR;
  201. vu32 AHBRSTR;
  202. vu32 CRGR2;
  203. vu32 CFGR3; // 0x30
  204. vu32 CR2;
  205. } RCC_TypeDef;
  206. /*------------------------ Real-Time Clock -----------------------------------*/
  207. typedef struct
  208. {
  209. vu32 TR;
  210. vu32 DR;
  211. vu32 CR;
  212. vu32 ISR;
  213. vu32 PRER; // 0x10
  214. u32 RESERVED0[2];
  215. vu32 ALRMAR;
  216. u32 RESERVED1; // 0x20
  217. vu32 WPR;
  218. vu32 SSR;
  219. vu32 SHIFTR;
  220. vu32 TSTR; // 0x30
  221. vu32 TSDR;
  222. vu32 TSSSR;
  223. vu32 CALR;
  224. vu32 TAFCR; // 0x40
  225. vu32 ALRMASSR;
  226. } RTC_TypeDef;
  227. /*------------------------ Serial Peripheral Interface -----------------------*/
  228. typedef struct
  229. {
  230. vu16 CR1;
  231. u16 RESERVED0;
  232. vu16 CR2;
  233. u16 RESERVED1;
  234. vu16 SR;
  235. u16 RESERVED2;
  236. vu16 DR;
  237. u16 RESERVED3;
  238. vu16 CRCPR;
  239. u16 RESERVED4;
  240. vu16 RXCRCR;
  241. u16 RESERVED5;
  242. vu16 TXCRCR;
  243. u16 RESERVED6;
  244. } SPI_TypeDef;
  245. /*------------------------ SysCfg --------------------------------------------*/
  246. typedef struct
  247. {
  248. vu32 CFGR1;
  249. vu32 reserved;
  250. vu32 EXTICR[4];
  251. vu32 CFGR2;
  252. } SYSCFG_TypeDef;
  253. /*------------------------ SystemTick ----------------------------------------*/
  254. typedef struct
  255. {
  256. vu32 CTRL;
  257. vu32 LOAD;
  258. vu32 VAL;
  259. vuc32 CALIB;
  260. } SysTick_TypeDef;
  261. /*------------------------ Advanced Control Timer ----------------------------*/
  262. typedef struct
  263. {
  264. vu16 CR1;
  265. u16 RESERVED0;
  266. vu16 CR2;
  267. u16 RESERVED1;
  268. vu16 SMCR;
  269. u16 RESERVED2;
  270. vu16 DIER;
  271. u16 RESERVED3;
  272. vu16 SR;
  273. u16 RESERVED4;
  274. vu16 EGR;
  275. u16 RESERVED5;
  276. vu16 CCMR1;
  277. u16 RESERVED6;
  278. vu16 CCMR2;
  279. u16 RESERVED7;
  280. vu16 CCER;
  281. u16 RESERVED8;
  282. vu16 CNT;
  283. u16 RESERVED9;
  284. vu16 PSC;
  285. u16 RESERVED10;
  286. vu16 ARR;
  287. u16 RESERVED11;
  288. vu16 RCR;
  289. u16 RESERVED12;
  290. vu16 CCR1;
  291. u16 RESERVED13;
  292. vu16 CCR2;
  293. u16 RESERVED14;
  294. vu16 CCR3;
  295. u16 RESERVED15;
  296. vu16 CCR4;
  297. u16 RESERVED16;
  298. vu16 BDTR;
  299. u16 RESERVED17;
  300. vu16 DCR;
  301. u16 RESERVED18;
  302. vu16 DMAR;
  303. u16 RESERVED19;
  304. } TIM1_TypeDef;
  305. /*------------------------ General Purpose Timer -----------------------------*/
  306. typedef struct
  307. {
  308. vu16 CR1;
  309. u16 RESERVED0;
  310. vu16 CR2;
  311. u16 RESERVED1;
  312. vu16 SMCR;
  313. u16 RESERVED2;
  314. vu16 DIER;
  315. u16 RESERVED3;
  316. vu16 SR;
  317. u16 RESERVED4;
  318. vu16 EGR;
  319. u16 RESERVED5;
  320. vu16 CCMR1;
  321. u16 RESERVED6;
  322. vu16 CCMR2;
  323. u16 RESERVED7;
  324. vu16 CCER;
  325. u16 RESERVED8;
  326. vu16 CNT;
  327. u16 RESERVED9;
  328. vu16 PSC;
  329. u16 RESERVED10;
  330. vu16 ARR;
  331. u16 RESERVED11[3];
  332. vu16 CCR1;
  333. u16 RESERVED12;
  334. vu16 CCR2;
  335. u16 RESERVED13;
  336. vu16 CCR3;
  337. u16 RESERVED14;
  338. vu16 CCR4;
  339. u16 RESERVED15[3];
  340. vu16 DCR;
  341. u16 RESERVED16;
  342. vu16 DMAR;
  343. u16 RESERVED17;
  344. } TIM_TypeDef;
  345. /*----------------- Basic timer TIM6 -----------------------------------------*/
  346. typedef struct
  347. {
  348. vu16 CR1;
  349. u16 RESERVED0;
  350. vu16 DIER;
  351. u16 RESERVED1;
  352. vu16 SR;
  353. u16 RESERVED2;
  354. vu16 EGR;
  355. u16 RESERVED3;
  356. vu16 CNT;
  357. u16 RESERVED4;
  358. vu16 PSC;
  359. u16 RESERVED5;
  360. vu16 ARR;
  361. u16 RESERVED6;
  362. } TIM6_TypeDef;
  363. /*----------------- Universal Synchronous Asynchronous Receiver Transmitter --*/
  364. typedef struct
  365. {
  366. vu32 CR1;
  367. vu32 CR2;
  368. vu16 CR3;
  369. u16 RESERVED0;
  370. vu16 BRR;
  371. u16 RESERVED1;
  372. u32 GTPR;
  373. vu32 RTOR;
  374. vu16 RQR;
  375. u16 RESERVED2;
  376. vu32 ISR;
  377. vu32 ICR;
  378. vu8 RDR;
  379. u8 RESERVED3[3];
  380. vu8 TDR;
  381. u8 RESERVED4[3];
  382. } USART_TypeDef;
  383. /*------------------------ Window WATCHDOG -----------------------------------*/
  384. typedef struct
  385. {
  386. vu32 CR;
  387. vu32 CFR;
  388. vu32 SR;
  389. } WWDG_TypeDef;
  390. /******************************************************************************/
  391. /* Peripheral memory map */
  392. /******************************************************************************/
  393. /* Peripheral and SRAM base address in the alias region */
  394. #define PERIPH_BB_BASE ((u32)0x42000000)
  395. #define SRAM_BB_BASE ((u32)0x22000000)
  396. /* Peripheral and SRAM base address in the bit-band region */
  397. #define SRAM_BASE ((u32)0x20000000)
  398. #define PERIPH_BASE ((u32)0x40000000)
  399. /* Peripheral memory map */
  400. #define APBPERIPH_BASE PERIPH_BASE
  401. #define AHB1PERIPH_BASE (PERIPH_BASE + 0x20000)
  402. #define AHB2PERIPH_BASE (PERIPH_BASE + 0x08000000)
  403. #define TIM3_BASE (APBPERIPH_BASE + 0x0400)
  404. #define TIM6_BASE (APBPERIPH_BASE + 0x1000)
  405. #define TIM14_BASE (APBPERIPH_BASE + 0x2000)
  406. #define RTC_BASE (APBPERIPH_BASE + 0x2800)
  407. #define WWDG_BASE (APBPERIPH_BASE + 0x2C00)
  408. #define IWDG_BASE (APBPERIPH_BASE + 0x3000)
  409. #define SPI2_BASE (APBPERIPH_BASE + 0x3800)
  410. #define USART2_BASE (APBPERIPH_BASE + 0x4400)
  411. #define I2C1_BASE (APBPERIPH_BASE + 0x5400)
  412. #define I2C2_BASE (APBPERIPH_BASE + 0x5800)
  413. #define PWR_BASE (APBPERIPH_BASE + 0x7000)
  414. #define SYSCFG_BASE (APBPERIPH_BASE + 0x10000)
  415. #define EXTI_BASE (APBPERIPH_BASE + 0x10400)
  416. #define ADC_BASE (APBPERIPH_BASE + 0x12400)
  417. #define TIM1_BASE (APBPERIPH_BASE + 0x12C00)
  418. #define SPI1_BASE (APBPERIPH_BASE + 0x13000)
  419. #define USART1_BASE (APBPERIPH_BASE + 0x13800)
  420. #define TIM15_BASE (APBPERIPH_BASE + 0x14000)
  421. #define TIM16_BASE (APBPERIPH_BASE + 0x14400)
  422. #define TIM17_BASE (APBPERIPH_BASE + 0x14800)
  423. #define DMA_BASE (AHB1PERIPH_BASE + 0x0000)
  424. #define DMA_Channel1_BASE (AHB1PERIPH_BASE + 0x0008)
  425. #define DMA_Channel2_BASE (AHB1PERIPH_BASE + 0x001C)
  426. #define DMA_Channel3_BASE (AHB1PERIPH_BASE + 0x0030)
  427. #define DMA_Channel4_BASE (AHB1PERIPH_BASE + 0x0044)
  428. #define DMA_Channel5_BASE (AHB1PERIPH_BASE + 0x0058)
  429. #define RCC_BASE (AHB1PERIPH_BASE + 0x1000)
  430. #define FLASH_BASE (AHB1PERIPH_BASE + 0x2000)
  431. #define GPIOA_BASE (AHB2PERIPH_BASE + 0x0000)
  432. #define GPIOB_BASE (AHB2PERIPH_BASE + 0x0400)
  433. #define GPIOC_BASE (AHB2PERIPH_BASE + 0x0800)
  434. #define GPIOD_BASE (AHB2PERIPH_BASE + 0x0c00)
  435. #define GPIOF_BASE (AHB2PERIPH_BASE + 0x1400)
  436. /* System Control Space memory map */
  437. #define SCS_BASE ((u32)0xE000E000)
  438. #define SysTick_BASE (SCS_BASE + 0x0010)
  439. #define NVIC_BASE (SCS_BASE + 0x0100)
  440. #define SCB_BASE (SCS_BASE + 0x0D00)
  441. /******************************************************************************/
  442. /* Peripheral declaration */
  443. /******************************************************************************/
  444. #define TIM1 ((TIM1_TypeDef *) TIM1_BASE)
  445. #define TIM3 ((TIM_TypeDef *) TIM3_BASE)
  446. #define TIM6 ((TIM6_TypeDef *) TIM6_BASE)
  447. #define TIM14 ((TIM_TypeDef *) TIM14_BASE)
  448. #define TIM15 ((TIM_TypeDef *) TIM15_BASE)
  449. #define TIM16 ((TIM_TypeDef *) TIM16_BASE)
  450. #define TIM17 ((TIM_TypeDef *) TIM17_BASE)
  451. #define RTC ((RTC_TypeDef *) RTC_BASE)
  452. #define WWDG ((WWDG_TypeDef *) WWDG_BASE)
  453. #define IWDG ((IWDG_TypeDef *) IWDG_BASE)
  454. #define USART2 ((USART_TypeDef *) USART2_BASE)
  455. #define USART1 ((USART_TypeDef *) USART1_BASE)
  456. #define I2C1 ((I2C_TypeDef *) I2C1_BASE)
  457. #define I2C2 ((I2C_TypeDef *) I2C2_BASE)
  458. #define PWR ((PWR_TypeDef *) PWR_BASE)
  459. #define EXTI ((EXTI_TypeDef *) EXTI_BASE)
  460. #define SYSCFG ((SYSCFG_TypeDef *) SYSCFG_BASE)
  461. #define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
  462. #define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
  463. #define GPIOC ((GPIO_TypeDef *) GPIOC_BASE)
  464. #define GPIOD ((GPIO_TypeDef *) GPIOD_BASE)
  465. #define GPIOF ((GPIO_TypeDef *) GPIOF_BASE)
  466. #define ADC1 ((ADC_TypeDef *) ADC1_BASE)
  467. #define ADC2 ((ADC_TypeDef *) ADC2_BASE)
  468. #define SPI1 ((SPI_TypeDef *) SPI1_BASE)
  469. #define SPI2 ((SPI_TypeDef *) SPI2_BASE)
  470. #define USART1 ((USART_TypeDef *) USART1_BASE)
  471. #define USART2 ((USART_TypeDef *) USART2_BASE)
  472. #define DMA ((DMA_TypeDef *) DMA_BASE)
  473. #define DMA_Channel1 ((DMA_Channel_TypeDef *) DMA_Channel1_BASE)
  474. #define DMA_Channel2 ((DMA_Channel_TypeDef *) DMA_Channel2_BASE)
  475. #define DMA_Channel3 ((DMA_Channel_TypeDef *) DMA_Channel3_BASE)
  476. #define DMA_Channel4 ((DMA_Channel_TypeDef *) DMA_Channel4_BASE)
  477. #define DMA_Channel5 ((DMA_Channel_TypeDef *) DMA_Channel5_BASE)
  478. #define DMA_Channel6 ((DMA_Channel_TypeDef *) DMA_Channel6_BASE)
  479. #define DMA_Channel7 ((DMA_Channel_TypeDef *) DMA_Channel7_BASE)
  480. #define FLASH ((FLASH_TypeDef *) FLASH_BASE)
  481. #define OB ((OB_TypeDef *) OB_BASE)
  482. #define RCC ((RCC_TypeDef *) RCC_BASE)
  483. #define SysTick ((SysTick_TypeDef *) SysTick_BASE)
  484. #define NVIC ((NVIC_TypeDef *) NVIC_BASE)
  485. #define SCB ((SCB_TypeDef *) SCB_BASE)
  486. #define eint() asm volatile("cpsie i")
  487. #define dint() asm volatile("cpsid i")
  488. #endif // __STM32F030_H
  489. typedef unsigned char uint8;
  490. typedef unsigned short uint16;
  491. typedef unsigned int uint32;
  492. typedef unsigned int uint;
  493. typedef int bool;