Tutorial: Using SDCC and CBL for EcoBT Programming

This page provides a gentle tutorial on how to

  • compile and link your code using SDCC
  • program your code image to EcoBT with the preloaded CBL firmware
  • test your code using LightBlue

Before you begin, we assume you have already

  • set up a Unix-like environment with (gnu)make, SDCC, Python 2.7.x, runflash.py and Makefile.mk (in your source directory), and CC2540/Makefile or CC2541/Makefile.
  • have LightBlue installed on an iOS device (shown here), BTools on Windows, or the equivalent client on Android or another OS.
  • have a BLE dongle that can be recognized by pyserial

1. Use LightBlue to scan nodes

  • Open LightBlue or similar client as a central device and scan. Turn on the EcoBT node with CBL firmware.

2. Modify the source file

  • Be sure you have the file named CodeGeneratorMain.c
  • Go to line 69, where it is overwriting members of the array attDeviceName.
    attDeviceName[0] = 'E';
    attDeviceName[1] = 'c';
    attDeviceName[2] = 'o';
    attDeviceName[3] = 'G';
    attDeviceName[4] = 'e';
    attDeviceName[5] = 'n';
    ....
  • Note that the originam name is “EcoGenBLE Node”. When you power up the node and open LightBlue, you get the following device:
  • You can change the attDeviceName to something different. For example,
    attDeviceName[0] = 'S';
    attDeviceName[1] = 'u';
    attDeviceName[2] = 'p';
    attDeviceName[3] = 'e';
    attDeviceName[4] = 'r';
    attDeviceName[5] = ' ';
    ....
  • Depending on whether your board has a CC2540 or CC2541, change into that diretory, which should already have a Makefile setup. If it compiles without error, then you can program the firmware into the node.
    % cd CC2541
    % make CodeGeneratorMain.bin
    % cd ..
    % python runflash.py CC2541/CodeGeneratorMain.bin ''
  • While inside runflash.py, you will be asked to select the COM port to which the dongle is connected, and then it will scan BLE devices that you want to pair with. After pairing, it will start programming the binary image and start running. For example, you may see something like the following (but it may be different)
    Available COM ports
    1: /dev/cu.Bluetooth-Incoming-Port
    2: /dev/cu.Bluetooth-Modem
    3: /dev/cu.usbmodem1411
    Select COM port: 3
    Starting device scan
    1:  08:AA:AA:AA:AA
    Scan Done
    Select node: 1
    > Code size: 423
    > Sent location packet
    > Sent section packet
    > Sent total code Segment:  22
    Programming:
    [################################################] 100%
    
    type any key to reprogram cc2541/CodeGeneratorMain
  • If you have seen something like this, then your firmware has been successfully programmed into the node, and the node has started executing. If you have LightBlue rescan devices again, you will see the device with the previous name again; but this is due to name caching. You can tap on the device with the old name, disconnect from it, scan again, and it will find the device with the updated name: