Skip to content

USB-CDC times out #1175

@sago35

Description

@sago35

Sometimes bytes from fmt.Printf () disappear.

temperature: 70.699997
temperature: 70.699997
temperature: 70.699997
tmperature: 70.699997
temperature: 70.699997
temperature: 70.699997
temperature: 70.587494
temperature: 70.587494
temperature: 70.925003
temperature: 70.925003
tmperature: 70.925003
temperature: 72.274994
temperature: 72.274994
temperature: 73.625000

The reason is that there is no retry after a timeout.
However, increasing the number of busy loops will have an impact on performance.

// src/machine/machine_atsamd51.go
func (usbcdc USBCDC) WriteByte(c byte) error {
    if usbLineInfo.lineState > 0 {
        // set the data
        // ...

        // wait for transfer to complete
        timeout := 3000
        for (getEPINTFLAG(usb_CDC_ENDPOINT_IN) & sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT1) == 0 {
            timeout--
            if timeout == 0 {
                return errors.New("USBCDC write byte timeout")
            }
        }
    }

    return nil
}


// src/machine/usb.go
func (usbcdc USBCDC) Write(data []byte) (n int, err error) {
    for _, v := range data {
        usbcdc.WriteByte(v)
        // !!! If err! = nil, go to the next byte !!!
    }
    return len(data), nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions