2025-01-13 12:45 AM - edited 2025-01-13 12:46 AM
Hello everyone,
I’m encountering an issue with the srand() function in my STM32H747 project, and I would appreciate your insights on what might be causing this problem.
Hardware:
Software setup:
Whenever I call the srand() function, my code immediately ends up in the exit handler.
To troubleshoot, I created a minimal project with no additional middleware (bare minimum setup), and in that setup, the srand() function works without any issues.
However, in my main project where I need both lwIP and FreeRTOS, calling srand() causes an exit. The project was created following this guide:
How to Create a Project for STM32H7 with Ethernet and lwIP Stack.
I made one modification to the guide: instead of using the default OS wrapper, I selected CMSIS_V2.
Currently, I am only using the M7 core.
I’ve attached an image showing the callstack where the issue occurs. I hope this helps in diagnosing the problem.
Here’s a link to my code: GitHub Repository
Does anyone have any ideas on what might be causing this issue? Could it be related to the use of CMSIS_V2, a conflict with FreeRTOS, or possibly a memory issue?
Thank you in advance for your help!
Best regards,
Oskar
2025-01-13 04:12 AM
Do you think it’s possible that this could be a hardware issue since I’m using a custom board? Also, I want to thank you — your input has already been very helpful!
2025-01-13 04:13 AM
@OskarP wrote:
Do you think it’s possible that this could be a hardware issue since I’m using a custom board?
I don't think so.. Hardfault is caused by something in the code and not by the hardware.
2025-01-13 05:00 AM
I’m currently using CubeIDE 1.17.0. I’ll try it on another PC with a fresh, clean installation of CubeIDE and will get back to you with the results.
2025-01-13 05:19 AM
Do you have a ST board: NUCLEO or DISCO so you can have a try?
2025-01-13 05:41 AM
So, I tried running the code compiled with a different new installation of CubeIDE 1.17.0, but I’m still encountering the same error.
Unfortunately, I don’t have an official ST board or a second custom board, as this is the first prototype. I will order a Nucleo or Discovery board and give it a try once it arrives.
In the meantime, I’ve added the code from my CubeIDE project. Maybe you can check if it works on your board.
2025-01-13 05:49 AM
Off-topic: Do you think the STM32H747I-DISCO is the right option for me, or is there another board that uses the STM32H747 microcontroller you would recommend?
2025-01-13 06:22 AM - edited 2025-01-13 06:23 AM
That depends on what you will do with it. STM32H747I-DISCO is OK but for this test I can recommend NUCLEO-H755 (cheaper than STM32H747I-DISCO).
2025-01-13 06:34 AM
But there is no srand() call in the attached project.
Put srand() in one of USER CODE START/ USER CODE END block, so when you generate the code it will not be removed.
2025-01-13 08:13 AM
I ordered the suggested Nucleo board for further testing. I will try to debug the hard fault using the tips provided in this thread: https://community.st.com/t5/stm32-mcus/how-to-debug-a-hardfault-on-an-arm-cortex-m-stm32/ta-p/672235
I have attached the latest code, where I moved the srand() call to USER CODE 2.
Best regards,
OskarP