STM32 虚拟串口有什么问题?我打不开
What is issue with STM32 Virtual Com Port? I can not open it
我有 Nucleo STM32H743ZI 开发板。我正在使用 CubeMX HAL(我尝试了几个版本)和 TrueStudio。 "Virtual COM port"出现在Windows10(我试过默认的Windows驱动和ST驱动)但是我不能打开端口。我的 C# 程序在我尝试打开它时给我写了 "The parameter is incorrect":
SerialPort port = new SerialPort("COM8", 9600, Parity.None, 8, StopBits.One);
port.Open(); // System.IO.IOException: 'The parameter is incorrect.'
同样的消息写给我程序 Realterm,PuTTY 什么都不做,"Tera Term" 程序工作正常 - 我可以向我的 MCU 程序发送和接收数据。
有谁知道是什么吗?
在我的 C# 程序和终端程序中我使用相同的参数
USB 设备查看器信息:
[Port1] : STMicroelectronics Virtual COM Port
Is Port User Connectable: yes
Is Port Debug Capable: no
Companion Port Number: 17
Companion Hub Symbolic Link Name: USB#ROOT_HUB30#4&2f29167c&0&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
Protocols Supported:
USB 1.1: yes
USB 2.0: yes
USB 3.0: no
Device Power State: PowerDeviceD0
---===>Device Information<===---
English product name: "STM32 Virtual ComPort"
ConnectionStatus:
Current Config Value: 0x01 -> Device Bus Speed: Full (is not SuperSpeed or higher capable)
Device Address: 0x0A
Open Pipes: 3
===>Device Descriptor<===
bLength: 0x12
bDescriptorType: 0x01
bcdUSB: 0x0200
bDeviceClass: 0x02 -> This is a Communication Device
bDeviceSubClass: 0x00
bDeviceProtocol: 0x00
bMaxPacketSize0: 0x40 = (64) Bytes
idVendor: 0x0483 = STMicroelectronics
idProduct: 0x5740
bcdDevice: 0x0200
iManufacturer: 0x01
English (United States) "STMicroelectronics"
iProduct: 0x02
English (United States) "STM32 Virtual ComPort"
iSerialNumber: 0x03
English (United States) "354BB9433137"
bNumConfigurations: 0x01
---===>Open Pipes<===---
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x82 -> Direction: IN - EndpointID: 2
bmAttributes: 0x03 -> Interrupt Transfer Type
wMaxPacketSize: 0x0008 = 0x08 bytes
bInterval: 0x10
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x01 -> Direction: OUT - EndpointID: 1
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x81 -> Direction: IN - EndpointID: 1
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
---===>Full Configuration Descriptor<===---
===>Configuration Descriptor<===
bLength: 0x09
bDescriptorType: 0x02
wTotalLength: 0x0043 -> Validated
bNumInterfaces: 0x02
bConfigurationValue: 0x01
iConfiguration: 0x00
bmAttributes: 0xC0 -> Self Powered
MaxPower: 0x32 = 100 mA
===>Interface Descriptor<===
bLength: 0x09
bDescriptorType: 0x04
bInterfaceNumber: 0x00
bAlternateSetting: 0x00
bNumEndpoints: 0x01
bInterfaceClass: 0x02 -> This is Communications (CDC Control) USB Device Interface Class
bInterfaceSubClass: 0x02
bInterfaceProtocol: 0x01
iInterface: 0x00
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 00 10 01
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 01 00 01
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x04
bDescriptorType: 0x24
04 24 02 02
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 06 00 01
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x82 -> Direction: IN - EndpointID: 2
bmAttributes: 0x03 -> Interrupt Transfer Type
wMaxPacketSize: 0x0008 = 0x08 bytes
bInterval: 0x10
===>Interface Descriptor<===
bLength: 0x09
bDescriptorType: 0x04
bInterfaceNumber: 0x01
bAlternateSetting: 0x00
bNumEndpoints: 0x02
bInterfaceClass: 0x0A -> This is a CDC Data USB Device Interface Class
bInterfaceSubClass: 0x00
bInterfaceProtocol: 0x00
iInterface: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x01 -> Direction: OUT - EndpointID: 1
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x81 -> Direction: IN - EndpointID: 1
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
STM32H7 的固件 FW1.4.0 工作不正常。我必须使用FW1.3.2和CubeMX 5.2.1.
但是如果我初始化 FMC 总线,虚拟 COM 端口再次工作不正常,如果我注释初始化,它再次工作正常
MX_USB_DEVICE_Init();
// MX_FMC_Init();
有趣的是,什么 C 函数:"fopen("COM6"、"r+")、fwrite、fgetc、fclose" - 在 Windows 10 和 FW1.4.0 中工作,无需端口配置。 FW1.4.0 的错误是在写入端口参数(波特率、位或其他)和虚拟 COM 端口 Windows 如果无法将参数写入 USB 设备
驱动程序出现异常
我有同样的问题,我可以读取设备并查看哪个 com 端口,但我无法打开一个。 (对于 CDC)
然后我遇到了以下 post,最后一个答案解决了我的问题:
https://community.st.com/s/question/0D50X00009XkgIYSAZ/unable-to-configure-serial-port-error-for-usb-cdc
那里提到如果你想通过 VCP 进行 RS232 通信,你需要添加几行。
我在 usbd_cdc_if.c 文件中添加了以下内容:
/*******************************************************************************/
/* Line Coding Structure */
/*-----------------------------------------------------------------------------*/
/* Offset | Field | Size | Value | Description */
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
/* 4 | bCharFormat | 1 | Number | Stop bits */
/* 0 - 1 Stop bit */
/* 1 - 1.5 Stop bits */
/* 2 - 2 Stop bits */
/* 5 | bParityType | 1 | Number | Parity */
/* 0 - None */
/* 1 - Odd */
/* 2 - Even */
/* 3 - Mark */
/* 4 - Space */
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
/*******************************************************************************/
static uint8_t lineCoding[7] // 115200bps, 1stop, no parity, 8bit
= { 0x00, 0xC2, 0x01, 0x00, 0x00, 0x00, 0x08 };
并调整了CDC_Control_FS函数:
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
/* USER CODE BEGIN 5 */
switch(cmd)
{
...
case CDC_SET_LINE_CODING:
memcpy(lineCoding, pbuf, sizeof(lineCoding));
break;
case CDC_GET_LINE_CODING:
memcpy(pbuf, lineCoding, sizeof(lineCoding));
break;
...
}
我希望这对你仍然有用。
我有 Nucleo STM32H743ZI 开发板。我正在使用 CubeMX HAL(我尝试了几个版本)和 TrueStudio。 "Virtual COM port"出现在Windows10(我试过默认的Windows驱动和ST驱动)但是我不能打开端口。我的 C# 程序在我尝试打开它时给我写了 "The parameter is incorrect":
SerialPort port = new SerialPort("COM8", 9600, Parity.None, 8, StopBits.One);
port.Open(); // System.IO.IOException: 'The parameter is incorrect.'
同样的消息写给我程序 Realterm,PuTTY 什么都不做,"Tera Term" 程序工作正常 - 我可以向我的 MCU 程序发送和接收数据。
有谁知道是什么吗?
在我的 C# 程序和终端程序中我使用相同的参数
USB 设备查看器信息:
[Port1] : STMicroelectronics Virtual COM Port
Is Port User Connectable: yes
Is Port Debug Capable: no
Companion Port Number: 17
Companion Hub Symbolic Link Name: USB#ROOT_HUB30#4&2f29167c&0&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
Protocols Supported:
USB 1.1: yes
USB 2.0: yes
USB 3.0: no
Device Power State: PowerDeviceD0
---===>Device Information<===---
English product name: "STM32 Virtual ComPort"
ConnectionStatus:
Current Config Value: 0x01 -> Device Bus Speed: Full (is not SuperSpeed or higher capable)
Device Address: 0x0A
Open Pipes: 3
===>Device Descriptor<===
bLength: 0x12
bDescriptorType: 0x01
bcdUSB: 0x0200
bDeviceClass: 0x02 -> This is a Communication Device
bDeviceSubClass: 0x00
bDeviceProtocol: 0x00
bMaxPacketSize0: 0x40 = (64) Bytes
idVendor: 0x0483 = STMicroelectronics
idProduct: 0x5740
bcdDevice: 0x0200
iManufacturer: 0x01
English (United States) "STMicroelectronics"
iProduct: 0x02
English (United States) "STM32 Virtual ComPort"
iSerialNumber: 0x03
English (United States) "354BB9433137"
bNumConfigurations: 0x01
---===>Open Pipes<===---
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x82 -> Direction: IN - EndpointID: 2
bmAttributes: 0x03 -> Interrupt Transfer Type
wMaxPacketSize: 0x0008 = 0x08 bytes
bInterval: 0x10
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x01 -> Direction: OUT - EndpointID: 1
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x81 -> Direction: IN - EndpointID: 1
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
---===>Full Configuration Descriptor<===---
===>Configuration Descriptor<===
bLength: 0x09
bDescriptorType: 0x02
wTotalLength: 0x0043 -> Validated
bNumInterfaces: 0x02
bConfigurationValue: 0x01
iConfiguration: 0x00
bmAttributes: 0xC0 -> Self Powered
MaxPower: 0x32 = 100 mA
===>Interface Descriptor<===
bLength: 0x09
bDescriptorType: 0x04
bInterfaceNumber: 0x00
bAlternateSetting: 0x00
bNumEndpoints: 0x01
bInterfaceClass: 0x02 -> This is Communications (CDC Control) USB Device Interface Class
bInterfaceSubClass: 0x02
bInterfaceProtocol: 0x01
iInterface: 0x00
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 00 10 01
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 01 00 01
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x04
bDescriptorType: 0x24
04 24 02 02
-> This is a Communications (CDC Control) USB Device Interface Class
===>Descriptor Hex Dump<===
bLength: 0x05
bDescriptorType: 0x24
05 24 06 00 01
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x82 -> Direction: IN - EndpointID: 2
bmAttributes: 0x03 -> Interrupt Transfer Type
wMaxPacketSize: 0x0008 = 0x08 bytes
bInterval: 0x10
===>Interface Descriptor<===
bLength: 0x09
bDescriptorType: 0x04
bInterfaceNumber: 0x01
bAlternateSetting: 0x00
bNumEndpoints: 0x02
bInterfaceClass: 0x0A -> This is a CDC Data USB Device Interface Class
bInterfaceSubClass: 0x00
bInterfaceProtocol: 0x00
iInterface: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x01 -> Direction: OUT - EndpointID: 1
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
===>Endpoint Descriptor<===
bLength: 0x07
bDescriptorType: 0x05
bEndpointAddress: 0x81 -> Direction: IN - EndpointID: 1
bmAttributes: 0x02 -> Bulk Transfer Type
wMaxPacketSize: 0x0040 = 0x40 bytes
bInterval: 0x00
STM32H7 的固件 FW1.4.0 工作不正常。我必须使用FW1.3.2和CubeMX 5.2.1.
但是如果我初始化 FMC 总线,虚拟 COM 端口再次工作不正常,如果我注释初始化,它再次工作正常
MX_USB_DEVICE_Init();
// MX_FMC_Init();
有趣的是,什么 C 函数:"fopen("COM6"、"r+")、fwrite、fgetc、fclose" - 在 Windows 10 和 FW1.4.0 中工作,无需端口配置。 FW1.4.0 的错误是在写入端口参数(波特率、位或其他)和虚拟 COM 端口 Windows 如果无法将参数写入 USB 设备
驱动程序出现异常我有同样的问题,我可以读取设备并查看哪个 com 端口,但我无法打开一个。 (对于 CDC)
然后我遇到了以下 post,最后一个答案解决了我的问题: https://community.st.com/s/question/0D50X00009XkgIYSAZ/unable-to-configure-serial-port-error-for-usb-cdc
那里提到如果你想通过 VCP 进行 RS232 通信,你需要添加几行。
我在 usbd_cdc_if.c 文件中添加了以下内容:
/*******************************************************************************/
/* Line Coding Structure */
/*-----------------------------------------------------------------------------*/
/* Offset | Field | Size | Value | Description */
/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/
/* 4 | bCharFormat | 1 | Number | Stop bits */
/* 0 - 1 Stop bit */
/* 1 - 1.5 Stop bits */
/* 2 - 2 Stop bits */
/* 5 | bParityType | 1 | Number | Parity */
/* 0 - None */
/* 1 - Odd */
/* 2 - Even */
/* 3 - Mark */
/* 4 - Space */
/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */
/*******************************************************************************/
static uint8_t lineCoding[7] // 115200bps, 1stop, no parity, 8bit
= { 0x00, 0xC2, 0x01, 0x00, 0x00, 0x00, 0x08 };
并调整了CDC_Control_FS函数:
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
/* USER CODE BEGIN 5 */
switch(cmd)
{
...
case CDC_SET_LINE_CODING:
memcpy(lineCoding, pbuf, sizeof(lineCoding));
break;
case CDC_GET_LINE_CODING:
memcpy(pbuf, lineCoding, sizeof(lineCoding));
break;
...
}
我希望这对你仍然有用。