Arm GCC crosstoolchain issues with Cortex-M0 CPUs

Posted: Jun 18, 2014 in Tech
Tags: , , , ,

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s