Shop OBEX P1 Docs P2 Docs Learn Events
another i2c / xmmc question — Parallax Forums

another i2c / xmmc question

Mark MaraMark Mara Posts: 64
edited 2013-07-21 17:32 in Propeller 1
I need some more help. I am working on a project using xmmc. I have been using the cog_c_toggle demo code as my model. I can open an i2c bus using i2cBootOpen() in the main routine with no problems, however, if I start a cog and try to the do the i2cBootOpen() from there I get an error message.

I can demonstrate my problem using the cog_c_toggle demo code. If I put a i2cBootOpen() in toggle.c it works fine if I put the i2cBootOpen() in toggle_fw.c I get this:
bottomshotserver:my_toggle_2 mam1$ make clean
rm -f *.o *.elf *.a *.cog *.ecog *.binary
bottomshotserver:my_toggle_2 mam1$ make MODEL=xmmc BOARD=c3
propeller-elf-gcc -Os -mxmmc  -o toggle.o -c toggle.c
propeller-elf-gcc -Os  -mcog -r -o toggle_fw.cog toggle_fw.c
propeller-elf-objcopy --localize-text --rename-section .text=toggle_fw.cog toggle_fw.cog
propeller-elf-gcc -Os -mxmmc  -fno-exceptions -fno-rtti -o toggle.elf toggle.o toggle_fw.cog
toggle_fw.cog: In function `_main':
:(toggle_fw.cog+0x54): relocation truncated to fit: R_PROPELLER_SRC against symbol `_i2cBootOpen' defined in .text section in /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/lib/xmmc/libc.a(cogload.o)
collect2: ld returned 1 exit status
make: *** [toggle.elf] Error 1
bottomshotserver:my_toggle_2 mam1$

Any help would be greatly appreciated.

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-07-21 08:26
    It's kind of a silly way to let us know something went wrong (provided by our friends a FSF) but ....

    Any time you see "relocation truncated to fit" it means your program has grown beyond the limits of the memory model.

    If you need i2c access in a COG sized program you have a few choices.

    1. Add some code to the COG C file usually via copy paste so you know the stack won't blow up.
    2. Use a mailbox handler in a CMM/LMM/XMM* main program that can provide services.

    There may be more, but these are obvious to me.
  • SRLMSRLM Posts: 5,045
    edited 2013-07-21 09:00
    You can also try adding the -Wl,--gc-sections -Wl,--print-gc-sections options to your gcc flags and see if that helps.

    Normally when working with CMM or LMM I see something like
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: main.elf section `.text' will not fit in region `hub'
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: region `hub' overflowed by 20808 bytes
    

    In your case I don't see the amount of overflow bytes.
  • Mark MaraMark Mara Posts: 64
    edited 2013-07-21 11:06
    Thanks for the replies. I added the suggested flags and that caused the overflow message to be replaced with an undefined symbol error:
    bottomshotserver:my_toggle_2 mam1$ make clean
    rm -f *.o *.elf *.a *.cog *.ecog *.binary
    bottomshotserver:my_toggle_2 mam1$ make MODEL=xmmc BOARD=c3
    propeller-elf-gcc -Os -Wl,--gc-sections -Wl,--print-gc-sections -mxmmc  -o toggle.o -c toggle.c
    propeller-elf-gcc -Os -Wl,--gc-sections -Wl,--print-gc-sections  -mcog -r -o toggle_fw.cog toggle_fw.c
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: Removing unused section '.boot' in file '/opt/parallax/lib/gcc/propeller-elf/4.6.1/spinboot.o'
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: Removing unused section '.text' in file '/opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/lib/crt0_cog.o'
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: Removing unused section '.text' in file '/var/folders/2d/w34p9ft573d2j2nr4l49whz00000gn/T//ccDadS1H.o'
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: Removing unused section '.text' in file '/opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/lib/crtend_cog.o'
    /opt/parallax/lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/bin/ld: gc-sections requires either an entry or an undefined symbol
    collect2: ld returned 1 exit status
    make: *** [toggle_fw.cog] Error 1
    bottomshotserver:my_toggle_2 mam1$
    

    I used these flags without understanding what they do. Could you point me at any documentation? I clearly need a better understanding of what is happening.

    I believe that jazzed is telling me that size of the i2c routines are such that I can not fit them into a cog so the only way to run them is from the main program. Is this correct?
  • SRLMSRLM Posts: 5,045
    edited 2013-07-21 15:37
    As it turns out, you've discovered the limits of where we're at with the garbage collection. I've only tested on CMM and LMM, and I forgot that it might not work (yet) with the other memory models. I'll try to take a look it but for now you'll have to take a different tack.
  • SRLMSRLM Posts: 5,045
    edited 2013-07-21 15:39
    You can also write your own I2C routines if you like, or maybe cut and paste from the library. I2C is a fairly light weight protocol (maybe 20 instructions each for shifting out and in a byte) so you'll have plenty of extra space in the cog if you're conservative.
  • blindstarblindstar Posts: 12
    edited 2013-07-21 17:32
    Thanks guys. I'll try implementing my own, application specific, i2c routines.
Sign In or Register to comment.