Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 3 1 2 3 LastLast
Results 1 to 25 of 65

Thread: T3: linking libarm_cortexM3l_math.a

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,722

    T3: linking libarm_cortexM3l_math.a

    Using Teensy3 with beta10 on Windows.
    I'm trying to test the code mentioned in this Arduino DUE forum:
    http://arduino.cc/forum/index.php/topic,140107.0.html

    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?

    Pete
    [edit] fixed a typo/idiocy
    Last edited by el_supremo; 01-04-2013 at 10:03 PM.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,722
    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.

    arm_convolution_example_f32
    runs but fails its internal SNR test

    arm_fft_bin_example
    hangs when it calls arm_cfft_radix4_f32

    Pete

  3. #3
    Member
    Join Date
    Jan 2013
    Location
    Salem, MA
    Posts
    49
    You should be able to just add

    INPUT(c:/dev/teensy/lib/libarm_cortexM4l_math.a)

    into the linker script file (mk20dx128.ld). Adjusting the absolute path of course.

  4. #4
    Member
    Join Date
    Jan 2013
    Location
    Salem, MA
    Posts
    49
    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.

  5. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,722
    Thanks very much I will give that a try.
    and yes, M3 should be M4 - thanks.

    Pete

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,722
    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.

    Pete

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,788
    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.

    http://www.pjrc.com/teensy/beta/ardu...patched.tar.gz

    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:

    http://code.google.com/p/arduino/wiki/BuildingArduino

    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.

  8. #8
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,722
    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.

    Pete
    Last edited by el_supremo; 01-04-2013 at 11:29 PM.

  9. #9
    Member
    Join Date
    Jan 2013
    Location
    Salem, MA
    Posts
    49
    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,

    247a248,252
    > 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,

    teensy3.build.additionalobject1=c:/dev/teensy/lib/libarm_cortexM4l_math.a

    and... it builds
    If you want to try this, the pde.jar is here.

  10. #10
    Member
    Join Date
    Jan 2013
    Location
    Salem, MA
    Posts
    49
    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.

  11. #11
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,722
    @hpyle
    Excellent! Thanks very much.
    I have put the .a file in
    C:\teensy\arduino-1.0.3\hardware\tools\arm-none-eabi\arm-none-eabi\lib
    so I added this line to my boards.txt file:
    teensy3.build.additionalobject1=-larm_cortexM4l_math

    Pete

  12. #12
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,722
    @hpyle
    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.

    Pete

  13. #13
    Member
    Join Date
    Jan 2013
    Location
    Salem, MA
    Posts
    49
    No, I have the same problem; both 8-bit and 16-bit fix_fft produce mush as far as I can tell.

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,788
    I've put this patch on my to-do list. Next time I work on the java code I'll incorporate this patch.

  15. #15
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,788
    I included this patch in Teensyduino 1.12.

  16. #16
    Member
    Join Date
    Jan 2013
    Location
    Salem, MA
    Posts
    49
    Thanks Paul!

  17. #17
    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 wintrmute; 05-23-2013 at 07:47 AM.

  18. #18
    OK, after some hassles with what I think were memory overruns, I've made a sketch that runs the FFT functions and completes.
    I thought I'd share the Perl script that monkey-patches the libraries into the command line as well in case that's useful to people.

    The perl script I mentioned is at: https://gist.github.com/TJC/5633484
    A complete sketch that compiles and produces output from the FFT on serial is at: https://gist.github.com/TJC/5633491

  19. #19
    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.
    13.86
    41.35
    7.63
    20.12
    22.34
    49.17
    31.38
    25.18
    26.54
    4.77
    35.07

  20. #20
    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.

    Thanks.

  21. #21
    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.

  22. #22
    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:

    Arduino/Contents/Resources/Java/hardware/arduino/...

    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?





    Quote Originally Posted by wintrmute View Post
    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.

  23. #23
    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.

  24. #24
    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.

  25. #25
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •