cancel
Showing results for 
Search instead for 
Did you mean: 

Troubles with FreeRTOS-HardFaults-Mallocs etc

AGaru
Associate III

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.

7 REPLIES 7
Bob S
Principal

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.

@Dave Nadler​  @Nawres GHARBI​ 

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

@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...

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

@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

AGaru
Associate III

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!

@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