9 years, 11 months ago.

RTOS maximum number of threads

My target mbed device is LPC1768. I have a bit confused about maximum number of threads that I can create. I am not able to create more than 4 threads. So, are there any idea about this issue?

2 Answers

9 years, 11 months ago.

The OS_TASKCNT is set to 14 for the TARGET_LPC1768. See RTX_Conf_CM.c. You should create 13 threads + main. What is the error ?

Yes, I have checked the OS_TASKCNT, it is 14. Here is a part of my code;

int main()
{
    //Start Threads 
    Thread threadUDP(UDP_thread);
    Thread threadRS485(RS485_thread);
    Thread threadGPIO(GPIO_thread);
    Thread threadRS232_1(RS232_1_thread);
    Thread threadRS232_2(RS232_2_thread);

    
    //Infinite Loop 
    while (1) 
    {
    	led1 = !led1;              
    	Thread::wait(1000);
    }
}

First of all, there is no comply error. The code is working. However, I can see that just first 4 threads(UDP_thread, RS485_thread, GPIO_thread and RS232_1 thread) are working. Even, "infinite loop" is not working. It is sure that I have a mistake, but I couldnt find where I need to check.

posted by Bora YILDIZ 25 Apr 2014

As I mentioned before there is no comply error. There is a functional problem after 4th thread. In the attached code threadRS232_2 and infinite loop is not working. But first 4 thread(threadUDP, threadRS485, threadGPIO, threadRS232_1) are working fine. Actually, the code is a bit more complicated. But I put a simplified version. Here is a bit detailed, but still there is no thread codes.

//**************************************************************************
//MAIN
//**************************************************************************
int main()
{

    //Initialize the System
    mainStart();
    
    //Start Threads (CURRENTLY, IT IS NOT POSSIBLE TO WORK WITH MORE THAN 4 THREADS) ASK TO SUPPORT!
    Thread threadUDP(UDP_thread);
    //Thread threadRS485(RS485_thread);
    Thread threadGPIO(GPIO_thread);
    Thread threadRS232_1(RS232_1_thread);
    //Thread threadRS232_2(RS232_2_thread);

    
    //Infinite Loop 
    while (1) 
    {
    led1 = !led1;              
    Thread::wait(1000);
    }
}


//**************************************************************************
// MAIN START
//**************************************************************************
void mainStart()
{
    //SYSTEM CONFIGURATION
    read_ConfigFile();
    
    //ETHERNET Use Static
    ethernet.init(IPAddress.c_str(), SubnetMask.c_str(), Gateway.c_str());     
    ethernet.connect();
    
    //UDP Init    
    UDP_server.bind(UDP_PORT);
    
    //RS485 Init
    RS485.baud(9600);
       
    //RS232_1 Init
    RS232_1.baud(9600);
    
    //RS232_2 Init
    RS232_2.baud(9600);
    RS232_2.format(8, Serial::Odd, 1);
    
    //GPIO
    GPIO1.mode(PullUp);
    GPIO2.mode(PullUp);
    GPIO3.mode(PullUp);
    GPIO4.mode(PullUp);
    GPIO5.mode(PullUp);
    GPIO6.mode(PullUp);
    GPIO7.mode(PullUp);
    GPIO8.mode(PullUp);
    
    //IR Init
    IR1 = 0.0f;
    IR2 = 0.0f;
    IR3 = 0.0f;
    IR4 = 0.0f;
    IR5 = 0.0f;
    IR6 = 0.0f;
     
    //System Initialize OK
    printf("System Initialize OK...\n");
    
}

My idea is that there is a memory issue. But I couldnt resolve the problem still. Are there any document about memory handling in RTOS?

Thanks, Bora

posted by Bora YILDIZ 10 May 2014
8 years, 9 months ago.

I'm getting similar problems. I have 8 threads, CPU is hanging very early. If I comment 4 of those threads, everything run fine, except that I don't have those 4 other threads anymore. I think I won't have choice to run things in the same thread to reduce threads count. :-(

I'm getting similar problems. But when I try fix INITIAL_SP in file RTX_CM_lib.h , it worked! In my case,

  1. elif defined(TARGET_STM32F103RB)
  2. define INITIAL_SP (0x20005000UL)
posted by Phuc Nguyen 25 Dec 2015