STM32F412 problem with full speed usb driver #stm32 #usb


Stefan Jaritz
 

Hej

In the last weeks there were some works on the USB driver regarding full speed and high speed. For me it seems, that some of these changes are breaking my code. Any one with the same problem?

I am attaching my test code, config and ubuntu syslog prints.


dmesg print:
[ 2198.025679] usb 1-5.2: device not accepting address 34, error -71
[ 2198.105302] usb 1-5.2: new full-speed USB device number 35 using xhci_hcd
[ 2198.105466] usb 1-5.2: Device not responding to setup address.
[ 2198.313357] usb 1-5.2: Device not responding to setup address.
[ 2198.521263] usb 1-5.2: device not accepting address 35, error -71
[ 2198.521371] usb 1-5-port2: unable to enumerate USB device

dts file:
&usbotg_fs {
    status = "ok";
};

board defconfig
CONFIG_USB=y
CONFIG_USB_DC_STM32=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_VID=0x2FE4
CONFIG_USB_DEVICE_PID=0x1
CONFIG_USB_DEVICE_MANUFACTURER="aaaa"
CONFIG_USB_DEVICE_PRODUCT="bbb"
CONFIG_USB_CDC_ACM=y
CONFIG_USB_COMPOSITE_DEVICE=n
CONFIG_USB_MASS_STORAGE=n

CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_DRV_CMD=y
CONFIG_UART_STM32_PORT_1=y
CONFIG_UART_STM32_PORT_3=y

main.c
typedef struct usb_uart {
    struct device *dev;
    struct k_sem data_arrived;
    uint8_t data_buf[64];
    int ready;
} usb_uart_t;
static usb_uart_t gUSBuart = {
    .ready = 0
};

static void usb_uart_interrupt_handler(struct device *dev)
{
    uart_irq_update(dev);

    if (uart_irq_rx_ready(dev)) {
        k_sem_give(&gUSBuart.data_arrived);
    }
}

static void usb_uart_write_data(const uint8_t * src, int n)
{
    if(!gUSBuart.ready) return;
    for(int i = 0; i < n; i++) {
        uart_poll_out(gUSBuart.dev, src[i]);
    }
}

static void usbUartThread(void) {

    u32_t baudrate, bytes_read, dtr = 0;
    int ret;

    gUSBuart.ready = 0;
    gUSBuart.dev = device_get_binding(CONFIG_CDC_ACM_PORT_NAME);
    if (!gUSBuart.dev) {
        printk("CDC ACM device not found\n");
        return;
    }

    k_sem_init(&gUSBuart.data_arrived, 0, 1);

    printk("Wait for DTR\n");
    while (1) {
        uart_line_ctrl_get(gUSBuart.dev, LINE_CTRL_DTR, &dtr);
        k_sleep(MSEC_PER_SEC * 1);
        if (dtr) break;
    }
    printk("DTR set, start test\n");

    /* They are optional, we use them to test the interrupt endpoint */
    ret = uart_line_ctrl_set(gUSBuart.dev, LINE_CTRL_DCD, 1);
    if (ret) {
        printk("Failed to set DCD, ret code %d\n", ret);
    }

    ret = uart_line_ctrl_set(gUSBuart.dev, LINE_CTRL_DSR, 1);
    if (ret) {
        printk("Failed to set DSR, ret code %d\n", ret);
    }

    /* Wait 1 sec for the host to do all settings */
    // k_busy_wait(1000000);

    ret = uart_line_ctrl_get(gUSBuart.dev, LINE_CTRL_BAUD_RATE, &baudrate);
    if (ret) {
        printk("Failed to get baudrate, ret code %d\n", ret);
    } else {
        printk("Baudrate detected: %d\n", baudrate);
    }

    // try to set baudrate
    baudrate = 460800;
    printk("try to set baudrate to %d\n", baudrate);
    ret = uart_line_ctrl_set(gUSBuart.dev, LINE_CTRL_BAUD_RATE, baudrate);
    if (ret) {
        printk("Failed to set baudrate to %d, ret code %d\n", baudrate, ret);
    } else {
        uart_line_ctrl_get(gUSBuart.dev, LINE_CTRL_BAUD_RATE, &baudrate);
        printk("Baudrate set to %d\n", baudrate);
    }

    uart_irq_callback_set(gUSBuart.dev, usb_uart_interrupt_handler);
    uart_irq_rx_enable(gUSBuart.dev);

    gUSBuart.ready = 1;

    // do nothing
    while (1) {
        k_sleep(MSEC_PER_SEC * 60);
    }
}

K_THREAD_DEFINE(usbUartThread_id, STACKSIZE, usbUartThread, NULL, NULL, NULL, PRIORITY, 0, K_NO_WAIT);

Join users@lists.zephyrproject.org to automatically receive all group messages.