Hardware, Software

Introduction to FRDM KL46Z and KDS

Outdated post alert: Sorry, this post is no longer being maintained. If you are loooking for some sample code for FRDM KL46Z visit: https://github.com/madaari/FRDM-KL46Z-developnment-board

Year ago, i wrote a tutorial on getting started with freescale’s FRDM KL46Z development board. since then it was just a draft, today, i thought of updating and releasing it. So, here it is:

But first of all, a very brief introduction of the development board and OpenSDA

FRDM KL46Z

Features

  • MKL46Z256VLL4MCU – 48 MHz, 256 KB flash, 32 KB SRAM, segment LCD, USB OTG (FS) , 100 LQFP
  • Capacitive touch slider, MMA8451Q accelerometer, MAG3110 magnetometer
  • Flexible power supply options – USB, coin cell battery, external source
  • Easy access to MCU I/O
  • Battery-ready, power-measurement access points
  • Form factor compatible with Arduino ™ R3 pin layout
  • OpenSDA debug interface
    • Mass storage device flash programming interface (default) – no tool installation required to evaluate demo apps
    • P&E debug interface provides run-control debugging and compatibility with IDE tools
    • CMSIS-DAP interface: new ARM standard for embedded debug interface

 

WHY FRDM KL46Z ???

 

 

Performance

• 48 MHz ARM® Cortex®-M0+ core

Memories and memory interfaces

• Up to 256 KB program flash memory
• Up to 32 KB SRAM

System peripherals

• Nine low-power modes to provide power optimization
based on application requirements
• COP Software watchdog
• 4-channel DMA controller, supporting up to 63 request sources
• Low-leakage wakeup unit
• SWD debug interface and Micro Trace Buffer
• Bit Manipulation Engine

Operating Characteristics

• Voltage range: 1.71 to 3.6 V
• Flash write voltage range: 1.71 to 3.6 V
• Temperature range (ambient): -40 to 105°C

Human-machine interface

• Segment LCD controller supporting up to 47
frontplanes and 8 backplanes, or 51 frontplanes and
4 backplanes
• Low-power hardware touch sensor interface (TSI)
• Up to 84 general-purpose input/output (GPIO)

Communication interfaces

• USB full-/low-speed On-the-Go controller with onchip
transceiver and 5 V to 3.3 V regulator
• Two 16-bit SPI modules
• I2S (SAI) module
• One low power UART module
• Two UART modules
• Two I2C module

Analog Modules

• 16-bit SAR ADC
• 12-bit DAC
• Analog comparator (CMP) containing a 6-bit DAC and programmable reference input

Timers

• Six channel Timer/PWM (TPM)
• Two 2-channel Timer/PWM modules
• Periodic interrupt timers
• 16-bit low-power timer (LPTMR)
• Real time clock

Security and integrity modules

• 80-bit unique identification number per chip

OpenSDA 

What’s  OpenSDA ?????

OpenSDA is a serial and debug adapter that is built into several NXP evaluation boards. It provides a bridge between your computer (or other USB host) and the embedded target processor, which can be used for debugging, flash programming, and serial communication, all over a simple USB cable.

Features

  • Debugging, flash programming, and serial communication over a single USB connection between a host and an embedded target processor
  • Quick and easy loading of firmware applications with a MSD bootloader
  • Whole OpenSDA solution available to the customer:
    • Circuit schematics available
    • OpenSDAv2 open-source mbed interface bootloader and firmware application
  • Fully compatible with third-party debugging solutions

Now, after a brief intro, let’s move on to our first code and environment setup.

ENVIRONMENT SETUP

Before starting I would like to introduce and thank my mentors namely Aman sir and  Rohan sir, for their efficient and immaculate teachings.

In this tutorial, we will be using kinetis design studio on windows 10 platform for programming our board.
The Kinetis® Design Studio (KDS) is a complimentary integrated development environment for Kinetis MCUs that enables robust editing, compiling and debugging of your designs. Based on free, open-source software including Eclipse, GNU Compiler Collection (GCC), GNU Debugger (GDB), and others, the Kinetis Design Studio IDE offers designers a simple development tool with no code-size limitations.More about KDS……..
So before starting, you need to download KDS software along with other reference material(Including the Reference manual of the board and datasheets of sensors onboard) from here.
Install both the .exe files(KDS and KDS SDK) and you’ll also need to install the open SDA driver for connecting your board to the KDS.
Follow instructions given here for setting up an SDA driver.

If SDA driver installation went ok ….. then,you can find your device under the  Device Manager as shown in the adjacent picture.

 

After installing all the necessary softwares open kinetis design studio.
B00000002
Start by entering the work space directory location and hit ok
B00000003

  1. Now click on File->New->Kinetis project
  2. Enter the name for your project then click next
  3. select Boards->Kinetis->FRDMKL46z ,hit next
  4. Since we are not using processor experts,leave the processor expert check box unchecked.
  5. Now you should see your project name in  project explorer (click on the icon on the extreme left if you can’t open project explorer)
  6. Now click [>] icon present before your project name,a drop-down list should appear
  7. click [>] icon present before source and you should see main.cpp listed on the list.
  8. double click main.cpp…and now you should see it’s content……..So we are now ready to write our first blinkLED program
  After successfully setting up your environment let’s head towards our first code.
You can find all codes from this tutorial on my Github repository here.
 

YOUR FIRST CODE

AIM: to blink the red LED present onboard

red_led_on

//RED led is at port E , Register 29 
#include "MKL46Z4.h" 
static int i = 0; 

int main(void) {
 SIM_SCGC5=SIM_SCGC5 | SIM_SCGC5_PORTE_MASK;//for providing clock to port E 
 PORTE_PCR29=1<<8;//for setting up register 29 as GPIO. Here,PCR stands for Port Control Register 
 GPIOE_PDDR=1<<29;//for setting up pin as output pin 
 GPIOE_PDOR=0<<29;//for switching on pin REMEMBER: here 0 will switch led on and 1 will switch it off //
 GPIO_PDOR=1<<29; //for turning off LED 
}

 

Explanation of the above code

 

So,first of all in order to switch red led you need to find the register and port allocated to that LED. For this, refer the image given below:
FRDMKL46Z-PIN MAP ADDITIONAL
As you can see RED LED is present at PTE29 which means port E and register number 29.
Ok, so now next step is to provide clock to the respective port(i.e PORT E) .For this refer the datasheet (KL46P121M48SF4RM) present in the package. Then under chapter 12(System Integration Module) of the datasheet click on memory map and register definition.
B00000004
here there are 4 SIM_SCGC registers mentioned.Click on the link adjacent to SIM_SCGC5 . You will then see:
B00000006
This is the description of the SIM_SCGC5 register . As you can now see that this register is used to give a clock to PORTE.
so,we include the line SIM_SCGC5 = SIM_SCGC5 | SIM_SCGC5_PORTE_MASK;
we the above line we  provide clock at PORTE without disturbing other clock distribution.
Here we could have also used SIM_SCGC5 = SIM_SCGC5_PORTE_MASK; but that would mean, giving clock ONLY to PORTE.
After giving clock,We need set pin 29 of port E as GPIO . For this,refer Memory map and register definition under PORT(Chapter 11) of the datasheet.
B00000011
Click on the link(See section) adjacent to PORTE_PCR29 .
B00000013
Here, 8-10 registers are for MUX. So, in order to set pin 29 as GPIO we need to give binary 001 i.e 1(in base 10) to pin 8.
For this,we have included the line: PORTE_PCR29=1<<8;
Now after setting up pin 29 as GPIO we need to specify whether we want to use that pin as input or output pin.For this refer, Memory map and register definition under Chapter 42(GPIO) of the datasheet.
B00000015
Click on the link next to GPIOE_PDDR.
B00000016
So, for setting the pin as output we need to put 1 at PIN 29 of GPIOE_PDDR register.
for this we have included the line: GPIOE_PDDR=1<<29;
voillaa!!!!!! we are now ready to give output to the led
So, for giving output we use PDOR(Port data output register). Refer to datasheet for its usage.
Thus,we use GPIOE_PDOR=0<<29; to switch on LED. Similarly, GPIOE_PDOR=1<<29; is for switching off the LED.

RUNNING AND DEBUGGING YOUR CODE

In order to run/debug code in KDS follow these steps:

  1. select debug configuration under the run menu.
  2. Then select <YOUR PROJECT NAME>_PNE in the list on the left
  3. Now select the debugger tab, and chose OpenSDA debugger USB port under interface(It should automatically detect port).
  4. Click on apply and then debug.(EASY !!!!!!!)
  5. That’s it!! you are now in the debug window. Click on the run icon(>). And then terminate the code by clicking on([])(red square).
  6. Now press the reset button on the board and Hurrah!!!!  RED LED is now On!!!!!!!!!!!

 

Tagged

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.