stm32f10x_regs.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. /*
  2. * stm32f10x_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_STKALIGN (1u<<9)
  43. #define SCB_CCR_BFHFNMIGN (1u<<8)
  44. #define SCB_CCR_DIV_0_TRP (1u<<4)
  45. #define SCB_CCR_UNALIGN_TRP (1u<<3)
  46. #define SCB_CCR_USERSETMPEND (1u<<1)
  47. #define SCB_CCR_NONBASETHRDENA (1u<<0)
  48. #define SCB_SHCSR_USGFAULTENA (1u<<18)
  49. #define SCB_SHCSR_BUSFAULTENA (1u<<17)
  50. #define SCB_SHCSR_MEMFAULTENA (1u<<16)
  51. #define SCB_SHCSR_SVCALLPENDED (1u<<15)
  52. #define SCB_SHCSR_BUSFAULTPENDED (1u<<14)
  53. #define SCB_SHCSR_MEMFAULTPENDED (1u<<13)
  54. #define SCB_SHCSR_USGFAULTPENDED (1u<<12)
  55. #define SCB_SHCSR_SYSTICKACT (1u<<11)
  56. #define SCB_SHCSR_PENDSVACT (1u<<10)
  57. #define SCB_SHCSR_MONITORACT (1u<< 8)
  58. #define SCB_SHCSR_SVCALLACT (1u<< 7)
  59. #define SCB_SHCSR_USGFAULTACT (1u<< 3)
  60. #define SCB_SHCSR_BUSFAULTACT (1u<< 1)
  61. #define SCB_SHCSR_MEMFAULTACT (1u<< 0)
  62. #define SCB_CFSR_DIVBYZERO (1u<<25)
  63. #define SCB_CFSR_UNALIGNED (1u<<24)
  64. #define SCB_CFSR_NOCP (1u<<19)
  65. #define SCB_CFSR_INVPC (1u<<18)
  66. #define SCB_CFSR_INVSTATE (1u<<17)
  67. #define SCB_CFSR_UNDEFINSTR (1u<<16)
  68. #define SCB_CFSR_BFARVALID (1u<<15)
  69. #define SCB_CFSR_STKERR (1u<<12)
  70. #define SCB_CFSR_UNSTKERR (1u<<11)
  71. #define SCB_CFSR_IMPRECISERR (1u<<10)
  72. #define SCB_CFSR_PRECISERR (1u<< 9)
  73. #define SCB_CFSR_IBUSERR (1u<< 8)
  74. #define SCB_CFSR_MMARVALID (1u<< 7)
  75. #define SCB_CFSR_MSTKERR (1u<< 4)
  76. #define SCB_CFSR_MUNSTKERR (1u<< 3)
  77. #define SCB_CFSR_DACCVIOL (1u<< 1)
  78. #define SCB_CFSR_IACCVIOL (1u<< 0)
  79. #define SCB_AIRCR_VECTKEY (0x05fau<<16)
  80. #define SCB_AIRCR_SYSRESETREQ (1u<<2)
  81. #define SCB_BASE 0xe000ed00
  82. /* Nested vectored interrupt controller */
  83. struct nvic {
  84. uint32_t iser[32]; /* 00: Interrupt set-enable */
  85. uint32_t icer[32]; /* 80: Interrupt clear-enable */
  86. uint32_t ispr[32]; /* 100: Interrupt set-pending */
  87. uint32_t icpr[32]; /* 180: Interrupt clear-pending */
  88. uint32_t iabr[64]; /* 200: Interrupt active */
  89. uint8_t ipr[80]; /* 300: Interrupt priority */
  90. };
  91. #define NVIC_BASE 0xe000e100
  92. /* Flash memory interface */
  93. struct flash {
  94. uint32_t acr; /* 00: Flash access control */
  95. uint32_t keyr; /* 04: FPEC key */
  96. uint32_t optkeyr; /* 08: Flash OPTKEY */
  97. uint32_t sr; /* 0C: Flash status */
  98. uint32_t cr; /* 10: Flash control */
  99. uint32_t ar; /* 14: Flash address */
  100. uint32_t rsvd; /* 18: - */
  101. uint32_t obr; /* 1C: Option byte */
  102. uint32_t wrpr; /* 20: Write protection */
  103. };
  104. #define FLASH_ACR_PRFTBS (1u<< 5)
  105. #define FLASH_ACR_PRFTBE (1u<< 4)
  106. #define FLASH_ACR_HLFCYA (1u<< 3)
  107. #define FLASH_ACR_LATENCY(w) ((w)<<0) /* wait states */
  108. #define FLASH_SR_EOP (1u<< 5)
  109. #define FLASH_SR_WRPRTERR (1u<< 4)
  110. #define FLASH_SR_PGERR (1u<< 2)
  111. #define FLASH_SR_BSY (1u<< 0)
  112. #define FLASH_CR_EOPIE (1u<<12)
  113. #define FLASH_CR_ERRIE (1u<<10)
  114. #define FLASH_CR_OPTWRE (1u<< 9)
  115. #define FLASH_CR_LOCK (1u<< 7)
  116. #define FLASH_CR_STRT (1u<< 6)
  117. #define FLASH_CR_OPTER (1u<< 5)
  118. #define FLASH_CR_OPTPG (1u<< 4)
  119. #define FLASH_CR_MER (1u<< 2)
  120. #define FLASH_CR_PER (1u<< 1)
  121. #define FLASH_CR_PG (1u<< 0)
  122. #define FLASH_BASE 0x40022000
  123. /* Power control */
  124. struct pwr {
  125. uint32_t cr; /* 00: Power control */
  126. uint32_t csr; /* 04: Power control/status */
  127. };
  128. #define PWR_CR_DBP (1u<< 8)
  129. #define PWR_BASE 0x40007000
  130. /* Backup */
  131. struct bkp {
  132. uint32_t _0[1]; /* 00: - */
  133. uint32_t dr1[10]; /* 04-28: Data block #1 */
  134. uint32_t rtccr; /* 2C: RTC clock calibration */
  135. uint32_t cr; /* 30: Control */
  136. uint32_t csr; /* 34: Control/status */
  137. uint32_t _1[2]; /* 38-3C: - */
  138. uint32_t dr2[32]; /* 40-BC: Data block #2 */
  139. };
  140. #define BKP_BASE 0x40006c00
  141. /* Reset and clock control */
  142. struct rcc {
  143. uint32_t cr; /* 00: Clock control */
  144. uint32_t cfgr; /* 04: Clock configuration */
  145. uint32_t cir; /* 08: Clock interrupt */
  146. uint32_t apb2rstr; /* 0C: APB2 peripheral reset */
  147. uint32_t apb1rstr; /* 10: APB1 peripheral reset */
  148. uint32_t ahbenr; /* 14: AHB periphernal clock enable */
  149. uint32_t apb2enr; /* 18: APB2 peripheral clock enable */
  150. uint32_t apb1enr; /* 1C: APB1 peripheral clock enable */
  151. uint32_t bdcr; /* 20: Backup domain control */
  152. uint32_t csr; /* 24: Control/status */
  153. uint32_t ahbrstr; /* 28: AHB peripheral clock reset */
  154. uint32_t cfgr2; /* 2C: Clock configuration 2 */
  155. };
  156. #define RCC_CR_PLL3RDY (1u<<29)
  157. #define RCC_CR_PLL3ON (1u<<28)
  158. #define RCC_CR_PLL2RDY (1u<<27)
  159. #define RCC_CR_PLL2ON (1u<<26)
  160. #define RCC_CR_PLLRDY (1u<<25)
  161. #define RCC_CR_PLLON (1u<<24)
  162. #define RCC_CR_CSSON (1u<<19)
  163. #define RCC_CR_HSEBYP (1u<<18)
  164. #define RCC_CR_HSERDY (1u<<17)
  165. #define RCC_CR_HSEON (1u<<16)
  166. #define RCC_CR_HSIRDY (1u<<1)
  167. #define RCC_CR_HSION (1u<<0)
  168. #define RCC_CFGR_PLLMUL(x) (((x)-2)<<18)
  169. #define RCC_CFGR_PLLXTPRE (1u<<17)
  170. #define RCC_CFGR_PLLSRC_HSI (0u<<16)
  171. #define RCC_CFGR_PLLSRC_PREDIV1 (1u<<16)
  172. #define RCC_CFGR_ADCPRE_DIV8 (3u<<14)
  173. #define RCC_CFGR_PPRE1_DIV2 (4u<<8)
  174. #define RCC_CFGR_SWS_HSI (0u<<2)
  175. #define RCC_CFGR_SWS_HSE (1u<<2)
  176. #define RCC_CFGR_SWS_PLL (2u<<2)
  177. #define RCC_CFGR_SWS_MASK (3u<<2)
  178. #define RCC_CFGR_SW_HSI (0u<<0)
  179. #define RCC_CFGR_SW_HSE (1u<<0)
  180. #define RCC_CFGR_SW_PLL (2u<<0)
  181. #define RCC_CFGR_SW_MASK (3u<<0)
  182. #define RCC_AHBENR_ETHMACRXEN (1u<<16)
  183. #define RCC_AHBENR_ETHMACTXEN (1u<<15)
  184. #define RCC_AHBENR_ETHMACEN (1u<<14)
  185. #define RCC_AHBENR_OTGFSEN (1u<<12)
  186. #define RCC_AHBENR_CRCEN (1u<< 6)
  187. #define RCC_AHBENR_FLITFEN (1u<< 4)
  188. #define RCC_AHBENR_SRAMEN (1u<< 2)
  189. #define RCC_AHBENR_DMA2EN (1u<< 1)
  190. #define RCC_AHBENR_DMA1EN (1u<< 0)
  191. #define RCC_APB1ENR_DACEN (1u<<29)
  192. #define RCC_APB1ENR_PWREN (1u<<28)
  193. #define RCC_APB1ENR_BKPEN (1u<<27)
  194. #define RCC_APB1ENR_CAN2EN (1u<<26)
  195. #define RCC_APB1ENR_CAN1EN (1u<<25)
  196. #define RCC_APB1ENR_USBEN (1u<<23)
  197. #define RCC_APB1ENR_I2C2EN (1u<<22)
  198. #define RCC_APB1ENR_I2C1EN (1u<<21)
  199. #define RCC_APB1ENR_USART5EN (1u<<20)
  200. #define RCC_APB1ENR_USART4EN (1u<<19)
  201. #define RCC_APB1ENR_USART3EN (1u<<18)
  202. #define RCC_APB1ENR_USART2EN (1u<<17)
  203. #define RCC_APB1ENR_SPI3EN (1u<<15)
  204. #define RCC_APB1ENR_SPI2EN (1u<<14)
  205. #define RCC_APB1ENR_WWDGEN (1u<<11)
  206. #define RCC_APB1ENR_TIM7EN (1u<< 5)
  207. #define RCC_APB1ENR_TIM6EN (1u<< 4)
  208. #define RCC_APB1ENR_TIM5EN (1u<< 3)
  209. #define RCC_APB1ENR_TIM4EN (1u<< 2)
  210. #define RCC_APB1ENR_TIM3EN (1u<< 1)
  211. #define RCC_APB1ENR_TIM2EN (1u<< 0)
  212. #define RCC_APB2ENR_USART1EN (1u<<14)
  213. #define RCC_APB2ENR_SPI1EN (1u<<12)
  214. #define RCC_APB2ENR_TIM1EN (1u<<11)
  215. #define RCC_APB2ENR_ADC2EN (1u<<10)
  216. #define RCC_APB2ENR_ADC1EN (1u<< 9)
  217. #define RCC_APB2ENR_IOPEEN (1u<< 6)
  218. #define RCC_APB2ENR_IOPDEN (1u<< 5)
  219. #define RCC_APB2ENR_IOPCEN (1u<< 4)
  220. #define RCC_APB2ENR_IOPBEN (1u<< 3)
  221. #define RCC_APB2ENR_IOPAEN (1u<< 2)
  222. #define RCC_APB2ENR_AFIOEN (1u<< 0)
  223. #define RCC_CSR_LPWRRSTF (1u<<31)
  224. #define RCC_CSR_WWDGRSTF (1u<<30)
  225. #define RCC_CSR_IWDGRSTF (1u<<29)
  226. #define RCC_CSR_SFTRSTF (1u<<28)
  227. #define RCC_CSR_PORRSTF (1u<<27)
  228. #define RCC_CSR_PINRSTF (1u<<26)
  229. #define RCC_CSR_RMVF (1u<<24)
  230. #define RCC_CSR_LSIRDY (1u<< 1)
  231. #define RCC_CSR_LSION (1u<< 0)
  232. #define RCC_AHBRSTR_ETHMACRST (1u<<14)
  233. #define RCC_AHBRSTR_OTGFSRST (1u<<12)
  234. #define RCC_BASE 0x40021000
  235. /* Independent Watchdog */
  236. struct iwdg {
  237. uint32_t kr; /* 00: Key */
  238. uint32_t pr; /* 04: Prescaler */
  239. uint32_t rlr; /* 08: Reload */
  240. uint32_t sr; /* 0C: Status */
  241. };
  242. #define IWDG_BASE 0x40003000
  243. /* General-purpose I/O */
  244. struct gpio {
  245. uint32_t crl; /* 00: Port configuration low */
  246. uint32_t crh; /* 04: Port configuration high */
  247. uint32_t idr; /* 08: Port input data */
  248. uint32_t odr; /* 0C: Port output data */
  249. uint32_t bsrr; /* 10: Port bit set/reset */
  250. uint32_t brr; /* 14: Port bit reset */
  251. uint32_t lckr; /* 18: Port configuration lock */
  252. };
  253. #define _GPI_pulled(level) (0x8u|((level)<<4))
  254. #define GPI_analog 0x0u
  255. #define GPI_floating 0x4u
  256. #define GPI_pull_down _GPI_pulled(LOW)
  257. #define GPI_pull_up _GPI_pulled(HIGH)
  258. #define GPO_pushpull(speed,level) (0x0u|(speed)|((level)<<4))
  259. #define GPO_opendrain(speed,level) (0x4u|(speed)|((level)<<4))
  260. #define AFO_pushpull(speed) (0x8u|(speed))
  261. #define AFO_opendrain(speed) (0xcu|(speed))
  262. #define _2MHz 2
  263. #define _10MHz 1
  264. #define _50MHz 3
  265. #define LOW 0
  266. #define HIGH 1
  267. #define GPIOA_BASE 0x40010800
  268. #define GPIOB_BASE 0x40010c00
  269. #define GPIOC_BASE 0x40011000
  270. #define GPIOD_BASE 0x40011400
  271. #define GPIOE_BASE 0x40011800
  272. #define GPIOF_BASE 0x40011c00
  273. #define GPIOG_BASE 0x40012000
  274. /* Alternative-function I/O */
  275. struct afio {
  276. uint32_t evcr; /* 00: Event control */
  277. uint32_t mapr; /* 04: AF remap and debug I/O configuration */
  278. uint32_t exticr1; /* 08: External interrupt configuration #1 */
  279. uint32_t exticr2; /* 0C: External interrupt configuration #2 */
  280. uint32_t exticr3; /* 10: External interrupt configuration #3 */
  281. uint32_t exticr4; /* 14: External interrupt configuration #4 */
  282. uint32_t rsvd; /* 18: - */
  283. uint32_t mapr2; /* 1C: AF remap and debug I/O configuration #2 */
  284. };
  285. #define AFIO_MAPR_SWJ_CFG_DISABLED (4u<<24)
  286. #define AFIO_MAPR_TIM4_REMAP_FULL (1u<<12)
  287. #define AFIO_MAPR_TIM3_REMAP_FULL (3u<<10)
  288. #define AFIO_MAPR_TIM3_REMAP_PARTIAL (2u<<10)
  289. #define AFIO_MAPR_TIM2_REMAP_FULL (3u<< 8)
  290. #define AFIO_MAPR_TIM2_REMAP_PARTIAL_1 (1u<< 8)
  291. #define AFIO_MAPR_TIM2_REMAP_PARTIAL_2 (2u<< 8)
  292. #define AFIO_MAPR_TIM1_REMAP_FULL (3u<< 6)
  293. #define AFIO_MAPR_TIM1_REMAP_PARTIAL (1u<< 6)
  294. #define AFIO_MAPR_USART3_REMAP_FULL (3u<< 4)
  295. #define AFIO_MAPR_USART3_REMAP_PARTIAL (1u<< 4)
  296. #define AFIO_BASE 0x40010000
  297. struct exti {
  298. uint32_t imr; /* 00: Interrupt mask */
  299. uint32_t emr; /* 04: Event mask */
  300. uint32_t rtsr; /* 08: Rising trigger selection */
  301. uint32_t ftsr; /* 0C: Falling trigger selection */
  302. uint32_t swier; /* 10: Software interrupt event */
  303. uint32_t pr; /* 14: Pending */
  304. };
  305. #define EXTI_BASE 0x40010400
  306. /* DMA */
  307. struct dma_chn {
  308. uint32_t ccr; /* +00: Configuration */
  309. uint32_t cndtr; /* +04: Number of data */
  310. uint32_t cpar; /* +08: Peripheral address */
  311. uint32_t cmar; /* +0C: Memory address */
  312. uint32_t rsvd; /* +10: - */
  313. };
  314. struct dma {
  315. uint32_t isr; /* 00: Interrupt status */
  316. uint32_t ifcr; /* 04: Interrupt flag clear */
  317. struct dma_chn ch1; /* 08: Channel 1 */
  318. struct dma_chn ch2; /* 1C: Channel 2 */
  319. struct dma_chn ch3; /* 30: Channel 3 */
  320. struct dma_chn ch4; /* 44: Channel 4 */
  321. struct dma_chn ch5; /* 58: Channel 5 */
  322. struct dma_chn ch6; /* 6C: Channel 6 */
  323. struct dma_chn ch7; /* 80: Channel 7 */
  324. };
  325. /* n=1..7 */
  326. #define DMA_ISR_TEIF(n) (8u<<(((n)-1)*4))
  327. #define DMA_ISR_HTIF(n) (4u<<(((n)-1)*4))
  328. #define DMA_ISR_TCIF(n) (2u<<(((n)-1)*4))
  329. #define DMA_ISR_GIF(n) (1u<<(((n)-1)*4))
  330. /* n=1..7 */
  331. #define DMA_IFCR_CTEIF(n) (8u<<(((n)-1)*4))
  332. #define DMA_IFCR_CHTIF(n) (4u<<(((n)-1)*4))
  333. #define DMA_IFCR_CTCIF(n) (2u<<(((n)-1)*4))
  334. #define DMA_IFCR_CGIF(n) (1u<<(((n)-1)*4))
  335. #define DMA_CCR_MEM2MEM (1u<<14)
  336. #define DMA_CCR_PL_LOW (0u<<12)
  337. #define DMA_CCR_PL_MEDIUM (1u<<12)
  338. #define DMA_CCR_PL_HIGH (2u<<12)
  339. #define DMA_CCR_PL_V_HIGH (3u<<12)
  340. #define DMA_CCR_MSIZE_8BIT (0u<<10)
  341. #define DMA_CCR_MSIZE_16BIT (1u<<10)
  342. #define DMA_CCR_MSIZE_32BIT (2u<<10)
  343. #define DMA_CCR_PSIZE_8BIT (0u<< 8)
  344. #define DMA_CCR_PSIZE_16BIT (1u<< 8)
  345. #define DMA_CCR_PSIZE_32BIT (2u<< 8)
  346. #define DMA_CCR_MINC (1u<< 7)
  347. #define DMA_CCR_PINC (1u<< 6)
  348. #define DMA_CCR_CIRC (1u<< 5)
  349. #define DMA_CCR_DIR_P2M (0u<< 4)
  350. #define DMA_CCR_DIR_M2P (1u<< 4)
  351. #define DMA_CCR_TEIE (1u<< 3)
  352. #define DMA_CCR_HTIE (1u<< 2)
  353. #define DMA_CCR_TCIE (1u<< 1)
  354. #define DMA_CCR_EN (1u<< 0)
  355. #define DMA1_BASE 0x40020000
  356. #define DMA2_BASE 0x40020400
  357. /* Timer */
  358. struct tim {
  359. uint32_t cr1; /* 00: Control 1 */
  360. uint32_t cr2; /* 04: Control 2 */
  361. uint32_t smcr; /* 08: Slave mode control */
  362. uint32_t dier; /* 0C: DMA/interrupt enable */
  363. uint32_t sr; /* 10: Status */
  364. uint32_t egr; /* 14: Event generation */
  365. uint32_t ccmr1; /* 18: Capture/compare mode 1 */
  366. uint32_t ccmr2; /* 1C: Capture/compare mode 2 */
  367. uint32_t ccer; /* 20: Capture/compare enable */
  368. uint32_t cnt; /* 24: Counter */
  369. uint32_t psc; /* 28: Prescaler */
  370. uint32_t arr; /* 2C: Auto-reload */
  371. uint32_t rcr; /* 30: Repetition counter */
  372. uint32_t ccr1; /* 34: Capture/compare 1 */
  373. uint32_t ccr2; /* 38: Capture/compare 2 */
  374. uint32_t ccr3; /* 3C: Capture/compare 3 */
  375. uint32_t ccr4; /* 40: Capture/compare 4 */
  376. uint32_t bdtr; /* 44: Break and dead-time */
  377. uint32_t dcr; /* 48: DMA control */
  378. uint32_t dmar; /* 4C: DMA address for full transfer */
  379. };
  380. #define TIM_CR1_ARPE (1u<<7)
  381. #define TIM_CR1_DIR (1u<<4)
  382. #define TIM_CR1_OPM (1u<<3)
  383. #define TIM_CR1_URS (1u<<2)
  384. #define TIM_CR1_UDIS (1u<<1)
  385. #define TIM_CR1_CEN (1u<<0)
  386. #define TIM_CR2_TI1S (1u<<7)
  387. #define TIM_CR2_MMS(x) ((x)<<4)
  388. #define TIM_CR2_CCDS (1u<<3)
  389. #define TIM_SMCR_ETP (1u<<15)
  390. #define TIM_SMCR_ETC (1u<<14)
  391. #define TIM_SMCR_ETPS(x) ((x)<<12)
  392. #define TIM_SMCR_ETF(x) ((x)<<8)
  393. #define TIM_SMCR_MSM (1u<<7)
  394. #define TIM_SMCR_TS(x) ((x)<<4)
  395. #define TIM_SMCR_SMS(x) ((x)<<0)
  396. #define TIM_DIER_TDE (1u<<14)
  397. #define TIM_DIER_CC4DE (1u<<12)
  398. #define TIM_DIER_CC3DE (1u<<11)
  399. #define TIM_DIER_CC2DE (1u<<10)
  400. #define TIM_DIER_CC1DE (1u<<9)
  401. #define TIM_DIER_UDE (1u<<8)
  402. #define TIM_DIER_TIE (1u<<6)
  403. #define TIM_DIER_CC4IE (1u<<4)
  404. #define TIM_DIER_CC3IE (1u<<3)
  405. #define TIM_DIER_CC2IE (1u<<2)
  406. #define TIM_DIER_CC1IE (1u<<1)
  407. #define TIM_DIER_UIE (1u<<0)
  408. #define TIM_SR_CC4OF (1u<<12)
  409. #define TIM_SR_CC3OF (1u<<11)
  410. #define TIM_SR_CC2OF (1u<<10)
  411. #define TIM_SR_CC1OF (1u<<9)
  412. #define TIM_SR_TIF (1u<<6)
  413. #define TIM_SR_CC4IF (1u<<4)
  414. #define TIM_SR_CC3IF (1u<<3)
  415. #define TIM_SR_CC2IF (1u<<2)
  416. #define TIM_SR_CC1IF (1u<<1)
  417. #define TIM_SR_UIF (1u<<0)
  418. #define TIM_EGR_TG (1u<<6)
  419. #define TIM_EGR_CC4G (1u<<4)
  420. #define TIM_EGR_CC3G (1u<<3)
  421. #define TIM_EGR_CC2G (1u<<2)
  422. #define TIM_EGR_CC1G (1u<<1)
  423. #define TIM_EGR_UG (1u<<0)
  424. #define TIM_CCMR1_OC2CE (1u <<15)
  425. #define TIM_CCMR1_OC2M(x) ((x)<<12)
  426. #define TIM_CCMR1_OC2PE (1u <<11)
  427. #define TIM_CCMR1_OC2FE (1u <<10)
  428. #define TIM_CCMR1_CC2S(x) ((x)<< 8)
  429. #define TIM_CCMR1_OC1CE (1u << 7)
  430. #define TIM_CCMR1_OC1M(x) ((x)<< 4)
  431. #define TIM_CCMR1_OC1PE (1u << 3)
  432. #define TIM_CCMR1_OC1FE (1u << 2)
  433. #define TIM_CCMR1_CC1S(x) ((x)<< 0)
  434. #define TIM_CCMR1_IC2F(x) ((x)<<12)
  435. #define TIM_CCMR1_IC2PSC(x) ((x)<<10)
  436. #define TIM_CCMR1_IC1F(x) ((x)<< 4)
  437. #define TIM_CCMR1_IC1PSC(x) ((x)<< 2)
  438. #define TIM_CCMR2_OC4CE (1u <<15)
  439. #define TIM_CCMR2_OC4M(x) ((x)<<12)
  440. #define TIM_CCMR2_OC4PE (1u <<11)
  441. #define TIM_CCMR2_OC4FE (1u <<10)
  442. #define TIM_CCMR2_CC4S(x) ((x)<< 8)
  443. #define TIM_CCMR2_OC3CE (1u << 7)
  444. #define TIM_CCMR2_OC3M(x) ((x)<< 4)
  445. #define TIM_CCMR2_OC3PE (1u << 3)
  446. #define TIM_CCMR2_OC3FE (1u << 2)
  447. #define TIM_CCMR2_CC3S(x) ((x)<< 0)
  448. #define TIM_CCMR2_IC4F(x) ((x)<<12)
  449. #define TIM_CCMR2_IC4PSC(x) ((x)<<10)
  450. #define TIM_CCMR2_IC3F(x) ((x)<< 4)
  451. #define TIM_CCMR2_IC3PSC(x) ((x)<< 2)
  452. #define TIM_OCM_FROZEN (0u)
  453. #define TIM_OCM_SET_HIGH (1u)
  454. #define TIM_OCM_SET_LOW (2u)
  455. #define TIM_OCM_TOGGLE (3u)
  456. #define TIM_OCM_FORCE_LOW (4u)
  457. #define TIM_OCM_FORCE_HIGH (5u)
  458. #define TIM_OCM_PWM1 (6u)
  459. #define TIM_OCM_PWM2 (7u)
  460. #define TIM_OCM_MASK (7u)
  461. #define TIM_CCS_OUTPUT (0u)
  462. #define TIM_CCS_INPUT_TI1 (1u)
  463. #define TIM_CCS_INPUT_TI2 (2u)
  464. #define TIM_CCS_INPUT_TRC (3u)
  465. #define TIM_CCS_MASK (3u)
  466. #define TIM_CCER_CC4P (1u<<13)
  467. #define TIM_CCER_CC4E (1u<<12)
  468. #define TIM_CCER_CC3P (1u<< 9)
  469. #define TIM_CCER_CC3E (1u<< 8)
  470. #define TIM_CCER_CC2P (1u<< 5)
  471. #define TIM_CCER_CC2E (1u<< 4)
  472. #define TIM_CCER_CC1P (1u<< 1)
  473. #define TIM_CCER_CC1E (1u<< 0)
  474. #define TIM_BDTR_MOE (1u<<15)
  475. #define TIM_BDTR_AOE (1u<<14)
  476. #define TIM_BDTR_BKP (1u<<13)
  477. #define TIM_BDTR_BKE (1u<<12)
  478. #define TIM_BDTR_OSSR (1u<<11)
  479. #define TIM_BDTR_OSSI (1u<<10)
  480. #define TIM_BDTR_LOCK(x) ((x)<<8)
  481. #define TIM_BDTR_DTG(x) ((x)<<0)
  482. #define TIM1_BASE 0x40012c00
  483. #define TIM2_BASE 0x40000000
  484. #define TIM3_BASE 0x40000400
  485. #define TIM4_BASE 0x40000800
  486. #define TIM5_BASE 0x40000c00
  487. #define TIM6_BASE 0x40001000
  488. #define TIM7_BASE 0x40001400
  489. /* SPI/I2S */
  490. struct spi {
  491. uint32_t cr1; /* 00: Control 1 */
  492. uint32_t cr2; /* 04: Control 2 */
  493. uint32_t sr; /* 08: Status */
  494. uint32_t dr; /* 0C: Data */
  495. uint32_t crcpr; /* 10: CRC polynomial */
  496. uint32_t rxcrcr; /* 14: RX CRC */
  497. uint32_t txcrcr; /* 18: TX CRC */
  498. uint32_t i2scfgr; /* 1C: I2S configuration */
  499. uint32_t i2spr; /* 20: I2S prescaler */
  500. };
  501. #define SPI_CR1_BIDIMODE (1u<<15)
  502. #define SPI_CR1_BIDIOE (1u<<14)
  503. #define SPI_CR1_CRCEN (1u<<13)
  504. #define SPI_CR1_CRCNEXT (1u<<12)
  505. #define SPI_CR1_DFF (1u<<11)
  506. #define SPI_CR1_RXONLY (1u<<10)
  507. #define SPI_CR1_SSM (1u<< 9)
  508. #define SPI_CR1_SSI (1u<< 8)
  509. #define SPI_CR1_LSBFIRST (1u<< 7)
  510. #define SPI_CR1_SPE (1u<< 6)
  511. #define SPI_CR1_BR_DIV2 (0u<< 3)
  512. #define SPI_CR1_BR_DIV4 (1u<< 3)
  513. #define SPI_CR1_BR_DIV8 (2u<< 3)
  514. #define SPI_CR1_BR_DIV16 (3u<< 3)
  515. #define SPI_CR1_BR_DIV32 (4u<< 3)
  516. #define SPI_CR1_BR_DIV64 (5u<< 3)
  517. #define SPI_CR1_BR_DIV128 (6u<< 3)
  518. #define SPI_CR1_BR_DIV256 (7u<< 3)
  519. #define SPI_CR1_BR_MASK (7u<< 3)
  520. #define SPI_CR1_MSTR (1u<< 2)
  521. #define SPI_CR1_CPOL (1u<< 1)
  522. #define SPI_CR1_CPHA (1u<< 0)
  523. #define SPI_CR2_TXEIE (1u<< 7)
  524. #define SPI_CR2_RXNEIE (1u<< 6)
  525. #define SPI_CR2_ERRIE (1u<< 5)
  526. #define SPI_CR2_SSOE (1u<< 2)
  527. #define SPI_CR2_TXDMAEN (1u<< 1)
  528. #define SPI_CR2_RXDMAEN (1u<< 0)
  529. #define SPI_SR_BSY (1u<< 7)
  530. #define SPI_SR_OVR (1u<< 6)
  531. #define SPI_SR_MODF (1u<< 5)
  532. #define SPI_SR_CRCERR (1u<< 4)
  533. #define SPI_SR_USR (1u<< 3)
  534. #define SPI_SR_CHSIDE (1u<< 2)
  535. #define SPI_SR_TXE (1u<< 1)
  536. #define SPI_SR_RXNE (1u<< 0)
  537. #define SPI1_BASE 0x40013000
  538. #define SPI2_BASE 0x40003800
  539. #define SPI3_BASE 0x40003C00
  540. /* I2C */
  541. struct i2c {
  542. uint32_t cr1; /* 00: Control 1 */
  543. uint32_t cr2; /* 04: Control 2 */
  544. uint32_t oar1; /* 08: Own address 1 */
  545. uint32_t oar2; /* 0C: Own address 2 */
  546. uint32_t dr; /* 10: Data */
  547. uint32_t sr1; /* 14: Status 1 */
  548. uint32_t sr2; /* 18: Status 2 */
  549. uint32_t ccr; /* 1C: Clock control */
  550. uint32_t trise; /* 20: Rise time */
  551. };
  552. #define I2C_CR1_SWRST (1u<<15)
  553. #define I2C_CR1_ALERT (1u<<13)
  554. #define I2C_CR1_PEC (1u<<12)
  555. #define I2C_CR1_POS (1u<<11)
  556. #define I2C_CR1_ACK (1u<<10)
  557. #define I2C_CR1_STOP (1u<< 9)
  558. #define I2C_CR1_START (1u<< 8)
  559. #define I2C_CR1_NOSTRETCH (1u<< 7)
  560. #define I2C_CR1_ENGC (1u<< 6)
  561. #define I2C_CR1_ENPEC (1u<< 5)
  562. #define I2C_CR1_ENARP (1u<< 4)
  563. #define I2C_CR1_SMBTYPE (1u<< 3)
  564. #define I2C_CR1_SMBUS (1u<< 1)
  565. #define I2C_CR1_PE (1u<< 0)
  566. #define I2C_CR2_LAST (1u<<12)
  567. #define I2C_CR2_DMAEN (1u<<11)
  568. #define I2C_CR2_ITBUFEN (1u<<10)
  569. #define I2C_CR2_ITEVTEN (1u<< 9)
  570. #define I2C_CR2_ITERREN (1u<< 8)
  571. #define I2C_CR2_FREQ(x) (x)
  572. #define I2C_SR1_SMBALERT (1u<<15)
  573. #define I2C_SR1_TIMEOUT (1u<<14)
  574. #define I2C_SR1_PECERR (1u<<12)
  575. #define I2C_SR1_OVR (1u<<11)
  576. #define I2C_SR1_AF (1u<<10)
  577. #define I2C_SR1_ARLO (1u<< 9)
  578. #define I2C_SR1_BERR (1u<< 8)
  579. #define I2C_SR1_ERRORS 0xdf00
  580. #define I2C_SR1_TXE (1u<< 7)
  581. #define I2C_SR1_RXNE (1u<< 6)
  582. #define I2C_SR1_STOPF (1u<< 4)
  583. #define I2C_SR1_ADD10 (1u<< 3)
  584. #define I2C_SR1_BTF (1u<< 2)
  585. #define I2C_SR1_ADDR (1u<< 1)
  586. #define I2C_SR1_SB (1u<< 0)
  587. #define I2C_SR1_EVENTS 0x001f
  588. #define I2C_SR2_PEC(x) ((x)<<15)
  589. #define I2C_SR2_DUALF (1u<< 7)
  590. #define I2C_SR2_SMBHOST (1u<< 6)
  591. #define I2C_SR2_SMBDEFAULT (1u<< 5)
  592. #define I2C_SR2_GENCALL (1u<< 4)
  593. #define I2C_SR2_TRA (1u<< 2)
  594. #define I2C_SR2_BUSY (1u<< 1)
  595. #define I2C_SR2_MSL (1u<< 0)
  596. #define I2C_CCR_FS (1u<<15)
  597. #define I2C_CCR_DUTY (1u<<14)
  598. #define I2C_CCR_CCR(x) (x)
  599. #define I2C1_BASE 0x40005400
  600. #define I2C2_BASE 0x40005800
  601. /* USART */
  602. struct usart {
  603. uint32_t sr; /* 00: Status */
  604. uint32_t dr; /* 04: Data */
  605. uint32_t brr; /* 08: Baud rate */
  606. uint32_t cr1; /* 0C: Control 1 */
  607. uint32_t cr2; /* 10: Control 2 */
  608. uint32_t cr3; /* 14: Control 3 */
  609. uint32_t gtpr; /* 18: Guard time and prescaler */
  610. };
  611. #define USART_SR_CTS (1u<<9)
  612. #define USART_SR_LBD (1u<<8)
  613. #define USART_SR_TXE (1u<<7)
  614. #define USART_SR_TC (1u<<6)
  615. #define USART_SR_RXNE (1u<<5)
  616. #define USART_SR_IDLE (1u<<4)
  617. #define USART_SR_ORE (1u<<3)
  618. #define USART_SR_NE (1u<<2)
  619. #define USART_SR_FE (1u<<1)
  620. #define USART_SR_PE (1u<<0)
  621. #define USART_CR1_UE (1u<<13)
  622. #define USART_CR1_M (1u<<12)
  623. #define USART_CR1_WAKE (1u<<11)
  624. #define USART_CR1_PCE (1u<<10)
  625. #define USART_CR1_PS (1u<< 9)
  626. #define USART_CR1_PEIE (1u<< 8)
  627. #define USART_CR1_TXEIE (1u<< 7)
  628. #define USART_CR1_TCIE (1u<< 6)
  629. #define USART_CR1_RXNEIE (1u<< 5)
  630. #define USART_CR1_IDLEIE (1u<< 4)
  631. #define USART_CR1_TE (1u<< 3)
  632. #define USART_CR1_RE (1u<< 2)
  633. #define USART_CR1_RWU (1u<< 1)
  634. #define USART_CR1_SBK (1u<< 0)
  635. #define USART_CR3_CTSIE (1u<<10)
  636. #define USART_CR3_CTSE (1u<< 9)
  637. #define USART_CR3_RTSE (1u<< 8)
  638. #define USART_CR3_DMAT (1u<< 7)
  639. #define USART_CR3_DMAR (1u<< 6)
  640. #define USART_CR3_SCEN (1u<< 5)
  641. #define USART_CR3_NACK (1u<< 4)
  642. #define USART_CR3_HDSEL (1u<< 3)
  643. #define USART_CR3_IRLP (1u<< 2)
  644. #define USART_CR3_IREN (1u<< 1)
  645. #define USART_CR3_EIE (1u<< 0)
  646. #define USART1_BASE 0x40013800
  647. #define USART2_BASE 0x40004400
  648. #define USART3_BASE 0x40004800
  649. /* USB Full Speed */
  650. struct usb {
  651. uint32_t epr[8]; /* 4*n: Endpoint n */
  652. uint32_t rsvd[8];
  653. uint32_t cntr; /* 40: Control */
  654. uint32_t istr; /* 44: Interrupt status */
  655. uint32_t fnr; /* 48: Frame number */
  656. uint32_t daddr; /* 4C: Device address */
  657. uint32_t btable; /* 50: Buffer table address */
  658. };
  659. struct usb_bufd {
  660. union {
  661. struct {
  662. uint32_t addr_tx; /* 00: Transmission buffer address */
  663. uint32_t count_tx; /* 04: Transmission byte count */
  664. uint32_t addr_rx; /* 08: Reception buffer address */
  665. uint32_t count_rx; /* 0C: Reception byte count */
  666. };
  667. struct {
  668. uint32_t addr_0; /* 00: Double buffer #0 address */
  669. uint32_t count_0; /* 04: Double buffer #0 byte count */
  670. uint32_t addr_1; /* 08: Double buffer #1 address */
  671. uint32_t count_1; /* 0C: Double buffer #1 byte count */
  672. };
  673. };
  674. };
  675. #define USB_EPR_CTR_RX (1u<<15)
  676. #define USB_EPR_DTOG_RX (1u<<14)
  677. #define USB_EPR_STAT_RX(x) ((x)<<12)
  678. #define USB_EPR_SETUP (1u<<11)
  679. #define USB_EPR_EP_TYPE(x) ((x)<<9)
  680. #define USB_EPR_EP_KIND_DBL_BUF (1<<8) /* USB_EP_TYPE_BULK */
  681. #define USB_EPR_EP_KIND_STATUS_OUT (1<<8) /* USB_EP_TYPE_CONTROL */
  682. #define USB_EPR_CTR_TX (1u<< 7)
  683. #define USB_EPR_DTOG_TX (1u<< 6)
  684. #define USB_EPR_STAT_TX(x) ((x)<<4)
  685. #define USB_EPR_EA(x) ((x)<<0)
  686. #define USB_STAT_DISABLED (0u)
  687. #define USB_STAT_STALL (1u)
  688. #define USB_STAT_NAK (2u)
  689. #define USB_STAT_VALID (3u)
  690. #define USB_STAT_MASK (3u)
  691. #define USB_EP_TYPE_BULK (0u)
  692. #define USB_EP_TYPE_CONTROL (1u)
  693. #define USB_EP_TYPE_ISO (2u)
  694. #define USB_EP_TYPE_INTERRUPT (3u)
  695. #define USB_EP_TYPE_MASK (3u)
  696. #define USB_CNTR_CTRM (1u<<15)
  697. #define USB_CNTR_PMAOVRM (1u<<14)
  698. #define USB_CNTR_ERRM (1u<<13)
  699. #define USB_CNTR_WKUPM (1u<<12)
  700. #define USB_CNTR_SUSPM (1u<<11)
  701. #define USB_CNTR_RESETM (1u<<10)
  702. #define USB_CNTR_SOFM (1u<< 9)
  703. #define USB_CNTR_ESOFM (1u<< 8)
  704. #define USB_CNTR_RESUME (1u<< 4)
  705. #define USB_CNTR_FSUSP (1u<< 3)
  706. #define USB_CNTR_LP_MODE (1u<< 2)
  707. #define USB_CNTR_PDWN (1u<< 1)
  708. #define USB_CNTR_FRES (1u<< 0)
  709. #define USB_ISTR_CTR (1u<<15)
  710. #define USB_ISTR_PMAOVR (1u<<14)
  711. #define USB_ISTR_ERR (1u<<13)
  712. #define USB_ISTR_WKUP (1u<<12)
  713. #define USB_ISTR_SUSP (1u<<11)
  714. #define USB_ISTR_RESET (1u<<10)
  715. #define USB_ISTR_SOF (1u<< 9)
  716. #define USB_ISTR_ESOF (1u<< 8)
  717. #define USB_ISTR_DIR (1u<< 4)
  718. #define USB_ISTR_GET_EP_ID(x) ((x)&0xf)
  719. #define USB_FNR_RXDP (1u<<15)
  720. #define USB_FNR_RXDM (1u<<14)
  721. #define USB_FNR_LCK (1u<<13)
  722. #define USB_FNR_GET_LSOF(x) (((x)>>11)&3)
  723. #define USB_FNR_GET_FN(x) ((x)&0x7ff)
  724. #define USB_DADDR_EF (1u<< 7)
  725. #define USB_DADDR_ADD(x) ((x)<<0)
  726. #define USB_BASE 0x40005c00
  727. #define USB_BUF_BASE 0x40006000
  728. /* USB On-The-Go Full Speed interface */
  729. struct usb_otg {
  730. uint32_t gotctl; /* 00: Control and status */
  731. uint32_t gotgint; /* 04: Interrupt */
  732. uint32_t gahbcfg; /* 08: AHB configuration */
  733. uint32_t gusbcfg; /* 0C: USB configuration */
  734. uint32_t grstctl; /* 10: Reset */
  735. uint32_t gintsts; /* 14: Core interrupt */
  736. uint32_t gintmsk; /* 18: Interrupt mask */
  737. uint32_t grxstsr; /* 1C: Receive status debug read */
  738. uint32_t grxstsp; /* 20: Receive status debug pop */
  739. uint32_t grxfsiz; /* 24: Receive FIFO size */
  740. union {
  741. uint32_t hnptxfsiz; /* 28: Host non-periodic transmit FIFO size */
  742. uint32_t dieptxf0; /* 28: Endpoint 0 transmit FIFO size */
  743. };
  744. uint32_t hnptxsts; /* 2C: Non-periodic transmit FIFO/queue status */
  745. uint32_t _0[2];
  746. uint32_t gccfg; /* 38: General core configuration */
  747. uint32_t cid; /* 3C: Core ID */
  748. uint32_t _1[48];
  749. uint32_t hptxfsiz; /* 100: Host periodic transmit FIFO size */
  750. uint32_t dieptxf1; /* 104: Device IN endpoint transmit FIFO #1 size */
  751. uint32_t dieptxf2; /* 108: Device IN endpoint transmit FIFO #2 size */
  752. uint32_t dieptxf3; /* 10C: Device IN endpoint transmit FIFO #3 size */
  753. uint32_t _2[188];
  754. uint32_t hcfg; /* 400: Host configuration */
  755. uint32_t hfir; /* 404: Host frame interval */
  756. uint32_t hfnum; /* 408: Host frame number / frame time remaining */
  757. uint32_t _3[1]; /* 40C: */
  758. uint32_t hptxsts; /* 410: Host periodic transmit FIFO / queue status */
  759. uint32_t haint; /* 414: Host all channels interrupt status */
  760. uint32_t haintmsk; /* 418: Host all channels interrupt mask */
  761. uint32_t _4[9];
  762. uint32_t hprt; /* 440: Host port control and status */
  763. uint32_t _5[47];
  764. struct {
  765. uint32_t charac; /* +00: Host channel-x characteristics */
  766. uint32_t _0[1];
  767. uint32_t intsts; /* +08: Host channel-x interrupt status */
  768. uint32_t intmsk; /* +0C: Host channel-x interrupt mask */
  769. uint32_t tsiz; /* +10: Host channel x transfer size */
  770. uint32_t _1[3];
  771. } hc[8]; /* 500..5E0: */
  772. uint32_t _6[128];
  773. uint32_t dcfg; /* 800: Device configuration */
  774. uint32_t dctl; /* 804: Device control */
  775. uint32_t dsts; /* 808: Device status */
  776. uint32_t _7[1];
  777. uint32_t diepmsk; /* 810: Device IN endpoint common interrupt mask */
  778. uint32_t doepmsk; /* 814: Device OUT endpoint common interrupt mask */
  779. uint32_t daint; /* 818: Device all endpoints interrupt status */
  780. uint32_t daintmsk; /* 81C: Device all endpoints interrupt mask */
  781. uint32_t _8[2];
  782. uint32_t dvbusdis; /* 828: Device VBUS discharge time */
  783. uint32_t dvbuspulse; /* 82C: Device VBUS pulsing time */
  784. uint32_t _9[1];
  785. uint32_t diepempmsk; /* 834: Device IN endpoint FIFO empty int. mask */
  786. uint32_t _10[50];
  787. struct {
  788. uint32_t ctl; /* +00: Device IN endpoint-x control */
  789. uint32_t _0[1];
  790. uint32_t intsts; /* +08: Device IN endpoint-x interrupt status */
  791. uint32_t _1[3];
  792. uint32_t txfsts; /* +18: Device IN endpoint-x transmit FIFO status */
  793. uint32_t _2[1];
  794. } diep[4]; /* 900..960: */
  795. uint32_t _11[96];
  796. struct {
  797. uint32_t ctl; /* +00: Device OUT endpoint-x control */
  798. uint32_t _0[1];
  799. uint32_t intsts; /* +08: Device OUT endpoint-x interrupt status */
  800. uint32_t _1[1];
  801. uint32_t tsiz; /* +10: Device OUT endpoint-x transmit FIFO status */
  802. uint32_t _2[3];
  803. } doep[4]; /* B00..B60: */
  804. uint32_t _12[160];
  805. uint32_t pcgcctl; /* E00: Power and clock gating control */
  806. };
  807. #define OTG_GAHBCFG_PTXFELVL (1u<< 8)
  808. #define OTG_GAHBCFG_TXFELVL (1u<< 7)
  809. #define OTG_GAHBCFG_GINTMSK (1u<< 0)
  810. #define OTG_GUSBCFG_CTXPKT (1u<<31)
  811. #define OTG_GUSBCFG_FDMOD (1u<<30)
  812. #define OTG_GUSBCFG_FHMOD (1u<<29)
  813. #define OTG_GUSBCFG_TRDT(x) ((x)<<10)
  814. #define OTG_GUSBCFG_HNPCAP (1u<< 9)
  815. #define OTG_GUSBCFG_SRPCAP (1u<< 8)
  816. #define OTG_GUSBCFG_PHYSEL (1u<< 6)
  817. #define OTG_GUSBCFG_TOCAL(x) ((x)<< 0)
  818. /* GINTSTS and GINTMSK */
  819. #define OTG_GINT_WKUPINT (1u<<31) /* Host + Device */
  820. #define OTG_GINT_SRQINT (1u<<30) /* H + D */
  821. #define OTG_GINT_DISCINT (1u<<29) /* H */
  822. #define OTG_GINT_CIDSCHG (1u<<28) /* H + D */
  823. #define OTG_GINT_PTXFE (1u<<26) /* H */
  824. #define OTG_GINT_HCINT (1u<<25) /* H */
  825. #define OTG_GINT_HPRTINT (1u<<24) /* H */
  826. #define OTG_GINT_IPXFR (1u<<21) /* H */
  827. #define OTG_GINT_IISOIXFR (1u<<20) /* D */
  828. #define OTG_GINT_OEPINT (1u<<19) /* D */
  829. #define OTG_GINT_IEPINT (1u<<18) /* D */
  830. #define OTG_GINT_EOPF (1u<<15) /* D */
  831. #define OTG_GINT_ISOODRP (1u<<14) /* D */
  832. #define OTG_GINT_ENUMDNE (1u<<13) /* D */
  833. #define OTG_GINT_USBRST (1u<<12) /* D */
  834. #define OTG_GINT_USBSUSP (1u<<11) /* D */
  835. #define OTG_GINT_ESUSP (1u<<10) /* D */
  836. #define OTG_GINT_GONAKEFF (1u<< 7) /* D */
  837. #define OTG_GINT_GINAKEFF (1u<< 6) /* D */
  838. #define OTG_GINT_NPTXFE (1u<< 5) /* H */
  839. #define OTG_GINT_RXFLVL (1u<< 4) /* H + D */
  840. #define OTG_GINT_SOF (1u<< 3) /* H + D */
  841. #define OTG_GINT_OTGINT (1u<< 2) /* H + D */
  842. #define OTG_GINT_MMIS (1u<< 1) /* H + D */
  843. #define OTG_GINT_CMOD (1u<< 0) /* H + D */
  844. #define OTG_RXSTS_PKTSTS_IN (2u)
  845. #define OTG_RXSTS_PKTSTS(r) (((r)>>17)&0xf)
  846. #define OTG_RXSTS_BCNT(r) (((r)>>4)&0x7ff)
  847. #define OTG_RXSTS_CHNUM(r) ((r)&0xf)
  848. #define OTG_GCCFG_SOFOUTEN (1u<<20)
  849. #define OTG_GCCFG_VBUSBSEN (1u<<19)
  850. #define OTG_GCCFG_VBUSASEN (1u<<18)
  851. #define OTG_GCCFG_PWRDWN (1u<<16)
  852. #define OTG_HCFG_FSLSS (1u<<2)
  853. #define OTG_HCFG_FSLSPCS (3u<<0)
  854. #define OTG_HCFG_FSLSPCS_48 (1u<<0)
  855. #define OTG_HCFG_FSLSPCS_6 (2u<<0)
  856. #define OTG_HPRT_PSPD_FULL (1u<<17)
  857. #define OTG_HPRT_PSPD_LOW (2u<<17)
  858. #define OTG_HPRT_PSPD_MASK (1u<<17) /* read-only */
  859. #define OTG_HPRT_PPWR (1u<<12)
  860. #define OTG_HPRT_PRST (1u<< 8)
  861. #define OTG_HPRT_PSUSP (1u<< 7)
  862. #define OTG_HPRT_PRES (1u<< 6)
  863. #define OTG_HPRT_POCCHNG (1u<< 5) /* raises HPRTINT */
  864. #define OTG_HPRT_POCA (1u<< 4)
  865. #define OTG_HPRT_PENCHNG (1u<< 3) /* raises HPRTINT */
  866. #define OTG_HPRT_PENA (1u<< 2)
  867. #define OTG_HPRT_PCDET (1u<< 1) /* raises HPRTINT */
  868. #define OTG_HPRT_PCSTS (1u<< 0)
  869. #define OTG_HPRT_INTS (OTG_HPRT_POCCHNG|OTG_HPRT_PENCHNG|OTG_HPRT_PCDET| \
  870. OTG_HPRT_PENA) /* PENA is also set-to-clear */
  871. /* HCINTSTS and HCINTMSK */
  872. #define OTG_HCINT_DTERR (1u<<10)
  873. #define OTG_HCINT_FRMOR (1u<< 9)
  874. #define OTG_HCINT_BBERR (1u<< 8)
  875. #define OTG_HCINT_TXERR (1u<< 7)
  876. #define OTG_HCINT_NYET (1u<< 6) /* high-speed only; not STM32F10x */
  877. #define OTG_HCINT_ACK (1u<< 5)
  878. #define OTG_HCINT_NAK (1u<< 4)
  879. #define OTG_HCINT_STALL (1u<< 3)
  880. #define OTG_HCINT_CHH (1u<< 1)
  881. #define OTG_HCINT_XFRC (1u<< 0)
  882. #define OTG_HCCHAR_CHENA (1u<<31)
  883. #define OTG_HCCHAR_CHDIS (1u<<30)
  884. #define OTG_HCCHAR_ODDFRM (1u<<29)
  885. #define OTG_HCCHAR_DAD(x) ((x)<<22)
  886. #define OTG_HCCHAR_MCNT(x) ((x)<<20)
  887. #define OTG_HCCHAR_ETYP_CTRL (0u<<18)
  888. #define OTG_HCCHAR_ETYP_ISO (1u<<18)
  889. #define OTG_HCCHAR_ETYP_BULK (2u<<18)
  890. #define OTG_HCCHAR_ETYP_INT (3u<<18)
  891. #define OTG_HCCHAR_LSDEV (1u<<17)
  892. #define OTG_HCCHAR_EPDIR_OUT (0u<<15)
  893. #define OTG_HCCHAR_EPDIR_IN (1u<<15)
  894. #define OTG_HCCHAR_EPNUM(x) ((x)<<11)
  895. #define OTG_HCCHAR_MPSIZ(x) ((x)<< 0)
  896. #define OTG_HCTSIZ_DPID_DATA0 (0u<<29)
  897. #define OTG_HCTSIZ_DPID_DATA2 (1u<<29)
  898. #define OTG_HCTSIZ_DPID_DATA1 (2u<<29)
  899. #define OTG_HCTSIZ_DPID_MDATA (3u<<29)
  900. #define OTG_HCTSIZ_DPID_SETUP (3u<<29)
  901. #define OTG_HCTSIZ_PKTCNT(x) ((x)<<19)
  902. #define OTG_HCTSIZ_XFRSIZ(x) ((x)<< 0)
  903. #define USB_OTG_BASE 0x50000000
  904. /*
  905. * Local variables:
  906. * mode: C
  907. * c-file-style: "Linux"
  908. * c-basic-offset: 4
  909. * tab-width: 4
  910. * indent-tabs-mode: nil
  911. * End:
  912. */