Command Line Interface: Difference between revisions

From Embedded Workshop
Jump to navigation Jump to search
m (JMerkle moved page Create to Command Line Interface)
No edit summary
Line 14: Line 14:
  Argument/'''word''' counter - '''argc'''
  Argument/'''word''' counter - '''argc'''
  Array of character pointers - '''argv'''
  Array of character pointers - '''argv'''
===Serial Character Input===
When using many of the STM32 NEUCLEO boards, the development board will often connect one of the processor's
serial ports to the on-board STM32F103RB debugger/loader/JTAG/USB-Serial interface.  This on-board device creates a
USB-Serial interface when you connect your development board to a host computer.  Check your NEUCLEO board's schematic.)
To use this interface, you need to indicate, via the new project setup wizard, that you need a "connectivity" module,
usually, UART2.  Enable this UART2 for full duplex operation, 115,200 baud, 8 data bits, no parity, 1 stop bit.  When you
connect from the host side, using a terminal program, such at Tera-term, you'll connect to the STM32-STLink USB
serial port, and use the same configuration options.
Reading from the serial port - The code:

Revision as of 13:58, 16 November 2020

Command Line Interface

Once you have a serial interface for debug / printf() output, and have the ability to read serial characters entered from a terminal program, you're ready to implement a command line interface.
Why a Command Line Interface?

Main reason - control
With the command line interface, you can interact with different functionality you've created within your project,
testing many of your functions, and validating your recently added code.

Components needed:

Serial character input method
Line buffer editor - minimal
Line buffer parser - split the command line up into words, with the expectation that the first word
  is a command, with any following words being command line parameters/arguments
Command table with expected number of arguments count
Argument/word counter - argc
Array of character pointers - argv

Serial Character Input

When using many of the STM32 NEUCLEO boards, the development board will often connect one of the processor's
serial ports to the on-board STM32F103RB debugger/loader/JTAG/USB-Serial interface.  This on-board device creates a
USB-Serial interface when you connect your development board to a host computer.  Check your NEUCLEO board's schematic.)
To use this interface, you need to indicate, via the new project setup wizard, that you need a "connectivity" module,
usually, UART2.  Enable this UART2 for full duplex operation, 115,200 baud, 8 data bits, no parity, 1 stop bit.  When you
connect from the host side, using a terminal program, such at Tera-term, you'll connect to the STM32-STLink USB
serial port, and use the same configuration options.

Reading from the serial port - The code: