Arduino-Lite, Lightweight AVR library developed by RoboPeak(2)

中文版请看这里

This is the second article in the series, which introduces the installation and usage of the Arduino-Lite.

Arduino-Lite is a lightweight high-performance firmware library for AVR mcus, which is developed based on the original Arduino project. We make it easy to use, just like the Arduino. Compared to the original library, Arduino-Lite generates smaller binaries and perform faster.

Some brief introduction to the Arudino-Lite: Arduino-Lite, Lightweight AVR library used by RoboPeak(1)

1. What are included in Arduino-Lite?

Arduino-Lite hosted on Google Code consists of:

  • Source code of Arduino-Lite firmware library
  • WINAVR (avr-gcc) compiler set
  • Arduino-Lite compiling system
  • Tools
  • Samples and templates

Arduino-Lite users only need to download the package to develop, compile, burn/upload and even debug AVR programs, along with system default text editors(notepad, vim); no third-party library are required. Arduino-Lite, for sure, do not prevent you from using any software or libraries.

2. Download and configure Arduino-Lite

2.1 Get Arduino-Lite

The open source version of Arduino-Lite can be retrived from Google Code:http://code.google.com/p/arduino-lite/。There are two ways to get Arduino-Lite:

  • Compressed Package

In the Download section of our Google Code project page, we released compressed packages of Arduino-Lite, what are named like arduino-lite-r1.0.zip. After downloading, no installation steps are needed, just decompress to some folder.

  • SVN

Check out any revision anonymously from the svn repository hosted on Google Code.

After downloading and decompression, the directory tree should like this:

  • src contains all source code of Arduino-Lite firmware library
  • User projects, templates and samples are placed under sketch directory
  • scripts contains some scripts related to the compilation process
  • bin contains tools and avr-gcc

2.2 Environment requirement

The Arduino-Lite firmware library is cross-platform, what can be compiled under almost all operating systems; but our compiling system is currently stick on windows. After some simple modification, our compiling system can also work well under Linux/MacOS. We will provide this support in the future.

The compiling system of Arduino-Lite has been tested under the following operating systems:

  • Windows XP 32bit
  • Windows Vista 32bit and 64bit
  • Windows 7 32bit and 64bit

2.3 Configuration at the first time

While you are using this tool-set for the first time (just checked out from svn or decompressed from the downloaded package), please just execute the batch “buildenv.cmd” at the root directory of Arduino-Lite. “buildenv.cmd” is responsible to set up the working environment of Arduino-Lite automatically:

  • Set up bash environment (based on msys)
  • Decompress the WINAVR (avr-gcc) compilers
  • Configure environment variables (if needed)

You should see the following command prompt window:

After executing this batch file, Arduino-Lite is ready to use.

3. Develop with Arduino-Lite

3.1 Create an Arduino-Lite project

The compilation system of Arduino-Lite follows the simple and stupid philosophy. No more third-party tools, no more makefiles, workable development environment is available out of box. Construct projects by writing Makefiles, using IDEs like AVRStudio, Eclipse or Arduino IDE are also welcomed.

The sketch directory of Arduino-lite is used to contain projects. In this example, we suppose the project is named “myAVR”. Some simple steps to achieve this:

a. Decompress the template.zip and get a directory tree like this:

(The “launchsh.cmd” should be seen at the sketch/template/ directory)

template.zip is the template of Arduino-Lite projects, what contains ready-to-use Makefile and sample source code at src/main.cpp.

The compilation system of Arduino-Lite use Makefile to compile source codes, which process are contained in a bash shell. You can launch a bash shell by executing “launchsh.cmd”.

b. Rename the template directory to your project’s name, in this case, “myAVR”

Utill now, a new Arduino-Lite project has been created, which will generate code for Atmega168 at 16MHz. The project contained by template.zip is a LED fading sample, will output at arduino pin 11. If your program need to work on different chip or frequency, please refer to the rest part of this article.

3.2 Add files to project

Just place source code under the src directory or its sub directories (.cpp, .c, .S, .h and .hpp files are supported), the compiling system will automatically compile and link them.

Just write code, and same, no need to modify the Makefile script.

For instance, the following figure is the project tree of one of RoboPeak projects. Arduino-Lite will compile the whole source tree automatically. Like a magic, isn’t it?

3.3 When and how to modify the Makefile script?

Makefile should be modified in the following situations:

  • Target device differs from the default configuration of the Makefile

By default, the Makefile generate binary for Atmega168 at 16MHz

  • Configure the upload/burn settings for target device

Arduino-Lite support serial port self-programming AVR bootloaders (Arduino compatiable) and programming blank AVR chips through RP USB Connector. If you need to configure the baud rate of the programmer, you need to modify the Makefile.

  • Configuration the fuse of AVR chips

While programming with the RP USB Connector, you can specify the fuse data in the Makefile

  • Customize the compilation process or referencing external libraries

If the compile-and-link-all model doesn’t fit your your requirement, or your project references libraries other than Arduino-Lite

Makefile scripts are located at the root directory of each projects, all codes need to be modified in which are marked by “TODO”s. The following example will make Makefile generate binary for Atmega48 at 1MHz, and use COM3 to upload firmware.

3.4 Compile the project

Arduino-Lite use the standard make command to construct project. In order to execute make, please run the launchsh.cmd batch file, which will launch the bash shell.

Enter “make” and press the enter key in the bash shell will trigger the project to compile:

If the project is compiled properly without any error, the script will show you some metadata of the binary:

图中,

  • The number in the red rectangle shows the firmware size (in bytes), this will be helpful to indicate if the firmware can be fully burned/uploaded to the target device.
  • The number in the orange rectangle show the minim requirement of the memory (sram) . This parameter can be used to evaluate if the memory of the target device is enough.

3.5 Burn/upload binary to target device

3.5.1 Program Arduino and Arduino-compatible boards

You can just use “make upload” to program avr chips with bootloader supporting STK500v1 protocol, including:

  • Most Arduino hardwares and its compatible boards delivered with the bootloader
  • Any avr chips with this bootloader

The source code and pre-compiled binary of the bootloader can be found under the src/bootloaders directory.

Before burning or uploading, please insure:

  1. The target hardware has connected properly to the PC, and get the serial port of it (COM3 is the default)
  2. Confirm the baud rate of the bootloader (19200 is the default)
  3. If these parameters are not the same as the default one, please modify the Makefile

After the connection, enter “make upload” to upload the new firmware. The process should be like this:

NOTICE: You might need to reboot the AVR chip manually on some non-standard Arduino devices.

3.5.2 Program any AVR chip based circuit system

Arduino-Lite compiling system integrated the support to AVR-Doper(http://www.obdev.at/products/vusb/avrdoper.html) and compatible programmers. You can use “make burn” to program any AVR chips or configure fuse.

RoboPeak developed a driver-less AVR-Doper compatible programmer support the usb port: RoboPeak USB Connector. We will introduce and open source this project in later articles.

Arduino-Lite support following burn/upload commands. The usage of these command are written at the end of this article.

  • make burn
  • make fuse
  • make lock
  • make erase

3.6 Available compilation targets

Compilation:

  • “make” or “make all”

Compile current project

  • make clean

Clean compilation results

Burn/Upload

  • make upload

Upload hex to AVR chips via serial port (through bootloaders for STK500v2)

  • make usbupload

Upload hex to AVR chips via usb port (through HidBootloaders)

  • make burn

Burn hex to target AVR chips through RoboPeak USB Connector (or other Avr-doper-compatible programmers)

  • make erase

Erase the target AVR chips through RoboPeak USB Connector (or other Avr-doper-compatible programmers)

  • make fuse

Configure the fuse data of the target AVR chips through RoboPeak USB Connector (or other Avr-doper-compatible programmers)

  • make lock

Configure the lock bits of the target AVR chips through RoboPeak USB Connector (or other Avr-doper-compatible programmers)

Code analysis and debugging

  • make dump

De-assemble compiled efl files to AVR asm instructions

  • make dumpobj

De-assemble compiled object files (*.o) to AVR asm instructions

In the next article, we will introduce the new functions provided by Arduino-Lite.

10 thoughts on “Arduino-Lite, Lightweight AVR library developed by RoboPeak(2)”

    1. We are still hark working on this issue, and cannot promise an exact release date of linux package, cos. there are a lot of test work to do. But, if you are rushing to use this feature, and you are a geek as well, the makefiles and source code of arduino-lite should be cross platform.

  1. I think this is a great idea. I want the library support of the Arduino for fast development, yet I want some control over the build process and access to the intermediate files.

    I downloaded the compiler and gave it a try. It works very well for the Mega series. However, I tried to target a small piece of code to the attiny2313 and it will not compile. The error is ” ‘PinMode’ was not declared in this scope”.

    Digging into the core files, the issue seems to be a lack of mapping table. Several files have the following comment.

    //no mapping table for tiny series, please use the MARCO version instead

    I would gladly try the MARCO version if I had any clue what that was or where to get it.

    Has anyone run the lite version on a tiny yet?

    Thanks.

    1. I changed from “pinMode” to “PIN_MODE” and the code now compiles. I guess the arduino syntax is only supported for the bigger parts.

      What is going on is still a big mystery. However, if you are having problems compiling for the smaller devices, I would suggest switching to the arduino-lite syntax where ever possible.

  2. Has anyone used the generated ELF file?

    I tried to use the ELF file in the AVR Studio simulator. While the part appears to be executing code in the simulator, I can only see a few core files like stdint.h and wiring.c . My code is not visible in the ELF file and other core code, like the serial port stuff, is also not visible. Since I cannot see my files, I cannot place any breakpoints in my code, or examine any variables in my code.

    I also attempted to create a project in Eclipse. When Eclipse expands the ELF file, it shows just the same few core files.

    I changed the make file flags to dwarf-2 and turned off optimization, as these can affect what remains in the final link stage. However, its still remains the same.

    I then compiled the original project targeted for a larger part with the full Arduino compiler. If I move that ELF file into the Eclipse project, it not only sees all the various files that are used in the build, but some how can find the original source code back on another hard drive.

    Anyone have a clue what is happening?
    Are there additional makefile flags that I need to enable?

    Thanks.

    —- Steve

  3. For compiling in Linux (Uuntu 10.04) i just changed some paths in arduino-lite/scripts/mak_avr_def.inc


    diff -w mak_avr_def-Linux.inc mak_avr_def.inc
    20,25c20,25
    < REMOVE := rm -f
    < MV := mv -f
    < MKDIR := mkdir -p
    < SED := sed
    < FIND := find
    REMOVE := $(TOOL_ROOT)/win32/posix/rm -f
    > MV := $(TOOL_ROOT)/win32/posix/mv -f
    > MKDIR := $(TOOL_ROOT)/win32/posix/mkdir -p
    > SED := $(TOOL_ROOT)/win32/posix/sed
    > FIND := $(TOOL_ROOT)/win32/posix/find
    > DIRNAME := $(TOOL_ROOT)/win32/posix/dirname
    27c27
    AVRDUDE := $(TOOL_ROOT)/win32/avrdude-arduino.exe
    50c50
    AVR_TOOLS_PATH = $(WINAVR_HOME)/bin
    110,116c110,116
    < CC = avr-gcc
    < CXX = avr-g++
    < OBJCOPY = avr-objcopy
    < OBJDUMP = avr-objdump
    < AR = avr-ar
    < SIZE = avr-size
    CC = $(AVR_TOOLS_PATH)/avr-gcc
    > CXX = $(AVR_TOOLS_PATH)/avr-g++
    > OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
    > OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
    > AR = $(AVR_TOOLS_PATH)/avr-ar
    > SIZE = $(AVR_TOOLS_PATH)/avr-size
    > NM = $(AVR_TOOLS_PATH)/avr-nm

Leave a Reply

Your email address will not be published. Required fields are marked *