Skip to content

Tutorial: How to port a radio module driver to RIOT OS

Nenaco edited this page Aug 2, 2016 · 24 revisions

Table of Contents

Attention: Work in progress (content is coming step by step / feel free and make corrections and add your experience)

How to port/develop a driver for a new radio module to RIOT-OS (for Netdev2)

The intention for this page is just to give RIOT newbies a guide to develop or port a driver for their prefered radio module. In fact there are actually many boards supported by RIOT OS but only a few radio modules. Maybe this page can help to change the situation.

Prerequisites:

  • First: You need two pieces of hardware - at least one microcontroller board (well known to work with RIOT) and the Radio Module for which you want to write the software driver. Blind programming (without having the hardware) maybe interesting, but doesn't really make sense....
  • Be shure you have all the documents of the module (which provides you information about connecting the module to the big wide world) and also from the silicon (chip datasheet, manual, application notes which can provide you information about protocols, timings, register-sets and so on...)
  • You need a working toolchain and a working programming environment / IDE (e.g. Eclipse)
  • You need a hardware emulation probe which provides you the possibily to programm your firmware onto the microcontroller-board and which provides you the possibility to trace through the code....
  • A connection to the microcontrollers serial port will be helpful. Sometimes it is very helpfull to direct debug messages inside of the running firmware to a serial port which could then be display on a terminal software on your development computer (workstation/PC). A helpfull piece of hardware could be a TTL-USB-UART, which connects the microcontrollers TTL-Serial Port to the PC.
  • A well known working "base-station"/border-router/receiver is needed. Take here a look onto the Wiki Article about the Raspberry-Pi 6LoWPAN bringup
  • And last, but not least you probably need an oscilloscope for measuring the traffic which is going on between the microcontroller board and the radio module (or should I say - "which should go on between....")

Hints about "How to Start"

  • Take a look into the code of software-drivers which could be used as a blue-print for your own driver. In the case of a **netdev2-radio-driver** this could be the code for the Atmel at86rf2xx family. The datasheet for this piece of silicon would be also helpful to understand what's going in in this driver - if not all parts are described in this tutorial ;-)
  • Stick together your hardware parts (microcontroller-board and radio-module). Most of the radio modules are using an SPI-Interface as the communication pipeline between the microcontroller and the radio-module. But don't forget the other necessary signals (chip-select(s), reset-line, interrupt-line(s), wake/sleep e.g.) and Last but not least the power-supply (VCC, GND).



Preview:

Which directories have to be created?

We have to create a directory unter the /drivers path which has the name of the later create driver and under this an include directory

mkdir ~/RIOT/drivers/<driver-name>

mkdir ~/RIOT/drivers/<driver-name>/include
mkdir ~/RIOT/sys/auto_init/netif/auto_init_<driver-name>.c

Which files have to be created?

The following file have to be created or copied from another driver

~/RIOT/drivers/<driver-name>/Makefile

~/RIOT/drivers/<driver-name>/<driver-name>.c

~/RIOT/drivers/<driver-name>/<driver-name>_internal.c

~/RIOT/drivers/<driver-name>/<driver-name>_getset.c

~/RIOT/drivers/<driver-name>/<driver-name>_netdev.c

~/RIOT/drivers/<driver-name>/include/<driver-name>_registers.h

~/RIOT/drivers/<driver-name>/include/<driver-name>_params.h

~/RIOT/drivers/<driver-name>/include/<driver-name>_internal.c
          - in this file, we implement the low-level / hardware-related functions,
            by meaning all routines which have to do with direct access to the
            registers of the radio module. 

~/RIOT/drivers/<driver-name>/include/<driver-name>_netdev.h

~/RIOT/drivers/include/<driver-name>.h

Which files have to be altered?

~/RIOT/drivers/Makefile.dep

~/RIOT/drivers/Makefile.include

Let's start

Altering the boards Makefile.dep

  • if you want to invoke the usage of the driver automatically together with a special board you have to add the following the following lines to the dependency-makefile of the board:
ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
   USEMODULE += <driver-name>
endif 

How to tell RIOT about the hardware connection of the radio module

  • Most IEEE802154 radio modules are connected to a microcontroller by the usage of an SPI interface
  • In the board.h file (RIOT/boards/include/board.h) you can tell the system which SPI interface of the microcontroller will be used and also which additional GPIOs are used for the control signals of the radio module
  • One example of the paragraph which defines the connectivity is shown here (example micro-controller is a STM32)
somewhere in the RIOT/boards/<board-name>/include/board.h file.......

#define <driver-name>_PARAMS_BOARD      {.spi = SPI_1, \
                                     .spi_speed = SPI_SPEED_5MHZ, \
                                     .cs_pin = GPIO_PIN(PORT_B, 12), \
                                     .int_pin = GPIO_PIN(PORT_A, 15), \
                                     .sleep_pin = GPIO_PIN(PORT_B, 9), \
                                     .reset_pin = GPIO_PIN(PORT_B, 8)}

Note: Here we see that the module is connected to SPI_1. The chip-select signal is connected to Port_B/12 port pin, the interrupt is connected to Port_A/15 port pin, the sleep signal is connected to Port_B/9 pin and last but not least the reset-input of the radio module is driven by the Port_B/8 port pin.

Clone this wiki locally