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

Bug on STM32F2 USB Low Layer HAL #13066

Closed
RamiroOliveira opened this issue Feb 5, 2019 · 6 comments
Closed

Bug on STM32F2 USB Low Layer HAL #13066

RamiroOliveira opened this issue Feb 5, 2019 · 6 comments
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 priority: low Low impact/importance bug

Comments

@RamiroOliveira
Copy link

Describe the bug
When creating a composite device using #12682 on a STM32 Nucleo F207ZG board, the kernel panics.
According to addr2line the faulty error occurs in ext/hal/st/stm32cube/stm32f2xx/drivers/src/stm32f2xx_ll_usb.c on line 573 because ep->maxpacket is 0 when a division operation occurs.

Using other boards (stm32f072b-disco) this issue doesn't occur which might point to an error on the F2 USB LL HAL.

Seems related with #7364.

@erwango @finikorg @ydamigos @loicpoulain

To Reproduce
Steps to reproduce the behavior:

  1. Pull PR USB Multi-instance support #12682
  2. Navigate to samples/subsys/usb/cdc_acm_composite/
    3 mkdir build; cd build
  3. cmake -DBOARD=nucleo_f207zg ..
  4. make flash
  5. Open console on ttyACM*
    minicom --device /dev/ttyACM0
    minicom --device /dev/ttyACM1
    minicom --device /dev/ttyACM2
  6. See error

Expected behavior
The sample should run without error and data sent from ACM1 should appear on ACM2 and vice-versa.

Impact
Kernel crashes

Screenshots or console output

Wait for DTR
DTR set, start test
Baudrate detected: 57600
Baudrate detected: 57600
***** USAGE FAULT *****
Division by zero
***** Hardware exception *****
Current thread ID = 0x20000a2c
Faulting instruction address = 0x8001ae8
Fatal fault in essential thread! Spinning...

Environment (please complete the following information):

@RamiroOliveira RamiroOliveira added the bug The issue is a bug, or the PR is fixing a bug label Feb 5, 2019
@galak galak added the priority: low Low impact/importance bug label Feb 5, 2019
@ydamigos
Copy link
Collaborator

ydamigos commented Feb 5, 2019

@RamiroOliveira Following the steps above, I tested cdc_acm_composite sample on olimexino_stm32 and stm32f3_disco. It works fine. But on my 96b_carbon kernel I get the same error.
A first observation is that the issue affects devices with OTGFS controller.

@loicpoulain
Copy link
Collaborator

loicpoulain commented Feb 8, 2019

@RamiroOliveira, @finikorg, @ydamigos , correct me if I'm wrong but AFAIU, CDC ACM requires 3 endpoints per instance whereas stm32f4 (and f2) usb otgfs offers only four bidirectional endpoints, which makes impossible to run the acm composite sample. I, however, agree that we should gracefully fail at build or runtime in such situation.

Note: It also explains why it works with stm32f3_disco (8 bidir endpoints)

@jfischer-no
Copy link
Collaborator

The stack should not start with this configuration, usb_validate_ep_cfg_data (and usb_dc_ep_check_cap in the driver) would fail. @RamiroOliveira can you please set USB_DRIVER_LOG_LEVEL to debug and post the console output?

@finikorg
Copy link
Collaborator

finikorg commented Feb 8, 2019

@RamiroOliveira, @finikorg, @ydamigos , correct me if I'm wrong but AFAIU, CDC ACM requires 3 endpoints per instance whereas stm32f4 (and f2) usb otgfs offers only four bidirectional endpoints, which makes impossible to run the acm composite sample. I, however, agree that we should gracefully fail at build or runtime in such situation.

Note: It also explains why it works with stm32f3_disco (8 bidir endpoints)

Do you mean DT_USB_NUM_BIDIR_ENDPOINTS. It has 4 endpoint in each direction, so should be just fine.

@galak galak added the platform: STM32 ST Micro STM32 label Feb 8, 2019
@ydamigos
Copy link
Collaborator

ydamigos commented Feb 9, 2019

@jfischer-phytec-iot The console output on my 96b_carbon:
96b_carbon-cdc_acm_composite-error-log.txt

For some reason HAL_PCD_EP_Open() in not called for ep 0x84. Later we try to write to ep 0x84 which is not opened (and, as a result, its maxpacket size is not configured, so it is zero) and stm32cube HAL function USB_EPStartXfer() fails because it contains a division with ep 0x84 maxpacker size.

Edit:
I tweaked the usb_dc_ep_enable() to print ep->state and it was NULL for ep 0x84.

...
[00:00:00.467,949] <dbg> usb_dc_stm32.usb_dc_ep_enable: ep 0x84 state was NULL
...

@ydamigos
Copy link
Collaborator

ydamigos commented Feb 9, 2019

As @loicpoulain mentioned (96b_carbon) stm32f4 offers 4 bidirectional endpoints (including EP0) so it can't run acm composite sample. DT_USB_NUM_BIDIR_ENDPOINTS includes EP0 so we need to take it into account when we check endpoint capabilities (usb_dc_ep_check_cap).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

7 participants