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 + KDS3.0 + KSDK 1.2.0] Tutorial: UART communication (using polling) with a console on the host through OpenSDA
  • 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: 8 Jun 2015 10:56 AM Date Created
  • Views 2261 views
  • Likes 0 likes
  • Comments 7 comments
  • polling
  • frdm-k64f
  • kds3.0
  • ksdk1.2.0
  • uart
Related
Recommended

[FRDM-K64F + KDS3.0 + KSDK 1.2.0] Tutorial: UART communication (using polling) with a console on the host through OpenSDA

bheemarao
bheemarao
8 Jun 2015

This project demonstrates UART through OpenSDA (character is printed back on console through the CDC port of the board) with the FRDM-K64F Board using New Kinetis Design Studio 3.0 IDE and using Kinetis Software development kit (KSDK) 1.2.0

This example will examine the efficiency of the transmit/receive uart drivers with using polling method. Transfer data between board and PC. Board will transfer and receive characters with PC through UART interface. Type characters from keyboard, the board will receive and then echo them to terminal screen.

 

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-uart polling” 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

Similarly add one more file i.e “hardware_init.c” from the location

“C:\Freescale\KSDK_1.2.0\examples\frdmk64f\driver_examples\gpio\hardware_init.c”

It looks like as shown below in KDS window

image

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

 

hardware_init.c: This file Enable clock for PORTs, setup board clock source, config pin which is required for hardware_init(); function called in main().

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

 

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


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

 

Please refer to my earlier blog build a platform library

Click Here

http://www.element14.com/community/community/designcenter/kinetis_kl2_freedom_board/blog/2015/05/29/frdm-k64f-kds-30-software-dev-kit-sdk-120-tutorial-gpio-toggling-using-interrupt-without-processor-expert

 

 

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”


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:

 

Delete all the contents and paste the below code:


#include "board.h"
#include "fsl_uart_hal.h"
#include "fsl_clock_manager.h"


int main(void)
{
    uint8_t  rxChar          = 0;
    uint32_t byteCountBuff   = 0;
    uint32_t uartSourceClock = 0;
    UART_Type * baseAddr     = BOARD_DEBUG_UART_BASEADDR;

    // Enable clock for PORTs, setup board clock source, config pin
    hardware_init();
    dbg_uart_init();


    // Initialize the uart module with base address and config structure
    CLOCK_SYS_EnableUartClock(BOARD_DEBUG_UART_INSTANCE);

    // Get working uart clock
    uartSourceClock = CLOCK_SYS_GetUartFreq(BOARD_DEBUG_UART_INSTANCE);

    // Initialize UART baud rate, bit count, parity and stop bit
    UART_HAL_SetBaudRate(baseAddr, uartSourceClock, BOARD_DEBUG_UART_BAUD);
    UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
    UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
    UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);
#endif

    // Enable the UART transmitter and receiver
    UART_HAL_EnableTransmitter(baseAddr);
    UART_HAL_EnableReceiver(baseAddr);

    // Inform to start polling example

    // Inform user of what to do
  
    printf("\n\r UART Send/Receive Polling Example\n\r");
    printf("\n\rType characters from keyboard, the board will receive and then echo them to terminal screen\n\r");


    while(true)
    {
        // Wait to receive input data
    if (kStatus_UART_Success == UART_HAL_ReceiveDataPolling(baseAddr, &rxChar, 1u))
        {
            // Send any character that received
            UART_HAL_SendDataPolling(baseAddr, &rxChar, 1u);
        }
    }

}


Explanation of Code:


hardware_init();

This function enable clock for PORTs, setup board clock source, config pin which is required for hardware.

 

dbg_uart_init();

This function enables us for printing the user data to the terminal using printf()


   CLOCK_SYS_EnableUartClock(BOARD_DEBUG_UART_INSTANCE);    
   uartSourceClock = CLOCK_SYS_GetUartFreq(BOARD_DEBUG_UART_INSTANCE); 
   UART_HAL_SetBaudRate(baseAddr, uartSourceClock, BOARD_DEBUG_UART_BAUD);
   UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
   UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
   UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);
#endif  
   UART_HAL_EnableTransmitter(baseAddr);
   UART_HAL_EnableReceiver(baseAddr);


The above function is required to Get working uart clock, Initialize UART baud rate, bit count, parity and stop bit, Enable the UART transmitter and receiver

 

The below lines performs the main task of our project requirement which is inside while(1)


if (kStatus_UART_Success == UART_HAL_ReceiveDataPolling(baseAddr, &rxChar, 1u))
        {
            // Send any character that received
            UART_HAL_SendDataPolling(baseAddr, &rxChar, 1u);
        }


Here the function UART_HAL_ReceiveDataPolling() keeps checking from user whether any keys have been pressed or not. If this is true then the kStatus_UART_Success is true and it enters inside the if statement where the data eentered by user which is saved in buffer rxChar is sent to uart port pins using the function UART_HAL_SendDataPolling().

 

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


image

Or click on hammer button as shown

 

image

Debug the application

 

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

 

Go to menu Run > Debug Configurations


image

As i have loaded PE micro OpenSDA driver for my K64F board,

Select GDB PEMicro interface 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


Note: You can run this project either by going to Debug configuration and run by single step or by creating binary image


Go to Debugger and select the OpenSDA option as shown below, click ‘Apply’ and ‘Debug’ button

 


image


You can see the process of debugging happening as shown below:


image

Now it is ready for debug/run our project

 

To run your program plug on K64F board to your computer and open the corresponding COM port (com port number can be noted from device manager after plugging the board) and settings as shown below.


image

My serial hyper terminal is connected to COM29 port number with baud rate of 115200 and click on ‘open’

Now click on resume button as shown below:


image

 


You can see the output as shown below: type a character it is printed back on console through the CDC port of the board.


image


image


I have enclosed the project folder and binary file for quick reference and testing.


Happy Async uart testing image image




Attachments:
  • Sign in to reply
  • bheemarao
    bheemarao over 10 years ago in reply to Former Member

    Hi Mayur,

     

    Below is the UART implementing using interrupt logic using KL25Z board available from mcuoneclipse, you can follow the same procedure for any other freedom board:

    http://mcuoneclipse.com/2012/10/14/tutorial-printf-and-hello-world-with-the-freedom-kl25z-board/

     

    on which freedom board do you want to implement this? you can let me know if you need any help.

     

    Best Regards

    Bheema Rao

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

    Thank you sir for your reply

    I want some help regarding uart Project. I want to receive data on uart using interrupt logic which  can be of variable size.

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

    Hi Mayur,

     

    Are you using the project folder that i have attached?

    Please check the workspace path while importing the project. Clean the project and build the project again and check whether the same error occurs.

     

    Best Regards

    Bheema Rao

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

    hi sir

    i am getting error regarding make file at

    DescriptionResourcePathLocationTypemake: *** multiple target patterns.  Stop.makefile/mayur/Debugline 56C/C++ Problem

    please guide me

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bheemarao
    bheemarao over 10 years ago in reply to sdorf

    Hi Shaul,

     

    I rechecked and tested at my side with P&E micro OpenSDA driver and it is working fine:

    Below is the snap shot of the working debugging window:

     

    image

    and also the single stepping while debugging is working fine:

    image

     

    Best Regards

    Bheema Rao

    • 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