7 years, 10 months ago.

About CMSIS-rots create thread beside the main.cpp

hi I'm trying to use osThreadCreate to create a thread

it's find on write on the main.cpp

But when I use it on the test.cpp file I create

the thread cant work!

this is my code

main.cpp

  1. include "mbed.h"
  2. include "cmsis_os.h"
  3. include "rtos.h"

void dump(const char* out); void test_thread(); void test1(void const *arg); extern void test3(void const *arg); Serial pc(USBTX, USBRX);

int main() { pc.baud(115200);

pc.printf("\n\rstart example\r\n");

test_thread();create thread test3 in the test_thread.cpp error

  1. if 1 osThreadDef (test1, osPriorityNormal, 512); osThreadCreate( osThread(test1), NULL);
  1. endif
  2. if 0 osThreadDef (test3, osPriorityNormal, 512); osThreadCreate( osThread(test1), NULL);
  1. endif

while(1) { pc.printf("\n\rentere delay\r\n"); osDelay (1000); } }

void test1(void const *arg){

while(1){

pc.printf("test1\n"); osDelay (1000);

} }

test_thread.cpp

  1. include "mbed.h"
  2. include "cmsis_os.h"
  3. include "rtos.h"

void test_thread(); void test3(void const*);

extern Serial pc;

  1. if 1 void test_thread(){

printf("create test3\n"); osThreadDef (test3, osPriorityNormal, 512); osThreadCreate( osThread(test3), NULL);

}

void test3(void const *arg){ osStatus status; while(1){ pc.printf("test3-1\n"); osDelay (1000); } }

}

  1. endif

in the main.cpp it look find when turn the 0 to 1 to create thread test3 in the main.cpp but it cant work when i use the function test_thread() to creat thread test3 on test_thread.cpp(it compile success). it will get stuck after printing create test3.

I have no idea to fix it thanks!

Be the first to answer this question.