T3: linking libarm_cortexM3l_math.a

Not open for further replies.


Well-known member
Using Teensy3 with beta10 on Windows.
I'm trying to test the code mentioned in this Arduino DUE forum:

The only way I have found to get the library to link in with the test code is to essentially do a compile from the command line - although I use a TCL script to make life easier.
The main problem is being able to insert "-larm_cortexM4l_math" immediately before "-lm" in the gcc command which links everything together. The boards.txt file has a way to insert link options but it only inserts them near the front of the command and the link fails with unresolved references if I do that.
I tried modifying compiler.java to allow me to insert the -l command where I want it but when I restart the IDE it doesn't have any effect.
My generic question is how can I insert a -l option near the end of the gcc command and more specifically, how do I get the IDE to use a modified compiler.java?

[edit] fixed a typo/idiocy :)
Last edited:
And FYI:
So far I have converted four of the examples from the CMSIS library that is in the Arduino DUE 1.5.1 distribution.
Two of them, arm_dotproduct_example_f32 and arm_fir_example_f32, run and pass their internal test.

runs but fails its internal SNR test

hangs when it calls arm_cfft_radix4_f32

You should be able to just add


into the linker script file (mk20dx128.ld). Adjusting the absolute path of course.
Aside: your example says M3. Are you using the M4 libraries, with

#define ARM_MATH_CM4

in your sketch? Should be faster than defining M3.
Modifying the linker script doesn't work properly - I'm probably doing something wrong.
It does seem to find everything in the library except for something called aeabi_f2lz and it also can't find memset.

One simple way, but not very convenient, would be to manually run the linker. For initial testing this probably makes sense.

In File > Preferences you can turn on verbose info while compiling.

You could just copy the (very long) linking command from Arduino's console panel to a command line, of course with the extra library added. It will overwrite the .elf file. Then copy the objcopy command that creates the .hex from the .elf. As long as the code as compiled successfully even once, the Teensy Loader will remember the name and directory of the .hex file, so after you manually rewrite the .elf and .hex, just leave the Teensy Loader in auto mode and press the button on Teensy.

That's not a very elegant solution, but it is simple and should at least let you test without having to alter the linker script or Arduino IDE. You could put the 2 commands into a script or batch file (if Windows) to automate this to some degree.

Teensyduino's modified .java files are installed to a src directory. You can edit that code, but to use your changes you'll need to recompile the IDE. The first and most difficult step is getting a copy of 1.0.3's source code, and then copying those .java files into it. The source tarball on Arduino's website is incomplete, so you must get it from github (with each Arduino release, I go through quite a lot of work to pull exactly the same code they used, and I compile on all 4 platforms and carefully verify the java bytecode output against Arduino's published downloads). To save you the trouble, here's my copy of 1.0.3's source with the patched .java files already in place.


Please let me know when you've downloaded this large file? I remove it from the server (this link will turn 404).

You'll need the Java JDK and Ant to compile this. On Windows, you'll probably need a cygwin setup to run. It's much easier on Mac and Linux. Also, you should use the JDK from Oracle, version 6u34. It might work if you use OpenJDK (the default on most Linux systems), but the Arduino developers and I use Oracle's JDK, so you'll get the same results if you use that version. This page has info about how to build the code:


After you recompile Arduino, you'll have a fresh copy of Arduino without the rest of the Teensyduino stuff. Everything else is just files, so you can copy the hardware/teensy and hardware/tools directories over to the freshly compiled copy. Of you can copy lib/pde.jar from the freshly compiled copy into the one with Teensyduino installed.

The new Arduino 1.5.x has a much more configurable build system. To be honest, I haven't looked at it in detail yet. I plan to support it when (or shortly after) they release 1.5.2. In theory, that system should make these types of customizations easier.
Hi Paul,
I have downloaded the file just in case I try to recompile the IDE - thankyou. But it isn't very likely I'll do that because it is a huge amount of work mucking about with cygwin on Windows.

I've written a TCL script which does all the heavy lifting after the verbose compile. I copy the entire gcc linking command and paste it into a TCL variable. Then I run the TCL script. The script extracts the name of the project and the path to the temporary directory from that variable and then inserts the "-larm_cortexM4l_math" in front of "-lm" (it also changes all the backslashes to slashes). Then it executes the gcc command. It then runs the two objcopy commands and follows that with the teensy_post_compile.
So I just do a compile in the IDE, copy and paste the string and then run the script. As long as it doesn't have any linker errors, the sketch is uploaded to the Teensy3 when I press the reset button.

Last edited:
Thanks Paul, Pete - lovely.
Maybe editing the linker script loads objects in the wrong sequence? It nearly-worked for me too, unresolved "sqrtf" with my test project.
So I rebuilt from Paul's source tree, and a small patch to Compiler.java,

> for (int i = 1; true; i++) {
> String additionalObject = boardPreferences.get("build.additionalobject" + i);
> if (additionalObject == null) break;
> baseCommandLinker.add(additionalObject);
> }

then editing hardware/teensy/boards.txt to add the path to the CMSIS library,


and... it builds :cool:
If you want to try this, the pde.jar is here.
Wow, it runs quick. For 1000 iterations,
fix_fft (uint16_t): 15.0 seconds
arm_cfft_radix4_f32 (float): 40.0 seconds
arm_cfft_radix4_q31 (int32_t): 5.2 seconds
arm_cfft_radix4_q15 (int16_t): 2.3 seconds.
Excellent! Thanks very much.
I have put the .a file in
so I added this line to my boards.txt file:

Did you have to do anything to fix_fft to make it work on Teensy3? The sketches I have which work on Arduino just produce garbage on Teensy3.

No, I have the same problem; both 8-bit and 16-bit fix_fft produce mush as far as I can tell.
OK, replying to myself, but here's where I got up to, which didn't require recompiling the arduino java ide.
Grab libarm_cortexM4l_math.a from the internet and copy it to your arduino folder, say into a 'lib' directory.
From the Arduino IDE, cp ./ide-1.5.2/hardware/arduino/sam/system/CMSIS/CMSIS/Include/* ide-1.0.5/hardware/teensy/cores/teensy3/
Also copy the arm_math.h file into that directory as well.

Then go into ide-1.0.5/hardware/tools/arm-none-eabi/bin and: mv arm-none-eabi-gcc arm-none-eabi.gcc.real
Then I created a tiny perl script to replace it, which checks if the arguments are mentioning a cortex cpu, and if so, add the -L and -l library options to include the library we downloaded earlier, and moves the -lm to the end of the array.

This works to compile and upload a sketch for me, but the Teensy seems to crash when it runs it.
Last edited:
By the way, some comments earlier were that only "mush" was coming out of the Cortex FFT routines.
I've just run the sample arm data through both the Teensy and also libfftw on my Ubuntu desktop, and the results came up the same, albeit with less precision on the cortex, but I think that's just the Serial library rounding floats to two decimal places.
Hi guys,

Seems like some interesting work here. I am interested to try out FFT too in my project. However, this discussion seems all too confusing for me.
I am running Mac OS 10.7.5, using Arduino 1.0.3 with Teensy loader 1.14 ( I installed the latest version but it appears as version 1.07 when I check the version in the toolbar "About").

What do I need to do to get my codes to compile? I already download the libarm_cortexM4l_math.a file but I don't know which folder to put it in. And whether I still need to edit any files or do some patching.

Appreciate any help I can get.

Did you read my two posts (#17 and #18) above yours? That's what you need to do. I think it should be the same on OSX as it was for me on Linux.
Yes, I did read your previous post. My problem is it seems like the arduino directory structure is quite different between mac and linux.

On my mac, the arduino folder is organized as follows:


I basically don't see any sam or CMSIS folder inside that. Just to make sure, I have enable hidden files to be seen too.

Inside my main Arduino root directory, I only see 2 folders, "Contents" and "scr". Do I create a new lib folder and put the libarm_cortexM4l_math.a inside it?

Did you read my two posts (#17 and #18) above yours? That's what you need to do. I think it should be the same on OSX as it was for me on Linux.
Ah, perhaps it wasn't clear from what I wrote, but when I was mentioning directories called "ide-1.0.5" and "ide-1.5.2" I was referring to those versions of the Arduino IDE.
ie. I've downloaded both versions, and installed them separately.
Then I've run teensyduino and installed it into the 1.0.5 one, and then manually copied some parts of 1.5.2 over myself.
Thanks for the clarification.

But I still can't find the CMSIS folder. Hmm, maybe Paul might be able to advise where it is if he happens to read this thread.
I think I know what is wrong. The CMSIS folder is found in the Arduino 1.5.2 distribution only. So I have to copy it and paste it into my Arduino 1.0.5 distribution.
Not open for further replies.