Skip to content

Setup SDCC developing environment with Eclipse

Rikka0_0小六花 edited this page Jul 1, 2019 · 5 revisions

Eclipse is a popular JAVA IDE, with the aid of Eclipse CDT plugin, it becomes a powerful IDE for C/C++ development. Eclipse CDT comes with much more functions and flexibility than conventional embedded-system IDEs (Keil uVersion, IAR, ST Vistual Develop, e.t.c...), e.g. find usage, refactor, code navigation, integrated support for version control systems, e.t.c...

Although it is possible to let the Eclipse use the Keil C51 compiler, this approach is not recommended, since: 1. Keil C51 compiler is Windows only, 2. Lots of modern C features are not supported. Therefore, Eclipse CDT + SDCC should be preferred.

Pre-requests

This tutorial will guide you through the setup of SDCC compiler and Eclipse CDT. (The following method only applys to Windows x86/x64, however, setting up Eclipse on Linux is similar and this article could be used as a reference).

We need the following as pre-requests:

  1. Java Development Kit(JDK) 1.8 64-Bit
  2. Eclipse 64-Bit
  3. Eclipse CDT
  4. Eclipse SDCC plugin (Patched for 64-bit Windows systems)
  5. MSYS
  6. SDCC

Eclipse SDCC plugin, SDCC and MSYS are packed in a single zip file and it is ready to use. Download is available here (Baidu Pan alternative).

Environment Setup

  1. Install Eclipse CDT (Necessary for C/C++ development) install and launch Eclipse, go to "Help" menu, then "Install New Software". Put http://download.eclipse.org/tools/cdt/releases/9.3/ in the "Work with:" textbox. Hit enter and wait for its response. CDT is massive, in this case we only need few components, so only check CDT Main Features->C/C++ Development Tools to minimize disk usage. Restart Eclipse after CDT installation.

  2. Unzip SDCC and MYSY to any folder, e.g. D:\Software\Develop\sdcc\bin and D:\Software\Develop\msys\bin. In Eclipse, go to "Windows" -> "Preference", then on left hand side, navigate through "C/C++ -> Build -> Environment", Add a new environment variable called PATH, its value should be SDCC path plus MSYS path, e.g.: D:\Software\Develop\sdcc\bin; D:\Software\Develop\msys\bin

Image

  1. Unzip the patched Eclipse SDCC plugin to the dropins folder under Eclipse install directory, then restart Eclipse. Dev environment setup is now complete.

Create Your First Project

  1. Launch eclipse, go to "File -> New -> Other", choose "C Project" and select Others -> MCS51 family (SDCC) for "Project Type", then click "Finish" to close the dialog.
  2. In "Project Explorer", right click the project and choose "Properties", click through "C/C++ Build -> Settings"
  3. In tab "Tool Settings", in the treeview, navigate to "SDCC Compiler -> Directories", then hit the + button, add <sdcc path>\sdcc\include (e.g. D:\Software\Develop\sdcc\include). You may also add <sdcc path>\sdcc\include\mcs51 to include headers for 8051 processors.

Image

  1. Go to tab "Build Steps", type packihx ${ProjName}.ihx > ${ProjName}.hex & makebin -p ${ProjName}.ihx ${ProjName}.bin for Post-build steps command, this tells SDCC to create .hex file and .bin file, which is required for programming the microcontroller.
  2. Go to "C/C++ General -> Preprocessor Include Paths, Macros etc.", In tab "Entries", choose "GNU C", select "CDT User Setting Entries", then hit the "Add" button. Click the combobox on the left-top corner of the window and choose "Preprocessor Macro", in field "Name", type __SDCC and put 1 for its value. Repeat same procedure for macro SDCC. This gives you a better experience when you navigating through the source code.
  3. Click "Apply and Close", happy coding!

What kind of patches have been done to Eclipse SDCC to make it work:

You don't need to perform any of the following, my zip file already contain these patches.

The original Eclipse SDCC plugin is slightly outdated and it might not work properly on the latest version of Eclipse or 64-bit Windows systems.

  1. Download the zip file and extract the net.sourceforge.eclipsesdcc-1.0.0-win32.x86 folder to <Eclipse Path>\dropins\net.sourceforge.eclipsesdcc-1.0.0-win32.x86.
  2. Copy the os folder from <Eclipse Path>\dropins\net.sourceforge.eclipsesdcc-1.0.0-win32.x86\plugins\net.sourceforge.eclipsesdcc.win32_1.0.0 to <Eclipse Path>\dropins\net.sourceforge.eclipsesdcc-1.0.0-win32.x86\plugins\net.sourceforge.eclipsesdcc_1.0.0, so that it works on 64-bit systems. (I'm not too sure why)
  3. Replace <Eclipse Path>\dropins\net.sourceforge.eclipsesdcc-1.0.0-win32.x86\plugins\net.sourceforge.eclipsesdcc_1.0.0\os\win32\sh.exe (the one with a weird icon) with <MSYS Path>\msys\bin\sh.exe. The original sh.exe has lots of unwanted characters in its console and they will confuse the Eclipse SDCC plugin.

Notes:

The same environment (SDCC+Eclipse) can be used for STM8 development, there's a heavily patched and experimental GDB which enables on-chip debugging for STM8. On-chip debugging is not supported on CH55x devices.