簡體   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