Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 7 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
10 years, 7 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 25 Apr 2014As 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 10 May 20149 years, 4 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. :-(