| View previous topic :: View next topic |
| Author |
Message |
tomtom69 n00b

Joined: 09 Nov 2010 Posts: 69
|
Posted: Sun Nov 25, 2012 9:07 pm Post subject: crossdev: buildinga toolchain for arm cortex-m4 |
|
|
Hi,
I am trying to build a toolchain for an arm cortex M4 device (stellaris launchpad from TI).
So far I suceeded to build a toolchain for the controller in this way:
crossdev -t arm-none-eabi
With this toolchain I am able to build simple programs which actually can be flash programmed and run on the target. So far so good.
However as soon as libc components are used, the programs crash. I found out (using objdump) that the reason is that the libc is in arm mode, but cortex M4 only supports thumb.
So if I use strcmp() the toolchain generates assembly code like:
38a: f001 e99a blx 16c0 <strcmp>
[...]
000016c0 <strcmp>:
16c0: e0202001 eor r2, r0, r1
This looks as the libc (or newlib) function "strcmp" is linked to the code for arm, but not for thumb. The instruction "blx" should change to arm mode but on cortex M4 this results in a usuage failure trap.
Specifying arm-none-eabi surely does not take a "cortex M4 = thumb only" target into account.
But how can I build an arm cross toolchain that includes a libc etc. which is compiled in thumb mode?
tom |
|
| Back to top |
|
 |
paulj Apprentice


Joined: 30 Sep 2004 Posts: 284 Location: Wales, UK
|
Posted: Wed Nov 28, 2012 5:40 pm Post subject: |
|
|
Some hints/ideas, as I don't actually know the answer. I came across:
| Code: | make CROSS=arm-none-eabi- TARGET_SYS=arm HOST_CC=gcc
TARGET_CFLAGS="-DLUAJIT_USE_SYSMALLOC -mthumb -mcpu=cortex-m4
-mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wa,-mimplicit-it=thumb"
|
This suggests to me that you need to set -mthumb (and maybe some other flags) in the CFLAGS for the target. Looking at the gentoo cross development page http://www.gentoo.org/proj/en/base/embedded/cross-development.xml, it looks like you can set a make.conf for the target.
Worth a try? |
|
| Back to top |
|
 |
tomtom69 n00b

Joined: 09 Nov 2010 Posts: 69
|
Posted: Sun Dec 02, 2012 6:32 pm Post subject: |
|
|
Surely worth a try
I now built a toolchain with
crossdev -t arm-stellaris-eabi
and modified make.conf (/usr/arm-stellaris-eabi/etc/portage/make.conf) in hope to get newlib compiled for thumb.
I added a line including
MARCH_TUNE="-mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wa,-mimplicit-it=thumb"
($MARCH_TUNE is included in $CFLAGS two lines below in make.conf). But this had no effect. To be sure that the MARCH_TUNE and CFLAGS are used, I added the bogus option "-mthumbofant" to both of them, but even then newlib always compiled without error.
So I assume the CFLAGS and MARCH_TUNE from my make.conf are not used for the build of newlib, because if it would be used, "-mthumbofant" should throw an error about an illegal command line switch.
I am wondering why the CFLAGS in my make.conf are not used for building the cross "newlib" target.
Or is there a different place to specify the CFLAGS for newlib?
tom |
|
| Back to top |
|
 |
tomtom69 n00b

Joined: 09 Nov 2010 Posts: 69
|
Posted: Tue Dec 25, 2012 7:14 pm Post subject: |
|
|
Meanwhile I got a solution for the thumb problem.
For everyone who wants to program a TI stellaris launchpad with gentoo linux:
I built a toolchain with
crossdev -t arm-stellaris-eabi --genv 'EXTRA_ECONF="--with-cpu=cortex-m4 --with-tune=cortex-m4 --with-mode=thumb --with-fpu=fpv4-sp-d16 --with-float-abi=softfp"'
I spent much time finding out that MARCH_TUNE in /usr/arm-stellaris-eabi/etc/portage/make.conf does not change anything for the gcc build. So I found the (somewhat brutal) option "EXTRA_ECONF" to influence the gcc compilation.
Compiling works now, however the FPU is not yet used (when I disassemble the code I can see that there is much code for FP emulation, despite of the FPU options given above and -mfpu=fpv4-sp-d16 -mfloat-abi=softfp given in CFLAGS of the target program. |
|
| Back to top |
|
 |
|