common_regs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * stm32/common_regs.h
  3. *
  4. * Core and peripheral register definitions.
  5. *
  6. * Written & released by Keir Fraser <keir.xen@gmail.com>
  7. *
  8. * This is free and unencumbered software released into the public domain.
  9. * See the file COPYING for more details, or visit <http://unlicense.org>.
  10. */
  11. /* SysTick timer */
  12. struct stk {
  13. uint32_t ctrl; /* 00: Control and status */
  14. uint32_t load; /* 04: Reload value */
  15. uint32_t val; /* 08: Current value */
  16. uint32_t calib; /* 0C: Calibration value */
  17. };
  18. #define STK_CTRL_COUNTFLAG (1u<<16)
  19. #define STK_CTRL_CLKSOURCE (1u<< 2)
  20. #define STK_CTRL_TICKINT (1u<< 1)
  21. #define STK_CTRL_ENABLE (1u<< 0)
  22. #define STK_MASK ((1u<<24)-1)
  23. #define STK_BASE 0xe000e010
  24. /* System control block */
  25. struct scb {
  26. uint32_t cpuid; /* 00: CPUID base */
  27. uint32_t icsr; /* 04: Interrupt control and state */
  28. uint32_t vtor; /* 08: Vector table offset */
  29. uint32_t aircr; /* 0C: Application interrupt and reset control */
  30. uint32_t scr; /* 10: System control */
  31. uint32_t ccr; /* 14: Configuration and control */
  32. uint32_t shpr1; /* 18: System handler priority reg #1 */
  33. uint32_t shpr2; /* 1C: system handler priority reg #2 */
  34. uint32_t shpr3; /* 20: System handler priority reg #3 */
  35. uint32_t shcsr; /* 24: System handler control and state */
  36. uint32_t cfsr; /* 28: Configurable fault status */
  37. uint32_t hfsr; /* 2C: Hard fault status */
  38. uint32_t _unused; /* 30: - */
  39. uint32_t mmar; /* 34: Memory management fault address */
  40. uint32_t bfar; /* 38: Bus fault address */
  41. };
  42. #define SCB_CCR_BP (1u<<18)
  43. #define SCB_CCR_IC (1u<<17)
  44. #define SCB_CCR_DC (1u<<16)
  45. #define SCB_CCR_STKALIGN (1u<< 9)
  46. #define SCB_CCR_BFHFNMIGN (1u<< 8)
  47. #define SCB_CCR_DIV_0_TRP (1u<< 4)
  48. #define SCB_CCR_UNALIGN_TRP (1u<< 3)
  49. #define SCB_CCR_USERSETMPEND (1u<< 1)
  50. #define SCB_CCR_NONBASETHRDENA (1u<< 0)
  51. #define SCB_SHCSR_USGFAULTENA (1u<<18)
  52. #define SCB_SHCSR_BUSFAULTENA (1u<<17)
  53. #define SCB_SHCSR_MEMFAULTENA (1u<<16)
  54. #define SCB_SHCSR_SVCALLPENDED (1u<<15)
  55. #define SCB_SHCSR_BUSFAULTPENDED (1u<<14)
  56. #define SCB_SHCSR_MEMFAULTPENDED (1u<<13)
  57. #define SCB_SHCSR_USGFAULTPENDED (1u<<12)
  58. #define SCB_SHCSR_SYSTICKACT (1u<<11)
  59. #define SCB_SHCSR_PENDSVACT (1u<<10)
  60. #define SCB_SHCSR_MONITORACT (1u<< 8)
  61. #define SCB_SHCSR_SVCALLACT (1u<< 7)
  62. #define SCB_SHCSR_USGFAULTACT (1u<< 3)
  63. #define SCB_SHCSR_BUSFAULTACT (1u<< 1)
  64. #define SCB_SHCSR_MEMFAULTACT (1u<< 0)
  65. #define SCB_CFSR_DIVBYZERO (1u<<25)
  66. #define SCB_CFSR_UNALIGNED (1u<<24)
  67. #define SCB_CFSR_NOCP (1u<<19)
  68. #define SCB_CFSR_INVPC (1u<<18)
  69. #define SCB_CFSR_INVSTATE (1u<<17)
  70. #define SCB_CFSR_UNDEFINSTR (1u<<16)
  71. #define SCB_CFSR_BFARVALID (1u<<15)
  72. #define SCB_CFSR_STKERR (1u<<12)
  73. #define SCB_CFSR_UNSTKERR (1u<<11)
  74. #define SCB_CFSR_IMPRECISERR (1u<<10)
  75. #define SCB_CFSR_PRECISERR (1u<< 9)
  76. #define SCB_CFSR_IBUSERR (1u<< 8)
  77. #define SCB_CFSR_MMARVALID (1u<< 7)
  78. #define SCB_CFSR_MSTKERR (1u<< 4)
  79. #define SCB_CFSR_MUNSTKERR (1u<< 3)
  80. #define SCB_CFSR_DACCVIOL (1u<< 1)
  81. #define SCB_CFSR_IACCVIOL (1u<< 0)
  82. #define SCB_AIRCR_VECTKEY (0x05fau<<16)
  83. #define SCB_AIRCR_SYSRESETREQ (1u<<2)
  84. #define SCB_BASE 0xe000ed00
  85. /* Nested vectored interrupt controller */
  86. struct nvic {
  87. uint32_t iser[32]; /* 00: Interrupt set-enable */
  88. uint32_t icer[32]; /* 80: Interrupt clear-enable */
  89. uint32_t ispr[32]; /* 100: Interrupt set-pending */
  90. uint32_t icpr[32]; /* 180: Interrupt clear-pending */
  91. uint32_t iabr[64]; /* 200: Interrupt active */
  92. uint8_t ipr[80]; /* 300: Interrupt priority */
  93. };
  94. #define NVIC_BASE 0xe000e100
  95. /* Independent Watchdog */
  96. struct iwdg {
  97. uint32_t kr; /* 00: Key */
  98. uint32_t pr; /* 04: Prescaler */
  99. uint32_t rlr; /* 08: Reload */
  100. uint32_t sr; /* 0C: Status */
  101. };
  102. #define IWDG_BASE 0x40003000
  103. struct exti {
  104. uint32_t imr; /* 00: Interrupt mask */
  105. uint32_t emr; /* 04: Event mask */
  106. uint32_t rtsr; /* 08: Rising trigger selection */
  107. uint32_t ftsr; /* 0C: Falling trigger selection */
  108. uint32_t swier; /* 10: Software interrupt event */
  109. uint32_t pr; /* 14: Pending */
  110. };
  111. /* Timer */
  112. struct tim {
  113. uint32_t cr1; /* 00: Control 1 */
  114. uint32_t cr2; /* 04: Control 2 */
  115. uint32_t smcr; /* 08: Slave mode control */
  116. uint32_t dier; /* 0C: DMA/interrupt enable */
  117. uint32_t sr; /* 10: Status */
  118. uint32_t egr; /* 14: Event generation */
  119. uint32_t ccmr1; /* 18: Capture/compare mode 1 */
  120. uint32_t ccmr2; /* 1C: Capture/compare mode 2 */
  121. uint32_t ccer; /* 20: Capture/compare enable */
  122. uint32_t cnt; /* 24: Counter */
  123. uint32_t psc; /* 28: Prescaler */
  124. uint32_t arr; /* 2C: Auto-reload */
  125. uint32_t rcr; /* 30: Repetition counter */
  126. uint32_t ccr1; /* 34: Capture/compare 1 */
  127. uint32_t ccr2; /* 38: Capture/compare 2 */
  128. uint32_t ccr3; /* 3C: Capture/compare 3 */
  129. uint32_t ccr4; /* 40: Capture/compare 4 */
  130. uint32_t bdtr; /* 44: Break and dead-time */
  131. uint32_t dcr; /* 48: DMA control */
  132. uint32_t dmar; /* 4C: DMA address for full transfer */
  133. uint32_t _pad; /* 50: - */
  134. uint32_t ccmr3; /* 54: Capture/compare mode 3 */
  135. uint32_t ccr5; /* 58: Capture/compare 5 */
  136. uint32_t ccr6; /* 5C: Capture/compare 6 */
  137. };
  138. #define TIM_CR1_ARPE (1u<<7)
  139. #define TIM_CR1_DIR (1u<<4)
  140. #define TIM_CR1_OPM (1u<<3)
  141. #define TIM_CR1_URS (1u<<2)
  142. #define TIM_CR1_UDIS (1u<<1)
  143. #define TIM_CR1_CEN (1u<<0)
  144. #define TIM_CR2_TI1S (1u<<7)
  145. #define TIM_CR2_MMS(x) ((x)<<4)
  146. #define TIM_CR2_CCDS (1u<<3)
  147. #define TIM_SMCR_ETP (1u<<15)
  148. #define TIM_SMCR_ETC (1u<<14)
  149. #define TIM_SMCR_ETPS(x) ((x)<<12)
  150. #define TIM_SMCR_ETF(x) ((x)<<8)
  151. #define TIM_SMCR_MSM (1u<<7)
  152. #define TIM_SMCR_TS(x) ((x)<<4)
  153. #define TIM_SMCR_SMS(x) ((x)<<0)
  154. #define TIM_DIER_TDE (1u<<14)
  155. #define TIM_DIER_CC4DE (1u<<12)
  156. #define TIM_DIER_CC3DE (1u<<11)
  157. #define TIM_DIER_CC2DE (1u<<10)
  158. #define TIM_DIER_CC1DE (1u<<9)
  159. #define TIM_DIER_UDE (1u<<8)
  160. #define TIM_DIER_TIE (1u<<6)
  161. #define TIM_DIER_CC4IE (1u<<4)
  162. #define TIM_DIER_CC3IE (1u<<3)
  163. #define TIM_DIER_CC2IE (1u<<2)
  164. #define TIM_DIER_CC1IE (1u<<1)
  165. #define TIM_DIER_UIE (1u<<0)
  166. #define TIM_SR_CC4OF (1u<<12)
  167. #define TIM_SR_CC3OF (1u<<11)
  168. #define TIM_SR_CC2OF (1u<<10)
  169. #define TIM_SR_CC1OF (1u<<9)
  170. #define TIM_SR_TIF (1u<<6)
  171. #define TIM_SR_CC4IF (1u<<4)
  172. #define TIM_SR_CC3IF (1u<<3)
  173. #define TIM_SR_CC2IF (1u<<2)
  174. #define TIM_SR_CC1IF (1u<<1)
  175. #define TIM_SR_UIF (1u<<0)
  176. #define TIM_EGR_TG (1u<<6)
  177. #define TIM_EGR_CC4G (1u<<4)
  178. #define TIM_EGR_CC3G (1u<<3)
  179. #define TIM_EGR_CC2G (1u<<2)
  180. #define TIM_EGR_CC1G (1u<<1)
  181. #define TIM_EGR_UG (1u<<0)
  182. #define TIM_CCMR1_OC2CE (1u <<15)
  183. #define TIM_CCMR1_OC2M(x) ((x)<<12)
  184. #define TIM_CCMR1_OC2PE (1u <<11)
  185. #define TIM_CCMR1_OC2FE (1u <<10)
  186. #define TIM_CCMR1_CC2S(x) ((x)<< 8)
  187. #define TIM_CCMR1_OC1CE (1u << 7)
  188. #define TIM_CCMR1_OC1M(x) ((x)<< 4)
  189. #define TIM_CCMR1_OC1PE (1u << 3)
  190. #define TIM_CCMR1_OC1FE (1u << 2)
  191. #define TIM_CCMR1_CC1S(x) ((x)<< 0)
  192. #define TIM_CCMR1_IC2F(x) ((x)<<12)
  193. #define TIM_CCMR1_IC2PSC(x) ((x)<<10)
  194. #define TIM_CCMR1_IC1F(x) ((x)<< 4)
  195. #define TIM_CCMR1_IC1PSC(x) ((x)<< 2)
  196. #define TIM_CCMR2_OC4CE (1u <<15)
  197. #define TIM_CCMR2_OC4M(x) ((x)<<12)
  198. #define TIM_CCMR2_OC4PE (1u <<11)
  199. #define TIM_CCMR2_OC4FE (1u <<10)
  200. #define TIM_CCMR2_CC4S(x) ((x)<< 8)
  201. #define TIM_CCMR2_OC3CE (1u << 7)
  202. #define TIM_CCMR2_OC3M(x) ((x)<< 4)
  203. #define TIM_CCMR2_OC3PE (1u << 3)
  204. #define TIM_CCMR2_OC3FE (1u << 2)
  205. #define TIM_CCMR2_CC3S(x) ((x)<< 0)
  206. #define TIM_CCMR2_IC4F(x) ((x)<<12)
  207. #define TIM_CCMR2_IC4PSC(x) ((x)<<10)
  208. #define TIM_CCMR2_IC3F(x) ((x)<< 4)
  209. #define TIM_CCMR2_IC3PSC(x) ((x)<< 2)
  210. #define TIM_OCM_FROZEN (0u)
  211. #define TIM_OCM_SET_HIGH (1u)
  212. #define TIM_OCM_SET_LOW (2u)
  213. #define TIM_OCM_TOGGLE (3u)
  214. #define TIM_OCM_FORCE_LOW (4u)
  215. #define TIM_OCM_FORCE_HIGH (5u)
  216. #define TIM_OCM_PWM1 (6u)
  217. #define TIM_OCM_PWM2 (7u)
  218. #define TIM_OCM_MASK (7u)
  219. #define TIM_CCS_OUTPUT (0u)
  220. #define TIM_CCS_INPUT_TI1 (1u)
  221. #define TIM_CCS_INPUT_TI2 (2u)
  222. #define TIM_CCS_INPUT_TRC (3u)
  223. #define TIM_CCS_MASK (3u)
  224. #define TIM_CCER_CC4P (1u<<13)
  225. #define TIM_CCER_CC4E (1u<<12)
  226. #define TIM_CCER_CC3P (1u<< 9)
  227. #define TIM_CCER_CC3E (1u<< 8)
  228. #define TIM_CCER_CC2P (1u<< 5)
  229. #define TIM_CCER_CC2E (1u<< 4)
  230. #define TIM_CCER_CC1P (1u<< 1)
  231. #define TIM_CCER_CC1E (1u<< 0)
  232. #define TIM_BDTR_MOE (1u<<15)
  233. #define TIM_BDTR_AOE (1u<<14)
  234. #define TIM_BDTR_BKP (1u<<13)
  235. #define TIM_BDTR_BKE (1u<<12)
  236. #define TIM_BDTR_OSSR (1u<<11)
  237. #define TIM_BDTR_OSSI (1u<<10)
  238. #define TIM_BDTR_LOCK(x) ((x)<<8)
  239. #define TIM_BDTR_DTG(x) ((x)<<0)
  240. /* SPI/I2S */
  241. struct spi {
  242. uint32_t cr1; /* 00: Control 1 */
  243. uint32_t cr2; /* 04: Control 2 */
  244. uint32_t sr; /* 08: Status */
  245. uint32_t dr; /* 0C: Data */
  246. uint32_t crcpr; /* 10: CRC polynomial */
  247. uint32_t rxcrcr; /* 14: RX CRC */
  248. uint32_t txcrcr; /* 18: TX CRC */
  249. uint32_t i2scfgr; /* 1C: I2S configuration */
  250. uint32_t i2spr; /* 20: I2S prescaler */
  251. };
  252. #define SPI_CR1_BIDIMODE (1u<<15)
  253. #define SPI_CR1_BIDIOE (1u<<14)
  254. #define SPI_CR1_CRCEN (1u<<13)
  255. #define SPI_CR1_CRCNEXT (1u<<12)
  256. #define SPI_CR1_DFF (1u<<11)
  257. #define SPI_CR1_RXONLY (1u<<10)
  258. #define SPI_CR1_SSM (1u<< 9)
  259. #define SPI_CR1_SSI (1u<< 8)
  260. #define SPI_CR1_LSBFIRST (1u<< 7)
  261. #define SPI_CR1_SPE (1u<< 6)
  262. #define SPI_CR1_BR_DIV2 (0u<< 3)
  263. #define SPI_CR1_BR_DIV4 (1u<< 3)
  264. #define SPI_CR1_BR_DIV8 (2u<< 3)
  265. #define SPI_CR1_BR_DIV16 (3u<< 3)
  266. #define SPI_CR1_BR_DIV32 (4u<< 3)
  267. #define SPI_CR1_BR_DIV64 (5u<< 3)
  268. #define SPI_CR1_BR_DIV128 (6u<< 3)
  269. #define SPI_CR1_BR_DIV256 (7u<< 3)
  270. #define SPI_CR1_BR_MASK (7u<< 3)
  271. #define SPI_CR1_MSTR (1u<< 2)
  272. #define SPI_CR1_CPOL (1u<< 1)
  273. #define SPI_CR1_CPHA (1u<< 0)
  274. #define SPI_CR2_TXEIE (1u<< 7)
  275. #define SPI_CR2_RXNEIE (1u<< 6)
  276. #define SPI_CR2_ERRIE (1u<< 5)
  277. #define SPI_CR2_SSOE (1u<< 2)
  278. #define SPI_CR2_TXDMAEN (1u<< 1)
  279. #define SPI_CR2_RXDMAEN (1u<< 0)
  280. #define SPI_SR_BSY (1u<< 7)
  281. #define SPI_SR_OVR (1u<< 6)
  282. #define SPI_SR_MODF (1u<< 5)
  283. #define SPI_SR_CRCERR (1u<< 4)
  284. #define SPI_SR_USR (1u<< 3)
  285. #define SPI_SR_CHSIDE (1u<< 2)
  286. #define SPI_SR_TXE (1u<< 1)
  287. #define SPI_SR_RXNE (1u<< 0)
  288. #define SPI1_BASE 0x40013000
  289. #define SPI2_BASE 0x40003800
  290. #define SPI3_BASE 0x40003C00
  291. /*
  292. * Local variables:
  293. * mode: C
  294. * c-file-style: "Linux"
  295. * c-basic-offset: 4
  296. * tab-width: 4
  297. * indent-tabs-mode: nil
  298. * End:
  299. */