stm32f10x_regs.h 35 KB

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