ZKit with Code::Blocks IDE

Some people prefer to use IDEs, for software development. This article explains how to use an IDE called Code::Blocks along with ZKit-51-v664 and ZKit-51-RD2 boards.

Code::Blocks has support for SDCC and ARM GCC, making it suitable for embedded software development. Some of the features we will demonstrate here:

  • Compiling using SDCC

  • Getting API Help

  • Flashing the Hex Files

While the article shows the Code::Blocks setup in GNU/Linux, most of it is applicable to Windows as well.

Installing Code::Blocks

Make sure you have installed, the ZKit-51-V664 software, from the BSP CD-ROM. Download and install Code::Blocks from http://www.codeblocks.org Unfortunately the current stable release, 12.11-2, does not have the 8051 project wizard, due to a bug.

The bug has been fixed in the Code::Blocks source repository and you can install a nightly build from Jen’s Debian repository or from Jen’s Fedora repository

Setting up the Compiler

Start Code::Blocks from the start menu. Code::Blocks will probe for available compilers. Based on your installation SDCC may or may not be auto-detected. We will configure it manually anyway, so there is nothing to worry, if doesn’t get auto-detected.

  • From the Code::Blocks menu choose "Settings > Compiler …", to open up the "Compiler Settings" dialog.

  • In the "Compiler Settings" dialog, select "SDCC Compiler" in the "Selected Compiler" combobox.

  • In the "Compiler Settings" tab, select the "Compiler Flags" subtab, and enable the "--model-large" checkbox.

    /static/images/cb-cc-flags.png
  • In the "Compiler Settings" tab, select the "Other Options" subtab, and enter "--xram-loc 1", in the text area.

    /static/images/cb-cc-options.png
  • In the "Linker Settings" tab, add /usr/share/zdev/include/zkit-51-v664/zdev.lib to the "Link Libraries" list.

  • In the "Search Directories" tab, select the "Compiler" subtab, and add the directory /usr/share/zdev/include/zkit-51-v664/. Select the "Linker" subtab, and add the directory /usr/share/zdev/lib/zkit-51-v664/

  • In the "Toolchain executables" tab, specify the path containing a bin folder with the SDCC executable. This is usually /usr or /usr/local.

Hello World in Code::Blocks

Create a new project by selecting "New > Project …". This will fire up the Project Wizard. Choose "MCS51 Project" from the list, and click "Go".

/static/images/cb-wizard-mcs51.png
Figure 1. MCS51 Project in Project Wizard

When prompted from the Project Title, enter "helloworld", and click "Next". When prompted from the memory model, specify "large". For the ZKit-51-v664, specify the memory sizes as shown below:

  • CODE Size: 65536 (64K).

  • IDATA Size: 256

  • XDATA Size: 1792

Type in the following simple helloworld program. You should be able to experience the benefits of Code::Blocks when you type in your program. Apart from the syntax highlighting, indentation, code folding, Code::Blocks also provides you function name completion, function prototype tool tips, etc.

#include <board.h>
#include <lcd.h>

void main(void)
{
    board_init();
    lcd_init();

    lcd_puts("Hello World");

    while(1);
}

Compile by selecting "Build > Build" from the menu. Your project should get built, and compilation errors if any should be reported. A screenshot of Code::Blocks in action is shown below.

/static/images/codeblocks-zdev.png
Figure 2. Code::Blocks in Action

Setting up the Flash Tool

Flashing the generated images, can be done from within Code::Blocks using the "Tools+" plugin. The "Tools+" plugin, allows a menu item to be created external tools, and when the menu item is selected the corresponding tool will be executed.

Select "Tools+ > Configure Tools …". In the dialog, click "New", to create a new tool. Enter the "Too Name" as "Code Download". Enter the following for the command, to invoke smash.

smash -P ${PROJECT_DIR}/${TARGET_OUTPUT_FILE) /dev/ttyUSB0

The PROJECT_DIR and TARGET_OUTPUT_FILE, as special variables that will be replaced by the project directory path, and the output file path respectively. Set the "Output to" combo to "Tools Output Window", the rest can be left at their defaults.

/static/images/cb-tools-smash.png
Figure 3. Flash Tool Configuration

When the menu item is invoked, smash will get executed the output, appears in the "Tools Output Window".

/static/images/cb-smash-output.png
Figure 4. Tools Output Window

Setting up API Reference

Code::Blocks has the ability to display help files, in various formats, including HTML and man. Code::Blocks can be configured to display ZDev man pages, as shown below.

  • Select "Settings > Environment", from the Code::Blocks menu.

  • Select "Help Files"

  • Click on "Add", to add a new API reference, and enter a name for the API reference, like "ZDev Help".

  • When asked, if you want to browse for help files, select "No".

  • In the textbox, below the API reference list, enter "man:/usr/share/man/man3". This specifies that path where

  • Code::Blocks should search for help files.

  • Select the check box "This is the default help file"

  • Click on "OK"

/static/images/cb-help-zdev.png
Figure 5. Help Setup

Highlight a function name like lcd_puts in the source code, by selecting it. Press F1, this should pop up the API reference for the lcd_puts() function.

Concluding Notes

Hope this article has demonstrated the features of Code::Blocks, and how they can be used along with the ZKit-51-V664 to simplify software development.