Skip to main content
Associate II
July 10, 2023
Question

USB not working in hard fault handler

  • July 10, 2023
  • 8 replies
  • 2566 views

I am trying to dump stack trace from hard fault handler using usb, but the usb not working in hardfault handler.

Any one please help me to know why usb not working in  hard fault handler, if there is a way to use usb in hard fault handler

This topic has been closed for replies.

8 replies

ST Technical Moderator
July 10, 2023

Hello @Anand m ,

Can you please share more details on your issue? Which hardware using ?

Did you check registers? Are you able to breakpoint in hardfault?

Try increase stack size.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
Anand mAuthor
Associate II
July 14, 2023

Thanks for your replay , i am using stm32L4 series and i increased the stack size but it not working inside hard fault

which register i need to check?

 

waclawek.jan
Super User
July 10, 2023

Hardfault is an interrupt of the highest priority. As USB runs using interrupts, those interrupts cannot be invoked until you leave the hardfault handler. Whether that's a good idea, is up to you to decide.

JW

Anand mAuthor
Associate II
July 14, 2023

Thanks for your replay , i am just a beginner

I am using stm32L4 series, is there any way to run usb inside the hardfault handler

waclawek.jan
Super User
July 15, 2023

> is there any way to run usb inside the hardfault handler

Not really (the long answer is, that it's not impossible, but with effort which is far beyond reasonable and far beyond capabilities of not only beginners).

Also, hardfault means that something went wrong, and you don't know, what went wrong. So, you don't want to run anything complicated in the hardfault . And USB *is* very, very complicated.

Better way is to have simpler means to communicate, e.g. through UART. Best is to use a debugger connected through SWD, such as STLink.

JW

Pavel A.
July 15, 2023

Or even save the debug info to SRAM, then do software reset (SRAM usually survives it) and send it out early in your program.

Tesla DeLorean
Guru
July 15, 2023

As Jan points out this is a bit of a gross-failure, and shouldn't happen in a normal system. If you exit the Hard Fault Handler into something else, at that point the interrupts should work again. Unless say it failed inside a USB interrupt.

You can put in sanity checking for pointers, etc, and have those report prior to critical failure, or as Pavel suggests report post-failure then next time you come up.

More practically use a regular serial / uart to spit out failure statistics. Again probably not going to be able to use interrupts / buffering in the normal sense.

 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..