hathach / tinyusb

An open source cross-platform USB stack for embedded system
https://www.tinyusb.org
MIT License
4.92k stars 1.03k forks source link

synopsys dcd_dwc2 device mode bug #1528

Open ClarkyKent opened 2 years ago

ClarkyKent commented 2 years ago

Operating System

Linux

Board

STM32H743x

Firmware

I am using custom FW where FreeRTOS is used and have 2 CDC in device mode. Vbus sensing is enabled.

What happened ?

If I power on the board with USB already connected. Everything is fine. 2 USB com ports get detected on host machine(Linux/Windows) and everything woks fine as intended. But if I power on our board without USB(as board has a battery as main source of power) and I do not attach USB, STM32H743 resets itself as soon as it executes connect dcd_connect(rhport);

How to reproduce ?

In order to reproduce this bug, it is important to have a board which is powered by a battery instead of USB. and then run any example from example. STM32h7 should reset when it tries to connect to USB after dcd_connect(rhport); command.

Debug Log as txt file

No response

Screenshots

No response

ClarkyKent commented 2 years ago

I have kind of found the solution to this. so replying here.

Once I have removed this following line in function dcd_init everything work as as intended. // Clear A override, force B Valid //dwc2->gotgctl = (dwc2->gotgctl & ~GOTGCTL_AVALOEN) | GOTGCTL_BVALOEN | GOTGCTL_BVALOVAL;

Even-though MCU is powered on and stack BLE is initialized, it does not resets itself anymore. and if i connect an USB , it starts to enumerate and it shows USB device on HOST machine.

I do not know if forcing B valid is necessary , and when i see the manual of STM32H7 it states that these registers are available only in Host mode.

image

image

hathach commented 2 years ago

In order to reproduce this bug, it is important to have a board which is powered by a battery instead of USB. and then run any example from example. STM32h7 should reset when it tries to connect to USB after dcd_connect(rhport); command.

can you specify which example to run and on which specific dev board.

ClarkyKent commented 2 years ago

Till now I tested on my custom PCB with STM32H743II for dual_cdc (with freertos)

EDIT: After building cdc_msc_freertos example code, on STM32H743ZI nucleo board it seems MCU does not resets itself with Nucleo board. But at the same time if removing line in dcd_init as stated in my previous post does not have any negative effect as well.

I will investigate further and let you know.

hathach commented 2 years ago

also, on your custom board, did the reset happen with bare-metal example e.g cdc_msc (without freertos) ?