element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Blog [FRDM-KL27Z + Kinetis Design Studio (KDS) + Software Dev Kit (SDK)] Tutorial: Toggling an RGB LED without Processor expert
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 1 Apr 2015 1:23 PM Date Created
  • Views 1025 views
  • Likes 2 likes
  • Comments 4 comments
  • freedom-board
  • kinetis
  • kds+ksdk
  • led-toggling
  • frdm-kl27z
Related
Recommended

[FRDM-KL27Z + Kinetis Design Studio (KDS) + Software Dev Kit (SDK)] Tutorial: Toggling an RGB LED without Processor expert

bheemarao
bheemarao
1 Apr 2015


Here is a tutorial for toggling RGB Led’s on FRDM-KL27Z board using Kinetis Design Studio IDE and using Kinetis Software development kit (KSDK).


Before we begin make sure below requirements are there as setup.


Required Hardware and Software:

 

1. FRDM-KL27Z Board loaded with MSD OpenSDA driver

(The firmware can be downloaded from FRDM-KL27-QSP)

2. Micro USB Cable

3. Kinetis Design Studio (v2.0.0)

(http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=KDS_IDE)

4. Kinetis Software Development Kit for KL27Z (KSDK-v1.1.0)

(Download Link Kinetis SDK1.1.0 Standalone for the FRDM-KL27Z - Windows Installer )


The features of the FRDM-KL27Z board are:

  • KL27Z64VLH4 MCU (48 MHz, 64 KB Flash, 16 KB RAM, low power, 64 LQFP package)
  • Capacitive touch slider, accelerometer MMA8451Q, Magnetometer MAG3110 ,Tri-color LED
  • Flexible power supply options – USB, coin cell battery, external source
  • Easy access to MCU I/O
  • Tri-color user‐controllable LEDs
  • Two (2) user push-button switches for NMI interrupts and LLWU wake up (SW1/SW3)
  • Thermistor sensor to measure temperature
  • Battery-ready, power-measurement access points
  • Form factor compatible with Arduino Tm R3 pin layout
  • New OpenSDA debug interface:
    • Mass storage device flash programming interface by default. No tool installation is required to evaluate demo applications.
    • P&E Micro Debug interface provides run-control debugging and compatibility with IDE tools.

 

image


Installing Kinetis SDK1.1.0 for KL27Z


First we need to install the Kinetis SDK1.1.0 standalone for FRDM-KL27Z freedom board. Below is the link to install.

Kinetis SDK1.1.0 Standalone for the FRDM-KL27Z - Windows Installer


It has been installed in below folder in my case:

C:\Freescale\KSDK1.1.0_KL27Z_1.0.0



Eclipse Update for Kinetis SDK1.1.0 (KL27Z)


Click on Help > Install New Software as shown below:

image

Click on Add as shown below

image

Next select Archive

image


Provide your path to the already installed directory

 

C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\tools\eclipse_update

 

Select “KSDK_1.1.0_KLx7Z_Eclipse_Update.zip” as shown below

image

Click on “Open”, and then “OK” in the “Add Repository” dialog box.

 

Check the box to the left of the KSDK Eclipse update and click “Next” in the lower right corner. Follow the remaining instructions to finish the installation of the update.

Once the update is applied, restart KDS for the changes to take effect.

 

Build the platform driver library

 

Before building and debugging any demo application in KSDK, the driver library project should be built to generate the library archives: ksdk_platform_lib.a. Because this library contains all binary codes for HAL and the peripheral drivers specific to the chip, each SoC has its own platform.a library archives.


Now we will proceed further building platform library

We need to Importing platform library from the KSDK installation path and build the library, follow below steps to import and build the platform library.


Open the KDS IDE by giving your default workspace and select ‘import’ option as shown below:


Select File>Import

image

Next select the option “Existing projects into Workspace” from General Tab and click “Next”

image

Click on “Browse” button as shown below:

image

 

Browse to navigate to KSDK1.1.0 installation folder and select the path as shown below


“C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\lib\ksdk_platform_lib\kds\KL27Z644”

image

Now select the Project, right click, clean and build the project as shown below:

image

image

 

You can see the build progress / status in console window, if everything goes well you can see build finishes as shown:


When the build is complete, the ‘libksdk_platform.a’ is generated in the directory according to the build target which is located here


“C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\lib\ksdk_platform_lib\kds\KL27Z644\Debug\ libksdk_platform.a”


We need to provide this path in our new project in "Cross ARM C++ Linker" option to add the KSDK library in the compiler. (this will be shown later while creating new project)


Creating New Project:


So let’s start in creating a new project using KDS + KSDK IDE

Open KDS IDE by double clicking the KDS icon present in your desktop:


It will ask for the Workspace, give the path of your choice and click ‘ok’

image

Next create a New project by clicking

 

  File -> New -> Kinetis Design Studio Project

image

Choose project name of your choice, i have given it as “K64-LED Blink-KSDK” and click Next.

image

You can select device either by ‘Boards’ or ‘Processor’ option, I am selecting the target device by processors as shown below:

image

You can see the Device part number of “MKL27Z64xxx4” click on “Next”


In the next screen you can find below options to be selected in Rapid Application Development window

Select the check box “Kinetis SDK”

 

 

And select the radio button “Absolute path” and browse for installed KSDK for KL27Z directory as shown below:

 

image

Provide the installed KSDK path i.e “C:\Freescale\KSDK1.1.0_KL27Z_1.0.0” then proceed further


image


Click finish to proceed further.


Now our created project platform is ready, You can see a KDS project window created for our New project.


image


It is necessary to include the required ‘board’ folder for this project. To add it right click on the project just created and chose "Import".


image

Select the “File System” and click on Next as shown below:

image

Now look for the board folder in the installed KSDK1.1.0 folder

C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\boards\frdmkl27z  as shown below:


Select only *.c and *.h files from option as shown below and proceed to Finish.

image

You can see the board header folder “frdmkl27z” is added to our project folder as shown:

image

We need to add the “boards.h” folder path to the project settings, it is done as shown below:

image

Now select our workspace path and the frdmkl27z folder which contains our board related header files:


image


Next we need to add the KSDK library in the compiler, this step is very important else u will not be able to compile your project.


To add this you need to right click the project and click in "Properties".

select "C/C++ Build" > "Settings".


Then click on “Tool Settings” and select "Miscellaneous" under "Cross ARM C++ Linker" option as shown below:

image

Click on add object button   as shown above and add the library here. image


The default path is

“C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\lib\ksdk_platform_lib\kds\KL27Z644\Debug\libksdk_platform.a”


image

And proceed further

image

Make sure the compiler knows the include path to the boards folder. As the board files are using a bunch of other include files of the SDK, I need to add some extra compiler include paths:


We have to add these include paths in ‘properties’ > ‘C/C++ General’ > ‘Paths and Symbols’ as shown and add the paths

image

The include files and corresponding paths to be provided are as given below:


File: fsl_gpio_driver.h

Path to be added C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\platform\drivers\inc

image

Similarly for the other include file paths as below

File: fsl_port_hal.h

Path to be added C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\platform\hal\inc

 

File: fsl_clock_manager.h

Path to be added C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\platform\system\inc

 

File: fsl_debug_console.h

Path to be added C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\platform\utilities\inc

 

File: fsl_os_abstraction.h

Path to be added C:\Freescale\KSDK1.1.0_KL27Z_1.0.0\platform\osa\inc


image


With this, I’m able to compile and link the board file

image

It builds with no error

image


Now our platform is ready and we need to write our code to toggle the RGB


It is necessary to include the boards.h file:

#include "board.h"

We are now proceeding further in coding our requirement to toggle RGB LEDs.

Refer to the board schematic the 3 LED’s are connected to Port-B and Port-A pins

image

You can see these LED’s are connected in active-Low connection, i.e common Anode, we should provide Low signal to port pins to glow a LED.


Led’s have been defined in board.h file

#define BOARD_GPIO_LED_RED              kGpioLED2

#define BOARD_GPIO_LED_GREEN            kGpioLED3

#define BOARD_GPIO_LED_BLUE            kGpioLED1


To know how GPIO have been defined in KSDK library click on include folder and navigate to /platform/drivers/inc

and select ‘fsl_gpio_driver.h’ as shown below:

image

By default kGpioLED1, kGpioLED2, kGpioLED3 have been already defined in library,

 

Now we shall toggle all the 3 LED’s one by one with some software delay() i.e blue is on for some time then blue+red is on for some time then blue+red+green is on for some time, this is one cycle of toggling pins and next time reverse happens i.e red+green is on (blue = off) and green is on (blue, red = off) then green also off (all the 3 led’s are off) this sequence loops back.


Below is my line of code to do this task

#include<stdio.h>

#include<stdlib.h>

#include"fsl_device_registers.h"

#include"fsl_debug_console.h"

#include"board.h"

#include"fsl_lpuart_hal.h"


staticint i = 0;

 

//void dbg_uart_init();

 

int main(void)

{

 

    /* Write your code here */

 

      hardware_init();

      GPIO_DRV_SetPinDir(kGpioLED1,kGpioDigitalOutput);  // kGpioDigitalOutput = 1=output

      GPIO_DRV_SetPinOutput(kGpioLED1); //set pin = led off


      GPIO_DRV_SetPinDir(kGpioLED2,kGpioDigitalOutput);  // kGpioDigitalOutput = 1=output

      GPIO_DRV_SetPinOutput(kGpioLED2); //set pin = led off

 

      GPIO_DRV_SetPinDir(kGpioLED3,kGpioDigitalOutput);  // kGpioDigitalOutput = 1=output

      GPIO_DRV_SetPinOutput(kGpioLED3); //set pin = led off

 

    /* This for loop should be replaced. By default this loop allows a single stepping. */

for (;;) {

 

      GPIO_DRV_TogglePinOutput(kGpioLED1); // Toggle LED1=Blue

for (i = 0; i<10000000; i++);  // software delay

 

      GPIO_DRV_TogglePinOutput(kGpioLED2); // Toggle LED2=Red

for (i = 0; i<10000000; i++);  // software delay

 

      GPIO_DRV_TogglePinOutput(kGpioLED3); //  Toggle LED3=Green

for (i = 0; i<10000000; i++);  // software delay

    }

/* Never leave main */

return 0;

}

////////////////////////////////////////////////////////////////////////////////

// EOF

////////////////////////////////////////////////////////////////////////////////

 

Explanation of the code:

 

Configuring the Port pin


GPIO_DRV_SetPinDir(kGpioLED1, kGpioDigitalOutput); // kGpioDigitalOutput = 1=output

This function configures the kGpioLED1 pin as digital output and by default this will be pull down to GND (i.e port pin driven to zero)

GPIO_DRV_SetPinOutput(kGpioLED1); //set pin = led off


This function sets /writes pin kGpioLED1 to ‘1’ which means the LED is in off condition.

Same thing is done for other 2 port led’s

 

Next in the infinite for loop we are toggling each pin sequentially with software delay();

for (;;) {

      GPIO_DRV_TogglePinOutput(kGpioLED1); // Toggle LED1=Blue

      for (i = 0; i<10000000; i++);  // software delay

 

      GPIO_DRV_TogglePinOutput(kGpioLED2); // Toggle LED2=Red

      for (i = 0; i<10000000; i++);  // software delay

 

      GPIO_DRV_TogglePinOutput(kGpioLED3); //  Toggle LED3=Green

      for (i = 0; i<10000000; i++);  // software delay

    }

Now it’s time to clean and compile/Build the project

image

You can see the build output as shown below:

image

 

Now we need to setup for Debug configuration:

As a pre-requisite the board is loaded with OpenSDA provided in “FRDM-KL27-QSP.zip”

image

 

Select ‘GDB PEMicro interface Debugging’ and double click or right click and select ‘New’

You can see a default name as project name as shown below: make sure under ‘Main’ tab C/C++ application there is *.elf file name of your project.

image

Next click on Debugger tab check the interface is selected to OpenSDA and port is assigned as shown below

image

(make sure you have connected the board to PC via USB mini connector to “Open SDA” J-13 jumper of the board)


Now you can see the Debug window opens ready for single stepping or Running the project as shown:

 

image

Click on Resume button or press ‘F8’ button for executing the project.


You can see the output as shown

image

Attached is the video recording of the project execution.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image


And i have enclosed the project folder and SREC file for quick view and execution.

 

Happy Toggling image image image

 






Attachments:
KL27 sdk.rar
KL27 sdk-srec.rar
  • Sign in to reply

Top Comments

  • FreescaleTools_and_Software
    FreescaleTools_and_Software over 10 years ago in reply to fvan +1
    Don't hesitate to contact Bheema or myself, if you need any support to get starting with your new FRDM-KL25Z
  • bheemarao
    bheemarao over 9 years ago in reply to Former Member

    Hi Rebel,

     

    You can try below 2 options:

     

    1) Import the enclosed tutorial project into your workspace and build. please check are you able to build this without errors?

    2) I have enclosed the srec executable files, you can directly drag and drop to your MSD detected FRDM-KL27Z opensda folder and check whether you are able to see LED blinking.

     

    Best Regards

    Bheema Rao

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    I tried everything you have mentioned but I cannot seem to get the LED's blinking. Could you help me debug the issue?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • FreescaleTools_and_Software
    FreescaleTools_and_Software over 10 years ago in reply to fvan

    Don't hesitate to contact Bheema or myself, if you need any support to get starting with your new FRDM-KL25Z image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fvan
    fvan over 10 years ago

    Recently bought a KL25Z, and it arrived yesterday. Your post will be useful to get me started, thanks!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube