Compile for 8051 using Keil

ZBOSS build procedure uses Keil’s build system

Quick instruction for build

  • run Keil with zigbee.uvmpw as parameter;
  • check "Include in Target Build" in the Options dialog for the desired test and uncheck it for all other tests;
  • if necessary, edit preprocessor definitions for zigbee/ folder. Definitions to change are:
ZB_NS_BUILD – if defined, this is NS simulator build, else hardware build
ZB_TRACE_LEVEL=4 – if defined, trace is on, level defines trace details level
DEBUG – if defined, run-time assertions are on
ZB_SECURITY – if defined, security is compiled, else excluded
ZB_ED_ROLE – if defined, code compiles for ZED, else for ZC/ZR

To switch preprocessor definition off, add x before it, so definitions are still visible in the Keil dialog and it is easy to switch it on.

  • Project/Rebuild zigbee(Zigbee).

Test name is always zig_test.

Keil build results are placed in stack/build and the build log is stored in stack/build/zig_test.m51.

Build and test run procedure for two UZ2400 devices

Requirements:

  1. Two devkits with uz2400 onboard
  2. Two JTAGS and Two Serial (or serial2usb) cable.
  3. Any available 802.15 or ZigBee® sniffer (We use Texas Instrumental CC2831 USB Dongle)
  4. Any available serial port sniffer.
  5. Keil uVision4 with installed SiLabs driver for SI usb debugger.

Test building:

1. Connect all devices described above, except one usb debugger (will be explained later).
2. Start uVision4, and load tests source code.
3. You need to prepare two firmware files (for coordinator and router)
4. For coordinator:
  4.1 Select zdo_start_zc from project tree.
  4.2 Mark it to be built in the project.
  4.3 Make sure, that no other tests are selected (there's main function in nwk_formation, nwk_discovery, mac_test, zdo_start_zc, zdo_start_zr, zdo_start_zr, pcon_test, crypto_test)
  4.4 Build project.
  4.5 Go to the project options->debug. Then, set up Silicon Labs Debugger, press settings and remember which device name is specified in the adapter selection menu.
  4.6 Flash device, by pressing flash->download.
5. Second device can be Router or End device.
   For router:
  5.1 Select zdo_start_zr from project tree.
  5.2 Same as for coordinator.
  5.3 Same as for coordinator.
  5.4 Same as for coordinator.
  5.5 Same, but select a device that is different from the one you remembered.
  5.6 Same as for coordinator.

   For end device:
  5.1 Select zdo_start_ze from project tree.
  5.2-5.3 Are the same as for coordinator or router.
  5.4 Go to the Project->Options for zigbee - Target "Zigbee", then select C51 tab and append a define ZB_ED_ROLE (but do not forget to undefine it before building coordinator or router tests).
      5.4.1 Build project.
  5.5 Same as for coordinator, but select a device that is different from the one you remembered.
  5.6 Same as for coordinator.

6. You have two flashed devices. Now, you can, if needed, set up serial and 802.15 sniffer.
7. Start ZC, and wait several seconds, while it performs Energy and Active scans. If you have any sniffer, you can see the beacon request.
8. Now start router (or end device), it will send another beacon request and join to our network and send test data packet.

Keil build internals

Build files for Keil are stored in the stack/ directory. They are: zigbee.uvmpw, zigbee.uvopt, zigbee.uvproj, zigbee.lin, rfd_zigbee.lin files.

Initially we designed Keil workspace as a project that generates a library and a project for a test that uses that library.

The problem is that Keil puts all library files into the same code bank while we need to put near all the stack code into library and only some of the routine-specific top of the test program into the main source file.

So, the tests must be included into the project that contains other files.

However, it is still needed to compile more than one test.

One of the only ways to resolve this problem: create folders in the project (one folder per subsystem) that are always compiled. Also, create individual subfolder per test, with main().

Only one test can be compiled. All other tests compilation must be switched off in the Options dialog: uncheck "Include in Target Build".

File zigbee.lin and its alternatives rfd_zigbee.lin and ffd_zigbee.lin are linker definitions for Keil.
There are two main things:

  • explanation for Keil that some functions do not call each other and there is no recursion (even though recursion is not used, Keil wrongfully treats calls via ZBOSS scheduler as recursion).
  • explanation for Keil that some functions are really called from zb_sched_loop_iteration functions, so Keil must create stubs for these calls in the COMMON segment.

To debug NS stack build, tune Keil to direct some UART to the COM port. debug_1.ini and debug_2.ini files used for it.