Why is shell terminated and MCU restarted in SDCard Demo?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why is shell terminated and MCU restarted in SDCard Demo?

1,514 Views
m4l490n
Contributor V

I successfully compiled and started a debug session for the mfs/examples/sdcard demo. But my serial terminal goes crazy and shows this over and over.

Shell (build: Oct 8 2019)
Copyright (c) 2013 Freescale Semiconductor;
shell>
shell> Terminating shell.
Shell exited, restarting...

Does anybody know if I need to do anything special to make this work? I single stepped through the Shell function in the shell.c file and I notice that the line:

if (!fgets(shell_ptr->CMD_LINE, sizeof(shell_ptr->CMD_LINE  ), shell_ptr->COMMAND_FP)) 

Always evaluates to true causing it to go to the "else" that contains:

shell_ptr->EXIT=TRUE;
break;

So this function just sets shell_ptr->EXIT to true and finishes. But it is supposed to keep executing in a loop giving a shell for me to type commands in,  isn't it?

Could someone advice?

Labels (1)
Tags (1)
0 Kudos
3 Replies

1,382 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Manuel:

I can not reproduce your issue on my side. I would suggest you check why the else brach hitted.

From the source code, it seems the problem is in  "shell_ptr->COMMAND_FP != stdin" .

you need to check the stdin and shell_ptr->COMMAND_FP .

               if (shell_ptr->COMMAND_FP != stdin)  {
                  fclose(shell_ptr->COMMAND_FP);
                  shell_ptr->COMMAND_FP = stdin;
                  shell_ptr->HISTORY[0]=0;
                  shell_ptr->CMD_LINE[0]=0;
                  printf("\n");
               } else  {
                  shell_ptr->EXIT=TRUE;
                  break;
               }

Regards

Daniel

0 Kudos

1,382 Views
m4l490n
Contributor V

danielchen@fsl‌ thank you very much for helping.

The problem is that shell_ptr->COMMAND_FP is equal to stdin, it was set before on line 76 which contains:

shell_ptr->COMMAND_FP = stdin;

I really don't understand the logic in the Shell function. This is what I'm watching the execution do; It sets shell_ptr->COMMAND_FP to stdin at line 76 in the beginning. Then it goes into the while on line 91 but since shell_ptr->EXIT is false and we have just entered the function and there is nothing on the command line, the if sentence if ((!shell_ptr->EXIT) && (shell_ptr->CMD_LINE[0] != '\0')) at line 93 evaluates to false and lines 95 to 125 are never executed.

The execution goes then to line 128 where if finds if (!shell_ptr->EXIT). And because shell_ptr->EXIT is false it goes into that "if" to execute the do-while loop. Line 133 contains an if (!fgets(shell_ptr->CMD_LINE, sizeof(shell_ptr->CMD_LINE  ), shell_ptr->COMMAND_FP)) that is going to evaluate to true because there is nothing on the command line thus taking the execution to line 134 to the if (shell_ptr->COMMAND_FP != stdin) and because shell_ptr->COMMAND_FP was set to stdin at line 76 in the beginning, then it's going to go to the else setting shell_ptr->EXIT to true and therefore terminating the shell and restarting.

So it doesn't make sense. I don't see how the code would execute differently. It seems that it is expecting to have something in shell_ptr->CMD_LINE which it won't because execution has just started.

How does your execution looks like if you are not seeing constant shell restarts?

0 Kudos

1,382 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Manuel:

Sorry.

One difference ,

In your case

It sets shell_ptr->COMMAND_FP to stdin at line 76 in the beginning. Then it goes into the while on line 91.

In my side, it goes to Shell_set_current_filesystem, not line91

pastedImage_2.png

Maybe you need to check macro SHELLCFG_USES_MFS

Regards

Daniel

0 Kudos