cancel
Showing results for 
Search instead for 
Did you mean: 

How to debug multi-threading problems

fakheri.ali
Associate II

Hi everyone.

we had performed a project with discovery f746 board that within it there just was a GUI task to run emwin functions.

Another functions(such as reading and writing in sd card by fatfs , usb, spi and stuff) were placed in the routines of Buttons.

After several times the process of USB (writing in USB flash memory) was ran , 

the running process stuck in RTOS's functions.

After that we decided to add another thread for USB In such a way that, after pressing related button ,a message is sent to this thread.

At the first it works fine but after several times running this thread, mkdir function (for creating a folder in USB flash memory) returns FR_NOT_ENOUGH_CORE value and the program stops running.

For resolving this problem we increased stack and heap size and memory that is assigned to the thread but it didn't affect.

Could anyone help us to resolve this problem?

We'll appreciate your suggestions.

6 REPLIES 6
T J
Lead

Inside your interrupts, only set status flags and store streams in static buffers.

in a single multipurpose worker thread, check all the flags & buffers and process all printf statements,

fakheri.ali
Associate II

Hi TJ.

Thanks for your reply.

In new version of our project we just added a new thread and the routine that was placed in Notification sent by related button was moved into new thread and another sections of projects haven't changed.

In old version of project that there just was one thread , mkdir function never had returned FR_NOT_ENOUGH_CORE value.

Actually we don't know how to check all the flags & buffers and process all printf statements.

It seems this problem is related to multi threading but we don't know how to find out running process and fix problem.

T J
Lead

I suggest that you roll back to a working solution and rework your updated functionality..

Need to instrument to understand flow.

For memory allocators, you're going to need to be able to walk the descriptors in the chain to understand memory usage and free space. Look for resource leaks, and fragmentation.

Other method is to wrap the malloc/free type calls to track who/what is allocating, when the call fails, when the free acts on memory already freed, and periodically looking for orphans where memory doesn't get freed on certain exit paths.

Check stack depth and heap integrity periodically so you can identify the culprits early

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

Hi Clive Two.Zero

Thanks for your reply.

In our project we have an sd card that some files and folders are saved on it.Now we've added USB msc mode in our project and we want when user press the "USB" button those files and folders saved on sd card would be transferred on USB flash memory.

As I mentioned in first post after several times running the routine (send files and folders on USB flash memory), mkdir and fopen functions return FR_NOT_ENOUGH_CORE.

Now we want to delete usbthread when the data are sent completely and when user press "USB" button again the usbthread be created again and in the end of thread, usbthread deleted.Unfortunately we couldn't do this until now.

I attached the code here.

If it's possible please take a look at this.

Best Regards

fakheri.ali
Associate II