diff --git a/components/finsh/shell.c b/components/finsh/shell.c index ea68a57ffa..6bdb418120 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -50,9 +50,11 @@ #endif /* finsh thread */ +#ifndef RT_USING_HEAP static struct rt_thread finsh_thread; ALIGN(RT_ALIGN_SIZE) static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE]; +#endif struct finsh_shell *shell; #if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)) @@ -721,7 +723,8 @@ __declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end = */ int finsh_system_init(void) { - rt_err_t result; + rt_err_t result = RT_EOK; + rt_thread_t tid; #ifdef FINSH_USING_SYMTAB #ifdef __CC_ARM /* ARM C Compiler */ @@ -764,29 +767,31 @@ int finsh_system_init(void) #endif #endif - /* create or set shell structure */ #ifdef RT_USING_HEAP - shell = (struct finsh_shell *)rt_malloc(sizeof(struct finsh_shell)); + /* create or set shell structure */ + shell = (struct finsh_shell *)rt_calloc(1, sizeof(struct finsh_shell)); if (shell == RT_NULL) { rt_kprintf("no memory for shell\n"); return -1; } + tid = rt_thread_create(FINSH_THREAD_NAME, + finsh_thread_entry, RT_NULL, + FINSH_THREAD_STACK_SIZE, FINSH_THREAD_PRIORITY, 10); #else shell = &_shell; -#endif - - memset(shell, 0, sizeof(struct finsh_shell)); - - rt_sem_init(&(shell->rx_sem), "shrx", 0, 0); + tid = &finsh_thread; result = rt_thread_init(&finsh_thread, FINSH_THREAD_NAME, finsh_thread_entry, RT_NULL, &finsh_thread_stack[0], sizeof(finsh_thread_stack), FINSH_THREAD_PRIORITY, 10); +#endif /* RT_USING_HEAP */ - if (result == RT_EOK) - rt_thread_startup(&finsh_thread); + rt_sem_init(&(shell->rx_sem), "shrx", 0, 0); + + if (tid != NULL && result == RT_EOK) + rt_thread_startup(tid); return 0; } INIT_APP_EXPORT(finsh_system_init);