Other Parts Discussed in Thread: MSP430-GCC-OPENSOURCE,
There is a seemingly strange behavior with the MSP430-GCC-OPENSOURCE compiler regarding global variables (sometimes).
The example project attached is a simplified example from the codebase I've been working with. In the file "twi.c" there is a global variable called "myvar". When initializing this variable with some values (0x0040, 0x0140, 0x0240, ... 0x0F40) the generated program is "broken".
Broken means (determined using debugger):
- The program never executes to main
- The program reaches __crt0_start as expected
- The program makes it to the call instruction in __crt0_init_bss
- The program then ends up at address 0x0004 (PC = 0x0004) which is a jump back to itself
- Between the call and first arrival at 0x0004 there are 516, 095 clock cycles (not instant jump)
Confusingly, the watchdog ISR accessing a global variable (see "wiring.c") is also required for the code to be "broken".
Steps to reproduce (use BugExample.zip)
- Import BugExample project into CCS
- Make sure the watchdog isr increments "wdt_overflow_count" in wiring.c
- Make sure a "broken" value is assigned to "myvar" in twi.c (see comments for broken and working values)
- Clean & build project
- Start a debug session
- Observe that the program never makes it to main
The program will work as intended if "myvar" is not one of the broken values or if the wdt isr does not increment (access?) "wdt_overflow_count".
This does not happen with the same program ported to the TI compiler (also attached as BugExampleTI.zip)