Wednesday, June 10, 2015

Getting started with ARM Cortex M4 - running your first project

As with every other new language/hardware, we start off with the hello world project. To do that, first open Kinetis Design Studio(KDS). Select File -> Import. In the Import wizard, select "Project of projects" -> Existing projects sets and click next. 


Browse the C drive to find the frdmk22f folder in the Freescale installation path. Find the hello world folder in the demo apps directory and open the kds folder. My installation path is as follows. "C:\Freescale\KSDK_1.2.0\examples\frdmk22f\demo_apps\hello_world\kds". Select the file named "hello_world.wsd" and import it into the project explorer of KDS. 


Now two different projects appear in the project explorer. Select the "kdsk_platform_lib_K22F51212", right click on it and select "Build project". The project should build successfully. If there is any problem, right click and select "Clean project" and then "Build project".


Now, right click on the "kdsk_platform_lib_K22F51212" project and select Delete. Do not check the "Delete project contents on disk" option. Now we have all our platform libraries built and ready. Next, right click on the "hello_world_frdmk22f" project and select "Clean project" and then "Build project". Now, the project should successfully build.

Next, we'll need to start a terminal window. I prefer putty. Figure out the com port of your development board to use in putty. Use 115200 kbps as the baud rate. Now, debug the project in KDS using GDB PEMicro debugger (Installing the debugger in KDS was already done in the previous post). Once in the debug perspective, press resume button. You should be able to see the output "Hello world!" in the terminal.



Cheers,
Vijay.

Getting started with ARM Cortex M4 - setting up debug environments

In this post, I'll write about setting up debug environments for Kinetis Design Studio(KDS). These tools are required for on chip debugging at runtime of the code.

PART A: Installing the GNU ARM Eclipse debugger
First we'll install the GNU ARM Eclipse tools, which sets up the OpenOCD. To do this, first open KDS. Select Help -> Install New Software... In the Install window, click the Add button on the top right corner.


The Name text area is optional. Type "http://gnuarmeclipse.sourceforge.net/updates" in the Location text area and click OK.


Expand the GNU ARM C/C++ Cross Development Tools and select the packages as shown below.


Click Next and accept the licence agreement and then Finish. The installation will take place in the background. After it is done, KDS needs to be restarted for changes to take effect.

PART B: Installing the PEMicro debugger
The following procedure will work both on KDS or any other standalone version of eclipse (Eclipse Luna). Follow the same procedure as above, except for the Location text area in the Add Repository window. Here, you have to type "http://www.pemicro.com/eclipse/updates". Rest of the procedure is the same.

To test the successful installation, we will write a basic hello world program and try to debug it in the next post.

Cheers,
Vijay.

Tuesday, June 9, 2015

Getting started with ARM Cortex M4 - working with Freescale FRDM-K22F

I’ve a Freescale FRDM-K22F development platform and we’ll setup the workspace for working and debugging. A prerequisite to this is to have the groundwork established as mentioned in my previous post – “Getting started with ARM Cortex M4 - setting up the work space”.

PART A – Running out of box demos
1.       Download and install the mbedOpenSDAv2.1 USB drivers found at

2.       Plug in a USB cable (standard micro USB cable) from a USB host to the OpenSDAv2.1 Micro-AB USB connector (J5). The FRDM-K22F will be powered by this USB connection. FRDM-K22F comes with the mass-storage device (MSD) Flash Programmer OpenSDAv2.1 Application preinstalled. It will appear as a removable storage drive with a volume label of MBED. The MSD Flash Programmer also includes a USB virtual serial port which requires an .INF file for proper installation in Windows. The necessary .INFfile is available in the mbedOpenSDAv2 .1 USB drivers (Step 1).

3.       Determine the symbolic name assigned to the FRDM-K22F virtual serial port. To do this in Windows, open Device Manager and look for the COM port named “mbedSerial Port”. My device is assigned the port 5.


4.       Open the serial terminal emulation program of your choice. I use Putty.

5.       Select the Connection Type as “Serial”. Set the com port as per step 3 and Speed(baud rate) to 115200. Hit Open.


6.       Press the any key on the keyboard or the SW3 pushbutton on the board to display the following message:
Select from the following menu:
 I. Bubble level –Single axis level using the red and green LEDs to indicate when the board is unlevel.
 II. eCompassdemo –Compass using the combined magnetometer and accelerometer to indicate the heading of board in reference to magnetic north.
III. USB CDC demo –Second serial terminal. (For additional details on the driver installation, refer to the instructions on the next page.)
IV. Metal Detector demo –Metal detector demo that indicates the direction and distance to a foreign metal object using the variable LED brightness as the indicator.
V. Stopwatch demo –Uses the real-time counter (RTC) to implement a stopwatch with 1/100th of a second precision.
VI. Air mouse demo –USB mouse using the accelerometer to determine where/how to move the cursor

7.       Enter a number key (1–6) on the keyboard to run each option from the Quick Start Demo. Further information will be displayed on the terminal as the demo runs.

PART B – Programming using the online mbed compiler
All ARM mbed enabled devices can be programmed using the online “open mbed compiler”. This is a very easy to use tool for novices. Visit the following link and create a mbed online account.

Next use your login to open the mbed online compiler. The online tool automatically detects your development board. In the top-left corner, click on the import button to open up the import wizard. Select the first project, “mbed_blinky” and click import (on the top-right corner). This project will be imported into your Program Workspace. Select the program in the Program Workspace and click on the compile button to perform a compile and download the binary file. Once the binary file is downloaded, drag and drop it into the “mbed” Removable device which shows up in My Computer. Then press the reset button on the development board and release it. The “mbed_blinky” program will start to run.

PART C – Programming using the Kinetis Design Studio
Freescale provides its own set of software IDE for development using the prototype board. This IDE is called the Kinetis Design Studio. The Kinetis Design Studio IDE is a complimentary integrated development environment for Kinetis MCUs that enables robust editing, compiling and debugging of your designs. Based on free, open-source software including Eclipse, GNU Compiler Collection (GCC), GNU Debugger (GDB), and others, the Kinetis Design Studio IDE offers designers a simple development tool with no code-size limitations. Furthermore, Processor Expert software enables your design with its knowledge base and helps create powerful applications with a few mouse clicks. Additional and new device support is installed through the Kinetis Software Development Kit (SDK). KDS can be downloaded from the following link. You may have to register to be able to download.


After the KDS and its dependencies are installed, you’ll get to start directly programming using the editor and debug the hardware with the OpenOCD tool.

To develop a sample project, select File -> New -> Kinetis Project. Give the project a name and click Next. Select Boards -> Kinetis -> FRDM-K22F and hit Finish.


Now, everything is good to go and you can start building code.

Getting started with ARM Cortex M4 - setting up the work space

The next series of posts are targeted at beginners to the ARM family. We will first need to install the required tools to get started.

The first thing required to make everything working is Java. Make sure you get the latest tools and set automatic updates on for all software you use. Also, make sure to download a 64 bit version of Java, if your processor is 64 bit or a 32 bit version otherwise. Java can be downloaded from the following link.

After Java is installed, download the latest version of MinGW tools for the gcc compiler. Also make sure the MSYS folder is inside the MinGW folder. Try to install all the software in their default paths. MinGW can be installed using the following setup.

Now, we will proceed with setting up the GNU tools for ARM embedded processors. Download the latest version of the executable file (.exe). I’ve downloaded the “gcc-arm-none-eabi-4_9-2015q1-20150306-win32.exe“ version, which is the current version at the time of this write-up. The tools can be downloaded from the below link.

We will also need to install the OpenOCD (Open On Chip Debugger) required for debugging. This can be downloaded from the following link.

And we need the eclipse plugin for the OpenOCD too, which can be downloaded from the following link.

Next, we need to add the Java, GNU tools for ARM and compiler variables to the system path to let the system know their locations. Right click on “My Computer” and select properties. Click on the “Advanced system settings” on the left pane to open up “System Properties” window.  Click on the “Environment Variables” under the “Advanced” tab. Browse for “Path” under “System variables” in the “Environment Variables” window, select it and click the “Edit” button. Add the following text(without quotes) to the beginning of the Path.
“C:\ProgramData\Oracle\Java\javapath;C:\MinGW\bin\;C:\MinGW\msys\1.0\bin; C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2015q1\bin\;C:\openocd-0.8.0\bin;”

Finally, we need to install an IDE. I recommend Eclipse as it is relatively simple and widely used. Eclipse Luna is the C/C++ version for Windows OS and can be downloaded from the link below.

Now everything should work perfectly. Go ahead and make a sample C++ project for testing the installation. Additionally, you could Fork somebody’s GIT repository (that has a makefile) and test if it works too.

Cheers,
Vijay.