When doing some project which involves a microcontroller I often have to write some test code/script in order to verify correct operation. This is typically a time consuming process. So some time ago, I started working on a small side-project, which would allow me to communicate with a microcontroller directly, either via UART-USB bridge or some other transport protocol. The idea was to basically recreate a unix like shell, where I could control peripherals, via short commands and maybe do some scripting as well and the whole project should be easy to expand and maintain.
Sources are available here.
The syntaxis I landed on is pretty simple, just a command name followed by a space and optional arguments. Arguments are always separated by a dash. Nothing more to say here.
Modules are made of a primary function which is called when command is executed and is responsible for handling argument parsing and error checking. There are several modules I've written sofar:
Actually does very little, takes no arguments. Waits a couple of seconds and causes uC to restart itself. Not particularly useful.
As expected, controls an onboard 12 bit ADC. Features:
- Single/All channel(s) read.
- Individual comparator/trigger on all channels
- Can write data to pool module
adc -c -0 // enable trigger on adc channel 0 adc -t -0 -7 // set trigger voltage to 0.7 Volts adc -s -5 // set timeout to 5 seconds and wait for trigger
Actually, just a placeholder for now, haven't started on this one yet.
Can control any port, with two access methods, pin mode and port mode (individual setting for each port).
- Read/Write operations (including to pool module)
- Individual port/pin mode access, individual pull-up assignments.
gpio -b -h // read port B and return port value as hex (value will be written to pool variable) gpio -b -g // read port B and return value as binary gpio -b -5 -5 // will set port B to 0x55 gpio -b -p // switch to pin mode gpio -b -4 -1 // set pin 4 high at port B
Executing "help -h" will display all modules with short descriptions
Generic timekeeping functionality, showing uptime and usage statistics
- Keeps track of uptime down to 1/10 of a second
- Can cause delay during script execution with either second/millisecond accurancy
time -m -1 // causes a 100 ms delay
Generic debug module, shows various info.
- Display current/previous command information (command code, id, arguments etc.)
- Display uart stats
- Display script/stack stats.
Microcontroller stats such as speed, flash and sram size. System interrupts status.
Scripting module used to record executed commands and run them in a loop or from-to specific positions
Example (Blink a Led):
gpio -b -p // set port B to pin mode queue -s // enable scripting module gpio - b -0 -1 // set pin 0 on port B to logic high time -m -1 // delay for 100 ms gpio -b -0 -0 // set pin on port B to logic low queue -f // enable continious script execution
Not sure why I wanted this module :)
Clears the screen when called. Works with PuTTY, should work with other terminals as well.
Contains 8 individual variables, where each variable has a history property which stores up to 7 previous values.
- Allmost any IO module can read/write to from pool variables
- Individual write access
- Increment/Decrement, Left/Right shift, Accumulate, Randomize, Bargraph functions
pool -s -0 // select variable at location 0 pool -i -8 // increment variable by 0x8 pool -c -3 // copy variable from current location to location 3 pool -s -3 // select variable 3 pool -f // convert variable at location 3 to unfilled bargraph value gpio -b -p // select port mode on port B gpio -b -v // write current pool value (at location 3) to gpio port B
This module can only be used within the scripting mode for conditional jumping.
- Branches on equal/nequal/larger/smaller
pool -Z // delete all pool variables pool -s -0 // select variable 0 queue -s // enable scripting mode pool -i -1 // increment variable by one jump -i -0 -1 // set jumping index to 1 jump -v -0 -8 // set jumping value to 8 jump -l // Jump to index 1, if value has not reached 8 queue -b // counter has reached 8, cancel script execution
Controls functions which are compiled together with the firmware and registered in proc module.
- Single/Continuous process execution
- Process scheduler with sequential/random patterns