From 41585364a77e8d8491c958525d1f0446fe2772e9 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 20 Feb 2016 18:53:30 +0000 Subject: Updated CDC demos under testhal with new shell. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8916 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/OTGv1/usb_lld.c | 5 +- testhal/STM32/STM32F0xx/USB_CDC/Makefile | 9 ++- testhal/STM32/STM32F0xx/USB_CDC/main.c | 78 +++---------------- testhal/STM32/STM32F1xx/USB_CDC/Makefile | 9 ++- testhal/STM32/STM32F1xx/USB_CDC/main.c | 70 ++---------------- testhal/STM32/STM32F37x/USB_CDC/Makefile | 9 ++- testhal/STM32/STM32F37x/USB_CDC/main.c | 79 +++----------------- testhal/STM32/STM32F3xx/USB_CDC/Makefile | 9 ++- testhal/STM32/STM32F3xx/USB_CDC/main.c | 78 +++---------------- testhal/STM32/STM32F3xx/USB_CDC_IAD/Makefile | 9 ++- testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c | 99 ++++++++----------------- testhal/STM32/STM32F4xx/USB_CDC/Makefile | 9 ++- testhal/STM32/STM32F4xx/USB_CDC/main.c | 78 +++---------------- testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile | 9 ++- testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c | 107 +++++++++------------------ testhal/STM32/STM32F7xx/USB_CDC/main.c | 14 ++-- 16 files changed, 159 insertions(+), 512 deletions(-) diff --git a/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c b/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c index ffdaaf3ca..88be41d73 100644 --- a/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c +++ b/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c @@ -690,10 +690,7 @@ void usb_lld_init(void) { { void *wsp = USBD1.wa_pump; _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(thread_t), - CH_DBG_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(thread_t), - (uint8_t *)wsp + sizeof(USBD1.wa_pump), + (uint8_t *)wsp + sizeof (USBD1.wa_pump), CH_DBG_STACK_FILL_VALUE); } #endif /* CH_DBG_FILL_THREADS */ diff --git a/testhal/STM32/STM32F0xx/USB_CDC/Makefile b/testhal/STM32/STM32F0xx/USB_CDC/Makefile index 8f429b941..f424a1ef7 100644 --- a/testhal/STM32/STM32F0xx/USB_CDC/Makefile +++ b/testhal/STM32/STM32F0xx/USB_CDC/Makefile @@ -94,6 +94,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk # Other files (optional). include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk # Define linker script file here LDSCRIPT= $(STARTUPLD)/STM32F072xB.ld @@ -108,9 +110,8 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) \ - $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ + $(STREAMSSRC) \ + $(SHELLSRC) \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -142,7 +143,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) # # Project, sources and paths diff --git a/testhal/STM32/STM32F0xx/USB_CDC/main.c b/testhal/STM32/STM32F0xx/USB_CDC/main.c index 9029ab48e..809e389a2 100644 --- a/testhal/STM32/STM32F0xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F0xx/USB_CDC/main.c @@ -31,58 +31,6 @@ /*===========================================================================*/ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) -#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) - -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%08lx %08lx %4lu %4lu %9s %lu\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.r13, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state]); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { @@ -125,9 +73,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { } static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {"write", cmd_write}, {NULL, NULL} }; @@ -150,10 +95,12 @@ static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); while (true) { - systime_t time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500; - palClearPad(GPIOC, GPIOC_LED_RED); + systime_t time; + + time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500; + palClearLine(LINE_LED_RED); chThdSleepMilliseconds(time); - palSetPad(GPIOC, GPIOC_LED_RED); + palSetLine(LINE_LED_RED); chThdSleepMilliseconds(time); } } @@ -162,7 +109,6 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point. */ int main(void) { - thread_t *shelltp = NULL; /* * System initializations. @@ -201,15 +147,15 @@ int main(void) { chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and check the button state. + * Normal main() thread activity, spawning shells. */ while (true) { - if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) - shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp)) { - chThdRelease(shelltp); /* Recovers memory of the previous shell. */ - shelltp = NULL; /* Triggers spawning of a new shell. */ + if (SDU1.config->usbp->state == USB_ACTIVE) { + thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg1); + chThdWait(shelltp); /* Waiting termination. */ + chThdFreeToHeap(shelltp); /* Returning memory to heap. */ } chThdSleepMilliseconds(1000); } diff --git a/testhal/STM32/STM32F1xx/USB_CDC/Makefile b/testhal/STM32/STM32F1xx/USB_CDC/Makefile index f8d1947b7..2815c4568 100644 --- a/testhal/STM32/STM32F1xx/USB_CDC/Makefile +++ b/testhal/STM32/STM32F1xx/USB_CDC/Makefile @@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk # Other files (optional). include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk # Define linker script file here LDSCRIPT= $(STARTUPLD)/STM32F103xB.ld @@ -113,9 +115,8 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) \ - $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ + $(STREAMSSRC) \ + $(SHELLSRC) \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -147,7 +148,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) # # Project, sources and paths diff --git a/testhal/STM32/STM32F1xx/USB_CDC/main.c b/testhal/STM32/STM32F1xx/USB_CDC/main.c index b5f4231ef..17c49f749 100644 --- a/testhal/STM32/STM32F1xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F1xx/USB_CDC/main.c @@ -31,58 +31,6 @@ /*===========================================================================*/ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) -#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) - -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%08lx %08lx %4lu %4lu %9s %lu\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.r13, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state]); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { @@ -125,9 +73,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { } static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {"write", cmd_write}, {NULL, NULL} }; @@ -163,7 +108,6 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point. */ int main(void) { - thread_t *shelltp = NULL; /* * System initializations. @@ -202,15 +146,15 @@ int main(void) { chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and check the button state. + * Normal main() thread activity, spawning shells. */ while (true) { - if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) - shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp)) { - chThdRelease(shelltp); /* Recovers memory of the previous shell. */ - shelltp = NULL; /* Triggers spawning of a new shell. */ + if (SDU1.config->usbp->state == USB_ACTIVE) { + thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg1); + chThdWait(shelltp); /* Waiting termination. */ + chThdFreeToHeap(shelltp); /* Returning memory to heap. */ } chThdSleepMilliseconds(1000); } diff --git a/testhal/STM32/STM32F37x/USB_CDC/Makefile b/testhal/STM32/STM32F37x/USB_CDC/Makefile index 66ad54f5f..fa2a139a1 100644 --- a/testhal/STM32/STM32F37x/USB_CDC/Makefile +++ b/testhal/STM32/STM32F37x/USB_CDC/Makefile @@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk # Other files (optional). include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk # Define linker script file here LDSCRIPT= $(STARTUPLD)/STM32F373xC.ld @@ -113,9 +115,8 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ - $(CHIBIOS)/os/various/shell.c \ + $(STREAMSSRC) \ + $(SHELLSRC) \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -147,7 +148,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) # # Project, sources and paths diff --git a/testhal/STM32/STM32F37x/USB_CDC/main.c b/testhal/STM32/STM32F37x/USB_CDC/main.c index f4adc6683..20db587df 100644 --- a/testhal/STM32/STM32F37x/USB_CDC/main.c +++ b/testhal/STM32/STM32F37x/USB_CDC/main.c @@ -37,58 +37,6 @@ /*===========================================================================*/ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) -#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) - -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state time\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%08lx %08lx %4lu %4lu %9s\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.r13, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state]); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { @@ -131,9 +79,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { } static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {"write", cmd_write}, {NULL, NULL} }; @@ -154,13 +99,14 @@ static THD_WORKING_AREA(waThread1, 128); static THD_FUNCTION(Thread1, arg) { (void)arg; - chRegSetThreadName("blinker"); while (true) { - systime_t time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500; - palClearPad(GPIOC, GPIOC_LED1); + systime_t time; + + time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500; + palClearLine(LINE_LED1); chThdSleepMilliseconds(time); - palSetPad(GPIOC, GPIOC_LED1); + palSetLine(LINE_LED1); chThdSleepMilliseconds(time); } } @@ -169,7 +115,6 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point. */ int main(void) { - thread_t *shelltp = NULL; /* * System initializations. @@ -208,15 +153,15 @@ int main(void) { chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and check the button state. + * Normal main() thread activity, spawning shells. */ while (true) { - if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) - shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp)) { - chThdRelease(shelltp); /* Recovers memory of the previous shell. */ - shelltp = NULL; /* Triggers spawning of a new shell. */ + if (SDU1.config->usbp->state == USB_ACTIVE) { + thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg1); + chThdWait(shelltp); /* Waiting termination. */ + chThdFreeToHeap(shelltp); /* Returning memory to heap. */ } chThdSleepMilliseconds(1000); } diff --git a/testhal/STM32/STM32F3xx/USB_CDC/Makefile b/testhal/STM32/STM32F3xx/USB_CDC/Makefile index 2eb85bcf4..0192d9877 100644 --- a/testhal/STM32/STM32F3xx/USB_CDC/Makefile +++ b/testhal/STM32/STM32F3xx/USB_CDC/Makefile @@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk # Other files (optional). include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk # Define linker script file here LDSCRIPT= $(STARTUPLD)/STM32F303xC.ld @@ -113,9 +115,8 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) \ - $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ + $(STREAMSSRC) \ + $(SHELLSRC) \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -147,7 +148,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) # # Project, sources and paths diff --git a/testhal/STM32/STM32F3xx/USB_CDC/main.c b/testhal/STM32/STM32F3xx/USB_CDC/main.c index 3c9d7334f..11bb6bf5c 100644 --- a/testhal/STM32/STM32F3xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F3xx/USB_CDC/main.c @@ -38,58 +38,6 @@ /*===========================================================================*/ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) -#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) - -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%08lx %08lx %4lu %4lu %9s %lu\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.r13, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state]); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { @@ -132,9 +80,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { } static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {"write", cmd_write}, {NULL, NULL} }; @@ -157,10 +102,12 @@ static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); while (true) { - systime_t time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500; - palClearPad(GPIOE, GPIOE_LED3_RED); + systime_t time; + + time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500; + palClearLine(LINE_LED3_RED); chThdSleepMilliseconds(time); - palSetPad(GPIOE, GPIOE_LED3_RED); + palSetLine(LINE_LED3_RED); chThdSleepMilliseconds(time); } } @@ -169,7 +116,6 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point. */ int main(void) { - thread_t *shelltp = NULL; /* * System initializations. @@ -208,15 +154,15 @@ int main(void) { chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and check the button state. + * Normal main() thread activity, spawning shells. */ while (true) { - if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) - shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp)) { - chThdRelease(shelltp); /* Recovers memory of the previous shell. */ - shelltp = NULL; /* Triggers spawning of a new shell. */ + if (SDU1.config->usbp->state == USB_ACTIVE) { + thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg1); + chThdWait(shelltp); /* Waiting termination. */ + chThdFreeToHeap(shelltp); /* Returning memory to heap. */ } chThdSleepMilliseconds(1000); } diff --git a/testhal/STM32/STM32F3xx/USB_CDC_IAD/Makefile b/testhal/STM32/STM32F3xx/USB_CDC_IAD/Makefile index 2eb85bcf4..0192d9877 100644 --- a/testhal/STM32/STM32F3xx/USB_CDC_IAD/Makefile +++ b/testhal/STM32/STM32F3xx/USB_CDC_IAD/Makefile @@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk # Other files (optional). include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk # Define linker script file here LDSCRIPT= $(STARTUPLD)/STM32F303xC.ld @@ -113,9 +115,8 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) \ - $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ + $(STREAMSSRC) \ + $(SHELLSRC) \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -147,7 +148,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) # # Project, sources and paths diff --git a/testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c b/testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c index 6023f418d..430f00848 100644 --- a/testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c +++ b/testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c @@ -38,58 +38,6 @@ /*===========================================================================*/ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) -#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) - -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%08lx %08lx %4lu %4lu %9s %lu\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.r13, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state]); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { @@ -132,9 +80,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { } static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {"write", cmd_write}, {NULL, NULL} }; @@ -176,6 +121,7 @@ static THD_FUNCTION(Thread1, arg) { int main(void) { thread_t *shelltp1 = NULL; thread_t *shelltp2 = NULL; + event_listener_t shell_el; /* * System initializations. @@ -188,7 +134,7 @@ int main(void) { chSysInit(); /* - * Initializes a serial-over-USB CDC driver. + * Initializes two serial-over-USB CDC drivers. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg1); @@ -207,8 +153,10 @@ int main(void) { /* * Shell manager initialization. + * Event zero is shell exit. */ shellInit(); + chEvtRegister(&shell_terminated, &shell_el, 0); /* * Creates the blinker thread. @@ -216,22 +164,35 @@ int main(void) { chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and check the button state. + * Normal main() thread activity, managing two shells. */ while (true) { - if (!shelltp1 && (SDU1.config->usbp->state == USB_ACTIVE)) - shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp1)) { - chThdRelease(shelltp1); /* Recovers memory of the previous shell. */ - shelltp1 = NULL; /* Triggers spawning of a new shell. */ + if (SDU1.config->usbp->state == USB_ACTIVE) { + /* Starting shells.*/ + if (shelltp1 == NULL) { + shelltp1 = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg1); + } + if (shelltp2 == NULL) { + shelltp2 = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg2); + } + + /* Waiting for an exit event then freeing terminated shells.*/ + chEvtWaitAny(EVENT_MASK(0)); + if (chThdTerminatedX(shelltp1)) { + chThdFreeToHeap(shelltp1); + shelltp1 = NULL; + } + if (chThdTerminatedX(shelltp2)) { + chThdFreeToHeap(shelltp2); + shelltp2 = NULL; + } } - if (!shelltp2 && (SDU2.config->usbp->state == USB_ACTIVE)) - shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp2)) { - chThdRelease(shelltp2); /* Recovers memory of the previous shell. */ - shelltp2 = NULL; /* Triggers spawning of a new shell. */ + else { + chThdSleepMilliseconds(1000); } - chThdSleepMilliseconds(1000); } } diff --git a/testhal/STM32/STM32F4xx/USB_CDC/Makefile b/testhal/STM32/STM32F4xx/USB_CDC/Makefile index d16929854..ba8aeed40 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC/Makefile +++ b/testhal/STM32/STM32F4xx/USB_CDC/Makefile @@ -100,6 +100,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk # Other files (optional). include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk # Define linker script file here LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld @@ -114,9 +116,8 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) \ - $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ + $(STREAMSSRC) \ + $(SHELLSRC) \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -148,7 +149,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) # # Project, sources and paths diff --git a/testhal/STM32/STM32F4xx/USB_CDC/main.c b/testhal/STM32/STM32F4xx/USB_CDC/main.c index 780a8e147..02853f63a 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F4xx/USB_CDC/main.c @@ -31,58 +31,6 @@ /*===========================================================================*/ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) -#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) - -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state time\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%08lx %08lx %4lu %4lu %9s\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.r13, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state]); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { @@ -125,9 +73,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { } static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {"write", cmd_write}, {NULL, NULL} }; @@ -154,14 +99,14 @@ static THD_FUNCTION(Thread1, arg) { time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500; #if defined(BOARD_ST_STM32F4_DISCOVERY) - palClearPad(GPIOD, GPIOD_LED4); + palClearLine(LINE_LED4); chThdSleepMilliseconds(time); - palSetPad(GPIOD, GPIOD_LED4); + palSetLine(LINE_LED4); chThdSleepMilliseconds(time); #else - palClearPad(GPIOC, GPIOC_LED); + palClearLine(LINE_LED); chThdSleepMilliseconds(time); - palSetPad(GPIOC, GPIOC_LED); + palSetLine(LINE_LED); chThdSleepMilliseconds(time); #endif } @@ -171,7 +116,6 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point. */ int main(void) { - thread_t *shelltp = NULL; /* * System initializations. @@ -210,15 +154,15 @@ int main(void) { chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and check the button state. + * Normal main() thread activity, spawning shells. */ while (true) { - if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) - shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp)) { - chThdRelease(shelltp); /* Recovers memory of the previous shell. */ - shelltp = NULL; /* Triggers spawning of a new shell. */ + if (SDU1.config->usbp->state == USB_ACTIVE) { + thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg1); + chThdWait(shelltp); /* Waiting termination. */ + chThdFreeToHeap(shelltp); /* Returning memory to heap. */ } chThdSleepMilliseconds(1000); } diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile b/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile index a9338699c..8f4205f24 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile @@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk # Other files (optional). include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk # Define linker script file here LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld @@ -113,9 +115,8 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) \ - $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ + $(STREAMSSRC) \ + $(SHELLSRC) \ usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -147,7 +148,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) # # Project, sources and paths diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c b/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c index 486942104..73751fb97 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c @@ -31,58 +31,6 @@ /*===========================================================================*/ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) -#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) - -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state time\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%08lx %08lx %4lu %4lu %9s\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.r13, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state]); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { @@ -125,9 +73,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { } static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {"write", cmd_write}, {NULL, NULL} }; @@ -155,12 +100,10 @@ static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); while (true) { - systime_t time; - - time = serusbcfg1.usbp->state == USB_ACTIVE ? 250 : 500; - palClearPad(GPIOC, GPIOC_LED); + systime_t time = serusbcfg1.usbp->state == USB_ACTIVE ? 250 : 500; + palClearLine(LINE_LED); chThdSleepMilliseconds(time); - palSetPad(GPIOC, GPIOC_LED); + palSetLine(LINE_LED); chThdSleepMilliseconds(time); } } @@ -171,6 +114,7 @@ static THD_FUNCTION(Thread1, arg) { int main(void) { thread_t *shelltp1 = NULL; thread_t *shelltp2 = NULL; + event_listener_t shell_el; /* * System initializations. @@ -202,31 +146,46 @@ int main(void) { /* * Shell manager initialization. + * Event zero is shell exit. */ shellInit(); + chEvtRegister(&shell_terminated, &shell_el, 0); /* - * Creates the blinker threads. + * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* - * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and check the button state. + * Normal main() thread activity, managing two shells. */ while (true) { - if (!shelltp1 && (SDU1.config->usbp->state == USB_ACTIVE)) - shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp1)) { - chThdRelease(shelltp1); /* Recovers memory of the previous shell. */ - shelltp1 = NULL; /* Triggers spawning of a new shell. */ + if (SDU1.config->usbp->state == USB_ACTIVE) { + /* Starting shells.*/ + if (shelltp1 == NULL) { + shelltp1 = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg1); + } + if (shelltp2 == NULL) { + shelltp2 = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg2); + } + + /* Waiting for an exit event then freeing terminated shells.*/ + chEvtWaitAny(EVENT_MASK(0)); + if (chThdTerminatedX(shelltp1)) { + chThdFreeToHeap(shelltp1); + shelltp1 = NULL; + } + if (chThdTerminatedX(shelltp2)) { + chThdFreeToHeap(shelltp2); + shelltp2 = NULL; + } } - if (!shelltp2 && (SDU2.config->usbp->state == USB_ACTIVE)) - shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp2)) { - chThdRelease(shelltp2); /* Recovers memory of the previous shell. */ - shelltp2 = NULL; /* Triggers spawning of a new shell. */ + else { + chThdSleepMilliseconds(1000); } - chThdSleepMilliseconds(1000); } } diff --git a/testhal/STM32/STM32F7xx/USB_CDC/main.c b/testhal/STM32/STM32F7xx/USB_CDC/main.c index d703f52c5..f3a11be5a 100644 --- a/testhal/STM32/STM32F7xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F7xx/USB_CDC/main.c @@ -109,7 +109,6 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point. */ int main(void) { - thread_t *shelltp = NULL; /* * System initializations. @@ -157,13 +156,12 @@ int main(void) { * Normal main() thread activity, spawning shells. */ while (true) { - if (!shelltp && (SDU2.config->usbp->state == USB_ACTIVE)) { - shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, NORMALPRIO + 1, - shellThread, (void *)&shell_cfg1); - } - else if (chThdTerminatedX(shelltp)) { - chThdFreeToHeap(shelltp); - shelltp = NULL; /* Triggers spawning of a new shell. */ + if (SDU2.config->usbp->state == USB_ACTIVE) { + thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + NORMALPRIO + 1, shellThread, + (void *)&shell_cfg1); + chThdWait(shelltp); /* Waiting termination. */ + chThdFreeToHeap(shelltp); /* Returning memory to heap. */ } #if 0 if (palReadPad(GPIOI, GPIOI_BUTTON_USER)) { -- cgit v1.2.3