ChibiOS on my cc2520+stm32f4 boards
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:
```bash
CHIBIOS = ../ChibiOS-RT-master
CHIBIOS = ../ChibiOS-RT-master
2. Build the project (to set up the required toolchain, see [this](/u/9ba1daeadfa301d0) post):
| |
| --- |
| ```bash
make -j4
``` |
make -j4
3. Upload the program (requires a recent version of OpenOCD):
| |
| --- |
| ```bash
make upload
``` |
make upload
4. In order to test the CLI interface, make sure that your user is added to the dialout group as described [here](http://askubuntu.com/questions/58119/changing-permissions-on-serial-port).
5. Open */dev/ttyACM0* (or ttyACM1 or ttyACMn) in your favourite serial terminal, e.g. screen:
| |
| --- |
| ```bash
screen /dev/ttyACM0
``` |
screen /dev/ttyACM0
6. You should see something like this:
```text
ChibiOS/RT Shell
ch>In order to list all available shell commands, type help and press enter. 7. In order to add new commands, create one like this:
| ```c |
| static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { |
(void)argv;
(void)argc;chprintf(chp, "This is a test command.\r\n"); }
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:
| |
| --- |
| ```c
static const ShellCommand commands[] = {
{"test", cmd_test}, // This line is for the command above
{"mem", cmd_mem},
{"threads", cmd_threads},
{NULL, NULL}
};
``` |
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:
| |
| --- |
| ```make
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT = -DSECURITY_CCM
endif
``` |
# 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.
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=7ZMDJJFHUSCV4&lc=US&item_name=vedder%2ese¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted)