DCC Sniffer

Bootloader

    For easier change of the application software a bootloader is used.

    The following steps must be performed to update the firmware:
    1. Before connecting the sniffer press the button and keep it pressed. Instead of the normal mode of operation now a boot loader is started, recognizably by the continuousbright ON and PRG leds. This boot loader now waits for a new software from the PC. This software will be loaded to the internal non volatile memory of OpenDCC.
    2. Copy sniffer_update.bat, sniffer.hex, sniffer.eep and avrosp.exe (see below) to a directory of your choice. Then open a command line entry and execute update_sniffer COM1 (resp. with the correct port number assigned by the operation system to the USB device). Important: COM1 must be typed in capitals! Now the update takes place and will copy both flash and eeprom content to the sniffer.
      (Note: the USB driver of the sniffer installs a serial port, this will be assigned a port number from the operation system (e.g. COM8). This number may change if a different USB port is used.
      You can retrieve the actual port through device manager.
    3. After download, the application will be started automatically.
    4. When the sniffer is connect without a key pressed it will start the application!

How it works

    The boot loader is a separate program, which is loaded completely to the end of the internal memory (here: 0x3800) By appropriate programming of the configuration bits (so-called fuses) the AVR is instructed to start program execution after RESET with the boot loader. The boot loader checks the button and if it is not pressed it will execute the normal RESET vector at 0x0000; You will more information in the Application Notes AVR109 and AVR911 from Atmel. There are also the source files for the bootloader on www.atmel.com.

    In order to create a the bootloader for the sniffer, the loaded source files must be adapted. You have to open preprocessor.xls and follow the guidelines. After configuration the boot loader can be built with "make".
    Hints:
      Do not open the makefile with an editor which replaces TABs by BLANKs.
      The linker calculates in units of bytes, therefore the doubled number compared to the fuses must be used.


    The following fuses are required to execute the boot loader:
  • BOOTRST = 0 (0=programmed): this redirect the RESET from 0x0000 to the boot loader;
  • BOOTSZ1 = 0 und BOOTSZ0 = 0: this indicates the size of the boot loader. This setting indicates a size of 1k words, i.e. the range from 0x0000 to 0x1BFF (93,5%) is used for the application, the range 0x1C00 to 0x1FFF is used by the boot loader.
  • BASEADDR = 0x3800: This instruction in the makefile of the boot loaders ensures that the boot loader is located to the correct area. (Note: the linker calculates with bytes, therefore: 0x3800 = 2*0x1C00)
    Interacting with the boot loader:
    A program must be started on the PC side, which interacts with the bootloader. There are several possibilities:
  • avrosp:
    I use this tool. It is includes in the AppNote AVR911. The command looks as follows:
    avrosp -dATmega162 -e -pf -vf -ifsniffer.hex -cCOM3
    The baud rate of the port must be adjusted correctly:
    mode com3 baud=19200 parity=n data=8
  • avrdude:
    This tool comes with WinAVR, the command looks as follows:
    avrdude -c avr910 -p m162 -P com8 -U flash:w:DCCsniffer.hex -U eeprom:w:DCCsniffer.eep -u -b 19200
  • Menu item 'Tools' in AVR Studio.

Documents

    Hex file of the boot loader: bootloader.hex For first time installation this file must be loaded with the ISP Programmer. Source code already adapted for this board: bootloader.zip

    Tool from Atmel for update of Flash and EEPROM: AVROSP.EXE

    Batch for easier update: update_sniffer.bat (if *.bat is not delivered by the provider: zip-file)
    Note: Simply copy sniffer.hex, sniffer.eep, avrosp.exe and this batch into a directory and start the batch. The batch also sets up the com port.
    In order to start a batch, one must open the command line. Unfortunately, the default after opening the command line is the 'home' directory. It easier to open the command line with right mouse button from the explorer. See here, how this can be acheived.


    Link: HTerm good terminal program