Skip to main content
Mujtaba
Associate III
December 7, 2018
Question

Why the MCU hangs?

  • December 7, 2018
  • 10 replies
  • 2763 views

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

    This topic has been closed for replies.

    10 replies

    saiteja
    Associate III
    December 7, 2018

    It is a Software problem check your code once.

    Mujtaba
    MujtabaAuthor
    Associate III
    December 7, 2018

    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?

    saiteja
    Associate III
    December 7, 2018

    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.

    AvaTar
    Senior III
    December 7, 2018

    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.

    Mujtaba
    MujtabaAuthor
    Associate III
    December 7, 2018

    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.

    Tesla DeLorean
    Guru
    December 7, 2018

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    PKuma.12
    Associate III
    May 2, 2019

    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?

    Tesla DeLorean
    Guru
    May 2, 2019

    Perhaps provide diagnostic or instrumentation output to understand the nature of the failure and the path it took to get there, rather than just add a watchdog to reset the processor when your code fails.

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