Skip to main content
Visitor II
July 28, 2020
Solved

STM32F0 Audio device HardFault_Handler(); error problem.

  • July 28, 2020
  • 3 replies
  • 3980 views

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.

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

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

    3 replies

    Visitor II
    July 28, 2020

    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

    MWask.1Author
    Visitor II
    July 28, 2020

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

    Visitor II
    July 28, 2020

    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

    Visitor II
    July 29, 2020

    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.

    MWask.1Author
    Visitor II
    July 29, 2020

    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

    Visitor II
    July 29, 2020

    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

    MWask.1Author
    Visitor II
    July 29, 2020

    Oh thank you all for your time. Problem has been resolved.

    Technical Moderator
    August 6, 2020

    Hello @MWask.1​ ,

    Please share the way that solved your problem, it may be helpful for other community users.

    Then, please select the post of user which is "Best Answer" or mark your post as answered the question,

    Best Regards,

    Imen

    MWask.1Author
    Visitor II
    August 12, 2020

    Hi @Imen DAHMEN​ ,

    This uC can not be used as Audio device. The reason is not enough RAM as @Community member​  and @prain​  stated. To resolve the problem I switched to different STM32 with enough memory for the task.