Skip to main content
Visitor II
November 8, 2019
Question

Troubles with FreeRTOS-HardFaults-Mallocs etc

  • November 8, 2019
  • 5 replies
  • 1849 views

Hello all,

i'm facing a lot of troubles to run my server application on stm32.

The server runs in a task. I'm using FreeRTOS.

I can't explain everything here but i can share the code.

First of all my application goes into HardFault in a kinda random way, for example if i comment a printf...then i undo the comment and it doesn't go in hardfault anymore.. If i make a change, even minimum and useless, it goes into hardfault ?!?!?

Another issue is malloc returning nothing. The pointer keeps pointing at 0.

If i use malloc in the main, before the kernel start, it works correctly. If i use it in the task it doesn't work at all. I could probably find another way than using malloc but the hardfaults are the biggest issues.

If you want i can share the code.

    This topic has been closed for replies.

    5 replies

    Super User
    November 8, 2019

    Did you search the forums before posting? There have been MANY posts on this. Search for "freertos malloc" (without quotes) you should see

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

    and also check our Dave's summary page that he links to in that post.

    Graduate II
    November 8, 2019

    @Dave Nadler​  @Nawres GHARBI​ 

    Explorer
    November 8, 2019

    @Community member​ - Follow the instructions here to fix your problem:

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

    @Markus GIRDLAND​ - What's the status on STM fixing this?

    NXP ships the provided code with MCUxpresso...

    November 12, 2019

    Does this problem pertain to both v1 and v2 of FreeRTOS?

    Explorer
    November 12, 2019

    @Mikhail Z​ - I'm not sure what you're asking about.

    FreeRTOS versions distributed with CubeMX are 10.x (Amazon versions).

    CMSIS versions are V1and V2.

    Neither FreeRTOS version nor CMSIS version have anything to do with this issue; all versions are affected.

    Hope that is clear,

    Best Regards, Dave

    AGaruAuthor
    Visitor II
    November 18, 2019

    Hi guys,

    thank you for the replies.

    I'm not using mallocs anymore now and i managed to establish the comunication between the server and the client.

    I'm encountering hardfaults when i use HAL_UART_Transmit. It's odd though, because it only happens if i use it from a particular callback. There are other callbacks with HAL_UART_Transmit and everything is fine there...

    I fought with HardFaults for 1 week now and managed to overcome the most of them. But i don't know the main cause.

    How can i find it out? Is there any register that i can check?

    I am new to FreeRTOS so i'd need step by step instructions.

    Thank you for your help!

    Explorer
    January 6, 2020

    @AGaru​ - While you may not be using malloc, the STM runtime and newlib both use malloc internally. If you are still having problems, follow the instructions here:

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