cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault_Handler after enable USB CDC and FreeRTOS

Khairul Akmal Zulkepli
Associate II

Hai, I having a problem with HardFault_Handler when I enable USB CDC and FreeRTOS. I have change the Stack and Heap size. Im using STM32F4 DISCOVERY board with latest STM32 IDE. Could someone point out what i have missing?

FOR USB

------------

1) Connectivity : USB_OTG_FS with Device_Only mode and disable VBUS

2) Middleware : USB_DEVICE, Class For FS IP : Communication Device Class

3) System Core : RCC, High Speed Clock (HSE) = Crystal. Low Speed Clock (LSE) : Crystal

FOR RTOS

--------------

1) System Core : SYS, Timebase Source : TIM6

2) Middleware : FREERTOS, Interface : CMSIS_V2

2 REPLIES 2
Bob S
Principal

> Could someone point out what i have missing?

Code in your fault handler to dump the fault register contents so you can see where your program was when the fault happened, and what the CPU might have been doing. Or the CubeIDE should have a debug window that decodes all that for you.

There are known issues with FreeRTOS and malloc() as described in the links below. And if you use printf(), you may be calling malloc() and not knowing it. So next try this:

https://community.st.com/s/question/0D50X0000BB1eL7SQJ/bug-cubemx-freertos-projects-corrupt-memory

Or if you don't want to go through all of that thread, it eventually points to this page where @Dave Nadler​ describes all the steps needed to make malloc

http://www.nadler.com/embedded/newlibAndFreeRTOS.html

Khairul Akmal Zulkepli
Associate II

Peace be upon you Bob S. Thanks for your answer it help me a lot. I have found the solution for my problems. Change the CMSIS_V2 to CMSIS_V1.

FOR USB

------------

1) Connectivity : USB_OTG_FS with Device_Only mode and disable VBUS

2) Middleware : USB_DEVICE, Class For FS IP : Communication Device Class

3) System Core : RCC, High Speed Clock (HSE) = Crystal. Low Speed Clock (LSE) : Crystal

FOR RTOS

--------------

1) System Core : SYS, Timebase Source : TIM6

2) Middleware : FREERTOS, Interface : CMSIS_V1