Skip to main content
Visitor II
August 23, 2022
Question

FreeRTOS and mail HardFault. Is the heap size? stack size? memory allocation?

  • August 23, 2022
  • 4 replies
  • 2416 views

Hello!

I have a STM32F407VET6 with FreeRTOS continuously receiving data, normally 250-300 characters every 4[ms], by UART+DMA, when it receives a '\n' and idle-line sends the data received to a mailbox(8 mails length). Then a receiver task get one mail from the mailbox and sends the data by USB.

The problem is that after 3-5 minutes operating I get a HardFault error and the STM32 stucks. The UART+DMA should be OK, I have tested it before and the when I disable the receiver tasks no HardFault error occurs. So, I think the receiver tasks is the problem, but what can be reason of this HardFault? Is the heap size? stack size? memory allocation?

Thank you!

    This topic has been closed for replies.

    4 replies

    Super User
    August 23, 2022

    Did you search this forum for the (hundreds?) other times this has been asked?

    If you are using CubeIDE, it has a fault analyzer that tells you what type of fault and the address of the instruction that caused the fault. If you are not using CubeIDE (or another IDE that has a built-in fault analyzer), then you need to add your own. Again, search this forum, @Community member​ (I think) has posted some examples in the past.

    SGonz.2Author
    Visitor II
    August 23, 2022

    I didnt found nor know that CubeIDE has a fault analyzer, thank you!

    I found that the problem is en HAL_TIM_IRQHandler() in the following line (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) with PRECISERR flag and htim1. I'm using TIM1 as SYS timebase source. Any idea?

    Super User
    August 24, 2022

    Do you have TWO hard faults in your program? See new topic: https://community.st.com/s/question/0D53W00001ksuL6SAI/freertos-and-usb-uart-preciserr-hardfault-any-idea

    As @Community member​ said in the other post, probably accessing an illegal address. The PC in the fault handler stack gives you the exact instruction that caused the fault. Look at the register it was using and see where it pointed. Also see PM0214 (ST Cortem M4 Programming Manual) section 4.4.12 for more info on faults and the meaning of the flags.

    If the line you show above is really the offender, my guess is "htim" is corrupted.

    Explorer
    March 25, 2025

    Did you find a solution? I have the same fault after UART+DMA interrupt.