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

usbtrace causes crash #12181

Open
Virus-V opened this issue Apr 19, 2024 · 3 comments
Open

usbtrace causes crash #12181

Virus-V opened this issue Apr 19, 2024 · 3 comments

Comments

@Virus-V
Copy link
Contributor

Virus-V commented Apr 19, 2024

When I was debugging the STM32F405 USB function, I encountered a crash.

image

It seemed that the data structure was damaged.

The cause of this problem is that the interrupt was responded to in the critical section.

This problem only occurred after I turned on the USB DEBUG function.

image

I found that in the syslog_putc function, different output functions are called according to the current calling context.

image

However, it does not handle the current situation in the critical section, resulting in task scheduling and interrupts being turned on in the critical section.

@acassis
Copy link
Contributor

acassis commented Apr 19, 2024

@Virus-V nice work finding and debugging this issue! Kudos!!!

@xiaoxiang781216 @raiden00pl any suggestion?

@Virus-V maybe using RAMLOG as SYSLOG instead of SYSLOG over serial could help, them you just run dmesg later to see what happened.

Note: take care with using USB Trace, as Greg explained some years ago: when you add tracing you are changing the timing of USB and it could introduce issues.

@xiaoxiang781216
Copy link
Contributor

This is a known issue we found many time before: #1138
One possible solution postpone the preemption until leave_critical_section.

@Virus-V
Copy link
Contributor Author

Virus-V commented Apr 20, 2024

It is unsafe to call syslog in a critical section.

Not only usbdev, there are similar codes in other drivers in nuttx (such as drivers/timers/pwm.c).

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

No branches or pull requests

3 participants