Creating a Library with Kinetis Design Studio

There is no special option in Kinetis Design Studio ‘New Project Wizard’ (NPW) to create a library (or archive). But it is really easy to create a library project.

Library File Created

Library Project

Outline

This post shows how to create a library project in the Freescale Kinetis Design Studio (KDS) (version v2.0.0 used). But this approach applies to any Eclipse based IDE using the GNU ARM Eclipse plugins.

The approach is very simple:

  1. Create a normal project with the NPW
  2. Transform it into a library project

Creating the Project

After I have created a project with File > New > Kinetis Design Studio project:

Bareboard project created

Bareboard project created

Static Library Artifact Type

The first step is to transform the project type from an ‘Executable’ into a ‘Static Library’ one. The setting is in the project properties (menu Project > Properties > C/C++ Build > Settings > Build Artifact)

Application Project Type

Application Project Type

Change it to ‘Static Library’:

Static Library Project Type

Static Library Project Type

The artifact (output file of the build) extension and prefix get automatically adjusted. This concludes the settings of the project, it is really that easy.

Removing not needed files

The next step is to remove application specific files which have been added to the project by the wizard:

  1. Linker Files: the library does not need a linker file, the library is a collection of object files only.
  2. Startup Code: the startup code belongs to the application, usually the library does not provide the startup code.
  3. Debugger configuration and launch configuration files: we are debugging the application from the application project, not with the library project.
  4. Main.c: typically the library consists of library modules, and does not have a main(). So we can remove this file too.
Removing application specific files

Removing application specific files

So select the above files and delete them from the project (DEL key or use the context menu and use ‘Delete’).

Adding Library Functionality

After that, I can add the library functionality and files to the project. In this example I add an AES encryption functionality to the library:

Added Library Content

Added Library Content

Building the Library

Building the library is like building an application: use one of the Project > Build to build it.

With this, the library (or archive) file will show up in the project:

Library File Created

Library File Created

With this, I have created a library project. And I can add further files and functionality to the library.

Summary

To create a library with Kinetis Design Studio, create a normal application project, change the Artifact Type to ‘Static Library’, remove the application specific files (debugger files, linker file, startup code and main()). Then I can use it as a library project.

Happy Libraring 🙂

Links

22 thoughts on “Creating a Library with Kinetis Design Studio

  1. Hi Erich, I’ve got a strange problem with a new KDS project. I’m linking to a shared library from my main application however during linking, I get the following errors:

    c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: TestProject.elf section `.interp’ will not fit in region `m_cfmprotrom’
    c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: section .dynamic loaded at [0001a018,0001a0cf] overlaps section .romp loaded at [0001a018,0001a03b]
    makefile:53: recipe for target ‘TestProject.elf’ failed
    c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: region `m_cfmprotrom’ overflowed by 2780 bytes

    Have you ever come across anything like this before? If I then remove the shared library from the Linker/Libraries list, the problems go away. There are no linker files associated with the shared library nor are there any startup files. I’m puzzled

    Like

    • Hi Kevin,
      yes, seen something like this. First, make sure that you build the library with the -g (default debug level) option.
      Second, it seems to me that your library includes constant data for the m_cfmprotrom section. Could it be that your library has included the startup code (usually the startup code has this?).
      I hope this helps,
      Erich

      Like

      • Hi Erich, I’ve turned on the “-g” option for the library. Initially there was a duplicate startup file which I’ve now removed but this hasn’t fixed the problem. I’m now getting the following errors (sorry, its a lot to pick through):

        arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -T “C:/Users/kevin/workspace.kds/MyProject/Project_Settings/Linker_Files/ProcessorExpert.ld” -Xlinker –gc-sections -L”C:/Users/kevin/workspace.kds/MyProject/Project_Settings/Linker_Files” -L”C:\Users\kevin\workspace.kds\MyLibrary\Debug” -Wl,-Map,”MyProject.map” -specs=nano.specs -specs=nosys.specs -pie -o “MyProject.elf” ./Sources/main.o ./Project_Settings/Startup_Code/startup.o -lMyLibrary
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: section .dynamic loaded at [00012228,000122ff] overlaps section .romp loaded at [00012228,0001224b]
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: BFD (GNU Tools for ARM Embedded Processors) 2.23.2.20140731 assertion fail /home/build/work/GCC-4-8-build/src/binutils/bfd/elf32-arm.c:7730
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: error: required section ‘.rel.plt’ not found in the linker script
        c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: final link failed: Invalid operation

        Like

      • I think this is the main culprit:

        section .dynamic loaded at [00012228,000122ff] overlaps section .romp loaded at [00012228,0001224b]

        Like

        • No, I think this is not the only thing. Try to start with a static library created with only one file (no startup code, etc, just a single file with a single function). Then add more files.

          Like

      • Hi Erich, I actually wanted to create a dynamic library but then common sense took over and I realised that this wasn’t possible. Doh. Static library it is. Sorry for my stupidity.

        Like

        • No problem :-). For a dynamic library you would have to write/use a library loader in your application (which you probably don’t need/want). The great thing is that the GNU tools support this, which is very useful say in a embedded Linux environment. Less common in a microcontroller area.

          Like

  2. I’m looking for good software-based AES implementations for microcontrollers. Is the library you created here available for download? I thought I recalled seeing some AES functionality in a PEx component in an article here, but I haven’t been able to find it.

    Like

  3. Pingback: How to use Custom Library Names with GNU Linker and Eclipse | MCU on Eclipse

  4. Pingback: Managing Project and Library Dependencies with Eclipse CDT | MCU on Eclipse

What do you think?

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