The schematics for the Freedom board is now available on the element14 Freedom Board site (you need to log into the element14 community first) as FRDM-KL25Z Schematics (SPF-27556_D).pdf (314.7 K)). So time to write a tutorial how to use the LED on that board.
❗ Note: since this tutorial, the LED component has been simplified. So some of the steps below are much simpler and easer. Please see LED’s for Kinetis, simplified | MCU on Eclipse. I have updated this post with the new instructions and images.
In “FreeRTOS with GCC, Cortex-M0+ and Kinetis KL25Z Freedom Board” and “A Shell for the KL25Z Freedom Board” I have used that board with an RTOS: FreeRTOS. But it is really easy to use that board without an RTOS (‘bare metal’) too. In this tutorial I’m providing step by step instructions to use the RGB LED on the Freedom KL25Z board with Processor Expert and the open source LED component.
❗ NOTE: this post has been written for CodeWarrior for MCU10.3 and it is using an earlier version of the LED component (using BitIO_LDD). Things have been greatly simplified with a new LED component, see this post. I recommend that you use the newer LED component from GitHub.
I’m using CodeWarrior which has the ARM gcc build tools integrated for the Kinetis family. This tutorial features the Freedom KL25Z board with the version 10.x (10.3) of CodeWarrior, but is applicable with minor changes for any other Kinetis board and as well for CodeWarrior for MCU10.x.
Additional Processor Expert Component Installation
In this tutorial I’m using additional open source Processor Expert components which are not part of the CodeWarrior Eclipse standard distribution:
Both *.PEupd files can be downloaded from the above links. To import them into CodeWarrior, I use the menu Processor Expert > Import Package:
Then I browse to the *.PEupd files and select them to import.
Hint: it is possible to import multiple components in a single step with selecting multiple files to import.
After importing the components, it might be necessary to refresh the components list. To make sure all Processor Expert Views are loaded, I use the menu Processor Expert > Show Views:
After importing, the LED and Wait component should show up in the Alphabetical tab of the Component Library view:
If not, a Refresh of the components might be needed:
Creating the Project
I use the menu File > New > Bareboard Project:
Next, I need to specify a name for my project:
Next, I select the MKL25Z128 as my device:
Hint: I can use the filter field to at the top of the dialog to filter the devices. In MCU10.3 I can simply type ‘kl25’, where in MCU10.2 I need ‘*kl25*’ as filter text.
Next, to select the debug connection. As the Freedom Board has the new OpenSDA on it, this is my choice:
In the next dialog, nothing has (or can) be changed. the ARM GNU GCC is the only (and default) tool-chain for Kinetis L (Cortex M0+) family:
Next, I select Processor Expert for my project:
Pressing ‘Finish’ creates the project for me:
In case the Processor Expert component are not shown, I need to open the components for the selected project:
Note: Now in MCU10.3 the project view and the Processor Expert Components view are clearly separate.
To add the LED component, I select it and use the ‘Add to project’ context menu:
Hint: instead of using the context menu, I can double click on the component to add it.
I do this 3 times, one for red, blue and green color. As I have missing settings, they show up with an error marker in the Components view:
I’m changing the settings in the Component Inspector for the three LED’s:
- Changing the Component name: this is an arbitrary name, and is used for the generated driver source files (.c and .h file). I name it LEDR, LEDG and LEDB for the three colors
- As according to the schematics the cathode of the LED is connected to the microcontroller pin, I specify ‘no’ for this property (Anode is on the microcontroller port side), and this means that a HIGH logical level of the pin will turn the LED on.
Linking to Microcontroller Pin
According to the FRDM-KL25Z Schematics (SPF-27556_D).pdf, the RGB LED is connected to following pins:
- Red: PTB18
- Green: PTB19
- Blue: PTD1
So I need to assign the pin to the LED component. For this, I unfold the LED component with clicing on the small triangle on the left side:
Then I select the LEDpin to show the properties in the Component Inspector. This shows some items in red as they are not assigned yet:
I assign PTB18 as pin:
💡 With CW for MCU10.5, I can type in the port name and it will filter automatically the entries. For earlier CodeWarrior versions I would need to select the pin from the list.
Next I configure the pin as output, and mark it for auto initialization so I do not need to call the initialization of it in my application:
The Field Name has to match the field name I used in the LED component.
Hint: If I specify the optional ‘Pin Signal’ name, then Processor Expert will document it in the list of pins used.
Optionally I can assign a name for the pin/signal so Processor Expert can generate a pin list for me:
I need to do the same procedure for the blue and green led. It is just that they use different pins:
As I want to busy wait between the LED toggling, I add the ‘Wait’ component to the project:
Now I have all my components together, time to generate code. For this I use the toolbar button:
This generates the code for my components:
Adding LED Code
The application main() is inside ProcessorExpert.c, where add my LED demo code:
Hint: An easy way to add code and function calls to components is to use drag & drop.
I build the project with the menu Project > Build Project or using the ‘hammer’ icon:
At this point there should be no problems, so the Problems view should just show empty:
To download and debug, I press the debug toolbar icon. An annoying thing in Eclipse is I first need to *select* the project first to select the right debug configuration:
So I select the project, then hover over the icon to make sure my project is selected. Otherwise I use the small drop down of the debug toolbar icon to select the right configuration:
This will start the debugger, and I can use the toolbar items in the Debug view to step through my code:
The project I have created in above steps can be downloaded from this link.
The steps presented here are really generic, and work for many boards and microcontrollers, especially for the Kinetis family. All what I need to know is the information to which pin the LED’s are connected. With this it is very easy to create a bare board (without RTOS) application blinking LED’s.
Happy enlightning 🙂