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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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-K64F + KDS 3.0 + Software Dev Kit (SDK) 1.2.0] Tutorial: GPIO Toggling using Interrupt 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: 29 May 2015 1:51 PM Date Created
  • Views 1268 views
  • Likes 0 likes
  • Comments 1 comment
  • interrupt
  • kds3.0
  • ksdk1.2.0
  • frdm-k64
Related
Recommended

[FRDM-K64F + KDS 3.0 + Software Dev Kit (SDK) 1.2.0] Tutorial: GPIO Toggling using Interrupt without Processor Expert

bheemarao
bheemarao
29 May 2015

Here is a tutorial working on GPIO based interrupt using KSDK. Toggling  Led using push button (interrupt based event) on FRDM-K64F board using New Kinetis Design Studio 3.0 IDE and using Kinetis Software development kit (KSDK).


Before we begin make sure below requirements are there as setup


Required Hardware and Software:

 

  • Kinetis Design Studio 3.0

(download link: KDS 3.0)

 

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

(Download Link Kinetis SDK 1.2 Mainline )

 

  • FRDM-K64F Board configured with JLink Debugger

(The firmware can be downloaded here: Firmware download)

 

  • Install ‘KSDK_1.2.0_Eclipse_Update’ you can find the update file and the instructions to install it in

‘C:\Freescale\KSDK_1.2.0\tools\eclipse_update’.

 

  • It is necessary to build KSDK Platform Driver Library (libksdk_platform.a)

Open ‘Getting Started with Kinetis SDK (KSDK) v.1.2.pdf’ located in ‘C:\Freescale\KSDK_1.2.0\doc’ and go to chapter ‘5.3 Build the platform library’.

 

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

 

  • Micro USB Cable

 

Create KDS project using KSDK


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+KSDK-gpio interrupt” and click Next.


image

You can select device either by ‘Boards’ or ‘Processor’ option

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


Develop the application


Right click over project folder and select New > Folder to create a new folder inside ‘project’ folder.


image


Name this folder ‘Board’ and click ‘Finish’.

image

Go to <C:\Freescale\KSDK_1.2.0\examples\frdmk64f> and copy all the source files (except the file FRDM-K64F.peb) in this folder to the folder ‘Board’ that was created in the project.

 

  • board.c
  • board.h
  • gpio_pins.c
  • gpio_pins.h
  • pin_mux.c
  • pin_mux.h

 

image

 

Right click copy the files and go to KDS project explorer select folder ‘Board’ right click and paste it.

image

It looks like as shown below in KDS window


image


board.c/h: The header file contains board board-specific configuration macros for things such as debug terminal configuration, push buttons, LEDs and other board board-specific items. The C file contains clock and oscillator initialization functions.

 

gpio_pins.c/h: Definitions used by the KSDK GPIO driver for the platform’s GPIO pins. These include push buttons and LEDs, but can include other items such as interrupt pins for external sensors, for example.

 

pin_mux.c/h: Contains peripheral-specific pin mux configurations. These functions can be called by the hardware_init() function or individually by the demo application.

 

Now create another folder “Utilities” inside our project folder as we did earlier.


image

 

Copy the below 2 files to this folder as we did earlier:

fsl_debug_console.c and fsl_debug_console.h

 

you can find them from below folders:

 

C:\Freescale\KSDK_1.2.0\platform\utilities\src\fsl_debug_console.c

C:\Freescale\KSDK_1.2.0\platform\utilities\inc\fsl_debug_console.h

 

fsl_debug_console.c/h: Provides initialization and basic functionality for the UART module that is connected to the debug interface.

 

NOTE: After copying ‘fsl_debug_console.c’ to utilities folder the prompt below may appear, in this case click ‘Yes’ and continue.


image

After copying these 2 files into folder ‘Utilities’ it looks as shown below:

image

Now we need to add these newly added folders to our ‘include paths’ into our project.

 

Select project folder, right click and select properties as shown below:

image

Then goto

“Project > Properties > C/C++ Build > Settings > Cross ARM C compiler > includes”


image

And add the Board and Utilities folder paths into this section as shown in below snapshots


image

Select Workspace > project folder and “Board” folder as shown below

image

Next, do similar way and add “Utilities” folder into include path:


image

After adding the paths it looks as shown below

image

Now you need to add platform related include paths that are required for build the project:


You need to add the below 4 paths to

Properties > C/C++ Build > Settings > Cross ARM C compiler > includes

 

C:\Freescale\KSDK_1.2.0\platform\osa\inc

C:\Freescale\KSDK_1.2.0\platform\hal\inc

C:\Freescale\KSDK_1.2.0\platform\system\inc

C:\Freescale\KSDK_1.2.0\platform\drivers\inc


image

After adding all the 4 paths it looks as shown below:

image

 

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

Select the below path

“C:\Freescale\KSDK_1.2.0\lib\ksdk_platform_lib\kds\K64F12”


image

Now build this project as shown below:

image

image


After successfully build you can see the library “libksdk_platform.a” is created under folder:

“C:\Freescale\KSDK_1.2.0\lib\ksdk_platform_lib\kds\K64F12\debug”

image


Adding the Platform Library to our project

 

We need to provide this path in our Newly created project.

 

Goto Project > Properties > C/C++ Build > Settings > Cross ARM C++ Linker > Miscellaneous


image

Click on “Apply” and then click “ok”


Now we have added all required include paths and libraries for our project we can precede further in writing our code:

Open the main.c file from source folder:


image

Delete all the contents and paste the below code:

 

#include"fsl_device_registers.h"
#include "board.h"
#include "pin_mux.h"
#include "fsl_clock_manager.h"
#include "fsl_debug_console.h"
#include <stdio.h>
 
int main(void)
{
/* enable clock for PORTs */

       CLOCK_SYS_EnablePortClock(PORTA_IDX);
       CLOCK_SYS_EnablePortClock(PORTB_IDX);
       CLOCK_SYS_EnablePortClock(PORTC_IDX);
       CLOCK_SYS_EnablePortClock(PORTE_IDX);

/* Init board clock */

       BOARD_ClockInit();
       dbg_uart_init();

       printf("\nHello World! \r\n");
       printf("\nPress SW2 to Toggle LED. \r\n");
// initialize the GPIO interrupt for push button for falling edge
       
switchPins[0].config.interrupt = kPortIntFallingEdge;
       
// Initializes GPIO driver

GPIO_DRV_Init(switchPins, ledPins);

while(1)
 {
 }
        return 0;
} //end of main 

// Define PORTC_IRQHandler (sw1) if GPIO_INTERRUPT is set

 void PORTC_IRQHandler()
       {
       GPIO_DRV_ClearPinIntFlag (kGpioSW2); // Clear IRQ flag
       GPIO_DRV_TogglePinOutput(BOARD_GPIO_LED_BLUE); // Toggle blue LED
       printf("\n Switch is pressed \r\n");
       }


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


image

Or click on hammer button as shown

image

You can see the build result

image

Debug the application

 

Now we will proceed further for debugging and test our written code:

 

Go to menu Run > Debug Configurations


image

Select GDB Segger J-Link Debugging option as shown below:


image

Click on Debug and proceed

 

Now we need connect the FRDM-K64 board to our computer via USB cable provided and open the serial hyperterminal window by knowing the port number from Device manager:

 

image

 

image

In my case it is connected to COM23 port, open any hyperterminal window application ( i am having putty)


image

My serial port settings are as shown in above picture:

 

Now click on Debug button from the below window


image

Below is the execution seen in serial window

image

I have enclosed the project folder and binaries for quick evaluation

 

You can watch the output recording for this project:


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



Happy Toggling using interrupt using KDS3.0 + KSDK 1.2.0


image image image



Attachments:
Binaries.rar
  • Sign in to reply
  • Former Member
    Former Member over 10 years ago

    Hi Sir my name is mayur

    i want some help from you

    I am Creating UART code using interrupt.

    I want to write IRQ handler for Externel UART Communication can u help me.

    I am sending my IRQ code below please send me any changes to do

     

     

    Code

    void PORTC_IRQHandler()

           {

           GPIO_DRV_ClearPinIntFlag(0); // Clear IRQ flag

          // GPIO_DRV_TogglePinOutput(BOARD_GPIO_LED_BLUE); // Toggle blue LED

          

           PORTC_ISFR = PORT_ISFR_ISF(0x40);

           }

    • 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