How To: MCUXpresso Config Tools

Learn how to use MCUXpresso Config Tool to generate configuration files for your Kinetis projects.

Prerequisites

For this tutorial we will use a Kinetis development board (FRDM-KL43Z) to show the process of generating a configuration file; followed by a simple test code. The application will be a simple LED that turns on when we press a button. You can use whatever Kinetis board you prefer, since they all come with the necessary components.

With that said, let’s get started!

What is MCUXpresso and MCUXpresso Config Tools

When working with industry level micro-controllers, we can easily discover that the configuration process is more complicated than prototyping platforms like Arduino. Usually this process includes assigning bits in memory blocks; which the processor will then use to figure out the peripheral configuration that we intend to use.

But doing this manually can be daunting; this is why the best part of MCU designers offer a graphic tool to ease this process. By using a graphical interface, developers can generate the code necessary to set up pins, clocks and peripherals.

In the case of NXP, this tool is called “MCUXpresso Config Tools” and it is what we will test today.

Download and installation of MCUXPresso Config Tool

The MCUXpresso IDE includes the MCUXPresso Config Tools. But if you are using a different IDE for your project you can download it here.

If you don’t have a SDK installed for your board on the IDE, be sure to check any of our Hello World tutorials to learn how to download and install one.

First Step: Creating the project

1.To start, let’s create a new project using the New Project Wizard and select your board from the list :

MCUXpresso IDE – New Project Dialog

The IDE sopports some devices by default, but others need to be installed; therefore, if you cannot see your board on the list, you may need to install the proper SDK.

MCUXpresso IDE – New C/C++ Project Wizard

2. After selecting the board, you will need to choose the drivers to include on the project, so make sure to select the GPIO Driver from the list.

MCUXpresso IDE – Project Driver Configuration

3. After finishing the wizard, the IDE generates the project. On the left side you can find an extensive list of files created by the assistant; this includes system configurations, drivers and a C file with the name of your project in the source folder. This file contains the start code of your application.

#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MKL43Z4.h"
#include "fsl_debug_console.h"


/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();

/* Init FSL debug console. */
BOARD_InitDebugConsole();
PRINTF("Hello World\n");

/* Force the counter to be placed into memory. */
volatile static int i = 0 ;
/* Enter an infinite loop, just incrementing a counter. */
while(1) {
    i++ ;
}

We encourage you to check the content of the board, device and drivers folder:

  • Board: Contains configurations regarding the development board; for instance, it can add a constant for the pin number and port of the LED on the board.
  • Device: Includes the configuration regarding the micro-controller you are developing for.
  • Drivers: It contains all the peripheral drivers we selected on the New Project Wizard. These are basically a list of functions that execute hardware operations. For example, enabling a GPIO and writing or reading a value from or to the pin.
Important Files Created by MCUXpresso Config Tool

4. We want to test is the generated code works, so let’s hit click on debug. The console should show “Hello World” and we know we are good to go.

Project Created – Main C File

Second Step: The Configuration

1.We need to configure the GPIO pins that we intend to use. Therefore, we start by opening the Config Tool: click on the green X icon on the top right of the Project Explorer. The initial set-up lasts a couple of seconds, after that it will open the pin configuration window.

MCUXpresso Tool – Pin Configuration Window

2. Right now all peripherals are marked on light green.

MCUXpresso Tool – Pin E31

This means that the driver have been generated, but the pins haven’t been routed. To do this, right click on a pin and select Route.

For example, on the FRDM-KL43Z, the red LED is connected to the pin E31 (E refers to the GPIO port and 31 in the pin number); as a result, this will be the pin we will select.

3. From here you have two options: you can route the signal on the main pins init function, or you can have a peripheral dedicated init function. This is a matter of choice; for example, you may want to route several functions to the same pin on different parts of your code, in which case the best option is to have a dedicated init function. On this particular case we want to keep it simple, so we will choose to go with the global init function, which turns out to be the default option already selected.

MCUXpresso Tool

4. Finally, we need to assign an identifier (I chose RED to signal the color of the LED) and a port direction: input or output. We know this is a LED, so we choose output.

MCUXpresso Tool – Routed Pins

5. Add the following line to the main function after “Hello World” and run. The red LED should turn on once the code is flashed in the board.

GPIO_PinWrite(GPIOE, 31U, 0U);

Third Step: Add The Button

Now we just need to add some interaction to our code, so let’s add the button!

1.First you need to rout the button, so let’s go back to the pin configuration screen and set up the following configuration following the same steps we did before:

Routed Pins – Led and Button Enabled

Important: Remember to set up the new pin (A4, corresponding to SW1 on the board’s datasheet) as an input.

2. Add the following code to the main function:

volatile int val;
while(1){
    val = GPIO_PinRead(GPIOA, 4U);
    GPIO_PinWrite(GPIOE, 31U, val);
}

The processor will constantly check if the button have been pressed and turn on the LED if necessary. Now let’s hit run and see what happens!

0 Shares

Leave a Reply

Your email address will not be published. Required fields are marked *

0 Shares
Tweet
Share