Introduction
What is the Arduino IDE environment ?
It is best that you let google answer this question, but to sum it up shortly:
- Arduino IDE is a « friendly » code editor that simplifies A LOT the code you have to actually write in order to have a working microprocessor as the only functions you have to write are setup() and loop()
- It is wildly used among the makers community, meaning you will always find libraries, forums, people give you the answers you are looking for: and this is PRICELESS
- It has already got all the basic code to blink a led, send data via serial or use the SPI protocol: which is useful !
But the main advantage is that once you have a working sketch, you just have to change the Board option to compile it for a different MCU and be able to perform the exact same tasks.
What are the Freescale freedom (FRDM) boards ?
You must know the arduino boards, as the brand is pretty famous, being the ones to popularize MCUs programming (mainly thanks to a friendly IDE ;-)). You probably also have heard of the Teensy, a very powerful, very easy to use arduino-like MCU. Or maybe the ESP-8266 ?
Deep down, all these are the same: a board with exposed pins, having all the necessary hardware to let you program it and blink a LED in just a few seconds.
There are actually a myriad of other boards, very similar to the arduino UNO or the teensy. These are made by the MCU manufacturers themselves so that developers can test MCUs and use its schematics as a (well designed) reference when designing their own circuits. Among these manufacturers you can find, among others:
- Freescale (FRDM boards)
- Texas instruments (launchpad)
- Microchip (bluetooth modules)
- Nordic Semi (nRFxx family: BLE & ANT)
- A LOT of others
The main difference with an arduino or a teensy board is that you cannot use arduino IDE to use these boards, so YOU have to write complicated code: assembly, linker and startup C code…
The main difficulty when working bare metal with a MCU being the latter. After experimenting it myself, I can testify that making a LED blink for the first time can take more than a week… well, we do not want that, do we ?
There is an alternative to Arduino IDE for these boards, it is called Mbed. Mbed is an online IDE, which is compatible with a lot of boards and already has lots of libraries. From my experience using it has actually been quite painful, as the compilation process can be quite long, and finding the right revision of your board code and the source/libraries a nighmare.
You will never beat independance, and I personally prefer to use my own GitHub account and deal with my software revisions myself than use something which such a high level of automation. To me, Arduino IDE being faster, more widly used, giving more information about compilation seems like a very good option, even for programming complex projects (with more than 10 different .c/.cpp files).
What this tutorial will let you accomplish
We will learn how to modify a few files (4 !) in the Arduino installation folder so that you will be able to use it to program your FRDM K64F and KL25Z boards with it !!!
Amazing isn’t it ?
The modifications
What they do
As I said before, this tutorial concerns Frescale FRDM boards. Freescale offers a rather wide range of MCUs, ordered by Families.
The FRDM KL25Z and K64F are both in the K families. It is declined in the following sub-families: K0x to K8x, each with its own different hardware capabilities. For more information: Freescale.
One very important / interesting thing: in the Freescale K family, despite the differences between the MCUs, a LOT of code can be re-used when switching MCUs. Basically the only things you need to rewrite are:
- Init / startup code
- Clock setup
You can keep everything that deals with SPI, UART, I2C, ADC, etc… Nice !!
Let’s do this Init code then !
Base installation
First, you need an Arduino IDE installation.
When this is done, go to PJRC’x website and download / install TeensyDuino. (PJRC)
We are basically use PJRC Teensyduino’s sources for all the hardware peripherals: Ethernet, SPI, UART, I2C, ADC, etc… And use our own Init code 🙂
The clock configuration code (CPU freq and crystal config.) was obtained from a Freescale-modified Eclips IDE using Processor Expert (magnificent piece of software, described here). If you like doing bare-metal projects and use your own hand-picked MCUs, I strongly advice you look into Processor Expert and more particularly mcuoneclipse.com, as it really is a goldmine !
Completing the installation
Modifying the startup c code
Adding clock configuration
Adding the boards in arduino IDE