文档CH32FV2x_V3xRM.PDF中关于OTG_FS/USBFS的描述问题

使用ch32v303的OTG_FS/USBFS,但是例程中的寄存器描述与文档CH32FV2x_V3xRM.PDF中关于OTG_FS/USBFS的描述并不一致,两者如何对应的?文档版本v1.6。例程:EXAM\USB\USBFS\DEVICE\CompatibilityHID

#define USBOTG_FS           ((USBOTG_FS_TypeDef *)USBFS_BASE)

#define USBFS_BASE            ((uint32_t)0x50000000)

image.png


image.png

您好,例程中的库是采用基地址与结构体映射的方式操作寄存器的,USBFS所有相关寄存器都可在USBOTGH_FS_TypeDef机构中找到对应关系。

typedef struct? __attribute__((packed))

{

? ?__IO uint8_t? ?BASE_CTRL;

? ?__IO uint8_t? ?HOST_CTRL;

? ?__IO uint8_t? ?INT_EN;

? ?__IO uint8_t? ?DEV_ADDR;

? ?__IO uint8_t? ?Reserve0;

? ?__IO uint8_t? ?MIS_ST;

? ?__IO uint8_t? ?INT_FG;

? ?__IO uint8_t? ?INT_ST;

? ?__IO uint16_t? RX_LEN;

? ?__IO uint16_t? Reserve1;

? ?__IO uint8_t? ?Reserve2;

? ?__IO uint8_t? ?HOST_EP_MOD;

? ?__IO uint16_t? Reserve3;

? ?__IO uint32_t? Reserve4;

? ?__IO uint32_t? Reserve5;

? ?__IO uint32_t? HOST_RX_DMA;

? ?__IO uint32_t? HOST_TX_DMA;

? ?__IO uint32_t? Reserve6;

? ?__IO uint32_t? Reserve7;

? ?__IO uint32_t? Reserve8;

? ?__IO uint32_t? Reserve9;

? ?__IO uint32_t? Reserve10;

? ?__IO uint16_t? Reserve11;

? ?__IO uint16_t? HOST_SETUP;

? ?__IO uint8_t? ?HOST_EP_PID;

? ?__IO uint8_t? ?Reserve12;

? ?__IO uint8_t? ?Reserve13;

? ?__IO uint8_t? ?HOST_RX_CTRL;

? ?__IO uint16_t? HOST_TX_LEN;

? ?__IO uint8_t? ?HOST_TX_CTRL;

? ?__IO uint8_t? ?Reserve14;

? ?__IO uint32_t? Reserve15;

? ?__IO uint32_t? Reserve16;

? ?__IO uint32_t? Reserve17;

? ?__IO uint32_t? Reserve18;

? ?__IO uint32_t? Reserve19;

? ?__IO uint32_t? OTG_CR;

? ?__IO uint32_t? OTG_SR;

}USBOTGH_FS_TypeDef;

BASE_CTRL即对应USBFS的基地址又对应R8_USB_CTRL(USB控制寄存器)。


建议文档的命名最好能跟寄存器名称一致,这样看这方便。


只有登录才能回复,可以选择微信账号登录