Table of contents:
- Introduction
- Crosstoolchain
- Building
- Flashing
- Debugging
In order to compile software for FRDM-KL25Z board we must be able to generate object code for ARM CPUs. It’s very likely that your Gentoo system runs on a non-ARM computer, so we require tools for handling generation and manipulation of object code targeted to a CPU architecture other that your computer’s.
Install crossdev, the Gentoo cross-toolchain generator:
localhost ~ # emerge sys-devel/crossdev
Have crossdev to build C cross-compiler, libc and other build tools for ARM CPUs:
localhost ~ # crossdev -t arm-none-eabi ----------------------------------------------------------- * crossdev version: 20131107 * Host Portage ARCH: amd64 * Target Portage ARCH: arm * Target System: arm-none-eabi * Stage: 3 (C compiler & libc) * ABIs: default * binutils: binutils-[latest] * gcc: gcc-[latest] * libc: newlib-[latest] * Log: /var/log/portage/cross-arm-none-eabi-binutils.log * Emerging cross-binutils ... [ ok ] * Log: /var/log/portage/cross-arm-none-eabi-gcc-stage1.log * Emerging cross-gcc-stage1 ... [ ok ] * Log: /var/log/portage/cross-arm-none-eabi-newlib.log * Emerging cross-newlib ... [ ok ]
Now your Gentoo system contains a damn good GNU cross-toolchain that can build code for ARM CPUs. All tools are prefixed by arm-none-eabi- indicating their purpose of being cross-tools for ARM in your non-ARM system:
user@localhost ~ $ cd /usr/bin user@localhost /usr/bin $ ls arm-none-eabi-* arm-none-eabi-addr2line arm-none-eabi-gcc-4.8.2 arm-none-eabi-nm arm-none-eabi-ar arm-none-eabi-gcc-ar arm-none-eabi-objcopy arm-none-eabi-as arm-none-eabi-gcc-nm arm-none-eabi-objdump arm-none-eabi-c++filt arm-none-eabi-gcc-ranlib arm-none-eabi-pkg-config arm-none-eabi-cpp arm-none-eabi-gcov arm-none-eabi-ranlib arm-none-eabi-cpp-4.8.2 arm-none-eabi-gcov-4.8.2 arm-none-eabi-readelf arm-none-eabi-dwp arm-none-eabi-gdb arm-none-eabi-run arm-none-eabi-elfedit arm-none-eabi-gprof arm-none-eabi-size arm-none-eabi-emerge arm-none-eabi-ld arm-none-eabi-strings arm-none-eabi-fix-root arm-none-eabi-ld.bfd arm-none-eabi-strip arm-none-eabi-gcc arm-none-eabi-ld.gold
For quick checking the usability of the cross-compiler, you can create a file named hello.c
containing:
#include <stdio.h> int main() { printf("Hello world\n"); return 0; }
Let’s see if the cross-compiler can generate executables for ARM:
user@localhost ~ $ arm-none-eabi-gcc -o hello hello.c user@localhost ~ $ file hello hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
Looks good.
Next in Building we’ll use the cross-toolchain to build an application developed specifically for the FRDM-KL25Z board.