diff --git a/TESTS/mbedmicro-rtos-mbed/threads/main.cpp b/TESTS/mbedmicro-rtos-mbed/threads/main.cpp index 24438409331..1fb638b3cd9 100644 --- a/TESTS/mbedmicro-rtos-mbed/threads/main.cpp +++ b/TESTS/mbedmicro-rtos-mbed/threads/main.cpp @@ -10,6 +10,17 @@ #error [NOT_SUPPORTED] test not supported #endif +/* + * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and + * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes + * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize. + */ +#if defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) + #define STACK_SIZE 512 +#else + #define STACK_SIZE DEFAULT_STACK_SIZE +#endif + using namespace utest::v1; // The counter type used accross all the tests @@ -32,7 +43,7 @@ void increment_with_wait(counter_t* counter) { } void increment_with_child(counter_t* counter) { - Thread child(counter, increment); + Thread child(counter, increment, osPriorityNormal, STACK_SIZE); child.join(); } @@ -41,7 +52,7 @@ void increment_with_murder(counter_t* counter) { // take ownership of the counter mutex so it prevent the child to // modify counter. LockGuard lock(counter->internal_mutex()); - Thread child(counter, increment); + Thread child(counter, increment, osPriorityNormal, STACK_SIZE); child.terminate(); } @@ -52,7 +63,7 @@ void increment_with_murder(counter_t* counter) { template void test_single_thread() { counter_t counter(0); - Thread thread(&counter, F); + Thread thread(&counter, F, osPriorityNormal, STACK_SIZE); thread.join(); TEST_ASSERT_EQUAL(counter, 1); } @@ -63,7 +74,7 @@ void test_parallel_threads() { Thread *threads[N]; for (int i = 0; i < N; i++) { - threads[i] = new Thread(&counter, F); + threads[i] = new Thread(&counter, F, osPriorityNormal, STACK_SIZE); } for (int i = 0; i < N; i++) { @@ -79,7 +90,7 @@ void test_serial_threads() { counter_t counter(0); for (int i = 0; i < N; i++) { - Thread thread(&counter, F); + Thread thread(&counter, F, osPriorityNormal, STACK_SIZE); thread.join(); }