cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 Audio device HardFault_Handler(); error problem.

MWask.1
Associate II

Hi,

I am currently trying to develop the Audio device on STM32F0 to stream audio data from USB to IS2 signal, although It worked without any issues on STM32F4 discovery board, when I am trying to apply same logic for Nucleo32 It does not seem to work at all. Windows displays the board like so:0693W000003BUJlQAO.png

I will try to describe my problem in more details; after successful compilation, while debugging, program stops on HardFault_Handler(); . Code part that seems to be error cause is in usbd_audio.c file in Middlewares section of the project.

0693W000003BUKAQA4.png

I tried to add more heap memory to solve this issue but changing it in the project does not seem to affect STM32F042K6TX_FLASH.ld and when I change it manually it gives an compilation error.

 0693W000003BUKKQA4.png

0693W000003BUKZQA4.png

The code is generated through STM32CubeMX, I have not done anything to it. Still I will attach them if someone would like to look through it.

Am I on good track? Did anyone had that issue before? Please share your thoughts.

1 ACCEPTED SOLUTION

Accepted Solutions

Can't have a 15KB buffer in a 6KB part, reevaluate

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

View solution in original post

15 REPLIES 15
prain
Senior III

STM32CubeIDE has a view named hard fault analyzer. when you are in debug ​mode and hard fault happened, see that view. It has some information about source of failure. take snapshots of it and post here

Thank you for the answer! I actually used it to find the code i highlighted on this picture 0693W000003BUKAQA4.png

Does the project include RTOS? Increasing heap memory in cubemx does not affect freeRTOS heap size. Also be aware that freeRTOS use special malloc function that is thread safe. wrap your malloc to freeRTOS malloc

Yeah, but what assembler code and register values does it hard fault with?

What's failing here? The malloc, the pdev structure, the haudio structure?

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

No only middleware I use is USB_DEVICE

0693W000003BbKbQAK.png

About the assembly code and registers at fault I am linking them right here

0693W000003BbLtQAK.png0693W000003BbLUQA0.png

prain
Senior III

I think you are using the pointer "haudio" ​without initialization. It may be a null pointer. put a break point at line 349. when the break point hits, check the pointer value. It must point to an address in your RAM space.

Seems like the pointer value is 0, so you are right, although what I did in this project was just generating the files in CubeMx. Any idea how to solve this issue?0693W000003Be55QAC.png

Simple way is:

USB_AUDIO_HandleTypeDef audio;

haudio = &audio;

Or you can:

USB_AUDIO_HandleTypeDef haudio;

then use dot "." instead of "->" when you want to reference haudio. example:

haudio->offset turns to haudio.offset