You can convert the ewl hello world project created for Kinetis devices to use newlib by making several changes to the build settings and the startup code. The purpose of these changes is to help the build process search the right directories for the right library files, and provide the right instructions to the linker.
Perform these steps to convert Kinetis project to use newlibe instead of EWL.
The Properties window appears. The left side of this window has a properties list. This list shows the build properties that apply to the current project.
The Properties window shows the corresponding build properties.
For example remove:
"${MCUToolsBaseDir}/ARM_GCC_Support/ewl/EWL_C/include" and
"${MCUToolsBaseDir}/ARM_GCC_Support/ewl/EWL_Runtime/ include"
This ensures that the compiler does not search in these EWL directories.
For example, remove:
"${MCUToolsBaseDir}/ARM_GCC_Support/ewl/lib/armv6-m"
The linker will not be searching for the ewl library.
-lc -lm -lgcc -lrdimon
The above changes to the build settings ensure that the build picks newlib instead of ewl. However to make the build complete, you need to provide a startup routine.
Newlib provides a startup routine called _start. However, you must write a wrapper startup function that will do the following tasks before calling newlib '_start'.
The following code demonstrates how what the wrapper startup file looks like. This file includes a __rom_to_ram_copy function along with wrapper startup function __thumb_startup.
To write a startup file and add it to the project, perform these steps.
Alternatively, you can also create a *. c file and port the following code to inline c code.
.syntax unified .arch armv6-m .text .thumb .thumb_func .align 2 .globl __rom_to_ram_copy .type __rom_to_ram_copy, %function __rom_to_ram_copy: ldr r1,=___ROM_AT ldr r2,=_sdata ldr r3,=_edata subs r3, r2 ble rom_to_ram_loop_end movs r4,0 rom_to_ram_loop_begin: ldr r0, [r1,r4] str r0, [r2,r4] adds r4, 4 cmp r4, r3 blt rom_to_ram_loop_begin rom_to_ram_loop_end: mov pc,lr .pool .size __rom_to_ram_copy, . - __rom_to_ram_copy .thumb_func .align 2 .globl __thumb_startup .type __thumb_startup, %function __thumb_startup: ldr r0, =_estack mov sp,r0 ldr r0, =__init_hardware blx r0 ldr r0, =__rom_to_ram_copy blx r0 ldr r0, =_start bx r0 .pool .size __thumb_startup, . - __thumb_startup .end