繁体   English   中英

STM32F4 的 USB CDC 设置和库出现问题

[英]Problem with USB CDC settings and libraries for STM32F4

我正在为STM32F401RBT6嵌入式应用程序,我正在尝试与 PC(Windows 10)建立连接,但系统无法识别该设备。 我由STMCubeMX生成并由Atollic调试的代码不起作用。 我看到并尝试重现几个示例,但任何方法都有效。 在代码中,我有我认为必要的所有库。

档案 档案2

我有这个由STMCubeMXCDC通信生成的档案,但我是新手,我不知道我必须对系统识别的 USB 的代码进行哪些修改。 有人可以帮助我吗?

Inside USBD_CDC_Init(..) function there is a malloc function which allocates about 540 Bytes memory on the Heap.

生成代码时,CubeMX 没有考虑到这一点。

因此,至少您必须在考虑这些额外字节的情况下定义堆大小,以使 USB CDC 端口正常工作。

除了 Soup(默认情况下只有 0x200 的堆导致的失败 malloc)之外,某些 Windows 版本在示例中的行编码有问题。

在 usbd_cdc_if.c 中,您应该添加:

/* USER CODE BEGIN PRIVATE_VARIABLES */
USBD_CDC_LineCodingTypeDef LineCoding =
    {
    115200, /* baud rate*/
    0x00,   /* stop bits-1*/
    0x00,   /* parity - none*/
    0x08    /* nb. of bits 8*/
    };

下面一点

static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
.
.
.
case CDC_SET_LINE_CODING:
    LineCoding.bitrate    = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\
                            (pbuf[2] << 16) | (pbuf[3] << 24));
    LineCoding.format     = pbuf[4];
    LineCoding.paritytype = pbuf[5];
    LineCoding.datatype   = pbuf[6];

break;

case CDC_GET_LINE_CODING:
    pbuf[0] = (uint8_t)(LineCoding.bitrate);
    pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8);
    pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16);
    pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24);
    pbuf[4] = LineCoding.format;
    pbuf[5] = LineCoding.paritytype;
    pbuf[6] = LineCoding.datatype;
break;

因此,如果主机尝试设置线路编码,他将不会得到未定义的数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM