usbcdc可以双向通信吗

usbcdc可以双向通信吗,第1张

以下就是要改动的地方

1将usbd_hid_corec和usbd_hid_cdc_wrapperc和他们的头文件加入进去,这两个文件可以在例程自带的USB库中找到

2将__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC]改为如下,这一步主要是修改设备描述符为复合设备

__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =

{

0x12, /bLength /

USB_DEVICE_DESCRIPTOR_TYPE, /bDescriptorType/

0x00, /bcdUSB /

0x02,

0xEF, /bDeviceClass/

0x02, /bDeviceSubClass/

0x01, /bDeviceProtocol/

USB_OTG_MAX_EP0_SIZE, /bMaxPacketSize/

LOBYTE(USBD_VID), /idVendor/

HIBYTE(USBD_VID), /idVendor/

LOBYTE(USBD_PID), /idVendor/

HIBYTE(USBD_PID), /idVendor/

0x00, /bcdDevice rel 200/

0x02,

USBD_IDX_MFC_STR, /Index of manufacturer string/

USBD_IDX_PRODUCT_STR, /Index of product string/

USBD_IDX_SERIAL_STR, /Index of serial number string/

USBD_CFG_MAX_NUM /bNumConfigurations/

} ; / USB_DeviceDescriptor /

3更改PID VID

#define USBD_VID 0x0483

#define USBD_PID 0xA105

3在usbd_hid_corec和h中修改以下地方,主要是添加HID 输入端口和报文,例程的库中USBD_HID_CfgDesc是只有USB HID输入端口(HID_IN_EP)没有输出端口(HID_OUT_EP)的,同样例程中的HID_MOUSE_ReportDesc报文是让电脑按鼠标的方式来处理USB数据的,现在改为传输64字节数据报文,然后就可以通过USB自定义协议来进行数据传输了。当然USB_HID_CONFIG_DESC_SIZ和HID_MOUSE_REPORT_DESC_SIZE两个数据长度也要修改

#define USB_HID_CONFIG_DESC_SIZ 41

#define USB_HID_DESC_SIZ 9

#define HID_MOUSE_REPORT_DESC_SIZE 33

__ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =

{

0x09, / bLength: Configuration Descriptor size /

USB_CONFIGURATION_DESCRIPTOR_TYPE, / bDescriptorType: Configuration /

USB_HID_CONFIG_DESC_SIZ,

/ wTotalLength: Bytes returned /

0x00,

0x01, /bNumInterfaces: 1 interface/

0x01, /bConfigurationValue: Configuration value/

0x00, /iConfiguration: Index of string descriptor describing

the configuration/

0xE0, /bmAttributes: bus powered and Support Remote Wake-up /

0x32, /MaxPower 100 mA: this current is used for detecting Vbus/

/ Descriptor of Joystick Mouse interface /

/ 09 /

0x09, /bLength: Interface Descriptor size/

USB_INTERFACE_DESCRIPTOR_TYPE,/bDescriptorType: Interface descriptor type/

0x00, /bInterfaceNumber: Number of Interface/

0x00, /bAlternateSetting: Alternate setting/

0x02, /bNumEndpoints/

0x03, /bInterfaceClass: HID/

0x01, /bInterfaceSubClass : 1=BOOT, 0=no boot/

0x02, /nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse/

0, /iInterface: Index of string descriptor/

/ Descriptor of Joystick Mouse HID /

/ 18 /

0x09, /bLength: HID Descriptor size/

HID_DESCRIPTOR_TYPE, /bDescriptorType: HID/

0x11, /bcdHID: HID Class Spec release number/

0x01,

0x00, /bCountryCode: Hardware target country/

0x01, /bNumDescriptors: Number of HID class descriptors to follow/

0x22, /bDescriptorType/

HID_MOUSE_REPORT_DESC_SIZE,/wItemLength: Total length of Report descriptor/

0x00,

/ Descriptor of Mouse endpoint /

/ 27 /

0x07, /bLength: Endpoint Descriptor size/

USB_ENDPOINT_DESCRIPTOR_TYPE, /bDescriptorType:/

HID_IN_EP, /bEndpointAddress: Endpoint Address (IN)/

0x03, /bmAttributes: Interrupt endpoint/

HID_IN_PACKET, /wMaxPacketSize: 4 Byte max /

0x00,

HID_FS_BINTERVAL, /bInterval: Polling Interval (10 ms)/

/ 34 /

0x07, /bLength: Endpoint Descriptor size/

USB_ENDPOINT_DESCRIPTOR_TYPE, /bDescriptorType:/

HID_OUT_EP, /bEndpointAddress: Endpoint Address (IN)/

0x03, /bmAttributes: Interrupt endpoint/

HID_OUT_PACKET, /wMaxPacketSize: 4 Byte max /

0x00,

HID_FS_BINTERVAL, /bInterval: Polling Interval (10 ms)/

/ 41 /

} ;

__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =

{

0x05, 0x8c, / USAGE_PAGE (ST Page) /

0x09, 0x01, / USAGE (Demo Kit) /

0xa1, 0x01, / COLLECTION (Application) /

0x09,0x03, // USAGE ID - Vendor defined

0x15,0x00, // LOGICAL_MINIMUM (0)

0x26,0x00, 0xFF, // LOGICAL_MAXIMUM (255)

0x75,0x08, // REPORT_SIZE (8bit)

0x95,0x40, // REPORT_COUNT (64Byte)

0x81,0x02, // INPUT (Data,Var,Abs)

0x09,0x04, // USAGE ID - Vendor defined

0x15,0x00, // LOGICAL_MINIMUM (0)

0x26,0x00,0xFF, // LOGICAL_MAXIMUM (255)

0x75,0x08, // REPORT_SIZE (8bit)

0x95,0x40, // REPORT_COUNT (64Byte)

0x91,0x02, // OUTPUT (Data,Var,Abs)

0xc0 / END_COLLECTION /

#endif

};

4将对应的USB HID 输入端口初始化添加上去

uint8_t USBD_HID_Init (void pdev,

uint8_t cfgidx)

{

/ Open EP IN /

DCD_EP_Open(pdev,

HID_IN_EP,

HID_IN_PACKET,

USB_OTG_EP_INT);

DCD_EP_Open(pdev,

HID_OUT_EP,

HID_OUT_PACKET,

USB_OTG_EP_INT);

#if 1

/ Prepare Out endpoint to receive next packet /

DCD_EP_PrepareRx(pdev,

HID_OUT_EP,

(uint8_t)(USB_HID_Rx_Buffer),

HID_OUT_PACKET);

#endif

return USBD_OK;

}

/

@brief USBD_HID_Init

DeInitialize the HID layer

@param pdev: device instance

@param cfgidx: Configuration index

@retval status

/

uint8_t USBD_HID_DeInit (void pdev,

uint8_t cfgidx)

{

/ Close HID EPs /

DCD_EP_Close (pdev , HID_IN_EP);

DCD_EP_Close (pdev , HID_OUT_EP);

return USBD_OK;

}

5在usbd_hid_cdc_wrapperc的USBD_HID_CDC_CfgDesc中,同样的添加USB输入端口,而IAD和配置接口那些人家已经帮你添加好了,照着用就行

__ALIGN_BEGIN static uint8_t USBD_HID_CDC_CfgDesc[USB_HID_CDC_CONFIG_DESC_SIZ] __ALIGN_END =

{

0x09, / bLength: Configuration Descriptor size /

USB_CONFIGURATION_DESCRIPTOR_TYPE, / bDescriptorType: Configuration /

USB_HID_CDC_CONFIG_DESC_SIZ,

/ wTotalLength: Bytes returned /

0x00,

0x03, /bNumInterfaces: 3 interfaces (2 for CDC, 1 for MSC)/

0x01, /bConfigurationValue: Configuration value/

0x00, /iConfiguration: Index of string descriptor describing

the configuration/

0xE0, /bmAttributes: bus powered and Support Remote Wake-up /

0x32, /MaxPower 100 mA: this current is used for detecting Vbus/

/ Descriptor of Joystick Mouse interface /

/ 09 /

0x09, /bLength: Interface Descriptor size/

USB_INTERFACE_DESCRIPTOR_TYPE,/bDescriptorType: Interface descriptor type/

HID_INTERFACE, /bInterfaceNumber: Number of Interface/

0x00, /bAlternateSetting: Alternate setting/

0x02, /bNumEndpoints/

0x03, /bInterfaceClass: HID/

0x01, /bInterfaceSubClass : 1=BOOT, 0=no boot/

0x02, /nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse/

0, /iInterface: Index of string descriptor/

/ Descriptor of Joystick Mouse HID /

/ 18 /

0x09, /bLength: HID Descriptor size/

HID_DESCRIPTOR_TYPE, /bDescriptorType: HID/

0x11, /bcdHID: HID Class Spec release number/

0x01,

0x00, /bCountryCode: Hardware target country/

0x01, /bNumDescriptors: Number of HID class descriptors to follow/

0x22, /bDescriptorType/

HID_MOUSE_REPORT_DESC_SIZE,/wItemLength: Total length of Report descriptor/

0x00,

/ Descriptor of Mouse endpoint /

/ 27 /

0x07, /bLength: Endpoint Descriptor size/

USB_ENDPOINT_DESCRIPTOR_TYPE, /bDescriptorType:/

HID_IN_EP, /bEndpointAddress: Endpoint Address (IN)/

0x03, /bmAttributes: Interrupt endpoint/

HID_IN_PACKET, /wMaxPacketSize: 4 Byte max /

0x00,

0x0A, /bInterval: Polling Interval (10 ms)/

/ 34 /

0x07, /bLength: Endpoint Descriptor size/

USB_ENDPOINT_DESCRIPTOR_TYPE, /bDescriptorType:/

HID_OUT_EP, /bEndpointAddress: Endpoint Address (IN)/

0x03, /bmAttributes: Interrupt endpoint/

HID_OUT_PACKET, /wMaxPacketSize: 4 Byte max /

0x00,

HID_FS_BINTERVAL, /bInterval: Polling Interval (10 ms)/

/ 41 /

/ /IAD should be positioned just before the CDC interfaces

IAD to associate the two CDC interfaces /

0x08, / bLength /

0x0B, / bDescriptorType /

0x01, / bFirstInterface /

0x02, / bInterfaceCount /

0x02, / bFunctionClass /

0x02, / bFunctionSubClass /

0x01, / bFunctionProtocol /

0x00, / iFunction (Index of string descriptor describing this function) /

/Interface Descriptor /

0x09, / bLength: Interface Descriptor size /

USB_INTERFACE_DESCRIPTOR_TYPE, / bDescriptorType: Interface /

/ Interface descriptor type /

CDC_COM_INTERFACE, / bInterfaceNumber: Number of Interface /

0x00, / bAlternateSetting: Alternate setting /

0x01, / bNumEndpoints: One endpoints used /

0x02, / bInterfaceClass: Communication Interface Class /

0x02, / bInterfaceSubClass: Abstract Control Model /

0x01, / bInterfaceProtocol: Common AT commands /

0x01, / iInterface: /

/Header Functional Descriptor/

0x05, / bLength: Endpoint Descriptor size /

0x24, / bDescriptorType: CS_INTERFACE /

0x00, / bDescriptorSubtype: Header Func Desc /

0x10, / bcdCDC: spec release number /

0x01,

/Call Management Functional Descriptor/

0x05, / bFunctionLength /

0x24, / bDescriptorType: CS_INTERFACE /

0x01, / bDescriptorSubtype: Call Management Func Desc /

0x00, / bmCapabilities: D0+D1 /

0x02, / bDataInterface: 2 /

/ACM Functional Descriptor/

0x04, / bFunctionLength /

0x24, / bDescriptorType: CS_INTERFACE /

0x02, / bDescriptorSubtype: Abstract Control Management desc /

0x02, / bmCapabilities /

/Union Functional Descriptor/

0x05, / bFunctionLength /

0x24, / bDescriptorType: CS_INTERFACE /

0x06, / bDescriptorSubtype: Union func desc /

0x01, / bMasterInterface: Communication class interface /

0x02, / bSlaveInterface0: Data Class Interface /

/Endpoint 2 Descriptor/

0x07, / bLength: Endpoint Descriptor size /

USB_ENDPOINT_DESCRIPTOR_TYPE, / bDescriptorType: Endpoint /

CDC_CMD_EP, / bEndpointAddress /

0x03, / bmAttributes: Interrupt /

LOBYTE(CDC_CMD_PACKET_SZE), / wMaxPacketSize: /

HIBYTE(CDC_CMD_PACKET_SZE),

0xFF, / bInterval: /

/---------------------------------------------------------------------------/

/Data class interface descriptor/

0x09, / bLength: Endpoint Descriptor size /

USB_INTERFACE_DESCRIPTOR_TYPE, / bDescriptorType: /

0x02, / bInterfaceNumber: Number of Interface /

0x00, / bAlternateSetting: Alternate setting /

0x02, / bNumEndpoints: Two endpoints used /

0x0A, / bInterfaceClass: CDC /

0x00, / bInterfaceSubClass: /

0x00, / bInterfaceProtocol: /

0x00, / iInterface: /

/Endpoint OUT Descriptor/

0x07, / bLength: Endpoint Descriptor size /

USB_ENDPOINT_DESCRIPTOR_TYPE, / bDescriptorType: Endpoint /

CDC_OUT_EP, / bEndpointAddress /

0x02, / bmAttributes: Bulk /

LOBYTE(CDC_DATA_MAX_PACKET_SIZE), / wMaxPacketSize: /

HIBYTE(CDC_DATA_MAX_PACKET_SIZE),

0x00, / bInterval: ignore for Bulk transfer /

/Endpoint IN Descriptor/

0x07, / bLength: Endpoint Descriptor size /

USB_ENDPOINT_DESCRIPTOR_TYPE, / bDescriptorType: Endpoint /

CDC_IN_EP, / bEndpointAddress /

0x02, / bmAttributes: Bulk /

LOBYTE(CDC_DATA_MAX_PACKET_SIZE), / wMaxPacketSize: /

HIBYTE(CDC_DATA_MAX_PACKET_SIZE),

0x00, / bInterval /

} ;

6在usbd_confh文件中修改输入输出端口和大小

#define HID_IN_EP 0x81

#define HID_IN_PACKET 0x40

#define HID_OUT_EP 0x01

#define HID_OUT_PACKET 0x40

#define CDC_IN_EP 0x83 / EP1 for data IN /

#define CDC_OUT_EP 0x03 / EP1 for data OUT /

#define CDC_CMD_EP 0x82 / EP2 for CDC commands /

7在usb_confh中修改缓冲区大小,这里不改端口3是发不出数据的

#ifdef USB_OTG_FS_CORE

#define RX_FIFO_FS_SIZE 64

#define TX0_FIFO_FS_SIZE 64

#define TX1_FIFO_FS_SIZE 64

#define TX2_FIFO_FS_SIZE 64

#define TX3_FIFO_FS_SIZE 64

7在main中while循环中添加一下测试代码

uint8_t test_buf[64]={2,2,3,4,5,6,2,4,5};

while(1)

{

if(usbstatus!=bDeviceState)

{

usbstatus=bDeviceState;

if(usbstatus==1)

{

POINT_COLOR=BLUE;

//LCD_ShowString(30,130,200,16,16,"USB Connected ");

LED1=0;//DS1ÁÁ

}else

{

POINT_COLOR=RED;

//LCD_ShowString(30,130,200,16,16,"USB disConnected ");

LED1=1;//DS1Ãð

}

}

if(USB_USART_RX_STA&0x8000)

{

VCP_DataRx(USB_USART_RX_BUF,64);

len=USB_USART_RX_STA&0x3FFF;

//USBD_HID_SendReport(&USB_OTG_dev,test_buf,64);

for(t=0;t<len;t++)

{

VCP_DataTx(USB_USART_RX_BUF[t]);

}

usb_printf("\r\n\r\n");

USB_USART_RX_STA=0;

}else

{

times++;

if(times%5000==0)

{

}

if(times%200==0)

{

delay_ms(20);

USBD_HID_SendReport(&USB_OTG_dev,test_buf,64);

delay_ms(20);

}

if(times%30==0)LED0=!LED0;

delay_ms(10);

}

这样就改好了,编译下载下去就可以在电脑端看到你的CDC和HID设备了

这是USB抓包和串口测试

代码可自行下载

>

CDC是英文CENTER FOR DISEASE CONTROL AND PREVENTION的缩写。

CDC的中文意思是疾病预防控制中心。

CDC的一些常用缩写:

Centers for Disease Control and Prevention

Community Development Corporation

Cairo Demographic Center

California Date Commission

California Democratic Council

California Department of Corrections

Call Data Channel

Call Detail Control (Sprint)

Call Directing Character

Call Directing Code

Cambridge Dancers' Club

Campus Distribution Center

Canada Development Corporation

Canadian Dairy Commission

Canadian Dairy Corporation

Canadian Department of Communications

Canterbury Development Corporation

Career Development Center

--禁用C2 审核跟踪和只限成功的登录

EXEC syssp_configure N'c2 audit mode', N'0'

GO

RECONFIGURE WITH OVERRIDE

GO

USE [master]

GO

EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'AuditLevel', REG_DWORD, 1

GO

SQLSERVER2008新增的审核功能

在sqlserver2008新增了审核功能,可以对服务器级别和数据库级别的 *** 作进行审核/审计,事实上,事件通知、更改跟踪、变更数据捕获(CDC)

都不是用来做审计的,只是某些人乱用这些功能,也正因为乱用这些功能导致踩坑

事件通知:性能跟踪

更改跟踪:用Sync Services来构建偶尔连接的系统

变更数据捕获(CDC):数据仓库的ETL 中的数据抽取(背后使用logreader)

而审核是SQLSERVER专门针对数据库安全的进行的审核,记住,他是专门的!

CDC 是change data capture,即变化数据捕捉。是数据库进行备份的一种方式,常用于大量数据的备份工作。分为入侵式的和非入侵式的备份方法,入侵式的有基于触发器备份、基于时间戳备份、基于快照备份,非入侵式的备份方法是基于日志的备份。

SQLServer中开启CDC之后,在某些情况下会导致事务日志空间被占满的现象为:

在执行增删改语句(产生事务日志)的过程中提示,The transaction log for database '' is full due to 'REPLICATION'(数据库“”的事务日志已满,原因为“REPLICATION”)

CDC以及复制的基本原理粗略地讲,对于日志的使用步骤如下:

1,每当基础表(开启了CDC或者replication的表)产生事务性 *** 作(增删改)之后,对应的事务日志写入日志文件,

2,此时的日志被状态被标记为Replication,也即处于待复制状态,这个活动状态跟数据库的还原模式无关,即便是简单还原模式,

3,然后有后台进程来读取这个日志,根据事务日志的内存写入目标表,

这个目标对于cdc来说是记录数据变化的系统表,

对于replication来说是写入distribution这个库

4,步骤3完成之后,事务日志被标记为正常状态,如果是简单还原模式,被后台进程解析过的事务日志被截断,可以重用

如果上述中间的第三个步骤出现问题,也即后台进程无法解析日志后释放可用的日志空间,再次往数据库中写入 *** 作,就会出现:数据库“TestDB”的事务日志已满,原因为“REPLICATION”的情况

以上就是关于usbcdc可以双向通信吗全部的内容,包括:usbcdc可以双向通信吗、stm32usbfscdc包大小、什么是CDC等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9503832.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存