Posts Tagged ‘linux’

português

While developing for the FRDM-KL25Z board using my own compilation of a gcc crosstoolchain, I’ve noticed a weirdness when my code makes use of integer division (/) or modulus (%) operations.

My arm-none-eabi crosstoolchain is based in binutils 2.24, gcc 4.8.2 and newlib 2.1.0. When executing / or % operations, execution crashes in one of ____aeabi_[u]idiv[mod]_from_thumb() runtime AEABI calls. This is a gdb backtrace of a tentative of %:

(gdb) bt
#0  Cpu_Interrupt () at Generated_Code/Cpu.c:85
#1  <signal handler called>
#2  0x0000236c in ____aeabi_uidivmod_from_thumb ()
#3  0x000021aa in LEDTimer_OnInterrupt (UserDataPtr=0x0 <__vect_table>) at Sources/Events.c:80
#4  0x00001f98 in TU1_OnCounterRestart (UserDataPtr=0x0 <__vect_table>) at Generated_Code/LEDTimer.c:149
#5  0x00002126 in TU1_Interrupt () at Generated_Code/TU1.c:185
#6  <signal handler called>
#7  main () at Sources/ProcessorExpert.c:66

This behavior is persistent even when compiling and linking with Cortex-M0 tuned options such as -mcpu=cortex-m0 -mthumb -mfloat-abi=soft.

It has been reported that gcc is generating wrong opcodes for Cortex-M0 when linking these aeabi runtime calls. One workaround is to link your code with an external, Cortex-M0 compatible aeabi such as libaeabi-cortexm0 by Jörg Mische.

When using libaeabi-cortexm0 in a Processor Expert project for FRDM-KL25Z in Linux, compile the library without crt.S in order to avoid duplicate symbols in the linking stage.

I updated my led blinking application for using a % operation in LEDTimer_OnInterrupt(), and also linking with libaeabi-cortexm0: frdm-kl25z-blink3-1.1.tar.gz. For details in how to build this application in Gentoo Linux, see Developing for FRDM-KL25Z platform in Linux.

Advertisements

português

Table of contents:

  1. Introduction
  2. Crosstoolchain
  3. Building
  4. Flashing
  5. Debugging

Previously in Flashing a led blinking application was recorded to FRDM-KL25Z board for execution. Here we use the GNU debugger for debugging this application during execution.

Build a cross debugger for ARM

localhost ~ # crossdev --ex-gdb -t arm-none-eabi
...

This should leave in your Gentoo system a cross gdb for the intended architecture:

localhost ~ # arm-none-eabi-gdb -ex quit
Python Exception  name 'os' is not defined: 

warning: 
Could not load the Python gdb module from `/usr/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.

GNU gdb (Gentoo 7.7 vanilla) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word".

Use OpenOCD as a remote end for gdb

OpenOCD has the ability of serving as the remote end of a gdb session, allowing debug commands to be sent to the board’s on-chip debugger. The Makefile in frdm-kl25z-blink3 sources has a target for setting up a cross gdb session with openocd as the remote for debugging frdm_kl25z_blink3:

user@localhost /tmp/frdm-kl25z-blink3-1.0 $ make debug
arm-none-eabi-gdb -ex "target remote | openocd -c \"gdb_port pipe; log_output debug.log; interface cmsis-dap\"
 -f ./support/openocd/kl25_init.cfg" -ex "monitor reset init" -ex "break main" -ex "continue" frdm_kl25z_blink3
Python Exception  name 'os' is not defined: 

warning: 
Could not load the Python gdb module from `/usr/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.

GNU gdb (Gentoo 7.7 vanilla) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from frdm_kl25z_blink3...done.
Remote debugging using | openocd -c "gdb_port pipe; log_output debug.log; interface cmsis-dap" -f ./support/openocd/kl25_init.cfg
Open On-Chip Debugger 0.8.0-dev-00350-g6c74255 (2014-02-14-16:00)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html
warning: Can not parse XML target description; XML support was disabled at compile time
0x00000000 in __vect_table ()
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00002038 msp: 0x20003000
Breakpoint 1 at 0x2114: file Sources/ProcessorExpert.c, line 53.
Continuing.

Breakpoint 1, main () at Sources/ProcessorExpert.c:53
53        PE_low_level_init();
(gdb)

As currently written, the debug target should restart execution of the application and stop in function main() due to a breakpoint. So at this state the execution is stopped (RGB led ceases to blink) and gdb is awaiting for debug commands.

Debug 🙂

Well it’s gdb; feel free to poke around for insightful debugging. The following is an example of catching the timer interruption handler where led colors are cycled:

(gdb) clear
Deleted breakpoint 1 
(gdb) break LEDTimer_OnInterrupt
Breakpoint 2 at 0x2078: file Sources/Events.c, line 80.
(gdb) continue
Continuing.

Breakpoint 2, LEDTimer_OnInterrupt (UserDataPtr=0x0 ) at Sources/Events.c:80
80              switch (led_state++) {
(gdb) list
75      /* ===================================================================*/
76      void LEDTimer_OnInterrupt(LDD_TUserData *UserDataPtr)
77      {
78        /* Write your code here ... */
79              static int led_state = 0;
80              switch (led_state++) {
81              case 0:
82                      RedLED_SetVal(RedLED_DeviceData);
83                      GreenLED_SetVal(GreenLED_DeviceData);
84                      BlueLED_SetVal(BlueLED_DeviceData);
(gdb) display led_state
1: led_state = 0
(gdb) continue
Continuing.

Breakpoint 2, LEDTimer_OnInterrupt (UserDataPtr=0x0 ) at Sources/Events.c:80
80              switch (led_state++) {
1: led_state = 1
(gdb) next
87                      RedLED_ClrVal(RedLED_DeviceData);
1: led_state = 2
(gdb) next
88                      break;
1: led_state = 2
(gdb) continue
Continuing.

Breakpoint 2, LEDTimer_OnInterrupt (UserDataPtr=0x0 ) at Sources/Events.c:80
80              switch (led_state++) {
1: led_state = 2
(gdb) continue
Continuing.

Breakpoint 2, LEDTimer_OnInterrupt (UserDataPtr=0x0 ) at Sources/Events.c:80
80              switch (led_state++) {
1: led_state = 3
(gdb) clear
Deleted breakpoint 2 
(gdb) continue
Continuing.
^C
Program received signal SIGINT, Interrupt.
main () at Sources/ProcessorExpert.c:66
66        for(;;){}
1: led_state = 6
(gdb) quit
A debugging session is active.

        Inferior 1 [Remote target] will be detached.

Quit anyway? (y or n) y
Detaching from program: /tmp/frdm-kl25z-blink3-1.0/frdm_kl25z_blink3, Remote target
Ending remote debugging.

user@localhost /tmp/frdm-kl25z-blink3-1.0 $ 

português

Table of contents:

  1. Introduction
  2. Crosstoolchain
  3. Building
  4. Flashing
  5. Debugging

Previously in Building we generated an ELF executable file as the result of building the frdm-kl25z-blink3 application:

user@localhost /tmp/frdm-kl25z-blink3-1.0 $ file frdm_kl25z_blink3 
frdm_kl25z_blink3: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped

Here we manage to record this file to the board’s flash memory for execution.

Update FRDM-KL25Z board with a CMSIS-DAP firmware

First, extract file CMSIS-DAP.S19 from Keil Application Note 232. This is a firwmare for FRDM-KL25Z that supports the CMSIS-DAP interface to the board’s on-chip debugger.

The following steps must be performed on Windows: Next, enter Bootloader mode in board by holding down the Reset button while plugging in an USB cable to the OpenSDA connector and your computer. (When the D4 led blinks you can release the button as this indicates bootloader mode.) The MSD Bootloader appears in Windows as a removable drive with a volume label of BOOTLOADER. Copy file CMSIS_DAP.s19 into the BOOTLOADER drive, wait for a few seconds and unplug the board.

Back to Gentoo Linux, replug the board and check for usb device with vendor ID 0xc251 and product ID 0xf002:

localhost ~ # lsusb
Bus 001 Device 023: ID c251:f002 Keil Software, Inc. 
...

Create file /etc/udev/rules.d/99-frdm-kl25z-cmsis-dap.rules containing:

SUBSYSTEM=="usb", ATTR{idVendor}=="c251", ATTR{idProduct}=="f002", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="hidraw", ACTION=="add", MODE="0660", GROUP="plugdev"

Unplug and replug the board again, and check that the created hidraw device file belongs to the plugdev group and is group writable:

localhost ~ # ls -l /dev/hidraw*
crw-rw---- 1 root plugdev 252, 0 Mar 10 21:58 /dev/hidraw0
...

This allows the flashing process to be performed by normal users belonging to the plugdev group.

Install OpenOCD with CMSIS-DAP support

For communicating with FRDM-KL25Z on-chip debugger in order to perform flashing, we use OpenOCD. Unfortunately at the moment of this writing the latest available version of OpenOCD from Portage tree (0.7.0-r1) does not support CMSIS-DAP; however I successfully used OpenOCD from openocd.zylin.com for flashing. You may want to grab a snapshot of the latest openocd source tree, unpack, build and install it:

localhost ~/src/openocd # ./configure --enable-cmsis-dap
...
OpenOCD configuration summary
--------------------------------------------------
CMSIS-DAP Compliant Debugger            yes

localhost ~/src/openocd # make
...

localhost ~/src/openocd # make install
...

In a clean Gentoo Linux system the configure phase will likely fail due to missing libraries and softwares; just emerge any required stuff and resume the process as shown above. You should end with a working openocd installation:

localhost ~ # openocd --version
Open On-Chip Debugger 0.8.0-dev-00350-g6c74255 (2014-02-14-16:00)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html

Flash frdm_kl25z_blink3 using OpenOCD

The Makefile in frdm-kl25z-blink3 sources has a target for taking care of flashing:

user@localhost /tmp/frdm-kl25z-blink3-1.0 $ make flash
openocd \
        -c 'interface cmsis-dap' \
        -f ./support/openocd/kl25_init.cfg \
        -f ./support/openocd/kl25_flash.cfg
Open On-Chip Debugger 0.8.0-dev-00350-g6c74255 (2014-02-14-16:00)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'cmsis-dap'
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
cortex_m reset_config sysresetreq
adapter speed: 50 kHz
Info : add flash_bank kinetis kl25.flash
#0 : kl25.flash (kinetis) at 0x00000000, size 0x00000000, buswidth 0, chipwidth 0
Info : CMSIS-DAP: FW Version = 1.0
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : DAP_SWJ Sequence (reset: 50+ '1' followed by 0)
Info : CMSIS-DAP: Interface ready
Info : clock speed 50 kHz
Info : IDCODE 0x0bc11477
Info : kl25.cpu: hardware has 2 breakpoints, 2 watchpoints
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00002038 msp: 0x20003000
** Programming Started **
auto erase enabled
Info : Probing flash info for bank 0
Info : Padding image section 0 with 832 bytes
Warn : flash configuration field erased, please reset the device
Warn : Kinetis L Series supports Program Longword execution only.
Info : Kinetis: FLASH Write ...
wrote 11264 bytes from file frdm_kl25z_blink3 in 14.069720s (0.782 KiB/s)
** Programming Finished **
** Verify Started **
verified 10060 bytes in 1.938245s (5.069 KiB/s)
** Verified OK **
** Resetting Target **
shutdown command invoked

If flashing succeeds the application should start automatically and the RGB led should blink repeatedly in a succession of red, green and blue colors.

Next in Debugging we’ll use OpenOCD as a remote server for the GNU debugger, so we can debug the flashed application.


References

português

Table of contents:

  1. Introduction
  2. Crosstoolchain
  3. Building
  4. Flashing
  5. Debugging

Despite a fair amount of tuning parameters is required to be passed to the builder, conceptually the process of building proper ARM executables for FRDM-KL25Z board is virtually the same as every other software building based on compilation and linking:

  • Preprocessing, where preprocessor symbols are resolved for each source code file (.c) of the project;
  • Compilation, where the results of preprocessing are parsed and an object code file (.o) is generated for each source code file. Object files contain machine code descriptions of functions written by the programmer;
  • Linking, where all object code files of the project are combined among themselves and with system libraries for resolution of function call dependencies. Typically the main result of the linking stage is an executable file for the target CPU architecture.

As an example of building I wrote a simple RGB LED blinking program for FRDM-KL25Z; please unpack it somewhere in your filesystem: frdm-kl25z-blink3-1.0.tar.gz

frdm-kl25z-blink3 was originally developed with CodeWarrior 10.4 for Windows, the official IDE from Freescale for development on kinetis and other products at the time of this writing. Codewarrior is delivered as an Eclipse based bundle and has a free (as in “free beer”) release for Windows that allows quick initial setup of board resources using Freescale Processor Expert technology. For Linux building of this CodeWarrior project I grabbed the following directories of the project’s workspace:

  • Generated_Code (allocation of board resources)
  • Project_Settings/Linker_Files (linker definitions)
  • Project_Settings/Startup_Code (registration of external function calls for program startup and termination)
  • Sources (event callbacks and main program entry point, this is where virtually all further development takes place after board resource configuration)

Moreover, as these files were generated by Processor Expert, for proper preprocessing and linking they depend on additional CodeWarrior system headers and ARM libraries. You need the following directories from a (Windows) CodeWarrior installation:

  • MCU/ARM_GCC_Support/ewl (Freescale Embedded Warrior Libraries)
  • MCU/ProcessorExpert/lib/Kinetis/pdd/inc (Kinetis PDD headers)

If you don’t have access to a Windows installation of CodeWarrior, you can as well download the free CodeWarrior for Microcontrollers 10.4 (Eclipse, offline) installer from Freescale, open it with file-roller (or other archive manager of your choice) and:

  • unzip com.freescale.mcu10_4.kinetis.updatesite.zip, unzip binary/com.freescale.kinetis.gcc_root_1.0.2, and copy MCU/ARM_GCC_Support/ewl
  • unzip Setup.exe, and copy $_OUTDIR/ProcessorExpert/lib/Kinetis/pdd/inc

The frdm-kl25z-blink3 project comes with a configuration script for checking the existence of these system directories as well as other issues that may affect the building. Edit build.sh for updating PDD_HEADERS_DIR and EWL_DIR with the correct locations of the above mentioned directories, and execute it for building the frdm_kl25z_blink3 ELF file for ARM:

user@localhost /tmp/frdm-kl25z-blink3-1.0 $ ./build.sh
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-eabi-strip... arm-none-eabi-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for arm-none-eabi-gcc... arm-none-eabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-none-eabi-gcc accepts -g... yes
checking for arm-none-eabi-gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of arm-none-eabi-gcc... gcc3
checking if Generated_Code/IO_Map.h exists in sources... yes
checking for Kinetis PDD headers location... /opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
checking for GPIO_PDD.h... yes
checking for LPTMR_PDD.h... yes
checking for EWL headers location... /opt/Freescale/MCU/ARM_GCC_Support/ewl
checking how to run the C preprocessor... arm-none-eabi-gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... no
checking for sys/stat.h... no
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... no
checking for strings.h... no
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... no
checking ansi_parms.h usability... yes
checking ansi_parms.h presence... yes
checking for ansi_parms.h... yes
checking CWCPlusLib.h usability... yes
checking CWCPlusLib.h presence... yes
checking for CWCPlusLib.h... yes
checking runtime_configuration.h usability... yes
checking runtime_configuration.h presence... yes
checking for runtime_configuration.h... yes
checking if Project_Settings/Linker_Files/ProcessorExpert.ld exists in sources... yes
checking for __init_registers in -lrt... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
make  all-am
make[1]: Entering directory `/tmp/frdm-kl25z-blink3-1.0'
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf -O0
-ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT BlueLED.o -MD
-MP -MF .deps/BlueLED.Tpo -c -o BlueLED.o `test -f 'Generated_Code/BlueLED.c'
|| echo './'`Generated_Code/BlueLED.c
mv -f .deps/BlueLED.Tpo .deps/BlueLED.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf -O0
-ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT Cpu.o -MD
-MP -MF .deps/Cpu.Tpo -c -o Cpu.o `test -f 'Generated_Code/Cpu.c' || echo
'./'`Generated_Code/Cpu.c
mv -f .deps/Cpu.Tpo .deps/Cpu.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf
-O0 -ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT
GreenLED.o -MD -MP -MF .deps/GreenLED.Tpo -c -o GreenLED.o `test -f
'Generated_Code/GreenLED.c' || echo './'`Generated_Code/GreenLED.c
mv -f .deps/GreenLED.Tpo .deps/GreenLED.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf
-O0 -ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT
LEDTimer.o -MD -MP -MF .deps/LEDTimer.Tpo -c -o LEDTimer.o `test -f
'Generated_Code/LEDTimer.c' || echo './'`Generated_Code/LEDTimer.c
mv -f .deps/LEDTimer.Tpo .deps/LEDTimer.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf -O0
-ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT PE_LDD.o -MD
-MP -MF .deps/PE_LDD.Tpo -c -o PE_LDD.o `test -f 'Generated_Code/PE_LDD.c'
|| echo './'`Generated_Code/PE_LDD.c
mv -f .deps/PE_LDD.Tpo .deps/PE_LDD.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf -O0
-ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT RedLED.o -MD
-MP -MF .deps/RedLED.Tpo -c -o RedLED.o `test -f 'Generated_Code/RedLED.c'
|| echo './'`Generated_Code/RedLED.c
mv -f .deps/RedLED.Tpo .deps/RedLED.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf -O0
-ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT TU1.o -MD
-MP -MF .deps/TU1.Tpo -c -o TU1.o `test -f 'Generated_Code/TU1.c' || echo
'./'`Generated_Code/TU1.c
mv -f .deps/TU1.Tpo .deps/TU1.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf -O0
-ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT Vectors.o -MD
-MP -MF .deps/Vectors.Tpo -c -o Vectors.o `test -f 'Generated_Code/Vectors.c'
|| echo './'`Generated_Code/Vectors.c
mv -f .deps/Vectors.Tpo .deps/Vectors.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf
-O0 -ffunction-sections -fdata-sections -Wall -fmessage-length=0
-MT __arm_end.o -MD -MP -MF .deps/__arm_end.Tpo -c -o __arm_end.o
`test -f 'Project_Settings/Startup_Code/__arm_end.c' || echo
'./'`Project_Settings/Startup_Code/__arm_end.c
mv -f .deps/__arm_end.Tpo .deps/__arm_end.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf
-O0 -ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT
__arm_start.o -MD -MP -MF .deps/__arm_start.Tpo -c -o __arm_start.o
`test -f 'Project_Settings/Startup_Code/__arm_start.c' || echo
'./'`Project_Settings/Startup_Code/__arm_start.c
mv -f .deps/__arm_start.Tpo .deps/__arm_start.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf -O0
-ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT Events.o
-MD -MP -MF .deps/Events.Tpo -c -o Events.o `test -f 'Sources/Events.c' ||
echo './'`Sources/Events.c
mv -f .deps/Events.Tpo .deps/Events.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf
-O0 -ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT
ProcessorExpert.o -MD -MP -MF .deps/ProcessorExpert.Tpo -c -o ProcessorExpert.o
`test -f 'Sources/ProcessorExpert.c' || echo './'`Sources/ProcessorExpert.c
mv -f .deps/ProcessorExpert.Tpo .deps/ProcessorExpert.Po
arm-none-eabi-gcc -DHAVE_CONFIG_H -I.  -I./Sources -I./Generated_Code
-I/opt/Freescale/MCU/ProcessorExpert/lib/Kinetis/pdd/inc
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_C/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include
-I/opt/Freescale/MCU/ARM_GCC_Support/ewl/EWL_Runtime/include/arm
-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2 -gstrict-dwarf -O0
-ffunction-sections -fdata-sections -Wall -fmessage-length=0 -MT sa_mtb.o
-MD -MP -MF .deps/sa_mtb.Tpo -c -o sa_mtb.o `test -f 'Sources/sa_mtb.c' ||
echo './'`Sources/sa_mtb.c
mv -f .deps/sa_mtb.Tpo .deps/sa_mtb.Po
arm-none-eabi-gcc  -mcpu=cortex-m0 -mthumb -mfloat-abi=soft -g3 -gdwarf-2
-gstrict-dwarf -O0 -ffunction-sections -fdata-sections -Wall -fmessage-length=0
-Xlinker --gc-sections -n -L/opt/Freescale/MCU/ARM_GCC_Support/ewl/lib/armv6-m
-T./Project_Settings/Linker_Files/ProcessorExpert.ld -o frdm_kl25z_blink3
BlueLED.o Cpu.o GreenLED.o LEDTimer.o PE_LDD.o RedLED.o TU1.o Vectors.o
__arm_end.o __arm_start.o Events.o ProcessorExpert.o sa_mtb.o  -lrt
make[1]: Leaving directory `/tmp/frdm-kl25z-blink3-1.0'

frdm_kl25z_blink3: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV),
statically linked, not stripped

Next in Flashing we record the frdm_kl25z_blink3 ELF to the FRDM-KL25Z board for execution.

português

Table of contents:

  1. Introduction
  2. Crosstoolchain
  3. Building
  4. Flashing
  5. 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.

português

Table of contents:

  1. Introduction
  2. Crosstoolchain
  3. Building
  4. Flashing
  5. Debugging

This series of posts depict my trials on building, flashing and debugging a sample application for the Freescale FRDM-KL25Z board in Gentoo GNU/Linux OS. The application (a simple multicolor LED blinking program) was originally developed using CodeWarrior 10.4 with Processor Expert for Windows. The relevant source files of the application were copied without any changes and compiled in Linux using GNU Autotools for configuring the build process.

What is covered:

  • Setup of an ARM crosstoolchain in Gentoo Linux;
  • Cross-building in Linux an application developed with CodeWarrior IDE;
  • Flashing an application to FRDM-KL25Z board in Linux;
  • Debugging a FRDM-KL25Z application in Linux.

A few things that are NOT covered:

  • Executing CodeWarrior IDE in Linux;
  • Updating sources of applications using Processor Expert in Linux;
  • Integration with Eclipse;
  • Setup steps known to be effective in GNU/Linux distros other than Gentoo (although a great deal of them is expected to be compatible).

Note: for an excellent tutorial on setting up a free and functional GNU gcc + Eclipse + debugger environment for use with the Freescale FRDM-KL25Z board in Windows, take a look at DIY Free Toolchain for Kinetis

Whenever possible, all instructions make use of free software tools.

Let’s get started in Crosstoolchain where we setup build tools for ARM CPUs in your Gentoo Linux system.