Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tun_umount_cb is not called for stm32f4xx #2872

Closed
1 task done
milabs opened this issue Nov 10, 2024 · 9 comments
Closed
1 task done

tun_umount_cb is not called for stm32f4xx #2872

milabs opened this issue Nov 10, 2024 · 9 comments
Labels

Comments

@milabs
Copy link

milabs commented Nov 10, 2024

Operating System

Linux

Board

STM32F4XX M

Firmware

cdc+dwc2

What happened ?

related to #1476

How to reproduce ?

cdc + dwc2 + USB configuration: D+/D- only, no VBUS pin used

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)


-- board reset

USBD init on controller 0, speed = Full
sizeof(usbd_device_t) = 44
sizeof(dcd_event_t) = 12
sizeof(tu_fifo_t) = 12
sizeof(tu_edpt_stream_t) = 20
CDC init
guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4
0x00001200, 0x4F54281A, 0x00000000, 0x229DCD20, 0x020001E8, 0x0FF08030
Fullspeed PHY init

-- usb cable plugged

    TX FIFO 0: allocated 16 words at offset 304
USBD Bus Reset : Full Speed

USBD Setup Received 80 06 00 01 00 00 40 00
  Get Descriptor Device
  Queue EP 80 with 18 bytes ...
USBD Xfer Complete on EP 80 with 18 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Bus Reset : Full Speed

USBD Setup Received 00 05 17 00 00 00 00 00
  Set Address
USBD Xfer Complete on EP 80 with 0 bytes

USBD Setup Received 80 06 00 01 00 00 12 00
  Get Descriptor Device
  Queue EP 80 with 18 bytes ...
USBD Xfer Complete on EP 80 with 18 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 00 06 00 00 0A 00
  Get Descriptor Device Qualifier
  Stall EP0

USBD Setup Received 80 06 00 06 00 00 0A 00
  Get Descriptor Device Qualifier
  Stall EP0

USBD Setup Received 80 06 00 06 00 00 0A 00
  Get Descriptor Device Qualifier
  Stall EP0

USBD Setup Received 80 06 00 02 00 00 09 00
  Get Descriptor Configuration[0]
  Queue EP 80 with 9 bytes ...
USBD Xfer Complete on EP 80 with 9 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 00 02 00 00 4B 00
  Get Descriptor Configuration[0]
  Queue EP 80 with 64 bytes ...
USBD Xfer Complete on EP 80 with 64 bytes
  Queue EP 80 with 11 bytes ...
USBD Xfer Complete on EP 80 with 11 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 00 03 00 00 FF 00
  Get Descriptor String[0]
  Queue EP 80 with 4 bytes ...
USBD Xfer Complete on EP 80 with 4 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 02 03 09 04 FF 00
  Get Descriptor String[2]
  Queue EP 80 with 32 bytes ...
USBD Xfer Complete on EP 80 with 32 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 01 03 09 04 FF 00
  Get Descriptor String[1]
  Queue EP 80 with 30 bytes ...
USBD Xfer Complete on EP 80 with 30 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 03 03 09 04 FF 00
  Get Descriptor String[3]
  Queue EP 80 with 34 bytes ...
USBD Xfer Complete on EP 80 with 34 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 00 09 01 00 00 00 00 00
  Set Configuration
  Open EP 81 with Size = 4
    TX FIFO 1: allocated 1 words at offset 303
  Open EP 02 with Size = 64
  Open EP 82 with Size = 64
    TX FIFO 2: allocated 16 words at offset 287
  Queue EP 02 with 64 bytes ...
  CDC opened
  Bind EP 81 to driver id 0
  Bind EP 02 to driver id 0
  Bind EP 82 to driver id 0
  Queue EP 80 with 0 bytes ...
USBD Xfer Complete on EP 80 with 0 bytes

USBD Setup Received 80 06 04 03 09 04 FF 00
  Get Descriptor String[4]
  Queue EP 80 with 52 bytes ...
USBD Xfer Complete on EP 80 with 52 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 21 20 00 00 00 00 07 00
  CDC control request
  Set Line Coding
  Queue EP 00 with 7 bytes ...
USBD Xfer Complete on EP 00 with 7 bytes
  0000:  80 25 00 00 00 00 08                             |.%.....|
CDC control complete
  Queue EP 80 with 0 bytes ...
USBD Xfer Complete on EP 80 with 0 bytes

-- usb cable unplugged

USBD Suspend : Remote Wakeup = 0

-- usb cable plugged

USBD Suspend : Remote Wakeup = 0
    TX FIFO 0: allocated 16 words at offset 304
USBD Bus Reset : Full Speed

USBD Setup Received 80 06 00 01 00 00 40 00
  Get Descriptor Device
  Queue EP 80 with 18 bytes ...
USBD Xfer Complete on EP 80 with 18 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes
USBD Bus Reset : Full Speed

USBD Setup Received 00 05 19 00 00 00 00 00
  Set Address
USBD Xfer Complete on EP 80 with 0 bytes

USBD Setup Received 80 06 00 01 00 00 12 00
  Get Descriptor Device
  Queue EP 80 with 18 bytes ...
USBD Xfer Complete on EP 80 with 18 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 00 06 00 00 0A 00
  Get Descriptor Device Qualifier
  Stall EP0

USBD Setup Received 80 06 00 06 00 00 0A 00
  Get Descriptor Device Qualifier
  Stall EP0

USBD Setup Received 80 06 00 06 00 00 0A 00
  Get Descriptor Device Qualifier
  Stall EP0

USBD Setup Received 80 06 00 02 00 00 09 00
  Get Descriptor Configuration[0]
  Queue EP 80 with 9 bytes ...
USBD Xfer Complete on EP 80 with 9 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 00 02 00 00 4B 00
  Get Descriptor Configuration[0]
  Queue EP 80 with 64 bytes ...
USBD Xfer Complete on EP 80 with 64 bytes
  Queue EP 80 with 11 bytes ...
USBD Xfer Complete on EP 80 with 11 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 00 03 00 00 FF 00
  Get Descriptor String[0]
  Queue EP 80 with 4 bytes ...
USBD Xfer Complete on EP 80 with 4 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 02 03 09 04 FF 00
  Get Descriptor String[2]
  Queue EP 80 with 32 bytes ...
USBD Xfer Complete on EP 80 with 32 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 01 03 09 04 FF 00
  Get Descriptor String[1]
  Queue EP 80 with 30 bytes ...
USBD Xfer Complete on EP 80 with 30 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 80 06 03 03 09 04 FF 00
  Get Descriptor String[3]
  Queue EP 80 with 34 bytes ...
USBD Xfer Complete on EP 80 with 34 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 00 09 01 00 00 00 00 00
  Set Configuration
  Open EP 81 with Size = 4
    TX FIFO 1: allocated 1 words at offset 303
  Open EP 02 with Size = 64
  Open EP 82 with Size = 64
    TX FIFO 2: allocated 16 words at offset 287
  Queue EP 02 with 64 bytes ...
  CDC opened
  Bind EP 81 to driver id 0
  Bind EP 02 to driver id 0
  Bind EP 82 to driver id 0
  Queue EP 80 with 0 bytes ...
USBD Xfer Complete on EP 80 with 0 bytes

USBD Setup Received 80 06 04 03 09 04 FF 00
  Get Descriptor String[4]
  Queue EP 80 with 52 bytes ...
USBD Xfer Complete on EP 80 with 52 bytes
  Queue EP 00 with 0 bytes ...
USBD Xfer Complete on EP 00 with 0 bytes

USBD Setup Received 21 20 00 00 00 00 07 00
  CDC control request
  Set Line Coding
  Queue EP 00 with 7 bytes ...
USBD Xfer Complete on EP 00 with 7 bytes
  0000:  80 25 00 00 00 00 08                             |.%.....|
CDC control complete
  Queue EP 80 with 0 bytes ...
USBD Xfer Complete on EP 80 with 0 bytes

-- usb cable plugged

USBD Suspend : Remote Wakeup = 0

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
@milabs milabs changed the title tun_umoun_cb is not called for stm32f4xx tun_umount_cb is not called for stm32f4xx Nov 10, 2024
@milabs
Copy link
Author

milabs commented Nov 10, 2024

Note, that in my test USBD Suspend : Remote Wakeup = 0 event does NOT always come on USB cable plug. So, it seems that at least that logic doesn't work well.

@HiFiPhile
Copy link
Collaborator

It's normal that tud_umount_cb() doesn't called on cable unplug, the information is not returned by DCD without Vbus connected.
You need also use tud_suspend_cb() for unplug detection.

@milabs
Copy link
Author

milabs commented Nov 10, 2024

tud_suspend_cb is not called every time I plug/unplug either, so it's not reliable as I see ... any ideas? @HiFiPhile

@HiFiPhile
Copy link
Collaborator

tud_suspend_cb is not called every time I plug/unplug either, so it's not reliable as I see ... any ideas? @HiFiPhile

Are you testing with stock examples ? Please post your schematic.

@milabs
Copy link
Author

milabs commented Nov 11, 2024

I'm using the following board:
https://stm32-base.org/boards/STM32F407VGT6-STM32F4XX-M.html

Board's schematic:
https://stm32-base.org/assets/pdf/boards/original-schematic-STM32F407VGT6_STM32F4XX_M.pdf

I don't use stock examples and here us a snippet with USB initialization of my project:

        long do_init(void) {
                GPIO_InitTypeDef gpio = { 0 };

                __HAL_RCC_GPIOA_CLK_ENABLE();

                //
                // NOTE: We use that code to reset USB on RESET so it'll be
                //       possible to open ttyACM right after flashing
                //

                gpio.Pin = GPIO_PIN_11 | GPIO_PIN_12;
                gpio.Mode = GPIO_MODE_OUTPUT_PP;
                gpio.Pull = GPIO_NOPULL;
                HAL_GPIO_Init(GPIOA, &gpio);

                //
                // 250ms delay is enough to wait after USB reset
                //

                HAL_Delay(250);

                // USB_OTG_FS GPIO Configuration
                // -----------------------------
                //   PA11 => USB_OTG_FS_DM
                //   PA12 => USB_OTG_FS_DP

                gpio.Pin = GPIO_PIN_11 | GPIO_PIN_12;
                gpio.Mode = GPIO_MODE_AF_PP;
                gpio.Pull = GPIO_NOPULL;
                gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
                gpio.Alternate = GPIO_AF10_OTG_FS;
                HAL_GPIO_Init(GPIOA, &gpio);

                // Peripheral clock enable
                __HAL_RCC_USB_OTG_FS_CLK_ENABLE();

                HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
                HAL_NVIC_EnableIRQ(OTG_FS_IRQn);

                // STM32F407VGT6 doesn't use VBUS sense (B device) explicitly disable it
                USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
                USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
                USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;

                return HAL_OK;
        }

@HiFiPhile
Copy link
Collaborator

I'm afraid it's more like a hardware limitation, on STM32F4-DISCO with HS breakout cable I managed to reproduce it (although pretty rare)

Sometimes nothing triggered in DWC2 when cable is unplugged, even not the early suspend flag.

@milabs
Copy link
Author

milabs commented Nov 11, 2024

@HiFiPhile Any API call I can use to force tinyusb to switch to disconnected state manually? Let's say I have ping/pong logic implemented on top of my data protocol so I can check if it timed out.

@HiFiPhile
Copy link
Collaborator

Any API call I can use to force tinyusb to switch to disconnected state manually

There is no dedicated API since the issue is specific to DWC2, but tud_deinit(BOARD_TUD_RHPORT); tud_init(BOARD_TUD_RHPORT); should do the job to reset state machine.

@milabs
Copy link
Author

milabs commented Nov 13, 2024

@HiFiPhile Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants