I/O exception error when using serialport.open()

前端 未结 5 1622
礼貌的吻别
礼貌的吻别 2020-12-02 23:32

FINAL UPDATE

It was our firmware the whole time. Embarrassing to a degree, but I\'m happy we can move forward and I can put learning Java off for an

5条回答
  •  不思量自难忘°
    2020-12-02 23:58

    I faced a similar problem as reported in this thread, but I managed to solve the problem!

    I am using STM32F2xx for the VCP!

    And indeed it was my firmware problem. I forgot to include serial port settings in my USB callback!

    The process of connecting a serial port from PC and firmware:

    1. When a PC opens a serial port communication, the PC will send some command into the "configuration endpoint"
    2. In the firmware, it would have a callback and the firmware will provide all the USB information (they call it a USB descriptor)
    3. USB information is the configuration of each endpoint, (for example, latency, data size transmission, and type of USB - high speed or low speed)
    4. Once the firmware has completed sending all the information, the PC will acknowledge and USB communication is successfully opened
    5. Then, the PC will send a command to get the serial port settings from the firmware
    6. Serial port settings are baudrate, data parity, and bit length.
    7. In firmware, it should reply the serial port settings back to PC (my mistake occurs here; I didn’t not send any serial port settings back to the PC)
    8. If successful, PC will start the serial port communication!
    9. If failed, PC will give an open serial port error (but, do note that this error sometimes is bypassed)

    In STM32 firmware code:

    static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length)
    {
        switch (cmd) {
           case CDC_GET_LINE_CODING:
            {
                // I was missing this part
                uint32_t baudrate = 9600;
                pbuf[0] = (uint8_t)(baudrate);
                pbuf[1] = (uint8_t)(baudrate >> 8);
                pbuf[2] = (uint8_t)(baudrate >> 16);
                pbuf[3] = (uint8_t)(baudrate >> 24);
                pbuf[4] = 0;
                pbuf[5] = 0;
                pbuf[6] = 8;
                break;
            }:
    ....
    

提交回复
热议问题