How to use the SEGGER Runtime Library with NXP's MCUXpresso

From SEGGER Wiki
Jump to: navigation, search

In order to use the SEGGER Runtime Library in the MCUXpresso IDE, follow these steps:

Preparations

  • Download and install MCUXpresso from nxp.com
  • Download and unzip emLib-C from segger.com
  • This will yield two folders:
  LIB
  Doc

Create a new project for the NXP MCU of your choice or import an SDK example project

  • Skip this step if you already have your own project
  • Make sure the project builds without errors

Copy the SEGGER Runtime Library LIB folder into your MCUXpresso project

Pic1.png

Make sure the LIB folder is part of the project

  • Right-click on the LIB folder and select “Properties”
  • In “C/C++ Build > Settings”, un-check the box that says “Exclude resource from build”

Pic2.png

  • Click “Apply and Close”

Add LIB folder to the list of include paths

  • Right-click on the project node in the project explorer and select “Properties”
  • Go to “C/C++ Build > Settings > MCU C Compiler > Includes”
  • Click “Add”
  • Add “../LIB” as new directory path

Pic3.png

  • Click “OK”
  • Click “Move Up” to move ../LIB to the first position in the list

Pic4.png

Remove existing library from the project

  • In the project properties, go to: “C/C++ Build > Settings > MCU Linker > Managed Linker Script”
  • In the “Library” pull-down menu, choose “No libraries”

Pic5.png

  • When prompted, click “Yes” to rebuild the index

Pic6.png

In source files that make calls to the SEGGER Runtime Library, include “__libc.h” (starting with a double-underscore)

Pic7.png

Build the project

  • You will most likely encounter linker errors related to functions like __assert(), __putchar(), and __getchar()
  • You need to implement these functions in your project according to your needs before the project will build correctly.
  • Dummy implementation of __putchar():
  int __putchar(int ch, __printf_tag_ptr pvoid) {
  return 1;
  }
  • Dummy implementation of __getchar():
  int __getchar(void) {
  return 1;
  }
  • Basic implementation of __assert():
  void __assert(const char *expression,
                const char *filename,
                int line) {
    for(;;) ;
  }
  • After implementing these functions, your project should build without errors
  • Consider cleaning the project before building it

Refer to the SEGGER Runtime Library User Guide in the Doc folder for additional information