A deeper look into Arduino IDE — How to customize Arduino IDE to compile for any embedded platform

Many people started to use arduino hardware as well as arduino IDE because of its simplicity and convenience in coding and programming a microcontroller, unlike other professional embedded software which usually takes days or weeks to learn the basics of using it. However, despite Arduino IDE’s simplicity in design, it’s also powerful enough to program some of the very sophisticated embedded hardware like Ameba RTL8722 which has 2 cores, tons of peripherals and most importantly dual-band WiFi and BLE 5.0. Today, I want to show you just a little how this was accomplished on Arduino IDE.

Introduction

According to Arduino IDE’s official release history, Arduino IDE start supporting 3rd party hardware starting from version 1.5.x series [1] . This works by letting 3rd party vendor provide a file to be unzipped into the hardware folder of Arduino’s sketchbook folder in which contains the compilation toolchain, drivers, libraries and some tools. But most importanly, 3 text files that instruct Arduino IDE on how to process 3rd party hardware’s code using the libraries/tools they provided. These 3 text files can usually be found in the hardware folder of Arduino’s sketchbook folder that was just unzipped into and they are,

platform.txt contains definitions for the CPU architecture used (compiler, build process parameters, tools used for upload, etc.)
boards.txt contains definitions for the boards (board name, parameters for building and uploading sketches, etc.)
programmers.txt contains definitions for external programmers (typically used to burn bootloaders or sketches on a blank CPU/board)
The key to customize Arduino IDE lays within the platform.txt file.

Customization via platform.txt

According to Arduino IDE’s official documentation,

“The platform.txt file is used to configure the build process. This is done through a list of recipes. Each recipe is a command line expression that explains how to call the compiler (or other tools) for every build step and which parameter should be passed.” [2].

A simple example is like this,

————————————————————————

##Compiler global definitions

compiler.path={runtime.ide.path}/tools/avr/bin/

compiler.c.cmd=avr-gcc

compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD

[……]

##Compile c files

recipe.c.o.pattern=”{compiler.path}{compiler.c.cmd}” {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} “{source_file}” -o “{object_file}”

How platform.txt works

If you are familiar with GNU make, you should have no problem understanding this format. It basically comprises of two main components, definition and recipe.

Definition is like variable declaration

Recipe is like a command line

Let’s say, if you want to add some new library into the 3rd party hardware folder, you may make a definition of your new library in your platform.txt and add this definition into the existing recipe if exist or create your own recipe whichever desirable. Same also applies if you want to add new flags into the build process and even wish to switch to a new toolchain. The details of how to write/edit a proper platform.txt can be found here.

Hope with this simple introduction to Arduino IDE’s advanced feature, you can better understand how it works with not only arduino’s hardware but also hundreds of other 3rd party hardware and how it is done.

Useful link
https://arduino.github.io/arduino-cli/latest/platform-specification/

1 Like

@xidameng Thanks for the writeup, Is there any way to add board definition to Arduino ide without the board manager or internet? is there anyway download the board package from GitHub and paste to specific folder to make it work? Thanks.

Hi @Salmanfarisvp,

Using board manager is the best way to download everything you need to run Ameba under Arduino’s setting because what you download from board manager includes not only the example code and libraries, but also the entire toolchain as well as utilities for image processing and uploading.

However, I do understand the need to install ameba package offline, so you may visit and download the package from Ameba official Github and arrange the unzipped content with reference to the directory downloaded using board manager.

Thanks for the quick replay. :slightly_smiling_face::+1:

Yeah, That’s true.

Thanks, I’ll try both ways, and let you know.

1 Like