From b9bef6b06e5a76f7543b32b61f6fd679e58ea8c0 Mon Sep 17 00:00:00 2001 From: ohagendorf Date: Fri, 2 Jan 2015 14:52:39 +0100 Subject: [PATCH] [DISCO/NUCLEO_L053xx] adding to RTOS - part3 Reverting the DEFAULT_STACK_SIZE changes in cmsis.oh.h and adding changes to RTOS_x tests, to create threads with the neccessary reduced stack sizes for these targets. --- libraries/rtos/rtx/TARGET_CORTEX_M/cmsis_os.h | 6 +----- libraries/tests/rtos/mbed/basic/main.cpp | 13 ++++++++++++- libraries/tests/rtos/mbed/isr/main.cpp | 13 ++++++++++++- libraries/tests/rtos/mbed/mail/main.cpp | 13 ++++++++++++- libraries/tests/rtos/mbed/mutex/main.cpp | 15 +++++++++++++-- libraries/tests/rtos/mbed/queue/main.cpp | 13 ++++++++++++- libraries/tests/rtos/mbed/semaphore/main.cpp | 17 ++++++++++++++--- libraries/tests/rtos/mbed/signals/main.cpp | 13 ++++++++++++- 8 files changed, 88 insertions(+), 15 deletions(-) diff --git a/libraries/rtos/rtx/TARGET_CORTEX_M/cmsis_os.h b/libraries/rtos/rtx/TARGET_CORTEX_M/cmsis_os.h index d8fcf8edd0..9f90ace987 100644 --- a/libraries/rtos/rtx/TARGET_CORTEX_M/cmsis_os.h +++ b/libraries/rtos/rtx/TARGET_CORTEX_M/cmsis_os.h @@ -121,11 +121,7 @@ used throughout the whole project. # define WORDS_STACK_SIZE 128 #endif -#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8) -# define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*1) -#else -# define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4) -#endif +#define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4) /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS. diff --git a/libraries/tests/rtos/mbed/basic/main.cpp b/libraries/tests/rtos/mbed/basic/main.cpp index 8cd33bd692..f1cf79f573 100644 --- a/libraries/tests/rtos/mbed/basic/main.cpp +++ b/libraries/tests/rtos/mbed/basic/main.cpp @@ -1,6 +1,17 @@ #include "mbed.h" #include "rtos.h" +/* + * 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_STM32L053R8) || defined(TARGET_STM32L053C8) +#define STACK_SIZE DEFAULT_STACK_SIZE/4 +#else +#define STACK_SIZE DEFAULT_STACK_SIZE +#endif + void print_char(char c = '*') { printf("%c", c); @@ -19,7 +30,7 @@ void led2_thread(void const *argument) { } int main() { - Thread thread(led2_thread); + Thread thread(led2_thread, NULL, osPriorityNormal, STACK_SIZE); while (true) { led1 = !led1; diff --git a/libraries/tests/rtos/mbed/isr/main.cpp b/libraries/tests/rtos/mbed/isr/main.cpp index 5b6b272f59..2855b7cede 100644 --- a/libraries/tests/rtos/mbed/isr/main.cpp +++ b/libraries/tests/rtos/mbed/isr/main.cpp @@ -7,6 +7,17 @@ #define QUEUE_PUT_ISR_VALUE 128 #define QUEUE_PUT_THREAD_VALUE 127 +/* + * 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_STM32L053R8) || defined(TARGET_STM32L053C8) + #define STACK_SIZE DEFAULT_STACK_SIZE/4 +#else + #define STACK_SIZE DEFAULT_STACK_SIZE +#endif + Queue queue; DigitalOut myled(LED1); @@ -25,7 +36,7 @@ void queue_thread(void const *argument) { } int main (void) { - Thread thread(queue_thread); + Thread thread(queue_thread, NULL, osPriorityNormal, STACK_SIZE); Ticker ticker; ticker.attach(queue_isr, 1.0); int isr_puts_counter = 0; diff --git a/libraries/tests/rtos/mbed/mail/main.cpp b/libraries/tests/rtos/mbed/mail/main.cpp index d1d9440f76..21aaf783bc 100644 --- a/libraries/tests/rtos/mbed/mail/main.cpp +++ b/libraries/tests/rtos/mbed/mail/main.cpp @@ -13,6 +13,17 @@ typedef struct { #define QUEUE_SIZE 16 #define QUEUE_PUT_DELAY 100 +/* + * 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_STM32L053R8) || defined(TARGET_STM32L053C8) + #define STACK_SIZE DEFAULT_STACK_SIZE/4 +#else + #define STACK_SIZE DEFAULT_STACK_SIZE +#endif + Mail mail_box; void send_thread (void const *argument) { @@ -29,7 +40,7 @@ void send_thread (void const *argument) { } int main (void) { - Thread thread(send_thread); + Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE); bool result = true; int result_counter = 0; diff --git a/libraries/tests/rtos/mbed/mutex/main.cpp b/libraries/tests/rtos/mbed/mutex/main.cpp index 9983c4228c..7f8987800f 100644 --- a/libraries/tests/rtos/mbed/mutex/main.cpp +++ b/libraries/tests/rtos/mbed/mutex/main.cpp @@ -5,6 +5,17 @@ #define THREAD_DELAY 50 #define SIGNALS_TO_EMIT 100 +/* + * 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_STM32L053R8) || defined(TARGET_STM32L053C8) + #define STACK_SIZE DEFAULT_STACK_SIZE/4 +#else + #define STACK_SIZE DEFAULT_STACK_SIZE +#endif + void print_char(char c = '*') { printf("%c", c); @@ -52,8 +63,8 @@ int main() { const int t1_delay = THREAD_DELAY * 1; const int t2_delay = THREAD_DELAY * 2; const int t3_delay = THREAD_DELAY * 3; - Thread t2(test_thread, (void *)t2_delay); - Thread t3(test_thread, (void *)t3_delay); + Thread t2(test_thread, (void *)t2_delay, osPriorityNormal, STACK_SIZE); + Thread t3(test_thread, (void *)t3_delay, osPriorityNormal, STACK_SIZE); while (true) { // Thread 1 action diff --git a/libraries/tests/rtos/mbed/queue/main.cpp b/libraries/tests/rtos/mbed/queue/main.cpp index ec4e78ec77..cff0e071ff 100644 --- a/libraries/tests/rtos/mbed/queue/main.cpp +++ b/libraries/tests/rtos/mbed/queue/main.cpp @@ -13,6 +13,17 @@ typedef struct { #define QUEUE_SIZE 16 #define QUEUE_PUT_DELAY 100 +/* + * 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_STM32L053R8) || defined(TARGET_STM32L053C8) + #define STACK_SIZE DEFAULT_STACK_SIZE/4 +#else + #define STACK_SIZE DEFAULT_STACK_SIZE +#endif + MemoryPool mpool; Queue queue; @@ -31,7 +42,7 @@ void send_thread (void const *argument) { } int main (void) { - Thread thread(send_thread); + Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE); bool result = true; int result_counter = 0; diff --git a/libraries/tests/rtos/mbed/semaphore/main.cpp b/libraries/tests/rtos/mbed/semaphore/main.cpp index 15cb8ce793..f474367303 100644 --- a/libraries/tests/rtos/mbed/semaphore/main.cpp +++ b/libraries/tests/rtos/mbed/semaphore/main.cpp @@ -6,6 +6,17 @@ #define SEMAPHORE_SLOTS 2 #define SEM_CHANGES 100 +/* + * 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_STM32L053R8) || defined(TARGET_STM32L053C8) + #define STACK_SIZE DEFAULT_STACK_SIZE/4 +#else + #define STACK_SIZE DEFAULT_STACK_SIZE +#endif + void print_char(char c = '*') { printf("%c", c); @@ -41,9 +52,9 @@ int main (void) { const int t1_delay = THREAD_DELAY * 1; const int t2_delay = THREAD_DELAY * 2; const int t3_delay = THREAD_DELAY * 3; - Thread t1(test_thread, (void *)t1_delay); - Thread t2(test_thread, (void *)t2_delay); - Thread t3(test_thread, (void *)t3_delay); + Thread t1(test_thread, (void *)t1_delay, osPriorityNormal, STACK_SIZE); + Thread t2(test_thread, (void *)t2_delay, osPriorityNormal, STACK_SIZE); + Thread t3(test_thread, (void *)t3_delay, osPriorityNormal, STACK_SIZE); while (true) { if (change_counter >= SEM_CHANGES or sem_defect == true) { diff --git a/libraries/tests/rtos/mbed/signals/main.cpp b/libraries/tests/rtos/mbed/signals/main.cpp index 6df01c1618..38c68daa26 100644 --- a/libraries/tests/rtos/mbed/signals/main.cpp +++ b/libraries/tests/rtos/mbed/signals/main.cpp @@ -6,6 +6,17 @@ #define SIGNAL_HANDLE_DELEY 25 #define SIGNAL_SET_VALUE 0x01 +/* + * 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_STM32L053R8) || defined(TARGET_STM32L053C8) + #define STACK_SIZE DEFAULT_STACK_SIZE/4 +#else + #define STACK_SIZE DEFAULT_STACK_SIZE +#endif + DigitalOut led(LED1); volatile int signal_counter = 0; @@ -19,7 +30,7 @@ void led_thread(void const *argument) { } int main (void) { - Thread thread(led_thread); + Thread thread(led_thread, NULL, osPriorityNormal, STACK_SIZE); bool result = true; while (true) {