123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017 |
- struct stk {
- uint32_t ctrl;
- uint32_t load;
- uint32_t val;
- uint32_t calib;
- };
- #define STK_CTRL_COUNTFLAG (1u<<16)
- #define STK_CTRL_CLKSOURCE (1u<< 2)
- #define STK_CTRL_TICKINT (1u<< 1)
- #define STK_CTRL_ENABLE (1u<< 0)
- #define STK_MASK ((1u<<24)-1)
- #define STK_BASE 0xe000e010
- struct scb {
- uint32_t cpuid;
- uint32_t icsr;
- uint32_t vtor;
- uint32_t aircr;
- uint32_t scr;
- uint32_t ccr;
- uint32_t shpr1;
- uint32_t shpr2;
- uint32_t shpr3;
- uint32_t shcsr;
- uint32_t cfsr;
- uint32_t hfsr;
- uint32_t _unused;
- uint32_t mmar;
- uint32_t bfar;
- };
- #define SCB_CCR_STKALIGN (1u<<9)
- #define SCB_CCR_BFHFNMIGN (1u<<8)
- #define SCB_CCR_DIV_0_TRP (1u<<4)
- #define SCB_CCR_UNALIGN_TRP (1u<<3)
- #define SCB_CCR_USERSETMPEND (1u<<1)
- #define SCB_CCR_NONBASETHRDENA (1u<<0)
- #define SCB_SHCSR_USGFAULTENA (1u<<18)
- #define SCB_SHCSR_BUSFAULTENA (1u<<17)
- #define SCB_SHCSR_MEMFAULTENA (1u<<16)
- #define SCB_SHCSR_SVCALLPENDED (1u<<15)
- #define SCB_SHCSR_BUSFAULTPENDED (1u<<14)
- #define SCB_SHCSR_MEMFAULTPENDED (1u<<13)
- #define SCB_SHCSR_USGFAULTPENDED (1u<<12)
- #define SCB_SHCSR_SYSTICKACT (1u<<11)
- #define SCB_SHCSR_PENDSVACT (1u<<10)
- #define SCB_SHCSR_MONITORACT (1u<< 8)
- #define SCB_SHCSR_SVCALLACT (1u<< 7)
- #define SCB_SHCSR_USGFAULTACT (1u<< 3)
- #define SCB_SHCSR_BUSFAULTACT (1u<< 1)
- #define SCB_SHCSR_MEMFAULTACT (1u<< 0)
- #define SCB_CFSR_DIVBYZERO (1u<<25)
- #define SCB_CFSR_UNALIGNED (1u<<24)
- #define SCB_CFSR_NOCP (1u<<19)
- #define SCB_CFSR_INVPC (1u<<18)
- #define SCB_CFSR_INVSTATE (1u<<17)
- #define SCB_CFSR_UNDEFINSTR (1u<<16)
- #define SCB_CFSR_BFARVALID (1u<<15)
- #define SCB_CFSR_STKERR (1u<<12)
- #define SCB_CFSR_UNSTKERR (1u<<11)
- #define SCB_CFSR_IMPRECISERR (1u<<10)
- #define SCB_CFSR_PRECISERR (1u<< 9)
- #define SCB_CFSR_IBUSERR (1u<< 8)
- #define SCB_CFSR_MMARVALID (1u<< 7)
- #define SCB_CFSR_MSTKERR (1u<< 4)
- #define SCB_CFSR_MUNSTKERR (1u<< 3)
- #define SCB_CFSR_DACCVIOL (1u<< 1)
- #define SCB_CFSR_IACCVIOL (1u<< 0)
- #define SCB_AIRCR_VECTKEY (0x05fau<<16)
- #define SCB_AIRCR_SYSRESETREQ (1u<<2)
- #define SCB_BASE 0xe000ed00
- struct nvic {
- uint32_t iser[32];
- uint32_t icer[32];
- uint32_t ispr[32];
- uint32_t icpr[32];
- uint32_t iabr[64];
- uint8_t ipr[80];
- };
- #define NVIC_BASE 0xe000e100
- struct flash {
- uint32_t acr;
- uint32_t keyr;
- uint32_t optkeyr;
- uint32_t sr;
- uint32_t cr;
- uint32_t ar;
- uint32_t rsvd;
- uint32_t obr;
- uint32_t wrpr;
- };
- #define FLASH_ACR_PRFTBS (1u<< 5)
- #define FLASH_ACR_PRFTBE (1u<< 4)
- #define FLASH_ACR_HLFCYA (1u<< 3)
- #define FLASH_ACR_LATENCY(w) ((w)<<0)
- #define FLASH_SR_EOP (1u<< 5)
- #define FLASH_SR_WRPRTERR (1u<< 4)
- #define FLASH_SR_PGERR (1u<< 2)
- #define FLASH_SR_BSY (1u<< 0)
- #define FLASH_CR_EOPIE (1u<<12)
- #define FLASH_CR_ERRIE (1u<<10)
- #define FLASH_CR_OPTWRE (1u<< 9)
- #define FLASH_CR_LOCK (1u<< 7)
- #define FLASH_CR_STRT (1u<< 6)
- #define FLASH_CR_OPTER (1u<< 5)
- #define FLASH_CR_OPTPG (1u<< 4)
- #define FLASH_CR_MER (1u<< 2)
- #define FLASH_CR_PER (1u<< 1)
- #define FLASH_CR_PG (1u<< 0)
- #define FLASH_BASE 0x40022000
- struct pwr {
- uint32_t cr;
- uint32_t csr;
- };
- #define PWR_CR_DBP (1u<< 8)
- #define PWR_BASE 0x40007000
- struct bkp {
- uint32_t _0[1];
- uint32_t dr1[10];
- uint32_t rtccr;
- uint32_t cr;
- uint32_t csr;
- uint32_t _1[2];
- uint32_t dr2[32];
- };
- #define BKP_BASE 0x40006c00
- struct rcc {
- uint32_t cr;
- uint32_t cfgr;
- uint32_t cir;
- uint32_t apb2rstr;
- uint32_t apb1rstr;
- uint32_t ahbenr;
- uint32_t apb2enr;
- uint32_t apb1enr;
- uint32_t bdcr;
- uint32_t csr;
- uint32_t ahbrstr;
- uint32_t cfgr2;
- };
- #define RCC_CR_PLL3RDY (1u<<29)
- #define RCC_CR_PLL3ON (1u<<28)
- #define RCC_CR_PLL2RDY (1u<<27)
- #define RCC_CR_PLL2ON (1u<<26)
- #define RCC_CR_PLLRDY (1u<<25)
- #define RCC_CR_PLLON (1u<<24)
- #define RCC_CR_CSSON (1u<<19)
- #define RCC_CR_HSEBYP (1u<<18)
- #define RCC_CR_HSERDY (1u<<17)
- #define RCC_CR_HSEON (1u<<16)
- #define RCC_CR_HSIRDY (1u<<1)
- #define RCC_CR_HSION (1u<<0)
- #define RCC_CFGR_PLLMUL(x) (((x)-2)<<18)
- #define RCC_CFGR_PLLXTPRE (1u<<17)
- #define RCC_CFGR_PLLSRC_HSI (0u<<16)
- #define RCC_CFGR_PLLSRC_PREDIV1 (1u<<16)
- #define RCC_CFGR_ADCPRE_DIV8 (3u<<14)
- #define RCC_CFGR_PPRE1_DIV2 (4u<<8)
- #define RCC_CFGR_SWS_HSI (0u<<2)
- #define RCC_CFGR_SWS_HSE (1u<<2)
- #define RCC_CFGR_SWS_PLL (2u<<2)
- #define RCC_CFGR_SWS_MASK (3u<<2)
- #define RCC_CFGR_SW_HSI (0u<<0)
- #define RCC_CFGR_SW_HSE (1u<<0)
- #define RCC_CFGR_SW_PLL (2u<<0)
- #define RCC_CFGR_SW_MASK (3u<<0)
- #define RCC_AHBENR_ETHMACRXEN (1u<<16)
- #define RCC_AHBENR_ETHMACTXEN (1u<<15)
- #define RCC_AHBENR_ETHMACEN (1u<<14)
- #define RCC_AHBENR_OTGFSEN (1u<<12)
- #define RCC_AHBENR_CRCEN (1u<< 6)
- #define RCC_AHBENR_FLITFEN (1u<< 4)
- #define RCC_AHBENR_SRAMEN (1u<< 2)
- #define RCC_AHBENR_DMA2EN (1u<< 1)
- #define RCC_AHBENR_DMA1EN (1u<< 0)
- #define RCC_APB1ENR_DACEN (1u<<29)
- #define RCC_APB1ENR_PWREN (1u<<28)
- #define RCC_APB1ENR_BKPEN (1u<<27)
- #define RCC_APB1ENR_CAN2EN (1u<<26)
- #define RCC_APB1ENR_CAN1EN (1u<<25)
- #define RCC_APB1ENR_USBEN (1u<<23)
- #define RCC_APB1ENR_I2C2EN (1u<<22)
- #define RCC_APB1ENR_I2C1EN (1u<<21)
- #define RCC_APB1ENR_USART5EN (1u<<20)
- #define RCC_APB1ENR_USART4EN (1u<<19)
- #define RCC_APB1ENR_USART3EN (1u<<18)
- #define RCC_APB1ENR_USART2EN (1u<<17)
- #define RCC_APB1ENR_SPI3EN (1u<<15)
- #define RCC_APB1ENR_SPI2EN (1u<<14)
- #define RCC_APB1ENR_WWDGEN (1u<<11)
- #define RCC_APB1ENR_TIM7EN (1u<< 5)
- #define RCC_APB1ENR_TIM6EN (1u<< 4)
- #define RCC_APB1ENR_TIM5EN (1u<< 3)
- #define RCC_APB1ENR_TIM4EN (1u<< 2)
- #define RCC_APB1ENR_TIM3EN (1u<< 1)
- #define RCC_APB1ENR_TIM2EN (1u<< 0)
- #define RCC_APB2ENR_USART1EN (1u<<14)
- #define RCC_APB2ENR_SPI1EN (1u<<12)
- #define RCC_APB2ENR_TIM1EN (1u<<11)
- #define RCC_APB2ENR_ADC2EN (1u<<10)
- #define RCC_APB2ENR_ADC1EN (1u<< 9)
- #define RCC_APB2ENR_IOPEEN (1u<< 6)
- #define RCC_APB2ENR_IOPDEN (1u<< 5)
- #define RCC_APB2ENR_IOPCEN (1u<< 4)
- #define RCC_APB2ENR_IOPBEN (1u<< 3)
- #define RCC_APB2ENR_IOPAEN (1u<< 2)
- #define RCC_APB2ENR_AFIOEN (1u<< 0)
- #define RCC_CSR_LPWRRSTF (1u<<31)
- #define RCC_CSR_WWDGRSTF (1u<<30)
- #define RCC_CSR_IWDGRSTF (1u<<29)
- #define RCC_CSR_SFTRSTF (1u<<28)
- #define RCC_CSR_PORRSTF (1u<<27)
- #define RCC_CSR_PINRSTF (1u<<26)
- #define RCC_CSR_RMVF (1u<<24)
- #define RCC_CSR_LSIRDY (1u<< 1)
- #define RCC_CSR_LSION (1u<< 0)
- #define RCC_AHBRSTR_ETHMACRST (1u<<14)
- #define RCC_AHBRSTR_OTGFSRST (1u<<12)
- #define RCC_BASE 0x40021000
- struct iwdg {
- uint32_t kr;
- uint32_t pr;
- uint32_t rlr;
- uint32_t sr;
- };
- #define IWDG_BASE 0x40003000
- struct gpio {
- uint32_t crl;
- uint32_t crh;
- uint32_t idr;
- uint32_t odr;
- uint32_t bsrr;
- uint32_t brr;
- uint32_t lckr;
- };
- #define _GPI_pulled(level) (0x8u|((level)<<4))
- #define GPI_analog 0x0u
- #define GPI_floating 0x4u
- #define GPI_pull_down _GPI_pulled(LOW)
- #define GPI_pull_up _GPI_pulled(HIGH)
- #define GPO_pushpull(speed,level) (0x0u|(speed)|((level)<<4))
- #define GPO_opendrain(speed,level) (0x4u|(speed)|((level)<<4))
- #define AFO_pushpull(speed) (0x8u|(speed))
- #define AFO_opendrain(speed) (0xcu|(speed))
- #define _2MHz 2
- #define _10MHz 1
- #define _50MHz 3
- #define LOW 0
- #define HIGH 1
- #define GPIOA_BASE 0x40010800
- #define GPIOB_BASE 0x40010c00
- #define GPIOC_BASE 0x40011000
- #define GPIOD_BASE 0x40011400
- #define GPIOE_BASE 0x40011800
- #define GPIOF_BASE 0x40011c00
- #define GPIOG_BASE 0x40012000
- struct afio {
- uint32_t evcr;
- uint32_t mapr;
- uint32_t exticr1;
- uint32_t exticr2;
- uint32_t exticr3;
- uint32_t exticr4;
- uint32_t rsvd;
- uint32_t mapr2;
- };
- #define AFIO_MAPR_SWJ_CFG_DISABLED (4u<<24)
- #define AFIO_MAPR_TIM4_REMAP_FULL (1u<<12)
- #define AFIO_MAPR_TIM3_REMAP_FULL (3u<<10)
- #define AFIO_MAPR_TIM3_REMAP_PARTIAL (2u<<10)
- #define AFIO_MAPR_TIM2_REMAP_FULL (3u<< 8)
- #define AFIO_MAPR_TIM2_REMAP_PARTIAL_1 (1u<< 8)
- #define AFIO_MAPR_TIM2_REMAP_PARTIAL_2 (2u<< 8)
- #define AFIO_MAPR_TIM1_REMAP_FULL (3u<< 6)
- #define AFIO_MAPR_TIM1_REMAP_PARTIAL (1u<< 6)
- #define AFIO_MAPR_USART3_REMAP_FULL (3u<< 4)
- #define AFIO_MAPR_USART3_REMAP_PARTIAL (1u<< 4)
- #define AFIO_BASE 0x40010000
- struct exti {
- uint32_t imr;
- uint32_t emr;
- uint32_t rtsr;
- uint32_t ftsr;
- uint32_t swier;
- uint32_t pr;
- };
- #define EXTI_BASE 0x40010400
- struct dma_chn {
- uint32_t ccr;
- uint32_t cndtr;
- uint32_t cpar;
- uint32_t cmar;
- uint32_t rsvd;
- };
- struct dma {
- uint32_t isr;
- uint32_t ifcr;
- struct dma_chn ch1;
- struct dma_chn ch2;
- struct dma_chn ch3;
- struct dma_chn ch4;
- struct dma_chn ch5;
- struct dma_chn ch6;
- struct dma_chn ch7;
- };
- #define DMA_ISR_TEIF(n) (8u<<(((n)-1)*4))
- #define DMA_ISR_HTIF(n) (4u<<(((n)-1)*4))
- #define DMA_ISR_TCIF(n) (2u<<(((n)-1)*4))
- #define DMA_ISR_GIF(n) (1u<<(((n)-1)*4))
- #define DMA_IFCR_CTEIF(n) (8u<<(((n)-1)*4))
- #define DMA_IFCR_CHTIF(n) (4u<<(((n)-1)*4))
- #define DMA_IFCR_CTCIF(n) (2u<<(((n)-1)*4))
- #define DMA_IFCR_CGIF(n) (1u<<(((n)-1)*4))
- #define DMA_CCR_MEM2MEM (1u<<14)
- #define DMA_CCR_PL_LOW (0u<<12)
- #define DMA_CCR_PL_MEDIUM (1u<<12)
- #define DMA_CCR_PL_HIGH (2u<<12)
- #define DMA_CCR_PL_V_HIGH (3u<<12)
- #define DMA_CCR_MSIZE_8BIT (0u<<10)
- #define DMA_CCR_MSIZE_16BIT (1u<<10)
- #define DMA_CCR_MSIZE_32BIT (2u<<10)
- #define DMA_CCR_PSIZE_8BIT (0u<< 8)
- #define DMA_CCR_PSIZE_16BIT (1u<< 8)
- #define DMA_CCR_PSIZE_32BIT (2u<< 8)
- #define DMA_CCR_MINC (1u<< 7)
- #define DMA_CCR_PINC (1u<< 6)
- #define DMA_CCR_CIRC (1u<< 5)
- #define DMA_CCR_DIR_P2M (0u<< 4)
- #define DMA_CCR_DIR_M2P (1u<< 4)
- #define DMA_CCR_TEIE (1u<< 3)
- #define DMA_CCR_HTIE (1u<< 2)
- #define DMA_CCR_TCIE (1u<< 1)
- #define DMA_CCR_EN (1u<< 0)
- #define DMA1_BASE 0x40020000
- #define DMA2_BASE 0x40020400
- struct tim {
- uint32_t cr1;
- uint32_t cr2;
- uint32_t smcr;
- uint32_t dier;
- uint32_t sr;
- uint32_t egr;
- uint32_t ccmr1;
- uint32_t ccmr2;
- uint32_t ccer;
- uint32_t cnt;
- uint32_t psc;
- uint32_t arr;
- uint32_t rcr;
- uint32_t ccr1;
- uint32_t ccr2;
- uint32_t ccr3;
- uint32_t ccr4;
- uint32_t bdtr;
- uint32_t dcr;
- uint32_t dmar;
- };
- #define TIM_CR1_ARPE (1u<<7)
- #define TIM_CR1_DIR (1u<<4)
- #define TIM_CR1_OPM (1u<<3)
- #define TIM_CR1_URS (1u<<2)
- #define TIM_CR1_UDIS (1u<<1)
- #define TIM_CR1_CEN (1u<<0)
- #define TIM_CR2_TI1S (1u<<7)
- #define TIM_CR2_MMS(x) ((x)<<4)
- #define TIM_CR2_CCDS (1u<<3)
- #define TIM_SMCR_ETP (1u<<15)
- #define TIM_SMCR_ETC (1u<<14)
- #define TIM_SMCR_ETPS(x) ((x)<<12)
- #define TIM_SMCR_ETF(x) ((x)<<8)
- #define TIM_SMCR_MSM (1u<<7)
- #define TIM_SMCR_TS(x) ((x)<<4)
- #define TIM_SMCR_SMS(x) ((x)<<0)
- #define TIM_DIER_TDE (1u<<14)
- #define TIM_DIER_CC4DE (1u<<12)
- #define TIM_DIER_CC3DE (1u<<11)
- #define TIM_DIER_CC2DE (1u<<10)
- #define TIM_DIER_CC1DE (1u<<9)
- #define TIM_DIER_UDE (1u<<8)
- #define TIM_DIER_TIE (1u<<6)
- #define TIM_DIER_CC4IE (1u<<4)
- #define TIM_DIER_CC3IE (1u<<3)
- #define TIM_DIER_CC2IE (1u<<2)
- #define TIM_DIER_CC1IE (1u<<1)
- #define TIM_DIER_UIE (1u<<0)
- #define TIM_SR_CC4OF (1u<<12)
- #define TIM_SR_CC3OF (1u<<11)
- #define TIM_SR_CC2OF (1u<<10)
- #define TIM_SR_CC1OF (1u<<9)
- #define TIM_SR_TIF (1u<<6)
- #define TIM_SR_CC4IF (1u<<4)
- #define TIM_SR_CC3IF (1u<<3)
- #define TIM_SR_CC2IF (1u<<2)
- #define TIM_SR_CC1IF (1u<<1)
- #define TIM_SR_UIF (1u<<0)
- #define TIM_EGR_TG (1u<<6)
- #define TIM_EGR_CC4G (1u<<4)
- #define TIM_EGR_CC3G (1u<<3)
- #define TIM_EGR_CC2G (1u<<2)
- #define TIM_EGR_CC1G (1u<<1)
- #define TIM_EGR_UG (1u<<0)
- #define TIM_CCMR1_OC2CE (1u <<15)
- #define TIM_CCMR1_OC2M(x) ((x)<<12)
- #define TIM_CCMR1_OC2PE (1u <<11)
- #define TIM_CCMR1_OC2FE (1u <<10)
- #define TIM_CCMR1_CC2S(x) ((x)<< 8)
- #define TIM_CCMR1_OC1CE (1u << 7)
- #define TIM_CCMR1_OC1M(x) ((x)<< 4)
- #define TIM_CCMR1_OC1PE (1u << 3)
- #define TIM_CCMR1_OC1FE (1u << 2)
- #define TIM_CCMR1_CC1S(x) ((x)<< 0)
- #define TIM_CCMR1_IC2F(x) ((x)<<12)
- #define TIM_CCMR1_IC2PSC(x) ((x)<<10)
- #define TIM_CCMR1_IC1F(x) ((x)<< 4)
- #define TIM_CCMR1_IC1PSC(x) ((x)<< 2)
- #define TIM_CCMR2_OC4CE (1u <<15)
- #define TIM_CCMR2_OC4M(x) ((x)<<12)
- #define TIM_CCMR2_OC4PE (1u <<11)
- #define TIM_CCMR2_OC4FE (1u <<10)
- #define TIM_CCMR2_CC4S(x) ((x)<< 8)
- #define TIM_CCMR2_OC3CE (1u << 7)
- #define TIM_CCMR2_OC3M(x) ((x)<< 4)
- #define TIM_CCMR2_OC3PE (1u << 3)
- #define TIM_CCMR2_OC3FE (1u << 2)
- #define TIM_CCMR2_CC3S(x) ((x)<< 0)
- #define TIM_CCMR2_IC4F(x) ((x)<<12)
- #define TIM_CCMR2_IC4PSC(x) ((x)<<10)
- #define TIM_CCMR2_IC3F(x) ((x)<< 4)
- #define TIM_CCMR2_IC3PSC(x) ((x)<< 2)
- #define TIM_OCM_FROZEN (0u)
- #define TIM_OCM_SET_HIGH (1u)
- #define TIM_OCM_SET_LOW (2u)
- #define TIM_OCM_TOGGLE (3u)
- #define TIM_OCM_FORCE_LOW (4u)
- #define TIM_OCM_FORCE_HIGH (5u)
- #define TIM_OCM_PWM1 (6u)
- #define TIM_OCM_PWM2 (7u)
- #define TIM_OCM_MASK (7u)
- #define TIM_CCS_OUTPUT (0u)
- #define TIM_CCS_INPUT_TI1 (1u)
- #define TIM_CCS_INPUT_TI2 (2u)
- #define TIM_CCS_INPUT_TRC (3u)
- #define TIM_CCS_MASK (3u)
- #define TIM_CCER_CC4P (1u<<13)
- #define TIM_CCER_CC4E (1u<<12)
- #define TIM_CCER_CC3P (1u<< 9)
- #define TIM_CCER_CC3E (1u<< 8)
- #define TIM_CCER_CC2P (1u<< 5)
- #define TIM_CCER_CC2E (1u<< 4)
- #define TIM_CCER_CC1P (1u<< 1)
- #define TIM_CCER_CC1E (1u<< 0)
- #define TIM_BDTR_MOE (1u<<15)
- #define TIM_BDTR_AOE (1u<<14)
- #define TIM_BDTR_BKP (1u<<13)
- #define TIM_BDTR_BKE (1u<<12)
- #define TIM_BDTR_OSSR (1u<<11)
- #define TIM_BDTR_OSSI (1u<<10)
- #define TIM_BDTR_LOCK(x) ((x)<<8)
- #define TIM_BDTR_DTG(x) ((x)<<0)
- #define TIM1_BASE 0x40012c00
- #define TIM2_BASE 0x40000000
- #define TIM3_BASE 0x40000400
- #define TIM4_BASE 0x40000800
- #define TIM5_BASE 0x40000c00
- #define TIM6_BASE 0x40001000
- #define TIM7_BASE 0x40001400
- struct spi {
- uint32_t cr1;
- uint32_t cr2;
- uint32_t sr;
- uint32_t dr;
- uint32_t crcpr;
- uint32_t rxcrcr;
- uint32_t txcrcr;
- uint32_t i2scfgr;
- uint32_t i2spr;
- };
- #define SPI_CR1_BIDIMODE (1u<<15)
- #define SPI_CR1_BIDIOE (1u<<14)
- #define SPI_CR1_CRCEN (1u<<13)
- #define SPI_CR1_CRCNEXT (1u<<12)
- #define SPI_CR1_DFF (1u<<11)
- #define SPI_CR1_RXONLY (1u<<10)
- #define SPI_CR1_SSM (1u<< 9)
- #define SPI_CR1_SSI (1u<< 8)
- #define SPI_CR1_LSBFIRST (1u<< 7)
- #define SPI_CR1_SPE (1u<< 6)
- #define SPI_CR1_BR_DIV2 (0u<< 3)
- #define SPI_CR1_BR_DIV4 (1u<< 3)
- #define SPI_CR1_BR_DIV8 (2u<< 3)
- #define SPI_CR1_BR_DIV16 (3u<< 3)
- #define SPI_CR1_BR_DIV32 (4u<< 3)
- #define SPI_CR1_BR_DIV64 (5u<< 3)
- #define SPI_CR1_BR_DIV128 (6u<< 3)
- #define SPI_CR1_BR_DIV256 (7u<< 3)
- #define SPI_CR1_BR_MASK (7u<< 3)
- #define SPI_CR1_MSTR (1u<< 2)
- #define SPI_CR1_CPOL (1u<< 1)
- #define SPI_CR1_CPHA (1u<< 0)
- #define SPI_CR2_TXEIE (1u<< 7)
- #define SPI_CR2_RXNEIE (1u<< 6)
- #define SPI_CR2_ERRIE (1u<< 5)
- #define SPI_CR2_SSOE (1u<< 2)
- #define SPI_CR2_TXDMAEN (1u<< 1)
- #define SPI_CR2_RXDMAEN (1u<< 0)
- #define SPI_SR_BSY (1u<< 7)
- #define SPI_SR_OVR (1u<< 6)
- #define SPI_SR_MODF (1u<< 5)
- #define SPI_SR_CRCERR (1u<< 4)
- #define SPI_SR_USR (1u<< 3)
- #define SPI_SR_CHSIDE (1u<< 2)
- #define SPI_SR_TXE (1u<< 1)
- #define SPI_SR_RXNE (1u<< 0)
- #define SPI1_BASE 0x40013000
- #define SPI2_BASE 0x40003800
- #define SPI3_BASE 0x40003C00
- struct i2c {
- uint32_t cr1;
- uint32_t cr2;
- uint32_t oar1;
- uint32_t oar2;
- uint32_t dr;
- uint32_t sr1;
- uint32_t sr2;
- uint32_t ccr;
- uint32_t trise;
- };
- #define I2C_CR1_SWRST (1u<<15)
- #define I2C_CR1_ALERT (1u<<13)
- #define I2C_CR1_PEC (1u<<12)
- #define I2C_CR1_POS (1u<<11)
- #define I2C_CR1_ACK (1u<<10)
- #define I2C_CR1_STOP (1u<< 9)
- #define I2C_CR1_START (1u<< 8)
- #define I2C_CR1_NOSTRETCH (1u<< 7)
- #define I2C_CR1_ENGC (1u<< 6)
- #define I2C_CR1_ENPEC (1u<< 5)
- #define I2C_CR1_ENARP (1u<< 4)
- #define I2C_CR1_SMBTYPE (1u<< 3)
- #define I2C_CR1_SMBUS (1u<< 1)
- #define I2C_CR1_PE (1u<< 0)
- #define I2C_CR2_LAST (1u<<12)
- #define I2C_CR2_DMAEN (1u<<11)
- #define I2C_CR2_ITBUFEN (1u<<10)
- #define I2C_CR2_ITEVTEN (1u<< 9)
- #define I2C_CR2_ITERREN (1u<< 8)
- #define I2C_CR2_FREQ(x) (x)
- #define I2C_SR1_SMBALERT (1u<<15)
- #define I2C_SR1_TIMEOUT (1u<<14)
- #define I2C_SR1_PECERR (1u<<12)
- #define I2C_SR1_OVR (1u<<11)
- #define I2C_SR1_AF (1u<<10)
- #define I2C_SR1_ARLO (1u<< 9)
- #define I2C_SR1_BERR (1u<< 8)
- #define I2C_SR1_ERRORS 0xdf00
- #define I2C_SR1_TXE (1u<< 7)
- #define I2C_SR1_RXNE (1u<< 6)
- #define I2C_SR1_STOPF (1u<< 4)
- #define I2C_SR1_ADD10 (1u<< 3)
- #define I2C_SR1_BTF (1u<< 2)
- #define I2C_SR1_ADDR (1u<< 1)
- #define I2C_SR1_SB (1u<< 0)
- #define I2C_SR1_EVENTS 0x001f
- #define I2C_SR2_PEC(x) ((x)<<15)
- #define I2C_SR2_DUALF (1u<< 7)
- #define I2C_SR2_SMBHOST (1u<< 6)
- #define I2C_SR2_SMBDEFAULT (1u<< 5)
- #define I2C_SR2_GENCALL (1u<< 4)
- #define I2C_SR2_TRA (1u<< 2)
- #define I2C_SR2_BUSY (1u<< 1)
- #define I2C_SR2_MSL (1u<< 0)
- #define I2C_CCR_FS (1u<<15)
- #define I2C_CCR_DUTY (1u<<14)
- #define I2C_CCR_CCR(x) (x)
- #define I2C1_BASE 0x40005400
- #define I2C2_BASE 0x40005800
- struct usart {
- uint32_t sr;
- uint32_t dr;
- uint32_t brr;
- uint32_t cr1;
- uint32_t cr2;
- uint32_t cr3;
- uint32_t gtpr;
- };
- #define USART_SR_CTS (1u<<9)
- #define USART_SR_LBD (1u<<8)
- #define USART_SR_TXE (1u<<7)
- #define USART_SR_TC (1u<<6)
- #define USART_SR_RXNE (1u<<5)
- #define USART_SR_IDLE (1u<<4)
- #define USART_SR_ORE (1u<<3)
- #define USART_SR_NE (1u<<2)
- #define USART_SR_FE (1u<<1)
- #define USART_SR_PE (1u<<0)
- #define USART_CR1_UE (1u<<13)
- #define USART_CR1_M (1u<<12)
- #define USART_CR1_WAKE (1u<<11)
- #define USART_CR1_PCE (1u<<10)
- #define USART_CR1_PS (1u<< 9)
- #define USART_CR1_PEIE (1u<< 8)
- #define USART_CR1_TXEIE (1u<< 7)
- #define USART_CR1_TCIE (1u<< 6)
- #define USART_CR1_RXNEIE (1u<< 5)
- #define USART_CR1_IDLEIE (1u<< 4)
- #define USART_CR1_TE (1u<< 3)
- #define USART_CR1_RE (1u<< 2)
- #define USART_CR1_RWU (1u<< 1)
- #define USART_CR1_SBK (1u<< 0)
- #define USART_CR3_CTSIE (1u<<10)
- #define USART_CR3_CTSE (1u<< 9)
- #define USART_CR3_RTSE (1u<< 8)
- #define USART_CR3_DMAT (1u<< 7)
- #define USART_CR3_DMAR (1u<< 6)
- #define USART_CR3_SCEN (1u<< 5)
- #define USART_CR3_NACK (1u<< 4)
- #define USART_CR3_HDSEL (1u<< 3)
- #define USART_CR3_IRLP (1u<< 2)
- #define USART_CR3_IREN (1u<< 1)
- #define USART_CR3_EIE (1u<< 0)
- #define USART1_BASE 0x40013800
- #define USART2_BASE 0x40004400
- #define USART3_BASE 0x40004800
- struct usb {
- uint32_t epr[8];
- uint32_t rsvd[8];
- uint32_t cntr;
- uint32_t istr;
- uint32_t fnr;
- uint32_t daddr;
- uint32_t btable;
- };
- struct usb_bufd {
- union {
- struct {
- uint32_t addr_tx;
- uint32_t count_tx;
- uint32_t addr_rx;
- uint32_t count_rx;
- };
- struct {
- uint32_t addr_0;
- uint32_t count_0;
- uint32_t addr_1;
- uint32_t count_1;
- };
- };
- };
- #define USB_EPR_CTR_RX (1u<<15)
- #define USB_EPR_DTOG_RX (1u<<14)
- #define USB_EPR_STAT_RX(x) ((x)<<12)
- #define USB_EPR_SETUP (1u<<11)
- #define USB_EPR_EP_TYPE(x) ((x)<<9)
- #define USB_EPR_EP_KIND_DBL_BUF (1<<8)
- #define USB_EPR_EP_KIND_STATUS_OUT (1<<8)
- #define USB_EPR_CTR_TX (1u<< 7)
- #define USB_EPR_DTOG_TX (1u<< 6)
- #define USB_EPR_STAT_TX(x) ((x)<<4)
- #define USB_EPR_EA(x) ((x)<<0)
- #define USB_STAT_DISABLED (0u)
- #define USB_STAT_STALL (1u)
- #define USB_STAT_NAK (2u)
- #define USB_STAT_VALID (3u)
- #define USB_STAT_MASK (3u)
- #define USB_EP_TYPE_BULK (0u)
- #define USB_EP_TYPE_CONTROL (1u)
- #define USB_EP_TYPE_ISO (2u)
- #define USB_EP_TYPE_INTERRUPT (3u)
- #define USB_EP_TYPE_MASK (3u)
- #define USB_CNTR_CTRM (1u<<15)
- #define USB_CNTR_PMAOVRM (1u<<14)
- #define USB_CNTR_ERRM (1u<<13)
- #define USB_CNTR_WKUPM (1u<<12)
- #define USB_CNTR_SUSPM (1u<<11)
- #define USB_CNTR_RESETM (1u<<10)
- #define USB_CNTR_SOFM (1u<< 9)
- #define USB_CNTR_ESOFM (1u<< 8)
- #define USB_CNTR_RESUME (1u<< 4)
- #define USB_CNTR_FSUSP (1u<< 3)
- #define USB_CNTR_LP_MODE (1u<< 2)
- #define USB_CNTR_PDWN (1u<< 1)
- #define USB_CNTR_FRES (1u<< 0)
- #define USB_ISTR_CTR (1u<<15)
- #define USB_ISTR_PMAOVR (1u<<14)
- #define USB_ISTR_ERR (1u<<13)
- #define USB_ISTR_WKUP (1u<<12)
- #define USB_ISTR_SUSP (1u<<11)
- #define USB_ISTR_RESET (1u<<10)
- #define USB_ISTR_SOF (1u<< 9)
- #define USB_ISTR_ESOF (1u<< 8)
- #define USB_ISTR_DIR (1u<< 4)
- #define USB_ISTR_GET_EP_ID(x) ((x)&0xf)
- #define USB_FNR_RXDP (1u<<15)
- #define USB_FNR_RXDM (1u<<14)
- #define USB_FNR_LCK (1u<<13)
- #define USB_FNR_GET_LSOF(x) (((x)>>11)&3)
- #define USB_FNR_GET_FN(x) ((x)&0x7ff)
- #define USB_DADDR_EF (1u<< 7)
- #define USB_DADDR_ADD(x) ((x)<<0)
- #define USB_BASE 0x40005c00
- #define USB_BUF_BASE 0x40006000
- struct usb_otg {
- uint32_t gotctl;
- uint32_t gotgint;
- uint32_t gahbcfg;
- uint32_t gusbcfg;
- uint32_t grstctl;
- uint32_t gintsts;
- uint32_t gintmsk;
- uint32_t grxstsr;
- uint32_t grxstsp;
- uint32_t grxfsiz;
- union {
- uint32_t hnptxfsiz;
- uint32_t dieptxf0;
- };
- uint32_t hnptxsts;
- uint32_t _0[2];
- uint32_t gccfg;
- uint32_t cid;
- uint32_t _1[48];
- uint32_t hptxfsiz;
- uint32_t dieptxf1;
- uint32_t dieptxf2;
- uint32_t dieptxf3;
- uint32_t _2[188];
- uint32_t hcfg;
- uint32_t hfir;
- uint32_t hfnum;
- uint32_t _3[1];
- uint32_t hptxsts;
- uint32_t haint;
- uint32_t haintmsk;
- uint32_t _4[9];
- uint32_t hprt;
- uint32_t _5[47];
- struct {
- uint32_t charac;
- uint32_t _0[1];
- uint32_t intsts;
- uint32_t intmsk;
- uint32_t tsiz;
- uint32_t _1[3];
- } hc[8];
- uint32_t _6[128];
- uint32_t dcfg;
- uint32_t dctl;
- uint32_t dsts;
- uint32_t _7[1];
- uint32_t diepmsk;
- uint32_t doepmsk;
- uint32_t daint;
- uint32_t daintmsk;
- uint32_t _8[2];
- uint32_t dvbusdis;
- uint32_t dvbuspulse;
- uint32_t _9[1];
- uint32_t diepempmsk;
- uint32_t _10[50];
- struct {
- uint32_t ctl;
- uint32_t _0[1];
- uint32_t intsts;
- uint32_t _1[3];
- uint32_t txfsts;
- uint32_t _2[1];
- } diep[4];
- uint32_t _11[96];
- struct {
- uint32_t ctl;
- uint32_t _0[1];
- uint32_t intsts;
- uint32_t _1[1];
- uint32_t tsiz;
- uint32_t _2[3];
- } doep[4];
- uint32_t _12[160];
- uint32_t pcgcctl;
- };
- #define OTG_GAHBCFG_PTXFELVL (1u<< 8)
- #define OTG_GAHBCFG_TXFELVL (1u<< 7)
- #define OTG_GAHBCFG_GINTMSK (1u<< 0)
- #define OTG_GUSBCFG_CTXPKT (1u<<31)
- #define OTG_GUSBCFG_FDMOD (1u<<30)
- #define OTG_GUSBCFG_FHMOD (1u<<29)
- #define OTG_GUSBCFG_TRDT(x) ((x)<<10)
- #define OTG_GUSBCFG_HNPCAP (1u<< 9)
- #define OTG_GUSBCFG_SRPCAP (1u<< 8)
- #define OTG_GUSBCFG_PHYSEL (1u<< 6)
- #define OTG_GUSBCFG_TOCAL(x) ((x)<< 0)
- #define OTG_GINT_WKUPINT (1u<<31)
- #define OTG_GINT_SRQINT (1u<<30)
- #define OTG_GINT_DISCINT (1u<<29)
- #define OTG_GINT_CIDSCHG (1u<<28)
- #define OTG_GINT_PTXFE (1u<<26)
- #define OTG_GINT_HCINT (1u<<25)
- #define OTG_GINT_HPRTINT (1u<<24)
- #define OTG_GINT_IPXFR (1u<<21)
- #define OTG_GINT_IISOIXFR (1u<<20)
- #define OTG_GINT_OEPINT (1u<<19)
- #define OTG_GINT_IEPINT (1u<<18)
- #define OTG_GINT_EOPF (1u<<15)
- #define OTG_GINT_ISOODRP (1u<<14)
- #define OTG_GINT_ENUMDNE (1u<<13)
- #define OTG_GINT_USBRST (1u<<12)
- #define OTG_GINT_USBSUSP (1u<<11)
- #define OTG_GINT_ESUSP (1u<<10)
- #define OTG_GINT_GONAKEFF (1u<< 7)
- #define OTG_GINT_GINAKEFF (1u<< 6)
- #define OTG_GINT_NPTXFE (1u<< 5)
- #define OTG_GINT_RXFLVL (1u<< 4)
- #define OTG_GINT_SOF (1u<< 3)
- #define OTG_GINT_OTGINT (1u<< 2)
- #define OTG_GINT_MMIS (1u<< 1)
- #define OTG_GINT_CMOD (1u<< 0)
- #define OTG_RXSTS_PKTSTS_IN (2u)
- #define OTG_RXSTS_PKTSTS(r) (((r)>>17)&0xf)
- #define OTG_RXSTS_BCNT(r) (((r)>>4)&0x7ff)
- #define OTG_RXSTS_CHNUM(r) ((r)&0xf)
- #define OTG_GCCFG_SOFOUTEN (1u<<20)
- #define OTG_GCCFG_VBUSBSEN (1u<<19)
- #define OTG_GCCFG_VBUSASEN (1u<<18)
- #define OTG_GCCFG_PWRDWN (1u<<16)
- #define OTG_HCFG_FSLSS (1u<<2)
- #define OTG_HCFG_FSLSPCS (3u<<0)
- #define OTG_HCFG_FSLSPCS_48 (1u<<0)
- #define OTG_HCFG_FSLSPCS_6 (2u<<0)
- #define OTG_HPRT_PSPD_FULL (1u<<17)
- #define OTG_HPRT_PSPD_LOW (2u<<17)
- #define OTG_HPRT_PSPD_MASK (1u<<17)
- #define OTG_HPRT_PPWR (1u<<12)
- #define OTG_HPRT_PRST (1u<< 8)
- #define OTG_HPRT_PSUSP (1u<< 7)
- #define OTG_HPRT_PRES (1u<< 6)
- #define OTG_HPRT_POCCHNG (1u<< 5)
- #define OTG_HPRT_POCA (1u<< 4)
- #define OTG_HPRT_PENCHNG (1u<< 3)
- #define OTG_HPRT_PENA (1u<< 2)
- #define OTG_HPRT_PCDET (1u<< 1)
- #define OTG_HPRT_PCSTS (1u<< 0)
- #define OTG_HPRT_INTS (OTG_HPRT_POCCHNG|OTG_HPRT_PENCHNG|OTG_HPRT_PCDET| \
- OTG_HPRT_PENA)
- #define OTG_HCINT_DTERR (1u<<10)
- #define OTG_HCINT_FRMOR (1u<< 9)
- #define OTG_HCINT_BBERR (1u<< 8)
- #define OTG_HCINT_TXERR (1u<< 7)
- #define OTG_HCINT_NYET (1u<< 6)
- #define OTG_HCINT_ACK (1u<< 5)
- #define OTG_HCINT_NAK (1u<< 4)
- #define OTG_HCINT_STALL (1u<< 3)
- #define OTG_HCINT_CHH (1u<< 1)
- #define OTG_HCINT_XFRC (1u<< 0)
- #define OTG_HCCHAR_CHENA (1u<<31)
- #define OTG_HCCHAR_CHDIS (1u<<30)
- #define OTG_HCCHAR_ODDFRM (1u<<29)
- #define OTG_HCCHAR_DAD(x) ((x)<<22)
- #define OTG_HCCHAR_MCNT(x) ((x)<<20)
- #define OTG_HCCHAR_ETYP_CTRL (0u<<18)
- #define OTG_HCCHAR_ETYP_ISO (1u<<18)
- #define OTG_HCCHAR_ETYP_BULK (2u<<18)
- #define OTG_HCCHAR_ETYP_INT (3u<<18)
- #define OTG_HCCHAR_LSDEV (1u<<17)
- #define OTG_HCCHAR_EPDIR_OUT (0u<<15)
- #define OTG_HCCHAR_EPDIR_IN (1u<<15)
- #define OTG_HCCHAR_EPNUM(x) ((x)<<11)
- #define OTG_HCCHAR_MPSIZ(x) ((x)<< 0)
- #define OTG_HCTSIZ_DPID_DATA0 (0u<<29)
- #define OTG_HCTSIZ_DPID_DATA2 (1u<<29)
- #define OTG_HCTSIZ_DPID_DATA1 (2u<<29)
- #define OTG_HCTSIZ_DPID_MDATA (3u<<29)
- #define OTG_HCTSIZ_DPID_SETUP (3u<<29)
- #define OTG_HCTSIZ_PKTCNT(x) ((x)<<19)
- #define OTG_HCTSIZ_XFRSIZ(x) ((x)<< 0)
- #define USB_OTG_BASE 0x50000000
|