element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • 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
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • 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
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Documents [FRDM-K64F + Kinetis Design Studio (KDS) + Software Dev Kit (SDK)] Tutorial: Toggling an RGB LED without Processor expert
  • Blog
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Freedom development platform requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 15 Sep 2014 4:46 AM Date Created
  • Last Updated Last Updated: 15 Sep 2014 10:04 AM
  • Views 614 views
  • Likes 0 likes
  • Comments 3 comments
Related
Recommended

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

Here is a tutorial for toggling RGB Led’s on FRDM-K64F 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:

  • FRDM-K64F Board configured with JLink Debugger

     (The firmware can be downloaded here: Firmware download)

  • Micro USB Cable
  • Kinetis Design Studio (v1.1.1 or newer)

     (You can now download the GA release, KDS 1.1.1, at: KDS-WINDOWS_IDE  )

  • Kinetis Software Development Kit (KSDK-v1.0.1)

     (Download Link Freescale Kinetis SDK_1.0.0 - Windows installer )

  • Eclipse Update for Freescale Kinetis SDK 1.0.0-GA

     (http://cache.freescale.com/lgfiles/sdk/SDK_1.0.0-GA_Update_for_Eclipse_1.0.1.zip)

  • Reference of FRDM-K64 user guide for schematic

    (http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FRDM-K64F&fpsp=1&tab=Design_Tools_Tab#)


The activity has been split into different sections as below:

1. Loading the OpenSDA V2 firmware to K64F board provided from Segger:

(refer to the link: HERE )

2. Setting up Kinetis Design Studio Environment Variable

3. Eclipse Update for Freescale Kinetis SDK 1.0.0-GA

(refer to the link: HERE )

4. Build the platform driver library

5. Creating New Project:

 

 

  • Setting up Kinetis Design Studio Environment Variable

 

After the installation of KDS the environment variable “KSDK_PATH” must be defined.

In the start-up menu, right click “Computer” and choose “Properties.”

In the left column, click “Advanced system settings.” You should get the following window:


image

 

Click the “Environment Variables” and make sure the KSDK_PATH is correct in the “User variables for <user name>”.


Add the new variable under “User variables…”. The name should be “KSDK_PATH”. The path is the same where by default the KSDK is installed. In this case the path is “C:\Freescale\KSDK_1.0.0”.

 

  • 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.


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 KSDK_1.0.0 installation folder and select the K64F12 folder and select ‘ok’.

image

Make sure the project is selected and click Finish as shown below

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:


image

When the build is complete, the ‘ksdk_platform_lib.a’ is generated in the directory according to the build target which is located here “C:/Freescale/KSDK_1.0.0/lib/ksdk_platform_lib/kds/K64F12/debug/ksdk_platform_lib.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 as shown


image

I am selecting the target device by Boards option and selected “FRDM-K64F” and click Next as shown below:

image

You can see the Device in target board is “MK64FN1M0LL12”

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 “Environment variable” by which default it displays “KSDK_PATH” which is in installed directory.

Make sure that "Processor Expert" is not checked.


Next click Finish button and proceed further.

image

You can see a KDS project window created for our New project. To see a relevant perspective windows click on ‘Windows>Reset Perspective’ as shown below:

  image

You can see below updated project window and is created and ready to include the source code.

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 following path: C:\Freescale\KSDK_1.0.0\boards\  as shown below:

image

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

image

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

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".

image

select "C/C++ Build" menu go to "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.

The default path is "C:\Freescale\KSDK_1.0.0\lib\ksdk_platform_lib\kds\K64F12\Debug\ksdk_platform_lib.a".

  image

And proceed further

image

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


Now, let’s toggle an RGB LED. It is necessary to include the boards.h file:

#include "board.h"

 

And build once to check it is error free.

image

After compiling i got an error saying that ‘board.h’ is not present the error is as shown below:

image

To overcome this error we need to add the path of board.h to #includes of our project.

Right click on project and select properties and select the choice as shown:

image

Now we need to add the path, click on ‘ADD..’ button and you can see a small windows appears as shown

image

 

Tick the check box ‘Is a workspace path’ and click on Workspace... as shown.

 

Select the directory that contains ‘board.h’ which we added earlier as shown:

image

Proceed further by clicking ‘ok’

You can see the path we selected appears in the last entry in listed down as shown:

image

Click on Apply and ‘OK’ and proceed further.

Now clean and build the project you can see the compilation results without errors.

 

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

Refer to the K64F board schematic the 3 LED’s are connected to Port-B and Port-E 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.

 

To know how GPIO have been defined in KSDK library click on include folder and navigate to /drivers/gpio and select ‘fsl_gpio_driver.h’ as shown below:

(we are accessing the GPIO feature through driver layer not from HAL)

image

 

The GPIO driver uses the virtual GPIO name rather than an actual port and a pin number.


By using the virtual name, each pin name is self-explanatory. To use the GPIO driver, an enumeration variable must be predefined in the user application files. The variable saves all GPIO pin information used in a project.

 

enum _gpio_pins

{

    kGpioLED11  = GPIO_MAKE_PIN(HW_GPIOB, 0x15), // PTB-21 = 0x15 -> BLUE LED.

    kGpioLED22  = GPIO_MAKE_PIN(HW_GPIOB, 0x16), // PTB-22 = 0x16 -> RED LED.

    kGpioLED33  = GPIO_MAKE_PIN(HW_GPIOE, 0x1A), // PTE-26 = 0x1A -> Green LED.

};

Actually by default kGpioLED1, kGpioLED2, kGpioLED3 have been already defined in library, just for our understanding i am creating another enum port variables for 3-LED as kGpioLED11, kGpioLED22, kGpioLED33

 

Now we shall toggle all the 3 LED’s one by one i.e RED on with delay/ RED off with delay,  Blue on with delay/ Blue off with delay, Green on with delay/ Green off with delay and loops back.

 

Below is my line of code to do this task

 

#include "fsl_device_registers.h"

#include "board.h"

 

enum _gpio_pins

{

    kGpioLED11  = GPIO_MAKE_PIN(HW_GPIOB, 0x15), // PTB-21 = 0x15 -> BLUE LED.

    kGpioLED22  = GPIO_MAKE_PIN(HW_GPIOB, 0x16), // PTB-22 = 0x16 -> RED LED.

    kGpioLED33  = GPIO_MAKE_PIN(HW_GPIOE, 0x1A), // PTE-26 = 0x1A -> Green LED.

};

 

static int i = 0;

int main(void)

{

    /* Write your code here */

          short value = 0;

          hardware_init();

 

          GPIO_DRV_SetPinDir(kGpioLED11, kGpioDigitalOutput); //configuring PTB21 port pin as output

          GPIO_DRV_WritePinOutput(kGpioLED11, 1); // driving the PTB21 port pin to HIGH == LED off

 

          GPIO_DRV_SetPinDir(kGpioLED22, kGpioDigitalOutput); //configuring PTB22 port pin as output

          GPIO_DRV_WritePinOutput(kGpioLED22, 1); // driving the PTB22 port pin to HIGH == LED off

 

          GPIO_DRV_SetPinDir(kGpioLED33, kGpioDigitalOutput);//configuring PTE26 port pin as output

          GPIO_DRV_WritePinOutput(kGpioLED33, 1); // driving the PTE26 port pin to HIGH == LED off

 

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

 

 

    for (;;) {

 

          value=0;

          GPIO_DRV_WritePinOutput(kGpioLED11, value); //Blue LED on

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

          value = value^1; // value=1

          GPIO_DRV_WritePinOutput(kGpioLED11, value); //Blue LED off

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

 

          value=0;

          GPIO_DRV_WritePinOutput(kGpioLED22, value); // RED LED on

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

          value = value^1; // value=1

          GPIO_DRV_WritePinOutput(kGpioLED22, value); // RED LED off

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

 

           value=0;

           GPIO_DRV_WritePinOutput(kGpioLED33, value); // Green LED on

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

           value = value^1; //1

           GPIO_DRV_WritePinOutput(kGpioLED33, value); // Green LED off

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

 

    }

    /* Never leave main */

    return 0;

}

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

// EOF

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

 

Explanation of the code:

 

Initializing the Port pin


enum _gpio_pins

{

    kGpioLED11  = GPIO_MAKE_PIN(HW_GPIOB, 0x15), // PTB-21 = 0x15 -> BLUE LED.

    kGpioLED22  = GPIO_MAKE_PIN(HW_GPIOB, 0x16), // PTB-22 = 0x16 -> RED LED.

    kGpioLED33  = GPIO_MAKE_PIN(HW_GPIOE, 0x1A), // PTE-26 = 0x1A -> Green LED.

};

Here we are enumerating the port pins as hardware GPIO ports and creating variables for it.

 

Configuring the Port pin


GPIO_DRV_SetPinDir(kGpioLED11, kGpioDigitalOutput); //configuring PTB21 port pin as output

 

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

 

GPIO_DRV_WritePinOutput(kGpioLED11, 1); // driving the PTB21 port pin to HIGH == LED off

 

This function assigns/writes PortB-21 pin 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 i.e performing logical ‘X-OR’ operation on the variable ‘value’ and assigning this to port pins

value=0;

          GPIO_DRV_WritePinOutput(kGpioLED11, value); //Blue LED on

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

          value = value^1; // value=1

          GPIO_DRV_WritePinOutput(kGpioLED11, value); //Blue LED off

                   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 “JLink_OpenSDA_V2.bin” OpenSDA_V2 application driver file. And same will be used for connecting hardware to PC.

image

Select ‘GDB SEGGER J-Link Debugging and double click or right click and select ‘New’


image

 

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 Debuger tab check ‘Device name’ field by default it will blank.

 

Now specify device name “MK64FN1M0xxx12” and click on apply and close the Debug configuration window as shown below:

image

Now connect FRDM-K64F board to PC through USB mini connector connecting to “SDA USB” port of board as shown:

image

Click on Debug icon as shown and select Debug Configuration and proceed to debug your project:


image

Click on Debug

image

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

 

You can see below video recording of the project execution from below link.

RGB Led Toggle using KDS+SDK using K64F Freedom board

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 for quick view and execution.

 

 

Happy Toggling image image

Attachments:
K64-LED Blink-KSDK-project file.rar
  • k64
  • freedom-board
  • kinetis
  • frdm-k64f
  • kds
  • led-toggling
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply
  • jagt48
    jagt48 over 8 years ago in reply to Former Member

    George,

     

    Did you close the "ksdk_platform_lib_k64F12" project before cleaning and building the "K64-LED-Blink-KSDK" project? If not then a similar error to what you are seeing is thrown on my machine. That step isn't included in this write-up as it appears that Bheema has cleared all of the other projects from the Project Explorer pane. Other than that this tutorial has been spot on for me.

     

    As for the /drivers/dma missing, that and a couple of other folders are missing for me as well when I build the library. It hasn't been an issue for me up to this point though. Are you still able to successfully build the library? Try the above and see if any errors or warnings are thrown and we can move on from there.

     

     

    -Joseph

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

    Hi George,

     

    What i observe is after the project is compiled in KDS tool cross check whether *.elf file has been generated in ~\workspace.kds\KDS-KSDK-K64 blink\Debug

    project folder, if it has been generated then manually provide a path in Debug configuration of KDS tool as shown below:

    image

    Manually type the path Debug\KDS-KSDK-K64 blink.elf and proceed further for Debug.

    Now it has to compile with out errors.

     

    If this does not work then import the attached project to your workspace and execute it.

     

    Best Regards

    Bheema Rao

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

    I have followed the above several times, including reinstalling SDK update, with several minor errors, however I am now stuck with the following errors!

    DescriptionResourcePathLocationTypemake: *** No rule to make target `C:/Freescale/KSDK_1.0.0/lib/ksdk_platform_lib/kds/K64F12/Debug/kdsk_platform_lib.a', needed by `KDSK_blink.elf'.  Stop.KDSK_blinkC/C++ ProblemDescriptionResourcePathLocationTypeInvalid project path: Include path not found (C:\Freescale\KSDK_1.0.0\platform\drivers\dma).ksdk_platform_lib_K64F12pathentryPath Entry Problem

    could you explain how to fixed this please

    regards

    georgemm101

    • 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 © 2023 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube