cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with srand() causing exit in STM32H747 Project with FreeRTOS and lwIP

OskarP
Associate

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:

  • MCU: STM32H747IIT6
  • Custom board

Software setup:

  • CubeMX-generated project
  • Cube CLT version: 1.17
  • Firmware version: 1.12.1

Problem Description

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.

What I’ve Tried So Far

  • Minimal project without lwIP and FreeRTOS -> srand(12345) works fine.
  • Project with lwIP and FreeRTOS -> srand(12345) causes an exit.

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

Callstack.JPG

18 REPLIES 18

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!


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

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: Be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

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.

Do you have a ST board: NUCLEO or DISCO so you can have a try?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: Be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

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.

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?

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

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: Be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: Be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

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