Getting Started with NXP's MCUXpresso with the FRDM-KL46Z

Created by Ben Roloff, last modified on Jan 22, 2019

Introduction

NXP has launched a new IDE to be able to handle both NXP and Freescale boards. They aren’t getting rid of the old IDEs, but any newer and future boards will primarily be focused on in the new IDE. The IDE is easy enough to download from their site. Now with the new IDE not all boards will be supported with SDKs. They have a list put together that shows you where each of their products can be used.
MCUXpresso Supported Devices Table.xlsx (139.9 KB)

Getting the SDK

It is super simple with this new IDE to get an SDK for a board. The IDE itself does not have too many boards preloaded. You only need to go to mcuxpresso.nxp.com from there you simply sign into or create an nxp.com account. You can choose to start a new configuration. There you can select what board you will plan on working on. For this one we will be using the FRDM-KL46Z.

You can go right to SDK builder and download it. The SDK comes with the necessary drivers and example programs.

After downloading the SDK open MCUXpresso. You only then need to drag the SDK into the Installed SDK window.

Getting the Project Started

Now to start a new project you can use file → new → project or just click on the New Project button in the quick select menu. Select the FRDM-KL46Z and hit next.

Next create a project name and check the Default board files, this gives you all the drivers. At this point you can hit the next button again.

On this page select the Redirect printf/scanf to UART. This will make it that all printf and scanf statements get sent right over UART0 and usb.

It is necessary to be using the default board files with the redirect printf/scanf to UART. If you do not select the default board files and instead use empty board files printf and scanf will just go to the debug console and not over UART. After that just hit finish and you will have a project loaded with the default board files and drivers.

Code

Now that you have your project made you can look at what was included. You will notice that there is a drivers folder. In this folder is fsl_uart. This uart driver can be very useful if you are looking to use uart1 or uart2 on the board, but if you are looking for uart over usb you need uart0. On the chip uart0 has different commands to uart1 and uart2. The usb uses uart0.

Main

int main(void) {
      /* Init board hardware. */
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
      /* Init FSL debug console. */
    BOARD_InitDebugConsole();
    int x = 0;
    int f = 0;
   
    while(1) {
        printf("\n\rGive a value for x: ");
        while(f == 0)
        {
            scanf("%d", &x);
            if (x != 0)
            {
                f = 1;
            };
        };
        printf("\n\rx = %d", x);
        x = 0;
        f = 0;
    }
    return 0 ;
}

Debugging

Debugging is easy in MCUXpresso. You can click the debug button on the tool bar or the debug project link in the quick select section. You will have a window pop up with all your options for debugging. Select which one you want and hit OK.

After the first debug these becomes the default debug. If you want to change your debug settings or what debugger you use just delete the debug.launch and release.launch files in the project folder.

The Debugger works as any common debugger. You can set breakpoints, pause, resume, step into, and step over. If you have experience with most debuggers this will all be familiar.

The other part is to make sure you have a terminal program like putty or teraterm. Using either of these will allow you to see what is coming over UART. If you are using PEMicro debugger as I am you will be on COM4. The baudrate is set to 115200.

Conclusion

MCUXpresso is the new IDE from NXP. It combines their LPC line and Freescale’s Kinetis line into one IDE. It isn’t too bad right now at launch, but it will definitely get some changes and improvements as time goes on. Their online config tool is good for get the base SDK, but it doesn’t have too much power at the moment for changing it on the fly as some other IDE config tools have.

Useful Links

image
KL46P121M48SF4RM.pdf (5.2 MB)

image
FRDM-KL46Z_UM.pdf (1.8 MB)

Comments

Any questions or comments please go to our TechForum