I have created a simple example where I use ChibiOS on my rf boards. You can download it here:
In order to build it, you need ChibiOS with the ST libraries in the ext directory, which you can download here:
Update: The ST libraries are no longer required, but you can still use the ChibiOS-version above if you’d like. It should work just as well with the official version.
In this example, there are two threads that send and receive RF packets between two RF boards. If this program is uploaded to two RF boards, the red LED on each board should blink because the other board sends packets to switch it on and off and vice versa. The green LED is on as long as the board receives acks from the other board. Auto-ack can also be switched off – then the green LED should be on all the time.
This example also emulates an USB modem when the USB cable is plugged in, so you can use you favourite serial terminal to connect to it. The baudrate is ignored and does not matter. On Ubuntu, it will show up as something like /dev/ttyACM0 (or 1 or n) depending on whether you have other USB modems.
How to use it
- Open the makefile and make sure that the CHIBIOS variable is set to where the ChibiOS-RT-master directory is located. If it is in the parent directory relative to the project, it should be:
CHIBIOS = ../ChibiOS-RT-master
- Build the project (to set up the required toolchain, see this post):
make -j4
- Upload the program (requires a recent version of OpenOCD):
make upload
- In order to test the CLI interface, make sure that your user is added to the dialout group as described here.
- Open /dev/ttyACM0 (or ttyACM1 or ttyACMn) in your favourite serial terminal, e.g. screen:
screen /dev/ttyACM0
- You should see something like this:
ChibiOS/RT Shell ch>
In order to list all available shell commands, type help and press enter.
- In order to add new commands, create one like this:
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { (void)argv; (void)argc; chprintf(chp, "This is a test command.\r\n"); }
and add it to the shell command list:
static const ShellCommand commands[] = { {"test", cmd_test}, // This line is for the command above {"mem", cmd_mem}, {"threads", cmd_threads}, {NULL, NULL} };
Adding security support
In order to enable encryption of the data, add -DSECURITY_CCM to USE_COPT in the makefile. It should look like this:
# C specific options here (added to USE_OPT). ifeq ($(USE_COPT),) USE_COPT = -DSECURITY_CCM endif |
Also, make sure that rf_security_key in main.c is the same for all the RF boards.
Pingback: CC2520 and STM32 RF boards | Benjamin's robotics
Pingback: Chibi/OS | David Albert