command shell

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
ruslanpopov
Posts: 35
Joined: Sun Aug 19, 2012 9:36 pm

command shell

Post by ruslanpopov »

Hello,

I have spent a lot of time trying to activate command shell for my stm32f100 board.
I have use USART1 to connect the chip to a computer. Any chprintf() calls work fine but shell keeps a silence.

All shell related code is separated in cmd.{h.c} files:

Code: Select all

/*
 * CMD.H
 */

#include <ch.h>
 
#define SHELL_SD        SD1
#define STDOUT_SD       SHELL_SD
#define STDIN_SD        SHELL_SD
#define SHELL_WA_SIZE   THD_WA_SIZE(2048)
 
void cmd_init(void);
void cmd_respawn(void);

/*
 * CMD.C
 */

#include <hal.h>
#include <shell.h>
#include <chprintf.h>
#include "cmd.h"
 
static Thread* th_shell;
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]);
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]);
static const ShellCommand commands[] = {
  {"mem", (shellcmd_t) cmd_mem},
  {"threads", (shellcmd_t) cmd_threads},
  {NULL, NULL}
};
static const ShellConfig config = {
  (BaseSequentialStream*) &SHELL_SD, commands
};
 

void cmd_init(void) {
  th_shell = NULL;
  shellInit();
}
 

void cmd_respawn(void) {
  if (!th_shell) {
    th_shell = shellCreate(&config,
                           SHELL_WA_SIZE,
                           NORMALPRIO);
  } else if (chThdTerminated(th_shell)) {
    chThdRelease(th_shell);
    th_shell = NULL;
  }
}
 

static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { .. }
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { .. }


In main.c I did the following:

Code: Select all

#include <ch.h>
#include <hal.h>
#include <chprintf.h>
#include "cmd.h"
#include "display.h"
 
int main(void) {
  halInit();
  chSysInit();
  sdStart(&SHELL_SD, NULL);
  cmd_init();
  chprintf((BaseSequentialStream*) &SHELL_SD, "started\n");

  while (!chThdShouldTerminate()) {
    cmd_respawn();
    chThdSleepMilliseconds(1000);
  }
}


In Makefile I did the folloing:

Code: Select all

CSRC = .. \
       $(CHIBIOS)/os/various/evtimer.c \
       $(CHIBIOS)/os/various/shell.c \
       $(CHIBIOS)/os/various/syscalls.c \
       $(CHIBIOS)/os/various/chprintf.c \
       main.c cmd.c


In mcuconf.h:

Code: Select all

#define STM32_SERIAL_USE_USART1             TRUE


Also, I have enabled CH_USE_MALLOC_HEAP and CH_USE_DYNAMIC.

But I still see no ChibiOS prompt in a terminal:

Code: Select all

$ miniterm.py -e -p /dev/ttyUSB0
--- Miniterm on /dev/ttyUSB0: 9600,8,N,1 ---
--- Quit: Ctrl+]  |  Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
started


Where I did a mistake?
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: command shell

Post by Tectu »

I didn't take a look at your code, but did you hit the enter key once? It often runs but doesn't show up until something is sent to it.
Otherwise, please take a look at the demos, many of them show how to use the shell correctly.


~ Tectu
ruslanpopov
Posts: 35
Joined: Sun Aug 19, 2012 9:36 pm

Re: command shell

Post by ruslanpopov »

I have forgot to check the results of shellCreate:

Code: Select all

    if (th_shell == NULL) {
      chprintf((BaseSequentialStream*) &SHELL_SD,
               "cmd respawn: heap of %d bytes can not be allocated\n",
               SHELL_WA_SIZE);
    }


Then I reduce SHELL_WA_SIZE and it works now.
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: command shell

Post by Tectu »

Nice to hear that you got it working, even thought I didn't really help :?


~ Tectu
Post Reply