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
- 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 ???
Memories and memory interfaces
Security and integrity modules
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.
- 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.
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 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 you board to the KDS.
Follow instructions given here for setting up 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 .
Start by entering the work space directory location and hit ok
- Now click on File->New->Kinetis project
- Enter the name for your project then click next
- select Boards->Kinetis->FRDMKL46z ,hit next
- Since we are not using processor expert ,leave the processor expert check box unchecked..
- Now you should see your project name in project explorer (click on the icon on extreme left if you can’t open project explorer)
- Now click [>] icon present before your project name,a drop down list should appear
- click [>] icon present before source and you should see main.cpp listed in the list.
- double click main.cpp…and now you should see it’s content……..So we are now ready to write our first blinkLED program
YOUR FIRST CODE
<span spellcheck="true">//RED led is at port E , Register 29
<span spellcheck="true">//static int i = 0;
SIM_SCGC5=SIM_SCGC5 | SIM_SCGC5_PORTE_MASK;<span spellcheck="true">//for providing clock to port E
</span>PORTE_PCR29=1<<8;<span spellcheck="true">//for setting up register 29 as GPIO. Here,PCR stands for Port Control Register
</span>GPIOE_PDDR=1<<29;<span spellcheck="true">//for setting up pin as output pin
</span>GPIOE_PDOR=0<<29;<span spellcheck="true">//for switching on pin REMEMBER: here 0 will switch led on and 1 will switch it off
</span><span spellcheck="true">//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:
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.
here there are 4 SIM_SCGC registers mentioned.Click on the link adjacent to SIM_SCGC5 .You will then see:
This is the description of SIM_SCGC5 register .As you can now see that this register is used to give 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.
Click on the link(See section) adjacent to PORTE_PCR29 .
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.
click on the link next to GPIOE_PDDR.
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 datasheet for it’s usage.
Thus,we use GPIOE_PDOR=0<<29; to switch on LED. Similarly, GPIOE_PDOR=1<<29; is for switching off LED.
RUNNING AND DEBUGGING YOUR CODE
In order to run/debug a code in KDS follow these steps:
- select debug configuration under run menu.
- Then select <YOUR PROJECT NAME>_PNE in the list on the left
- Now select debugger tab , and chose OpenSDA debugger USB port under interface(It should automatically detect port).
- click on apply and then debug.(EASY !!!!!!!)
- That’s it!! you are now in the debug window. Click on run icon(>) .And then terminate the code by clicking on()(red square).
- Now press the reset button on the board and Hurrah!!!! RED LED is now On!!!!!!!!!!!