energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
795 stars 671 forks source link

Generated code does not run 2nd time #24

Closed pbrier closed 12 years ago

pbrier commented 12 years ago

When I make a program (simple led blink and download it, it will not run. (MSP430G2553 device, 1 or 16Mhz clock tested). Oddly, it will run when I first download a program I made with the stand-alone msp430-gcc compiler (ubuntu linux package) using mspdebug and THEN use the energia IDE. When I download the same program again, it will NOT run.

To recap: 1) download externally compiled program (LED bliker) with MSPdebug: OK 2) Compile and Download program with Energia: OK (runs) 3) Compile and Download same program with Energia: NOK (halts) 4) Downloading hex file same program with mspdebug, or resetting board: NOK

It seems there may be something wrong with the initialization code / clock selection (WDT timeout?) Any ideas?

rei-vilo commented 12 years ago

Which OS are you using?

pbrier commented 12 years ago

It seems the startup code is not linked in correctly. main() is called directly, instead of the crt0 code. The stack is not set-up correctly. also the section .rodata. (static const vars) ends up in RAM (0x200) so something is wrong with the compiler or compiler flags!

What I use:

Ubuntu linux 10.04

GCC information:

msp430-gcc -v Using built-in specs. Reading specs from /usr/lib/gcc/msp430/4.5.3/../../../../msp430/lib/msp430mcu.spec COLLECT_GCC=msp430-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/msp430/4.5.3/lto-wrapper Target: msp430 Configured with: '/build/buildd/gcc-msp430-4.5.3~mspgcc-4.5.2-20110612/./gcc-4.5.3/configure' -v --enable-languages=c,c++ --prefix=/usr --infodir='/usr/share/info' --mandir='/usr/share/man' --bindir='/usr/bin' --libexecdir='/usr/lib' --libdir='/usr/lib' --ena ble-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --disable-libssp --build=i686-linux-gnu --host=i686-linux-gnu --target=msp430 Thread model: single gcc version 4.5.3 (GCC)

robertinant commented 12 years ago

Hi Peter, thanks for the report. We only got the Linux port up and running a couple of days ago. Before that, I have been using OS X and Windows. I did not run into this issue. A quick check on OS X using mspdebug and msp430-gdb shows the following:

(gdb) tar rem localhost:2000
Remote debugging using localhost:2000
_reset_vector__ () at ../../gcc-4.6.2/gcc/config/msp430/crt0.S:105
(gdb)

When stepping through the code it properly goes through all the data / stack initialization and clearing of the bss. It seems that we are on a different version of gcc. Rick has done most of the Linux work so maybe he can comment also.

Using built-in specs.
Reading specs from /opt/msp430/bin/../lib/gcc/msp430/4.6.2/../../../../msp430/lib/msp430mcu.spec
COLLECT_GCC=msp430-gcc
COLLECT_LTO_WRAPPER=/opt/msp430/bin/../libexec/gcc/msp430/4.6.2/lto-wrapper
Target: msp430
Configured with: ../gcc-4.6.2/configure --target=msp430 --enable-languages=c,c++ --program-prefix=msp430- --prefix=/Users/rwessels/mspgcc-install
Thread model: single
gcc version 4.6.2 20111026 (mspgcc dev 20120311) (GCC) 
robertinant commented 12 years ago

Peter,

I just recalled that I had an issue similar but not sure if this is related or not. Here is the link to the mspgcc mailing list archive discussing the issue. http://sourceforge.net/mailarchive/forum.php?thread_name=CAPOJ94NNvGdpgE%3DjikOynVXPRPQaABVn%2BMJJUr3jxz_Opg%3Dt4w%40mail.gmail.com&forum_name=mspgcc-users

RickKimball commented 12 years ago

prbrier, could you turn on the verbose output in energia and post the console output here? which version of mspdebug are you using?

-rick

pbrier commented 12 years ago

Hi Rob, Rick,

attached is the disassembly of the correct and incorrectly generated code. You can see: no stack or init. Some observations:

1) There seems to be a problem with the linker if main() is in an archive (core.a) I can link all the .o files in the temp directory together without a problem (running app)

2) I was able to compile and link from the IDE by changing the compiler and linker options: I replaced this in the compile step:

//"-Wl,-gc-sections,-u,main", "-Wl,-u,main",

and removed these: // "-Os", // optimize for size // "-ffunction-sections", // place each function in its own section // "-fdata-sections",

Now it works (sort of) for simple programs (i.e. blink). If you use C++ code (e.g. the timer serial example) I have missing references to the standard c functions (libc) like strcpy(), memcpy() etc. Maybe a C/C++ name mangling problem.

With regards,

Peter

On 04/16/2012 05:21 PM, RickKimball wrote:

prbrier, could you turn on the verbose output in energia and post the console output here?

-rick


Reply to this email directly or view it on GitHub: https://github.com/energia/Energia/issues/24#issuecomment-5154618

Energia Code:


Disassembly of section .text:

0000c000 <main>:
     c000:    b2 40 80 5a     mov    #23168, &0x0120    ;#0x5a80
     c004:    20 01
     c006:    f2 43 22 00     mov.b    #-1, &0x0022    ;r3 As==11
     c00a:    d2 43 21 00     mov.b    #1, &0x0021    ;r3 As==01
     c00e:    b0 12 a6 c0     call    #0xc0a6
     c012:    b0 12 20 c0     call    #0xc020
     c016:    b0 12 2a c0     call    #0xc02a
     c01a:    fd 3f           jmp    $-4          ;abs 0xc016

0000c01c <__ctors_end>:
     c01c:    30 40 c8 c0     br    #0xc0c8

0000c020 <setup>:
     c020:    c2 43 21 00     mov.b    #0, &0x0021    ;r3 As==00
     c024:    f2 43 21 00     mov.b    #-1, &0x0021    ;r3 As==11
     c028:    fb 3f           jmp    $-8          ;abs 0xc020

0000c02a <loop>:

Correct code:

a.out: file format elf32-msp430

Disassembly of section .text:

0000c000 <__init_stack>: c000: 31 40 00 04 mov #1024, r1 ;#0x0400

0000c004 <__low_level_init>: c004: 15 42 20 01 mov &0x0120,r5 c008: 75 f3 and.b #-1, r5 ;r3 As==11 c00a: 35 d0 08 5a bis #23048, r5 ;#0x5a08

0000c00e <__do_copy_data>: c00e: 3f 40 00 00 mov #0, r15 ;#0x0000 c012: 0f 93 tst r15 c014: 07 24 jz $+16 ;abs 0xc024 c016: 82 45 20 01 mov r5, &0x0120 c01a: 2f 83 decd r15 c01c: 9f 4f c2 ca mov -13630(r15),512(r15);0xcac2(r15), 0x0200(r15) c020: 00 02 c022: f9 23 jnz $-12 ;abs 0xc016

0000c024 <__do_clear_bss>: c024: 3f 40 2a 00 mov #42, r15 ;#0x002a c028: 0f 93 tst r15 c02a: 06 24 jz $+14 ;abs 0xc038 c02c: 82 45 20 01 mov r5, &0x0120 c030: 1f 83 dec r15 c032: cf 43 00 02 mov.b #0, 512(r15);r3 As==00, 0x0200(r15) c036: fa 23 jnz $-10 ;abs 0xc02c

0000c038

: c038: 04 41 mov r1, r4 c03a: 24 53 incd r4 c03c: b0 12 68 c3 call #0xc368 c040: b0 12 54 c0 call #0xc054 c044: b0 12 c8 c0 call #0xc0c8 c048: fd 3f jmp $-4 ;abs 0xc044

0000c04a <stop_progExec>: c04a: 32 d0 f0 00 bis #240, r2 ;#0x00f0 c04e: fd 3f jmp $-4 ;abs 0xc04a

RickKimball commented 12 years ago

Peter,

Can you tell us where you got your 4.5.3 gcc compiler? Was it an apt-get or did you compile it yourself? I think early versions of non patched 4.5.3 had this problem however that was addressed with patches. I'm using a fully patched 4.5.3 and the newest 4.6 that both are compiled from scratch and they both work fine. I'm running Ubuntu 11.04. ... actually I see that you are using the apt get version from reading earlier posts..

You might want to try a newer version of gcc

pbrier commented 12 years ago

I got it from ubuntu packages that I downloaded for ubuntu 11.04 . They could be outdated.

Can you provide a specific version with Energia, that is known to work? I can get the sources and patch it, but a pre-patched source tree would be better.

Using standard ubuntu or debian pre-comiled versions would be ideal in the future. (that the is situation with avr-gcc) But then they should be of sufficient quality.

With regards,

Peter

On 04/16/2012 07:35 PM, RickKimball wrote:

Peter,

Can you tell us where you got your 4.5.3 gcc compiler? Was it an apt-get or did you compile it yourself? I think early versions of non patched 4.5.3 had this problem however that was addressed with patches. I'm using a fully patched 4.5.3 and the newest 4.6 that both are compiled from scratch and they both work fine. I'm running Ubuntu 11.04.


Reply to this email directly or view it on GitHub: https://github.com/energia/Energia/issues/24#issuecomment-5157803

RickKimball commented 12 years ago

http://dawn.dev.hu/~ice/tmp/build-mspgcc .. that script will fetch and download the 4.6 branch of gcc and compile for linux https://gist.github.com/1529568 -- this script builds the 4.5.3 with all available patches.

These are the toolchains I'm using.

-rick

RickKimball commented 12 years ago

I'm using the latest git version of mspdebug built from source.

pbrier commented 12 years ago

On 04/16/2012 09:15 PM, RickKimball wrote:

http://dawn.dev.hu/~ice/tmp/build-mspgcc .. that script will fetch and download the 4.6 branch of gcc and compile for linux https://gist.github.com/1529568 -- this script builds the 4.5.3 with all available patches.

These are the toolchains I'm using.

-rick


Reply to this email directly or view it on GitHub: https://github.com/energia/Energia/issues/24#issuecomment-5160047 OK, thanks. Fetching at the moment.

pbrier commented 12 years ago

Downloaded and compiled msp-gcc 4.6 from source, compiled my MSP program and run: OK!

Ubuntu version of MSP430-GCC (or my installation) seems to be broken.

Hint: there are quite some dependencies you net to " apt-get install" to compile. Installation dir of the compiler is "/opt/mspgcc". So you need to include /opt/mspgcc/bin to the path, or make links in /usr/bin to find the compiler.

Maybe include correct msp430gcc source tree (and binaries?) in the Energia project to be sure the correct compiler is used.

robertinant commented 12 years ago

Happy to hear you got it going. Including a linux toolchains in Energia is food for thought. Maybe we can find somebody in the community that is willing to maintain mspgcc for the various distributions once Energia takes to the sky's :-)