cancel
Showing results for 
Search instead for 
Did you mean: 

Why the MCU hangs?

Mujtaba
Senior

Dear friends,

I am using STM32F107RCt6 MCU and I am running a TCP server on it using LwIP and freeRTOS.

The total heap size of freeRTOS is 10KB and there are two tasks which each task has 256 wods stack. One task is used for Modbus TCP server and the other one is used for Modbus RTU thread.

The Modbus RTU thread works correctly alone and everything works fine but when I add the Modbus TCP server, the MCU hangs and stops working and both tasks don't work anymore.

I am using the latest version of CubeMX and STM32F1 hal libraries.

Any helps would be appreciate,

Mujtaba

10 REPLIES 10
saiteja
Associate II

It is a Software problem check your code once.

AvaTar
Lead

You need to dig deeper.

You can go the simple way, and single-step the code to check where it fails, or work backward from the fault.

Probably a core hardfault.

Thanks for your quick reply.

I have done it using examples provided by ST.

I create a netconn tcp connection and then listen to the clients trying to connect to.

After receiving data from clients, and sending back the data to the client, the connections is closed and netbuff is deleted.

Could you give me more information where to check?

Thanks for your quick reply.

I have done it using examples provided by ST.

I create a netconn tcp connection and then listen to the clients trying to connect to.

After receiving data from clients, and sending back the data to the client, the connections is closed and netbuff is deleted.

Could you give me more information where to check?

Thanks for your quick reply.

the problem is, it doen’t stop working immediately.

Sometimes it took more than 5 6 hours and even more.

The Client is a C# software application that monitors the mcu.

Is there anyway to connect the debugger to the MCU and it does not reset the MCU as soon as it connects to it?

I use st-link v2 debugger.

i have never worked on tcp connection with STM controller but MCU's mostly hang due to deadlock.

Did you call any error handler function...?

option

Do one thing when you are adding the modbus it has to enter in to one function. In that function starting put led on and give delay of 100ms and at function end make the led off. so that you get some confirmation about function so, try to crack that function code.

I donot think mcu gets lock because there are two tasks running and uf the tcp server thread gets lock somewhere, the other task most work correctly.

I believe it is a hardfault error but I can’t find where it is.

The code works correctly hours and hours but at some point it enters in one of fault errors handler and when I attach the debugger (st-link v2), it restarts the mcu and it works fine again.

You mean plug the debugger in afterwards and postmortem? Always a bit hit-n-miss in my experience. Make sure not to "connect under reset", but rather "hot plug", in the connection options.

For a real time system you'd do much better with instrumentation to understand flow and interaction, and have diagnostic output in Error_Handler and HardFault_Handler to provide clear and actionable data.

Check also for adequate heap and stack allocations, and have routines to observe/measure stack depth periodically.

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

Hi I am using STM32L1 series microcontroller in meter when I connect my meter to MODBUS it become hang. I don't know what is the problem.

I made changes in my code I added watchdog timer in my code but It restart the device not store the values.

could you please help me outwith this issue?