Search

Technical Discussion Group Forum

This forum is provided for user discussion. While Beacon EmbeddedWorks support staff and engineers participate, Beacon EmbeddedWorks does not guarantee the accuracy of all information within in the Technical Discussion Group (TDG).

The "Articles" forums provide brief Articles written by Beacon EmbeddedWorks engineers that address the most frequently asked technical questions.

To receive email notifications when updates are posted for a Beacon EmbeddedWorks product download, please subscribe to the TDG Forum of interest.

TDG Forum

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 16 Apr 2008 07:27 AM by  tombrus
Problems running some floating point benchmark code
 5 Replies
Sort:
You are not authorized to post a reply.
Author Messages

RossLeppard



New Member


Posts:
New Member


--
10 Apr 2008 08:23 AM
    Hi all,
    I'm trying to get some simple floating point benchmark code to run on my LITEKIT board but I'm getting nowhere fast and am running out of ideas.

    I'm using the sample application, LED_Flasher, that came with the board as a starting point and I've got my code working by just inserting it into the example. For the level of accuracy I need just running the code 100 times and toggling the LED and timing it by stop watch is fine for the moment.
    I've used the 'exec' LoLo command and although it works it runs very slowly, I belive because with the supplied GNU toolchain and the exec method the code is running without the cache enabled and without using the VFP co-processor?

    I found a couple of posts on here about updating the GNU toolchain and I think I've now done that (basically just used the script in this thread viewtopic.php?f=29&t=1430 many thanks Tombrus). Now however my code just generates an "Unhandled Exception: exception mode: undef", as a guess I think this is because the C library floating point initialisation is using VFP instructions before the co-processer is enabled?

    This is where I'm pretty much stuck, I think I need to modify the start up code to enable the co-processor but have no idea how to go about that Unfortunately I come from a Windows/PowerPC background and my experience with Cygwin/GNU/ARM is pretty much non-existant.

    Does anyone have any simple startup framework code that I could easily insert my code into or any suggestions as to how I could go about moddifying the example code to set this up?

    Many Thanks,

    Ross Leppard

    tombrus



    New Member


    Posts:
    New Member


    --
    11 Apr 2008 01:17 AM
    Hi Ross,

    I just put this next to my main:
    void ENABLE_VFP (void) {
    asm(" mrc p15, 0, r0, c1, c0, 2");
    asm(" orr r0, r0, #(0xf << 20)");
    asm(" mcr p15, 0, r0, c1, c0, 2");
    asm(" mov r0, #0x40000000");
    asm(" fmxr fpexc, r0");
    }
    and called ENABLE_VFP() first thing in main(). That did it for me.

    -Tom

    RossLeppard



    New Member


    Posts:
    New Member


    --
    11 Apr 2008 02:18 AM
    Thanks for that Tombrus, unfortunately it doesn't seem to have worked, I still get the same unhandled exception. I've tried putting that code as the first call in Main() as you suggested and also tried it as the first code in the apicrt0.S file after _start.
    I'm wondering whether I really have built the GNU toolchain correctly or whether the fault lies there. Below is an example of the command line generated by the Makefile for the compilation: -

    arm-elf-gcc -c -mcpu="arm1136jf-s" -mlittle-endian -fno-omit-frame-pointer -fno-builtin -O0 -Wall -g -mfpu=vfp -ggdb -DBASE_ADDRESS=0x80000000+0x00100000 -DMEMAP_BASE_SDRAM=0x80000000 -DBOOTFLASH_PHYS_BASE=0xA0000000 -DLOGIC_CARDENGINE_IMX31_10 -DCONFIG_IN_FLASH=0 -fno-builtin led_flasher.c -o led_flasher.o

    arm-elf-gcc -mcpu="arm1136jf-s" -D_ASM_ -mfpu=vfp -DBASE_ADDRESS=0x80000000+0x00100000 -DMEMAP_BASE_SDRAM=0x80000000 -DBOOTFLASH_PHYS_BASE=0xA0000000 -DLOGIC_CARDENGINE_IMX31_10 -DCONFIG_IN_FLASH=0 -c -o arch/arm11/apicrt0.o arch/arm11/apicrt0.S

    arm-elf-gcc -mcpu="arm1136jf-s" -mlittle-endian -fno-omit-frame-pointer -fno-builtin -O0 -Wall -g -mfpu=vfp -ggdb -DBASE_ADDRESS=0x80000000+0x00100000 -DMEMAP_BASE_SDRAM=0x80000000 -DBOOTFLASH_PHYS_BASE=0xA0000000 -DLOGIC_CARDENGINE_IMX31_10 -DCONFIG_IN_FLASH=0 -fno-builtin -nostdlib -N -o led_flasher-IMX31_10_R.elf -T api.lds led_flasher.o arch/arm11/apicrt0.o arch/arm11/arch_led_flasher.o OpenGLWrapper.o Rendering.o VectorFont.o -lm -lc -lgcc


    Is there anything obvious wrong or missing there? The compilation gives a couple of warnings about unused variables but no errors and it links fine to give the .ELF output file.
    Are there any checks or diagnostics I can do to verify the toolchain is correct?

    Many Thanks,

    Ross Leppard

    tombrus



    New Member


    Posts:
    New Member


    --
    11 Apr 2008 02:59 AM
    I do not know the exact compiler flags, but you can de-assemble your *.o files and see if they contain VFP instructions. Use the arm-elf-objdump command for it, it should be next to your arm-elf-gcc command. It should show assembler code like FMUL FADD,FDIV in there. The registers of the VFP have names like s14 (single) or d5 (double) that should also give you an indication. If it shows calls to library functions instead (BL xxxx) then your toolchain is not generating VFP instructions.

    As an example, this is part of some disassembled floating point code for me:
    2c: e59f3094 ldr r3, [pc, #148] ; c8 <.text+0xc8>
    30: e50b3014 str r3, [fp, #-20]
    34: ed1b7a04 flds s14, [fp, #-16]
    38: ed5b7a05 flds s15, [fp, #-20]
    3c: ee677a27 fmuls s15, s14, s15
    40: ed4b7a06 fsts s15, [fp, #-24]
    44: ed5b7a06 flds s15, [fp, #-24]
    48: eefd7ae7 ftosizs s15, s15
    4c: ee172a90 fmrs r2, s15
    50: ed5b7a06 flds s15, [fp, #-24]
    54: eeb76ae7 fcvtds d6, s15
    58: ed9f7b14 fldd d7, [pc, #80]
    5c: ee366b47 fsubd d6, d6, d7
    60: ed9f7b14 fldd d7, [pc, #80]
    64: ee267b07 fmuld d7, d6, d7
    68: eebd7bc7 ftosizd s14, d7
    6c: ee173a10 fmrs r3, s14
    Hope this helps.

    -Tom

    RossLeppard



    New Member


    Posts:
    New Member


    --
    16 Apr 2008 06:38 AM
    Thanks for that Tom.
    After several frustrating days I've found what was causing my crashes but it's rather puzzling. I used the code you put in one of your posts to get serial output to give me some basic debugging and found that my code was actually running but was crashing on certain operations. To cut a (very) long story short the VFP is enabled and the correct assembler instructions are being generated and executed and seem to work for basic operations, add, multiply etc. However when I use the Sin and Cos functions they seem to always return Infinity which then flow into my other calculations and cause exceptions. From looking at the MAP files and the generated assembler I can see that the standard Math library Sin and Cos routines are being called so I'm guessing it once again points to some problem with the way I generated the VFP enabled version of the GNU Toolchain and libraries?

    On a related note is anyone aware of any free windows based ARM compilers that would work with the LITEKIT?

    Many Thanks,

    Ross

    tombrus



    New Member


    Posts:
    New Member


    --
    16 Apr 2008 07:27 AM
    Sorry, I can not help you there, I did not use sin() cos() functions. You may have to recompile the library with your compiler version, but that is just a hunch.
    I would be interested in the solution though

    About Windows/Compiler: if I understand well the main stream free compiler for windows is GNU under cygwin. But that is just GNU-tools...

    -Tom

    Oh, and glad to hear I am not the only one with a continuous feeling of frustration....
    You are not authorized to post a reply.