# How to add a new radio board to the library

The following section illustrates how to add your own radio board to the µracoli build process, For illustration of the steps, the board tiny230 from DL8DTL is used.

Create two board identifiers.

Select a short and a long name for the board.

The short name should contain 4 ... 8 lower case letters and numbers, e.g. tiny230. It is used for naming the board in the scons build process (`scons tiny230`) and identifying the generated libraries and executables (`ls install/*/*_tiny230.*`).

The long name should contain 12 ... 16 upper case letters and numbers and underlines, e.g. TINY_230. It is used as symbolic name for a unique board identifier, defined in Src/Lib/Inc/const.h.

Create a board abstraction header file

The board abstraction header file (e.g. Src/Lib/Inc/boards/board_tiny230.h) defines macros for accessing the ressources of the radio board, such as SPI and GPIO pins.

The board abstraction header files are located in the directory Src/Lib/Inc/boards.

Before you start to write your own board abstraction file from scratch, have a look into the already existing files. Either you copy one of the existing files and modify it or you simply add an alias to an existing board. See board_rbb.h for an example, how the aliases rbb230, rbb231 and rbb212 are handled.

The alias method should always used, if the boards belongs to the same family and are rebuilds/clones of existing ones, but should have a new name.

Modify const.h

Add the long name to the file Src/Lib/Inc/const.h and give it a unique number.

    Src/Lib/Inc/const.h #define  ZGB_LINK_231    (51)
    Src/Lib/Inc/const.h #define  ZGB_LINK_212    (52)
    Src/Lib/Inc/const.h
    Src/Lib/Inc/const.h /* DIY and wirewrap projects */
    Src/Lib/Inc/const.h #define  TINY_230        (90)
    Src/Lib/Inc/const.h #define  STK500_MEGA8    (91)
    Src/Lib/Inc/const.h #define  STK500_MEGA16   (92)

If your newly added radio board uses a MCU, that is not yet used, you also need to add a unique define

Add the board to the file board.cfg

Add a configruation section to Src/Lib/Inc/boards/board.cfg.

    [tiny230]
    aliases    = tiny231
    comment    = Joerg's (DL8DTL) ATtiny44 with AT86RF230
    include    = boards/board_tiny230.h
    cpu        = attiny84
    bootoffset = 0x0
    ccflags    =
    f_cpu      = 8000000UL
    no_app     = diag rdiag wuart wuart2 sniffer
    no_xmpl    = xmpl_keys xmpl_key_events xmpl_hif xmpl_hif_echo
                 xmpl_radio_stream

Parameters:

  | [sectionname] | This is name of the board, it must be a unique among all board and alias names.
  | aliases | A space seperated list of aliased derivates of this board
  | comment | The comment is displayed when `scons -h` is used.
  | include | Name of the board abstraction header file.
  | cpu | MCU name which is used in mmcu option of avr-gcc.
  | bootoffset | Location address of the boot loader.
  | ccflags | Additional compiler parameters, like -I or -D options.
  | f_cpu | MCU clock frequency
  | no_app | applications that should be excluded from the build, e.g. due to the lack of ressources.
  | no_xmpl | examples that should be excluded from the build, e.g. due to the lack of ressources.
  | more_xmpls | board specific example applications.

Build the software of the new radio board

    scons install\inc\board_cfg.h
    scons tiny230

- copy board_dummy.h to board_xbrdm32.h
  - fill wiring comment
  - replace include guards BOARD_DUMMY_H with BOARD_XBRDM32_H
  - fill CPU_TYPE (see const.h, if necessarry add your cpu there)
  - fill all "..." placeholder according your wiring
  - for impl. of the Macros TRX_IRQ_INIT, DI_TRX_IRQ,EI_TRX_IRQ consult the CPU data sheet
  - in necessary adapt the inline function SPI_INIT
  - implement LED_SET_VALUE and LED_GET_VALUE in order to reflect if your LED's react inverted (STK500) or not.
  - TUNED_OSCCAL is necessarry if your CPU uses the internal RC Oscilator and runs at different voltage level then during the factory calibration of your CPU. Use the calosc.c application in order to check this. Tuning the OSCCAL register is only needed, if you need a correct uart baud rate.