Instance of C++ class halts ATmega2560

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a really strange problem. This is my test code:

 

Demo.h

#include <stdlib.h>

class TestClass
{
    public:
    TestClass();
    
    private:
};

Demo.cpp:

#include "Demo.h"

TestClass::TestClass()
{
    
}

main.cpp:

#include "Demo.h"

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#define setOutput(port, pin)    ((DDR(port)) |= (1 << (pin)))
#define setInput(port, pin)     ((DDR(port)) &= ~(1 << (pin)))
#define setAnalogIn(port, pin)  do \
{ \
    setInput((port), (pin)); \
    setLow((port), (pin)); \
} while (0)
#define setLow(port, pin)       ((port) &= ~(1 << (pin)))
#define setHigh(port, pin)      ((port) |= (1 << (pin)))
#define readPin(port, pin)      (((PIN(port)) >> (pin)) & 0x01)

#define DDR(port)               (*(&port-1))
#define PIN(port)               (*(&port-2))

//TestClass testing;

int main()
{
    cli();
    setOutput(PORTB, 7);

    int16_t baud_count = ((F_CPU / 8) + (38400 / 2)) / 38400;
    UBRR0 = (baud_count >> 1) - 1;

    //8 bit, no parity, 1 stop bit
    UCSR0C = (1<<UCSZ01) | (1<<UCSZ00);

    //enable receiver, transmitter and receive interrupt
    UCSR0B = (1<<RXEN0) | (1<<TXEN0);

    sei();

    while(1)
    {
        
        while ((UCSR0A & (1 << UDRE0)) == 0) {};
        UDR0 = 144;
        
        while ((UCSR0A & (1 << UDRE0)) == 0) {};
        UDR0 = 127;
        
        while ((UCSR0A & (1 << UDRE0)) == 0) {};
        UDR0 = 127;

        _delay_ms(1000);
    }
}

Notice how class instance is commented out. This code works fine. It simply sends some data over UART every second. Once I uncomment creation of class instance, nothing happens. I get no output from UART. What is wrong here? Here's output from GCC:

 

avr-g++ -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -Wall -c -DNDEBUG -DARCH=ARCH_AVR8 -DF_CPU=16000000UL  -DEEPROM_SIZE=4096 -DBOOT_START_ADDR= -O2 -mmcu=atmega2560   -MD -MP -MF "build/firmware/Demo.d" -MT"build/firmware/Demo.d" -MT"build/firmware/Demo.o" -o "build/firmware/Demo.o" "firmware/Demo.cpp" 
Finished building: firmware/Demo.cpp
mkdir -p build/firmware
avr-g++ -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -Wall -c -DNDEBUG -DARCH=ARCH_AVR8 -DF_CPU=16000000UL  -DEEPROM_SIZE=4096 -DBOOT_START_ADDR= -O2 -mmcu=atmega2560   -MD -MP -MF "build/firmware/main.d" -MT"build/firmware/main.d" -MT"build/firmware/main.o" -o "build/firmware/main.o" "firmware/main.cpp" 
Finished building: firmware/main.cpp
avr-g++ -ofw_mega.elf  build/firmware/Demo.o build/firmware/main.o -mmcu=atmega2560 -Wl,--gc-sections -mrelax -Wl,--start-group -Wl,-lm -Wl,--end-group
Finished building target: fw_mega.elf

Sadly, I don't have debugger to figure out where does app halt. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Shantea wrote:
Sadly, I don't have debugger to figure out where does app halt. 

But Studio has a Simulator. Run the code in that and see if you find anything "interesting".

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which gcc version?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:

Which gcc version?

 

It's 4.9.2. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post the .lss file

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you add a LED blink to your loop, just to be sure it's not executed?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Post the .lss file

 

Here's the working .lss file:

 


fw_mega.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000000  00800200  00800200  000001ac  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         00000158  00000000  00000000  00000054  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .comment      00000011  00000000  00000000  000001ac  2**0
                  CONTENTS, READONLY
  3 .note.gnu.avr.deviceinfo 00000040  00000000  00000000  000001c0  2**2
                  CONTENTS, READONLY

Disassembly of section .text:

00000000 <__vectors>:
   0:	71 c0       	rjmp	.+226    	; 0xe4 <__ctors_end>
   2:	00 00       	nop
   4:	79 c0       	rjmp	.+242    	; 0xf8 <__bad_interrupt>
   6:	00 00       	nop
   8:	77 c0       	rjmp	.+238    	; 0xf8 <__bad_interrupt>
   a:	00 00       	nop
   c:	75 c0       	rjmp	.+234    	; 0xf8 <__bad_interrupt>
   e:	00 00       	nop
  10:	73 c0       	rjmp	.+230    	; 0xf8 <__bad_interrupt>
  12:	00 00       	nop
  14:	71 c0       	rjmp	.+226    	; 0xf8 <__bad_interrupt>
  16:	00 00       	nop
  18:	6f c0       	rjmp	.+222    	; 0xf8 <__bad_interrupt>
  1a:	00 00       	nop
  1c:	6d c0       	rjmp	.+218    	; 0xf8 <__bad_interrupt>
  1e:	00 00       	nop
  20:	6b c0       	rjmp	.+214    	; 0xf8 <__bad_interrupt>
  22:	00 00       	nop
  24:	69 c0       	rjmp	.+210    	; 0xf8 <__bad_interrupt>
  26:	00 00       	nop
  28:	67 c0       	rjmp	.+206    	; 0xf8 <__bad_interrupt>
  2a:	00 00       	nop
  2c:	65 c0       	rjmp	.+202    	; 0xf8 <__bad_interrupt>
  2e:	00 00       	nop
  30:	63 c0       	rjmp	.+198    	; 0xf8 <__bad_interrupt>
  32:	00 00       	nop
  34:	61 c0       	rjmp	.+194    	; 0xf8 <__bad_interrupt>
  36:	00 00       	nop
  38:	5f c0       	rjmp	.+190    	; 0xf8 <__bad_interrupt>
  3a:	00 00       	nop
  3c:	5d c0       	rjmp	.+186    	; 0xf8 <__bad_interrupt>
  3e:	00 00       	nop
  40:	5b c0       	rjmp	.+182    	; 0xf8 <__bad_interrupt>
  42:	00 00       	nop
  44:	59 c0       	rjmp	.+178    	; 0xf8 <__bad_interrupt>
  46:	00 00       	nop
  48:	57 c0       	rjmp	.+174    	; 0xf8 <__bad_interrupt>
  4a:	00 00       	nop
  4c:	55 c0       	rjmp	.+170    	; 0xf8 <__bad_interrupt>
  4e:	00 00       	nop
  50:	53 c0       	rjmp	.+166    	; 0xf8 <__bad_interrupt>
  52:	00 00       	nop
  54:	51 c0       	rjmp	.+162    	; 0xf8 <__bad_interrupt>
  56:	00 00       	nop
  58:	4f c0       	rjmp	.+158    	; 0xf8 <__bad_interrupt>
  5a:	00 00       	nop
  5c:	4d c0       	rjmp	.+154    	; 0xf8 <__bad_interrupt>
  5e:	00 00       	nop
  60:	4b c0       	rjmp	.+150    	; 0xf8 <__bad_interrupt>
  62:	00 00       	nop
  64:	49 c0       	rjmp	.+146    	; 0xf8 <__bad_interrupt>
  66:	00 00       	nop
  68:	47 c0       	rjmp	.+142    	; 0xf8 <__bad_interrupt>
  6a:	00 00       	nop
  6c:	45 c0       	rjmp	.+138    	; 0xf8 <__bad_interrupt>
  6e:	00 00       	nop
  70:	43 c0       	rjmp	.+134    	; 0xf8 <__bad_interrupt>
  72:	00 00       	nop
  74:	41 c0       	rjmp	.+130    	; 0xf8 <__bad_interrupt>
  76:	00 00       	nop
  78:	3f c0       	rjmp	.+126    	; 0xf8 <__bad_interrupt>
  7a:	00 00       	nop
  7c:	3d c0       	rjmp	.+122    	; 0xf8 <__bad_interrupt>
  7e:	00 00       	nop
  80:	3b c0       	rjmp	.+118    	; 0xf8 <__bad_interrupt>
  82:	00 00       	nop
  84:	39 c0       	rjmp	.+114    	; 0xf8 <__bad_interrupt>
  86:	00 00       	nop
  88:	37 c0       	rjmp	.+110    	; 0xf8 <__bad_interrupt>
  8a:	00 00       	nop
  8c:	35 c0       	rjmp	.+106    	; 0xf8 <__bad_interrupt>
  8e:	00 00       	nop
  90:	33 c0       	rjmp	.+102    	; 0xf8 <__bad_interrupt>
  92:	00 00       	nop
  94:	31 c0       	rjmp	.+98     	; 0xf8 <__bad_interrupt>
  96:	00 00       	nop
  98:	2f c0       	rjmp	.+94     	; 0xf8 <__bad_interrupt>
  9a:	00 00       	nop
  9c:	2d c0       	rjmp	.+90     	; 0xf8 <__bad_interrupt>
  9e:	00 00       	nop
  a0:	2b c0       	rjmp	.+86     	; 0xf8 <__bad_interrupt>
  a2:	00 00       	nop
  a4:	29 c0       	rjmp	.+82     	; 0xf8 <__bad_interrupt>
  a6:	00 00       	nop
  a8:	27 c0       	rjmp	.+78     	; 0xf8 <__bad_interrupt>
  aa:	00 00       	nop
  ac:	25 c0       	rjmp	.+74     	; 0xf8 <__bad_interrupt>
  ae:	00 00       	nop
  b0:	23 c0       	rjmp	.+70     	; 0xf8 <__bad_interrupt>
  b2:	00 00       	nop
  b4:	21 c0       	rjmp	.+66     	; 0xf8 <__bad_interrupt>
  b6:	00 00       	nop
  b8:	1f c0       	rjmp	.+62     	; 0xf8 <__bad_interrupt>
  ba:	00 00       	nop
  bc:	1d c0       	rjmp	.+58     	; 0xf8 <__bad_interrupt>
  be:	00 00       	nop
  c0:	1b c0       	rjmp	.+54     	; 0xf8 <__bad_interrupt>
  c2:	00 00       	nop
  c4:	19 c0       	rjmp	.+50     	; 0xf8 <__bad_interrupt>
  c6:	00 00       	nop
  c8:	17 c0       	rjmp	.+46     	; 0xf8 <__bad_interrupt>
  ca:	00 00       	nop
  cc:	15 c0       	rjmp	.+42     	; 0xf8 <__bad_interrupt>
  ce:	00 00       	nop
  d0:	13 c0       	rjmp	.+38     	; 0xf8 <__bad_interrupt>
  d2:	00 00       	nop
  d4:	11 c0       	rjmp	.+34     	; 0xf8 <__bad_interrupt>
  d6:	00 00       	nop
  d8:	0f c0       	rjmp	.+30     	; 0xf8 <__bad_interrupt>
  da:	00 00       	nop
  dc:	0d c0       	rjmp	.+26     	; 0xf8 <__bad_interrupt>
  de:	00 00       	nop
  e0:	0b c0       	rjmp	.+22     	; 0xf8 <__bad_interrupt>
	...

000000e4 <__ctors_end>:
  e4:	11 24       	eor	r1, r1
  e6:	1f be       	out	0x3f, r1	; 63
  e8:	cf ef       	ldi	r28, 0xFF	; 255
  ea:	d1 e2       	ldi	r29, 0x21	; 33
  ec:	de bf       	out	0x3e, r29	; 62
  ee:	cd bf       	out	0x3d, r28	; 61
  f0:	00 e0       	ldi	r16, 0x00	; 0
  f2:	0c bf       	out	0x3c, r16	; 60
  f4:	02 d0       	rcall	.+4      	; 0xfa <main>
  f6:	2e c0       	rjmp	.+92     	; 0x154 <_exit>

000000f8 <__bad_interrupt>:
  f8:	83 cf       	rjmp	.-250    	; 0x0 <__vectors>

000000fa <main>:
  fa:	f8 94       	cli
  fc:	27 9a       	sbi	0x04, 7	; 4
  fe:	89 e1       	ldi	r24, 0x19	; 25
 100:	90 e0       	ldi	r25, 0x00	; 0
 102:	90 93 c5 00 	sts	0x00C5, r25
 106:	80 93 c4 00 	sts	0x00C4, r24
 10a:	86 e0       	ldi	r24, 0x06	; 6
 10c:	80 93 c2 00 	sts	0x00C2, r24
 110:	88 e1       	ldi	r24, 0x18	; 24
 112:	80 93 c1 00 	sts	0x00C1, r24
 116:	78 94       	sei
 118:	20 e9       	ldi	r18, 0x90	; 144
 11a:	9f e7       	ldi	r25, 0x7F	; 127
 11c:	80 91 c0 00 	lds	r24, 0x00C0
 120:	85 ff       	sbrs	r24, 5
 122:	fc cf       	rjmp	.-8      	; 0x11c <main+0x22>
 124:	20 93 c6 00 	sts	0x00C6, r18
 128:	80 91 c0 00 	lds	r24, 0x00C0
 12c:	85 ff       	sbrs	r24, 5
 12e:	fc cf       	rjmp	.-8      	; 0x128 <main+0x2e>
 130:	90 93 c6 00 	sts	0x00C6, r25
 134:	80 91 c0 00 	lds	r24, 0x00C0
 138:	85 ff       	sbrs	r24, 5
 13a:	fc cf       	rjmp	.-8      	; 0x134 <main+0x3a>
 13c:	90 93 c6 00 	sts	0x00C6, r25
 140:	3f ef       	ldi	r19, 0xFF	; 255
 142:	43 ed       	ldi	r20, 0xD3	; 211
 144:	80 e3       	ldi	r24, 0x30	; 48
 146:	31 50       	subi	r19, 0x01	; 1
 148:	40 40       	sbci	r20, 0x00	; 0
 14a:	80 40       	sbci	r24, 0x00	; 0
 14c:	e1 f7       	brne	.-8      	; 0x146 <main+0x4c>
 14e:	00 c0       	rjmp	.+0      	; 0x150 <main+0x56>
 150:	00 00       	nop
 152:	e4 cf       	rjmp	.-56     	; 0x11c <main+0x22>

00000154 <_exit>:
 154:	f8 94       	cli

00000156 <__stop_program>:
 156:	ff cf       	rjmp	.-2      	; 0x156 <__stop_program>

Here's the non-working one:


fw_mega.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000000  00800200  00800200  00000214  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         000001a0  00000000  00000000  00000074  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .bss          00000001  00800200  00800200  00000214  2**0
                  ALLOC
  3 .comment      00000011  00000000  00000000  00000214  2**0
                  CONTENTS, READONLY
  4 .note.gnu.avr.deviceinfo 00000040  00000000  00000000  00000228  2**2
                  CONTENTS, READONLY

Disassembly of section .text:

00000000 <__vectors>:
   0:	72 c0       	rjmp	.+228    	; 0xe6 <__ctors_end>
   2:	00 00       	nop
   4:	91 c0       	rjmp	.+290    	; 0x128 <__bad_interrupt>
   6:	00 00       	nop
   8:	8f c0       	rjmp	.+286    	; 0x128 <__bad_interrupt>
   a:	00 00       	nop
   c:	8d c0       	rjmp	.+282    	; 0x128 <__bad_interrupt>
   e:	00 00       	nop
  10:	8b c0       	rjmp	.+278    	; 0x128 <__bad_interrupt>
  12:	00 00       	nop
  14:	89 c0       	rjmp	.+274    	; 0x128 <__bad_interrupt>
  16:	00 00       	nop
  18:	87 c0       	rjmp	.+270    	; 0x128 <__bad_interrupt>
  1a:	00 00       	nop
  1c:	85 c0       	rjmp	.+266    	; 0x128 <__bad_interrupt>
  1e:	00 00       	nop
  20:	83 c0       	rjmp	.+262    	; 0x128 <__bad_interrupt>
  22:	00 00       	nop
  24:	81 c0       	rjmp	.+258    	; 0x128 <__bad_interrupt>
  26:	00 00       	nop
  28:	7f c0       	rjmp	.+254    	; 0x128 <__bad_interrupt>
  2a:	00 00       	nop
  2c:	7d c0       	rjmp	.+250    	; 0x128 <__bad_interrupt>
  2e:	00 00       	nop
  30:	7b c0       	rjmp	.+246    	; 0x128 <__bad_interrupt>
  32:	00 00       	nop
  34:	79 c0       	rjmp	.+242    	; 0x128 <__bad_interrupt>
  36:	00 00       	nop
  38:	77 c0       	rjmp	.+238    	; 0x128 <__bad_interrupt>
  3a:	00 00       	nop
  3c:	75 c0       	rjmp	.+234    	; 0x128 <__bad_interrupt>
  3e:	00 00       	nop
  40:	73 c0       	rjmp	.+230    	; 0x128 <__bad_interrupt>
  42:	00 00       	nop
  44:	71 c0       	rjmp	.+226    	; 0x128 <__bad_interrupt>
  46:	00 00       	nop
  48:	6f c0       	rjmp	.+222    	; 0x128 <__bad_interrupt>
  4a:	00 00       	nop
  4c:	6d c0       	rjmp	.+218    	; 0x128 <__bad_interrupt>
  4e:	00 00       	nop
  50:	6b c0       	rjmp	.+214    	; 0x128 <__bad_interrupt>
  52:	00 00       	nop
  54:	69 c0       	rjmp	.+210    	; 0x128 <__bad_interrupt>
  56:	00 00       	nop
  58:	67 c0       	rjmp	.+206    	; 0x128 <__bad_interrupt>
  5a:	00 00       	nop
  5c:	65 c0       	rjmp	.+202    	; 0x128 <__bad_interrupt>
  5e:	00 00       	nop
  60:	63 c0       	rjmp	.+198    	; 0x128 <__bad_interrupt>
  62:	00 00       	nop
  64:	61 c0       	rjmp	.+194    	; 0x128 <__bad_interrupt>
  66:	00 00       	nop
  68:	5f c0       	rjmp	.+190    	; 0x128 <__bad_interrupt>
  6a:	00 00       	nop
  6c:	5d c0       	rjmp	.+186    	; 0x128 <__bad_interrupt>
  6e:	00 00       	nop
  70:	5b c0       	rjmp	.+182    	; 0x128 <__bad_interrupt>
  72:	00 00       	nop
  74:	59 c0       	rjmp	.+178    	; 0x128 <__bad_interrupt>
  76:	00 00       	nop
  78:	57 c0       	rjmp	.+174    	; 0x128 <__bad_interrupt>
  7a:	00 00       	nop
  7c:	55 c0       	rjmp	.+170    	; 0x128 <__bad_interrupt>
  7e:	00 00       	nop
  80:	53 c0       	rjmp	.+166    	; 0x128 <__bad_interrupt>
  82:	00 00       	nop
  84:	51 c0       	rjmp	.+162    	; 0x128 <__bad_interrupt>
  86:	00 00       	nop
  88:	4f c0       	rjmp	.+158    	; 0x128 <__bad_interrupt>
  8a:	00 00       	nop
  8c:	4d c0       	rjmp	.+154    	; 0x128 <__bad_interrupt>
  8e:	00 00       	nop
  90:	4b c0       	rjmp	.+150    	; 0x128 <__bad_interrupt>
  92:	00 00       	nop
  94:	49 c0       	rjmp	.+146    	; 0x128 <__bad_interrupt>
  96:	00 00       	nop
  98:	47 c0       	rjmp	.+142    	; 0x128 <__bad_interrupt>
  9a:	00 00       	nop
  9c:	45 c0       	rjmp	.+138    	; 0x128 <__bad_interrupt>
  9e:	00 00       	nop
  a0:	43 c0       	rjmp	.+134    	; 0x128 <__bad_interrupt>
  a2:	00 00       	nop
  a4:	41 c0       	rjmp	.+130    	; 0x128 <__bad_interrupt>
  a6:	00 00       	nop
  a8:	3f c0       	rjmp	.+126    	; 0x128 <__bad_interrupt>
  aa:	00 00       	nop
  ac:	3d c0       	rjmp	.+122    	; 0x128 <__bad_interrupt>
  ae:	00 00       	nop
  b0:	3b c0       	rjmp	.+118    	; 0x128 <__bad_interrupt>
  b2:	00 00       	nop
  b4:	39 c0       	rjmp	.+114    	; 0x128 <__bad_interrupt>
  b6:	00 00       	nop
  b8:	37 c0       	rjmp	.+110    	; 0x128 <__bad_interrupt>
  ba:	00 00       	nop
  bc:	35 c0       	rjmp	.+106    	; 0x128 <__bad_interrupt>
  be:	00 00       	nop
  c0:	33 c0       	rjmp	.+102    	; 0x128 <__bad_interrupt>
  c2:	00 00       	nop
  c4:	31 c0       	rjmp	.+98     	; 0x128 <__bad_interrupt>
  c6:	00 00       	nop
  c8:	2f c0       	rjmp	.+94     	; 0x128 <__bad_interrupt>
  ca:	00 00       	nop
  cc:	2d c0       	rjmp	.+90     	; 0x128 <__bad_interrupt>
  ce:	00 00       	nop
  d0:	2b c0       	rjmp	.+86     	; 0x128 <__bad_interrupt>
  d2:	00 00       	nop
  d4:	29 c0       	rjmp	.+82     	; 0x128 <__bad_interrupt>
  d6:	00 00       	nop
  d8:	27 c0       	rjmp	.+78     	; 0x128 <__bad_interrupt>
  da:	00 00       	nop
  dc:	25 c0       	rjmp	.+74     	; 0x128 <__bad_interrupt>
  de:	00 00       	nop
  e0:	23 c0       	rjmp	.+70     	; 0x128 <__bad_interrupt>
	...

000000e4 <__ctors_start>:
  e4:	c3 00       	.word	0x00c3	; ????

000000e6 <__ctors_end>:
  e6:	11 24       	eor	r1, r1
  e8:	1f be       	out	0x3f, r1	; 63
  ea:	cf ef       	ldi	r28, 0xFF	; 255
  ec:	d1 e2       	ldi	r29, 0x21	; 33
  ee:	de bf       	out	0x3e, r29	; 62
  f0:	cd bf       	out	0x3d, r28	; 61
  f2:	00 e0       	ldi	r16, 0x00	; 0
  f4:	0c bf       	out	0x3c, r16	; 60

000000f6 <__do_clear_bss>:
  f6:	22 e0       	ldi	r18, 0x02	; 2
  f8:	a0 e0       	ldi	r26, 0x00	; 0
  fa:	b2 e0       	ldi	r27, 0x02	; 2
  fc:	01 c0       	rjmp	.+2      	; 0x100 <.do_clear_bss_start>

000000fe <.do_clear_bss_loop>:
  fe:	1d 92       	st	X+, r1

00000100 <.do_clear_bss_start>:
 100:	a1 30       	cpi	r26, 0x01	; 1
 102:	b2 07       	cpc	r27, r18
 104:	e1 f7       	brne	.-8      	; 0xfe <.do_clear_bss_loop>

00000106 <__do_global_ctors>:
 106:	10 e0       	ldi	r17, 0x00	; 0
 108:	c3 e7       	ldi	r28, 0x73	; 115
 10a:	d0 e0       	ldi	r29, 0x00	; 0
 10c:	00 e0       	ldi	r16, 0x00	; 0
 10e:	05 c0       	rjmp	.+10     	; 0x11a <__do_global_ctors+0x14>
 110:	21 97       	sbiw	r28, 0x01	; 1
 112:	01 09       	sbc	r16, r1
 114:	80 2f       	mov	r24, r16
 116:	fe 01       	movw	r30, r28
 118:	39 d0       	rcall	.+114    	; 0x18c <__tablejump2__>
 11a:	c2 37       	cpi	r28, 0x72	; 114
 11c:	d1 07       	cpc	r29, r17
 11e:	80 e0       	ldi	r24, 0x00	; 0
 120:	08 07       	cpc	r16, r24
 122:	b1 f7       	brne	.-20     	; 0x110 <__do_global_ctors+0xa>
 124:	03 d0       	rcall	.+6      	; 0x12c <main>
 126:	3a c0       	rjmp	.+116    	; 0x19c <_exit>

00000128 <__bad_interrupt>:
 128:	6b cf       	rjmp	.-298    	; 0x0 <__vectors>

0000012a <_ZN9TestClassC1Ev>:
 12a:	08 95       	ret

0000012c <main>:
 12c:	f8 94       	cli
 12e:	27 9a       	sbi	0x04, 7	; 4
 130:	89 e1       	ldi	r24, 0x19	; 25
 132:	90 e0       	ldi	r25, 0x00	; 0
 134:	90 93 c5 00 	sts	0x00C5, r25
 138:	80 93 c4 00 	sts	0x00C4, r24
 13c:	86 e0       	ldi	r24, 0x06	; 6
 13e:	80 93 c2 00 	sts	0x00C2, r24
 142:	88 e1       	ldi	r24, 0x18	; 24
 144:	80 93 c1 00 	sts	0x00C1, r24
 148:	78 94       	sei
 14a:	20 e9       	ldi	r18, 0x90	; 144
 14c:	9f e7       	ldi	r25, 0x7F	; 127
 14e:	80 91 c0 00 	lds	r24, 0x00C0
 152:	85 ff       	sbrs	r24, 5
 154:	fc cf       	rjmp	.-8      	; 0x14e <main+0x22>
 156:	20 93 c6 00 	sts	0x00C6, r18
 15a:	80 91 c0 00 	lds	r24, 0x00C0
 15e:	85 ff       	sbrs	r24, 5
 160:	fc cf       	rjmp	.-8      	; 0x15a <main+0x2e>
 162:	90 93 c6 00 	sts	0x00C6, r25
 166:	80 91 c0 00 	lds	r24, 0x00C0
 16a:	85 ff       	sbrs	r24, 5
 16c:	fc cf       	rjmp	.-8      	; 0x166 <main+0x3a>
 16e:	90 93 c6 00 	sts	0x00C6, r25
 172:	3f ef       	ldi	r19, 0xFF	; 255
 174:	43 ed       	ldi	r20, 0xD3	; 211
 176:	80 e3       	ldi	r24, 0x30	; 48
 178:	31 50       	subi	r19, 0x01	; 1
 17a:	40 40       	sbci	r20, 0x00	; 0
 17c:	80 40       	sbci	r24, 0x00	; 0
 17e:	e1 f7       	brne	.-8      	; 0x178 <main+0x4c>
 180:	00 c0       	rjmp	.+0      	; 0x182 <main+0x56>
 182:	00 00       	nop
 184:	e4 cf       	rjmp	.-56     	; 0x14e <main+0x22>

00000186 <_GLOBAL__sub_I_testing>:
 186:	80 e0       	ldi	r24, 0x00	; 0
 188:	92 e0       	ldi	r25, 0x02	; 2
 18a:	cf cf       	rjmp	.-98     	; 0x12a <_ZN9TestClassC1Ev>

0000018c <__tablejump2__>:
 18c:	ee 0f       	add	r30, r30
 18e:	ff 1f       	adc	r31, r31
 190:	88 1f       	adc	r24, r24
 192:	8b bf       	out	0x3b, r24	; 59
 194:	07 90       	elpm	r0, Z+
 196:	f6 91       	elpm	r31, Z
 198:	e0 2d       	mov	r30, r0
 19a:	19 94       	eijmp

0000019c <_exit>:
 19c:	f8 94       	cli

0000019e <__stop_program>:
 19e:	ff cf       	rjmp	.-2      	; 0x19e <__stop_program>

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:

Can you add a LED blink to your loop, just to be sure it's not executed?

 

Yeah, I've added that. Same thing. Program simply doesn't run once class instance is created.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Post the .lss file

...and they are now in #7.  Johan is a resident C++ advocate, and could probably suss out the situation with a long glance.  For me, it would take a lot longer.  Or a simulator session. ;)

 

For an amateur guess after a quick look,  the prologue has the do_global_ctors section which invokes tablejump2 which uses ELPM and EIJMP.  I wonder if RAMPZ is right for this tiny test program?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Dec 7, 2017 - 04:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The non-working LSS looks (on the surface) fine. When C++ c'tors are used it does this:

 108:	c3 e7       	ldi	r28, 0x73	; 115
 10a:	d0 e0       	ldi	r29, 0x00	; 0

and then subsequently this:

 110:	21 97       	sbiw	r28, 0x01	; 1
 112:	01 09       	sbc	r16, r1 

so that starts at 0x0072 and works "backwards" through a list of c'tor addresses. The 0x0072 this accesses then is:

000000e4 <__ctors_start>:
  e4:	c3 00       	.word	0x00c3	; ????

(0x72 * 2 = 0xE4) and that's a list of routines to be called. The first one is 0x00C3 and making a word to byte translation is means it will arrive at:

00000186 <_GLOBAL__sub_I_testing>:
 186:	80 e0       	ldi	r24, 0x00	; 0
 188:	92 e0       	ldi	r25, 0x02	; 2
 18a:	cf cf       	rjmp	.-98     	; 0x12a <_ZN9TestClassC1Ev>

which is the constructor for TestClass (it just does a "return (int)0" effectively) Rather curiously that ends with an RJMP to 0x12A but that's OK because it's just:

0000012a <_ZN9TestClassC1Ev>:
 12a:	08 95       	ret

So the only thing that might go wrong in all this is:

 118:	39 d0       	rcall	.+114    	; 0x18c <__tablejump2__>

and that is:

0000018c <__tablejump2__>:
 18c:	ee 0f       	add	r30, r30
 18e:	ff 1f       	adc	r31, r31
 190:	88 1f       	adc	r24, r24
 192:	8b bf       	out	0x3b, r24	; 59
 194:	07 90       	elpm	r0, Z+
 196:	f6 91       	elpm	r31, Z
 198:	e0 2d       	mov	r30, r0
 19a:	19 94       	eijmp

which is doing an indirect jump off the location Z enters with. As you will recall:

000000e4 <__ctors_start>:
  e4:	c3 00       	.word	0x00c3	; ????

So all that could really go wrong here would be if the ELPM was looking in the wrong place.

 

So is this code based at 0x0000 or is this something in a bootloader with a non 0 base?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So all that could really go wrong here would be if the ELPM was looking in the wrong place.

 

And that uses RAMPZ, right?  Indeed RAMPZ is at 0x3b.  R24 changed from word to byte address, right?  So what is R24 at entrance to this routine?  I can't really tell...

112:	01 09       	sbc	r16, r1
 114:	80 2f       	mov	r24, r16

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What the hell. I haven't mentioned that I'm uploading binary to target using avrdude/USBasp using this command:

 

avrdude -p m2560 -c usbasp -U flash:w:fw_mega.hex:i

Now the interesting part: The "non-working" binary WORKS if I upload it through Atmel Studio using AVRISPmkII. Huh?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I actually solved the issue by updating firmware on USBasp from here:

https://github.com/bperrybap/usb...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Make sure you're really using the correct hex file when programming using avrdude. (We've all done this mistake one time or another. I'm not  saying this  is definitively it, but it's a possibility that might be overlooked because of it's blatant obviousness..)

 

Cliff's already done a better analysis of the .lss than I could do in less than an hour or so.

 

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Shantea wrote:

... I haven't mentioned that I'm uploading binary to target using avrdude/USBasp using this command:

 

avrdude -p m2560 -c usbasp -U flash:w:fw_mega.hex:i

But the dumps you showed were from fw_mega.elf

 

I don't know how the pieces interact between the different ISP tools (hardware and program), and the .elf representation to the .hex

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An avr-gcc/g++ toolchain normally produces the hex from the ELF.

 

Avrdude uses the hex (as hass been showed above).

 

Atmel Studio normally uses the ELF directly to program the AVR.

 

My bets are still on the hex not being the correct one, matching (derived from) the working ELF, and that while upgrading the  USBasp firmware the hex wass also rebuilt without the OP realizing he did that. Thus it seemed that the firmware upgrade did the trick, but.. All just a hypothesis, that will be hard (and somewhat meaningless) to test now.

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Shantea wrote:

... I haven't mentioned that I'm uploading binary to target using avrdude/USBasp using this command:

 

avrdude -p m2560 -c usbasp -U flash:w:fw_mega.hex:i

But the dumps you showed were from fw_mega.elf

 

I don't know how the pieces interact between the different ISP tools (hardware and program), and the .elf representation to the .hex

 

It was the same thing either with .elf or .hex (didn't work). Updated firmware solved it. Really weird, I've never run into this before.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@JohanEkdahl:

 

After compiling, I got two files: .hex and .elf. Neither worked when uploading it via USBasp. Those *same* files both worked fine when uploaded using Atmel Studio (note: just uploaded, not compiled). Updating firmware on USBasp solved the problem - now I can upload those *same* files (that is, .hex using avrdude). Note how the files haven't been changed.

Last Edited: Thu. Dec 7, 2017 - 07:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

What's the point of SEI enabling interrupts without ISR implementation?
 

avrfreaks does not support Opera. Profile inactive.