"for" loops not working with array

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

writing a simple for loop test...

 

attiny1614 (new tinyavr1 series)

toolchain = avr8-gnu-toolchain-3.6.2.1759-linux_x86_64 

 

compile options tried... (with -Os)

OPT='-D__AVR_ATtiny1614__ -D__AVR_DEVICE_NAME__=attiny1614 -D__AVR_DEV_LIB_NAME__=tn1614 -DF_CPU=12000000UL -Wall -Wno-volatile-register-var -gdwarf-2 -std=gnu99 -ffreestanding -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -finline-limit=3 -fno-inline-small-functions  -ffunction-sections  -fdata-sections  -mcall-prologues -flto'

OPT='-D__AVR_ATtiny1614__ -D__AVR_DEVICE_NAME__=attiny1614 -D__AVR_DEV_LIB_NAME__=tn1614 -DF_CPU=12000000UL -Wall -gdwarf-2 -std=gnu99 -ffreestanding -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums'

 

This is my code...

 

	while(1)
	{
		wdt_reset();

		//test function
		U8 ary1[] = {0x01,0x02,0x03,0x04,0x05}; //5 bytes

		glcd_clear();
		glcd_pos_chr(0,0);
		gui_Hex(ary1[0]);
		gui_Hex(ary1[1]);
		gui_Hex(ary1[2]);
		gui_Hex(ary1[3]);
		gui_Hex(ary1[4]);

		//loop not working
		glcd_pos_chr(1,0);
		for(U8 i=0; i<5; i++)
		{
			U8 x = ary1[i];
			gui_Hex(x); glcd_num(i,0); glcd_char(' ');
		}

		//loop not working
		glcd_pos_chr(2,0);
		for(U8 i=0; i<5; i++)
		{
			U8 x = ary1[i];
			glcd_num(x,0); glcd_char(' ');
		}

		_delay_ms(3000);
		wdt_reset();
	}

The loops dont work, they output 0xFF, here is the assembly...

	while(1)
	{
		wdt_reset();
 92e:	a8 95       	wdr

		//test function
		U8 ary1[] = {0x01,0x02,0x03,0x04,0x05}; //5 bytes
 930:	85 e0       	ldi	r24, 0x05	; 5
 932:	e2 e3       	ldi	r30, 0x32	; 50
 934:	fa e8       	ldi	r31, 0x8A	; 138
 936:	de 01       	movw	r26, r28
 938:	11 96       	adiw	r26, 0x01	; 1
 93a:	01 90       	ld	r0, Z+
 93c:	0d 92       	st	X+, r0
 93e:	8a 95       	dec	r24
 940:	e1 f7       	brne	.-8      	; 0x93a <main+0xaa>

		glcd_clear();
 942:	0e 94 3e 04 	call	0x87c	; 0x87c <glcd_clear>
		glcd_pos_chr(0,0);
 946:	60 e0       	ldi	r22, 0x00	; 0
 948:	80 e0       	ldi	r24, 0x00	; 0
 94a:	0e 94 09 04 	call	0x812	; 0x812 <glcd_pos>
		gui_Hex(ary1[0]);
 94e:	81 e0       	ldi	r24, 0x01	; 1
 950:	0e 94 bd 01 	call	0x37a	; 0x37a <gui_Hex>
		gui_Hex(ary1[1]);
 954:	82 e0       	ldi	r24, 0x02	; 2
 956:	0e 94 bd 01 	call	0x37a	; 0x37a <gui_Hex>
		gui_Hex(ary1[2]);
 95a:	83 e0       	ldi	r24, 0x03	; 3
 95c:	0e 94 bd 01 	call	0x37a	; 0x37a <gui_Hex>
		gui_Hex(ary1[3]);
 960:	84 e0       	ldi	r24, 0x04	; 4
 962:	0e 94 bd 01 	call	0x37a	; 0x37a <gui_Hex>
		gui_Hex(ary1[4]);
 966:	85 e0       	ldi	r24, 0x05	; 5
 968:	0e 94 bd 01 	call	0x37a	; 0x37a <gui_Hex>

		//loop not working
		glcd_pos_chr(1,0);
 96c:	60 e0       	ldi	r22, 0x00	; 0
 96e:	81 e0       	ldi	r24, 0x01	; 1
 970:	0e 94 09 04 	call	0x812	; 0x812 <glcd_pos>
 974:	8e 01       	movw	r16, r28
 976:	0f 5f       	subi	r16, 0xFF	; 255
 978:	1f 4f       	sbci	r17, 0xFF	; 255
 97a:	78 01       	movw	r14, r16
 97c:	41 2c       	mov	r4, r1
 97e:	51 2c       	mov	r5, r1
 980:	32 01       	movw	r6, r4
		for(U8 i=0; i<5; i++)
		{
			U8 x = ary1[i];
			gui_Hex(x); glcd_num(i,0); glcd_char(' ');
 982:	f7 01       	movw	r30, r14
 984:	81 91       	ld	r24, Z+
 986:	7f 01       	movw	r14, r30
 988:	0e 94 bd 01 	call	0x37a	; 0x37a <gui_Hex>
 98c:	40 e0       	ldi	r20, 0x00	; 0
 98e:	c3 01       	movw	r24, r6
 990:	b2 01       	movw	r22, r4
 992:	0e 94 af 02 	call	0x55e	; 0x55e <glcd_num>
 996:	80 e2       	ldi	r24, 0x20	; 32
 998:	0e 94 72 02 	call	0x4e4	; 0x4e4 <glcd_char>
 99c:	ff ef       	ldi	r31, 0xFF	; 255
 99e:	4f 1a       	sub	r4, r31
 9a0:	5f 0a       	sbc	r5, r31
 9a2:	6f 0a       	sbc	r6, r31
 9a4:	7f 0a       	sbc	r7, r31
		gui_Hex(ary1[3]);
		gui_Hex(ary1[4]);

		//loop not working
		glcd_pos_chr(1,0);
		for(U8 i=0; i<5; i++)
 9a6:	85 e0       	ldi	r24, 0x05	; 5
 9a8:	48 16       	cp	r4, r24
 9aa:	51 04       	cpc	r5, r1
 9ac:	61 04       	cpc	r6, r1
 9ae:	71 04       	cpc	r7, r1
 9b0:	41 f7       	brne	.-48     	; 0x982 <main+0xf2>
			U8 x = ary1[i];
			gui_Hex(x); glcd_num(i,0); glcd_char(' ');
		}

		//loop not working
		glcd_pos_chr(2,0);
 9b2:	60 e0       	ldi	r22, 0x00	; 0
 9b4:	82 e0       	ldi	r24, 0x02	; 2
 9b6:	0e 94 09 04 	call	0x812	; 0x812 <glcd_pos>
		for(U8 i=0; i<5; i++)
		{
			U8 x = ary1[i];
 9ba:	f8 01       	movw	r30, r16
 9bc:	61 91       	ld	r22, Z+
 9be:	8f 01       	movw	r16, r30
			glcd_num(x,0); glcd_char(' ');
 9c0:	70 e0       	ldi	r23, 0x00	; 0
 9c2:	80 e0       	ldi	r24, 0x00	; 0
 9c4:	90 e0       	ldi	r25, 0x00	; 0
 9c6:	40 e0       	ldi	r20, 0x00	; 0
 9c8:	0e 94 af 02 	call	0x55e	; 0x55e <glcd_num>
 9cc:	80 e2       	ldi	r24, 0x20	; 32
 9ce:	0e 94 72 02 	call	0x4e4	; 0x4e4 <glcd_char>
			gui_Hex(x); glcd_num(i,0); glcd_char(' ');
		}

		//loop not working
		glcd_pos_chr(2,0);
		for(U8 i=0; i<5; i++)
 9d2:	c0 16       	cp	r12, r16
 9d4:	d1 06       	cpc	r13, r17
 9d6:	89 f7       	brne	.-30     	; 0x9ba <main+0x12a>
 9d8:	80 e3       	ldi	r24, 0x30	; 48
 9da:	95 e7       	ldi	r25, 0x75	; 117
 9dc:	f5 01       	movw	r30, r10
 9de:	31 97       	sbiw	r30, 0x01	; 1
 9e0:	f1 f7       	brne	.-4      	; 0x9de <main+0x14e>
 9e2:	01 97       	sbiw	r24, 0x01	; 1
 9e4:	d9 f7       	brne	.-10     	; 0x9dc <main+0x14c>
			U8 x = ary1[i];
			glcd_num(x,0); glcd_char(' ');
		}

		_delay_ms(3000);
		wdt_reset();
 9e6:	a8 95       	wdr

	}

output when I directly index is 01 02 03 04 05 ... example gui_Hex(ary1[0]); 

but the array loops output... FF FF FF FF FF ... example for(U8 i=0; i<5; i++){ gui_Hex(ary1[i]); } //U8 is defined as uint8_t

any suggestions as to what is going on would be appreciated.

This topic has a solution.
Last Edited: Mon. Dec 3, 2018 - 04:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well the below code works... but what the heck, why should I have to use pgm_read_byte, I know for sure I am not out of memory using a 5 bytes array, the above post is valid C code.

This is a problem because I want to be able to pass the array around and modify it in functions, I cannot modify PROGMEM, but that seems to be the only way it works.

 

	//test xmt an rcv
	while(1)
	{
		wdt_reset();

		//https://www.avrfreaks.net/forum/local-array-problem
		//test function
		static const U8 ary1[] PROGMEM = {0x01,0x02,0x03,0x04,0x05}; //5 bytes

		glcd_clear();

		//works
		glcd_pos_chr(0,0);
		const U8* p = ary1;
		gui_Hex( pgm_read_byte(p) ); p++;
		gui_Hex( pgm_read_byte(p) ); p++;
		gui_Hex( pgm_read_byte(p) ); p++;
		gui_Hex( pgm_read_byte(p) ); p++;
		gui_Hex( pgm_read_byte(p) );

		//works, BUT ONLY IF ARRAY IS PROGMEM !!!
		p = ary1;
		glcd_pos_chr(1,0);
		for(U8 i=0; i<5; i++)
		{
			U8 x = pgm_read_byte(p); p++;
			gui_Hex(x); glcd_num(i,0); glcd_char(' ');
		}

		_delay_ms(3000);
		wdt_reset();
	}

 

Last Edited: Mon. Dec 3, 2018 - 03:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No idea of what I'm talking about but here it goes:

	U8 ary1[] = {0x01,0x02,0x03,0x04,0x05}; //5 bytes
 930:	85 e0       	ldi	r24, 0x05	; 5
 932:	e2 e3       	ldi	r30, 0x32	; 50
 934:	fa e8       	ldi	r31, 0x8A	; 138
 936:	de 01       	movw	r26, r28
 938:	11 96       	adiw	r26, 0x01	; 1
 93a:	01 90       	ld	r0, Z+            ***********this should be lpm
 93c:	0d 92       	st	X+, r0
 93e:	8a 95       	dec	r24
 940:	e1 f7       	brne	.-8      	; 0x93a <main+0xaa>

somehow the data is not being copied to ram correctly as it should use lpm (above) to read the data from flash and put it into ram at start up in a NORMAL AVR.

 

Maybe there is some magical incantation that you need to use in order to make the flash visible in the linear map and so it can use ld but I haven't played with the new AVRs long enough to know.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

if I do "volatile U8 ary1" everything including direct index of the variable results in 0xFF everytime...

if I do "U8 ary1" only inside of loops with the array results in 0xFF everytime...

If I do "static volatile U8 ary1" or PROGMEM... it works correctly

so it seems the only way to be able to modify the array is to use "static volatile" ... that is the magic that makes it work as expect, but that does not play nice with string functions that do not want volatile passed in...

static volatile not required on atmega or normal attiny series, this is happening on tinyavr1 series 1614 chip.

 

	//test xmt an rcv
	while(1)
	{
		wdt_reset();

		//test function
		static volatile U8 ary1[5] = {0x01,0x02,0x03,0x04,0x05}; //5 bytes (just volatile, everything was FF)

		//works
		glcd_clear();
		glcd_pos_chr(0,0);
		gui_Hex(ary1[0]);
		gui_Hex(ary1[1]);
		gui_Hex(ary1[2]);
		gui_Hex(ary1[3]);
		gui_Hex(ary1[4]);

		//loop not working
		glcd_pos_chr(1,0);
		for(U8 i=0; i<5; i++)
		{
			U8 x = ary1[i];
			gui_Hex(x); glcd_num(i,0); glcd_char(' ');
		}

		//loop not working
		glcd_pos_chr(2,0);
		for(U8 i=0; i<5; i++)
		{
			U8 x = ary1[i];
			glcd_num(x,0); glcd_char(' ');
		}

		_delay_ms(3000);
		wdt_reset();
	}

 

Last Edited: Mon. Dec 3, 2018 - 06:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you do the direct array addressing the access of ary1 gets optimized out and the values are loaded directly.  That explains why it fails when you add 'volatile', since now you're forcing an array access.

 

What happens if you add this before accessing the array in the for loop?

 

for (u8 i = 0; i < 5; i++)
{
    ary1[i] = i+1;
}

I bet it works then.  If so, your array is not getting initialized correctly.  The array data is getting copied from RAM to RAM (the loop at 0x93A), so you need to find out if during startup the data is getting copied from FLASH to that hidden RAM array (pointed to by Z).  Your program listing should show that happening, and where the hidden RAM array is located, and if Z points to that same location at the declaration of ary1, as it must to work correctly.

Last Edited: Mon. Dec 3, 2018 - 04:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

... so you need to find out if during startup the data is getting copied from FLASH to that hidden RAM array (pointed to by Z) ...

I checked and don't think it is

 

I also just took a working simple program that compiles on atmega, and attiny's, tried it on the new tinyavr1614, and it does not work... compiled using same toolchain avr8-gnu-toolchain-3.6.2.1759-linux_x86_64 

simple stuff like...   char str[9];   itoa(num,str,10);   ....  I cant get to work...

 

I just made a really simple test program, dumps bytes over uart. connected to my logic analyzer and the loop still only xmt's 0xFF instead of the correct data

 

entire sample program that exhibits the issue is below...

#include <inttypes.h>
#include <avr/io.h>
#include <avr/sleep.h>
#include <util/delay.h>        //_delay_ms() or _delay_us()

#define U8 uint8_t
#define xmt_wait() while(!(USART0_STATUS & USART_DREIF_bm))
#define xmt(val)   xmt_wait(); USART0_TXDATAL=val

void xmt_data(U8 data)
{
    xmt(data);
}

inline void uart_init()
{
    //setup USART [BPS:9600,BITS:8,PARITY:NONE,STOPBITS:1,FLOWCTRL:XON/XOFF]
    
    //setup ports
    PORTB.DIRCLR = PIN3_bm; //Sets the PB3 RX port as an input.
    //PORTB.PIN3CTRL |= PORT_PULLUPEN_bm; //turn on PB3 pullup (we use external 10K pullup)
    PORTB.DIRSET = PIN2_bm; //Sets the PB2 TX port as an output.
    
    //set baud ... Async Normal Mode BAUD_VALUE = F_CPU/(DESIRED_BAUD*16))*64;
    #define ASYNC_NORMAL_MODE_BAUD(baud)    ((U16)(((double)F_CPU) / (((double)baud)*16.0) * 64.0))
    USART0_BAUD = 5000; //is 9600 baud
    
    //set mode of operation (BITS:8,PARITY:NONE,STOPBITS:1)
    #define ASYNCHRONOUS 0x00
    #define PARITY_NONE  0x00
    #define DATA_BITS_8  0x03
    USART0_CTRLC = (ASYNCHRONOUS << USART_CMODE_gp) | (PARITY_NONE << USART_PMODE_gp) | (DATA_BITS_8 << USART_CHSIZE_gp);
    
    //enable interrupt for receive
    //USART0_CTRLA = USART_RXCIE_bm;
    
    //enable transmitter and receiver, normal uart mode
    USART0_CTRLB = USART_RXEN_bm | USART_TXEN_bm;    
}

void main(void) __attribute__((noreturn));  
void main(void)
{
    //select external 12MHz clk
    CPU_CCP           = 0xD8; //pg57 allow writing to protected registers
    CLKCTRL_MCLKCTRLA = 0x03; //pg85 select external lock
    CPU_CCP           = 0xD8; //pg57 allow writing to protected registers
    CLKCTRL_MCLKCTRLB = 0x00; //pg86 no prescaler
    while(CLKCTRL_MCLKSTATUS & CLKCTRL_SOSC_bm); //pg88 wait for clock switch to complete    
        
    //init uart
    uart_init();
    
    while(1)
    {
        //test function
        U8 ary1[] = {11,22,33,44,55}; //5 bytes
        
        //direct index
        xmt_data(ary1[0]);
        xmt_data(ary1[1]);
        xmt_data(ary1[2]);
        xmt_data(ary1[3]);
        xmt_data(ary1[4]);
        
        //loop not working
        for(U8 i=0; i<5; i++)
        {
            U8 x = ary1[i];
            xmt_data(x);
        }
    }
}

Here is the assembly for it....


main.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000000  00803800  00000175  00000209  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         00000170  00000000  00000000  00000094  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .rodata       00000005  00008170  00000170  00000204  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .comment      00000030  00000000  00000000  00000209  2**0
                  CONTENTS, READONLY
  4 .note.gnu.avr.deviceinfo 00000040  00000000  00000000  0000023c  2**2
                  CONTENTS, READONLY
  5 .debug_aranges 00000028  00000000  00000000  0000027c  2**0
                  CONTENTS, READONLY, DEBUGGING
  6 .debug_info   00001b55  00000000  00000000  000002a4  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_abbrev 00001990  00000000  00000000  00001df9  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_line   000002be  00000000  00000000  00003789  2**0
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_frame  00000044  00000000  00000000  00003a48  2**2
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_str    00000be1  00000000  00000000  00003a8c  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_loc    00000054  00000000  00000000  0000466d  2**0
                  CONTENTS, READONLY, DEBUGGING
 12 .debug_ranges 00000018  00000000  00000000  000046c1  2**0
                  CONTENTS, READONLY, DEBUGGING

Disassembly of section .text:

00000000 <__vectors>:
   0:    0c 94 3e 00     jmp    0x7c    ; 0x7c <__ctors_end>
   4:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
   8:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
   c:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  10:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  14:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  18:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  1c:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  20:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  24:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  28:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  2c:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  30:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  34:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  38:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  3c:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  40:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  44:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  48:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  4c:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  50:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  54:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  58:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  5c:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  60:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  64:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  68:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  6c:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  70:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  74:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>
  78:    0c 94 48 00     jmp    0x90    ; 0x90 <__bad_interrupt>

0000007c <__ctors_end>:
  7c:    11 24           eor    r1, r1
  7e:    1f be           out    0x3f, r1    ; 63
  80:    cf ef           ldi    r28, 0xFF    ; 255
  82:    cd bf           out    0x3d, r28    ; 61
  84:    df e3           ldi    r29, 0x3F    ; 63
  86:    de bf           out    0x3e, r29    ; 62
  88:    0e 94 51 00     call    0xa2    ; 0xa2 <main>
  8c:    0c 94 b6 00     jmp    0x16c    ; 0x16c <_exit>

00000090 <__bad_interrupt>:
  90:    0c 94 00 00     jmp    0    ; 0x0 <__vectors>

00000094 <xmt_data>:
#define xmt_wait() while(!(USART0_STATUS & USART_DREIF_bm))
#define xmt(val)   xmt_wait(); USART0_TXDATAL=val

void xmt_data(U8 data)
{
    xmt(data);
  94:    90 91 04 08     lds    r25, 0x0804    ; 0x800804 <__TEXT_REGION_LENGTH__+0x700804>
  98:    95 ff           sbrs    r25, 5
  9a:    fc cf           rjmp    .-8          ; 0x94 <xmt_data>
  9c:    80 93 02 08     sts    0x0802, r24    ; 0x800802 <__TEXT_REGION_LENGTH__+0x700802>
  a0:    08 95           ret

000000a2 <main>:
    USART0_CTRLB = USART_RXEN_bm | USART_TXEN_bm;    
}

void main(void) __attribute__((noreturn));  
void main(void)
{
  a2:    a5 e0           ldi    r26, 0x05    ; 5
  a4:    b0 e0           ldi    r27, 0x00    ; 0
  a6:    e7 e5           ldi    r30, 0x57    ; 87
  a8:    f0 e0           ldi    r31, 0x00    ; 0
  aa:    0c 94 a9 00     jmp    0x152    ; 0x152 <__prologue_saves__+0x18>
    //select external 12MHz clk
    CPU_CCP           = 0xD8; //pg57 allow writing to protected registers
  ae:    88 ed           ldi    r24, 0xD8    ; 216
  b0:    84 bf           out    0x34, r24    ; 52
    CLKCTRL_MCLKCTRLA = 0x03; //pg85 select external lock
  b2:    93 e0           ldi    r25, 0x03    ; 3
  b4:    90 93 60 00     sts    0x0060, r25    ; 0x800060 <__TEXT_REGION_LENGTH__+0x700060>
    CPU_CCP           = 0xD8; //pg57 allow writing to protected registers
  b8:    84 bf           out    0x34, r24    ; 52
    CLKCTRL_MCLKCTRLB = 0x00; //pg86 no prescaler
  ba:    10 92 61 00     sts    0x0061, r1    ; 0x800061 <__TEXT_REGION_LENGTH__+0x700061>
    while(CLKCTRL_MCLKSTATUS & CLKCTRL_SOSC_bm); //pg88 wait for clock switch to complete    
  be:    80 91 63 00     lds    r24, 0x0063    ; 0x800063 <__TEXT_REGION_LENGTH__+0x700063>
  c2:    80 fd           sbrc    r24, 0
  c4:    fc cf           rjmp    .-8          ; 0xbe <main+0x1c>
inline void uart_init()
{
    //setup USART [BPS:9600,BITS:8,PARITY:NONE,STOPBITS:1,FLOWCTRL:XON/XOFF]
    
    //setup ports
    PORTB.DIRCLR = PIN3_bm; //Sets the PB3 RX port as an input.
  c6:    88 e0           ldi    r24, 0x08    ; 8
  c8:    80 93 22 04     sts    0x0422, r24    ; 0x800422 <__TEXT_REGION_LENGTH__+0x700422>
    //PORTB.PIN3CTRL |= PORT_PULLUPEN_bm; //turn on PB3 pullup (we use external 10K pullup)
    PORTB.DIRSET = PIN2_bm; //Sets the PB2 TX port as an output.
  cc:    84 e0           ldi    r24, 0x04    ; 4
  ce:    80 93 21 04     sts    0x0421, r24    ; 0x800421 <__TEXT_REGION_LENGTH__+0x700421>
    
    //set baud ... Async Normal Mode BAUD_VALUE = F_CPU/(DESIRED_BAUD*16))*64;
    #define ASYNC_NORMAL_MODE_BAUD(baud)    ((U16)(((double)F_CPU) / (((double)baud)*16.0) * 64.0))
    USART0_BAUD = 5000; //is 9600 baud
  d2:    88 e8           ldi    r24, 0x88    ; 136
  d4:    93 e1           ldi    r25, 0x13    ; 19
  d6:    80 93 08 08     sts    0x0808, r24    ; 0x800808 <__TEXT_REGION_LENGTH__+0x700808>
  da:    90 93 09 08     sts    0x0809, r25    ; 0x800809 <__TEXT_REGION_LENGTH__+0x700809>
    
    //set mode of operation (BITS:8,PARITY:NONE,STOPBITS:1)
    #define ASYNCHRONOUS 0x00
    #define PARITY_NONE  0x00
    #define DATA_BITS_8  0x03
    USART0_CTRLC = (ASYNCHRONOUS << USART_CMODE_gp) | (PARITY_NONE << USART_PMODE_gp) | (DATA_BITS_8 << USART_CHSIZE_gp);
  de:    83 e0           ldi    r24, 0x03    ; 3
  e0:    80 93 07 08     sts    0x0807, r24    ; 0x800807 <__TEXT_REGION_LENGTH__+0x700807>
    
    //enable interrupt for receive
    //USART0_CTRLA = USART_RXCIE_bm;
    
    //enable transmitter and receiver, normal uart mode
    USART0_CTRLB = USART_RXEN_bm | USART_TXEN_bm;    
  e4:    80 ec           ldi    r24, 0xC0    ; 192
  e6:    80 93 06 08     sts    0x0806, r24    ; 0x800806 <__TEXT_REGION_LENGTH__+0x700806>
  ea:    7e 01           movw    r14, r28
  ec:    86 e0           ldi    r24, 0x06    ; 6
  ee:    e8 0e           add    r14, r24
  f0:    f1 1c           adc    r15, r1
    uart_init();
    
    while(1)
    {
        //test function
        U8 ary1[] = {11,22,33,44,55}; //5 bytes
  f2:    85 e0           ldi    r24, 0x05    ; 5
  f4:    e0 e7           ldi    r30, 0x70    ; 112
  f6:    f1 e8           ldi    r31, 0x81    ; 129
  f8:    de 01           movw    r26, r28
  fa:    11 96           adiw    r26, 0x01    ; 1
  fc:    01 90           ld    r0, Z+
  fe:    0d 92           st    X+, r0
 100:    8a 95           dec    r24
 102:    e1 f7           brne    .-8          ; 0xfc <main+0x5a>
        
        //direct index
        xmt_data(ary1[0]);
 104:    8b e0           ldi    r24, 0x0B    ; 11
 106:    0e 94 4a 00     call    0x94    ; 0x94 <xmt_data>
        xmt_data(ary1[1]);
 10a:    86 e1           ldi    r24, 0x16    ; 22
 10c:    0e 94 4a 00     call    0x94    ; 0x94 <xmt_data>
        xmt_data(ary1[2]);
 110:    81 e2           ldi    r24, 0x21    ; 33
 112:    0e 94 4a 00     call    0x94    ; 0x94 <xmt_data>
        xmt_data(ary1[3]);
 116:    8c e2           ldi    r24, 0x2C    ; 44
 118:    0e 94 4a 00     call    0x94    ; 0x94 <xmt_data>
        xmt_data(ary1[4]);
 11c:    87 e3           ldi    r24, 0x37    ; 55
 11e:    0e 94 4a 00     call    0x94    ; 0x94 <xmt_data>
 122:    8e 01           movw    r16, r28
 124:    0f 5f           subi    r16, 0xFF    ; 255
 126:    1f 4f           sbci    r17, 0xFF    ; 255
        
        //loop not working
        for(U8 i=0; i<5; i++)
        {
            U8 x = ary1[i];
            xmt_data(x);
 128:    f8 01           movw    r30, r16
 12a:    81 91           ld    r24, Z+
 12c:    8f 01           movw    r16, r30
 12e:    0e 94 4a 00     call    0x94    ; 0x94 <xmt_data>
        xmt_data(ary1[2]);
        xmt_data(ary1[3]);
        xmt_data(ary1[4]);
        
        //loop not working
        for(U8 i=0; i<5; i++)
 132:    0e 15           cp    r16, r14
 134:    1f 05           cpc    r17, r15
 136:    c1 f7           brne    .-16         ; 0x128 <main+0x86>
 138:    dc cf           rjmp    .-72         ; 0xf2 <main+0x50>

0000013a <__prologue_saves__>:
 13a:    2f 92           push    r2
 13c:    3f 92           push    r3
 13e:    4f 92           push    r4
 140:    5f 92           push    r5
 142:    6f 92           push    r6
 144:    7f 92           push    r7
 146:    8f 92           push    r8
 148:    9f 92           push    r9
 14a:    af 92           push    r10
 14c:    bf 92           push    r11
 14e:    cf 92           push    r12
 150:    df 92           push    r13
 152:    ef 92           push    r14
 154:    ff 92           push    r15
 156:    0f 93           push    r16
 158:    1f 93           push    r17
 15a:    cf 93           push    r28
 15c:    df 93           push    r29
 15e:    cd b7           in    r28, 0x3d    ; 61
 160:    de b7           in    r29, 0x3e    ; 62
 162:    ca 1b           sub    r28, r26
 164:    db 0b           sbc    r29, r27
 166:    cd bf           out    0x3d, r28    ; 61
 168:    de bf           out    0x3e, r29    ; 62
 16a:    09 94           ijmp

0000016c <_exit>:
 16c:    f8 94           cli

0000016e <__stop_program>:
 16e:    ff cf           rjmp    .-2          ; 0x16e <__stop_program>

 

Last Edited: Mon. Dec 3, 2018 - 05:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and the exact same code, same toolchain, works fine for the attiny841

 

#include <inttypes.h>
#include <avr/io.h>
#include <avr/sleep.h>
#include <util/delay.h>		//_delay_ms() or _delay_us()

#define U8 uint8_t
#define BIT(x)      (0x01 << (x))

#ifdef __AVR_ATtiny1614__
	#define xmt_wait() while(!(USART0_STATUS & USART_DREIF_bm))
	#define xmt(val)   xmt_wait(); USART0_TXDATAL=val
#else
	#define xmt_wait() while(!(UCSR0A & BIT(UDRE0)))
	#define xmt(val)   xmt_wait(); UDR0=val
#endif

void xmt_data(U8 data)
{
	xmt(data);
}

inline void uart_init()
{
	#ifdef __AVR_ATtiny1614__
		//setup USART [BPS:9600,BITS:8,PARITY:NONE,STOPBITS:1,FLOWCTRL:XON/XOFF]

		//setup ports
		PORTB.DIRCLR = PIN3_bm; //Sets the PB3 RX port as an input.
		//PORTB.PIN3CTRL |= PORT_PULLUPEN_bm; //turn on PB3 pullup (we use external 10K pullup)
		PORTB.DIRSET = PIN2_bm; //Sets the PB2 TX port as an output.

		//set baud ... Async Normal Mode BAUD_VALUE = F_CPU/(DESIRED_BAUD*16))*64;
		#define ASYNC_NORMAL_MODE_BAUD(baud)    ((U16)(((double)F_CPU) / (((double)baud)*16.0) * 64.0))
		USART0_BAUD = 5000; //is 9600 baud

		//set mode of operation (BITS:8,PARITY:NONE,STOPBITS:1)
		#define ASYNCHRONOUS 0x00
		#define PARITY_NONE  0x00
		#define DATA_BITS_8  0x03
		USART0_CTRLC = (ASYNCHRONOUS << USART_CMODE_gp) | (PARITY_NONE << USART_PMODE_gp) | (DATA_BITS_8 << USART_CHSIZE_gp);

		//enable interrupt for receive
		//USART0_CTRLA = USART_RXCIE_bm;

		//enable transmitter and receiver, normal uart mode
		USART0_CTRLB = USART_RXEN_bm | USART_TXEN_bm;
	#else

		UCSR0B = BIT(RXCIE0)|BIT(RXEN0)|BIT(TXEN0);//RX ISR en, RX en, TX en
		UCSR0C = BIT(UCSZ01)|BIT(UCSZ00);//Async, NoParity, 8DataBits, 1StopBit
		UBRR0H = 0;  //high byte must be written before low (pg138)
		UBRR0L = 77; //9600 bps @ 12MHz, 0.2% accuracy, U2Xn = 0
	#endif
}

void main(void) __attribute__((noreturn));
void main(void)
{
	#ifdef __AVR_ATtiny1614__
		//select external 12MHz clk
		CPU_CCP           = 0xD8; //pg57 allow writing to protected registers
		CLKCTRL_MCLKCTRLA = 0x03; //pg85 select external lock
		CPU_CCP           = 0xD8; //pg57 allow writing to protected registers
		CLKCTRL_MCLKCTRLB = 0x00; //pg86 no prescaler
		while(CLKCTRL_MCLKSTATUS & CLKCTRL_SOSC_bm); //pg88 wait for clock switch to complete
	#else
	//fuse set for external 12MHz XTL
	#endif	

	//init uart
	uart_init();

	while(1)
	{
		//test function
		U8 ary1[] = {11,22,33,44,55}; //5 bytes

		//direct index
		xmt_data(ary1[0]);
		xmt_data(ary1[1]);
		xmt_data(ary1[2]);
		xmt_data(ary1[3]);
		xmt_data(ary1[4]);

		//loop not working
		for(U8 i=0; i<5; i++)
		{
			U8 x = ary1[i];
			xmt_data(x);
		}
	}
}

assembly for tiny841


main.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000006  00800100  00000112  00000186  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         00000112  00000000  00000000  00000074  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .comment      00000030  00000000  00000000  0000018c  2**0
                  CONTENTS, READONLY
  3 .note.gnu.avr.deviceinfo 0000003c  00000000  00000000  000001bc  2**2
                  CONTENTS, READONLY
  4 .debug_aranges 00000028  00000000  00000000  000001f8  2**0
                  CONTENTS, READONLY, DEBUGGING
  5 .debug_info   000008bd  00000000  00000000  00000220  2**0
                  CONTENTS, READONLY, DEBUGGING
  6 .debug_abbrev 000007fe  00000000  00000000  00000add  2**0
                  CONTENTS, READONLY, DEBUGGING
  7 .debug_line   00000295  00000000  00000000  000012db  2**0
                  CONTENTS, READONLY, DEBUGGING
  8 .debug_frame  00000044  00000000  00000000  00001570  2**2
                  CONTENTS, READONLY, DEBUGGING
  9 .debug_str    000003a2  00000000  00000000  000015b4  2**0
                  CONTENTS, READONLY, DEBUGGING
 10 .debug_loc    00000054  00000000  00000000  00001956  2**0
                  CONTENTS, READONLY, DEBUGGING
 11 .debug_ranges 00000018  00000000  00000000  000019aa  2**0
                  CONTENTS, READONLY, DEBUGGING

Disassembly of section .text:

00000000 <__vectors>:
   0:	1d c0       	rjmp	.+58     	; 0x3c <__ctors_end>
   2:	2f c0       	rjmp	.+94     	; 0x62 <__bad_interrupt>
   4:	2e c0       	rjmp	.+92     	; 0x62 <__bad_interrupt>
   6:	2d c0       	rjmp	.+90     	; 0x62 <__bad_interrupt>
   8:	2c c0       	rjmp	.+88     	; 0x62 <__bad_interrupt>
   a:	2b c0       	rjmp	.+86     	; 0x62 <__bad_interrupt>
   c:	2a c0       	rjmp	.+84     	; 0x62 <__bad_interrupt>
   e:	29 c0       	rjmp	.+82     	; 0x62 <__bad_interrupt>
  10:	28 c0       	rjmp	.+80     	; 0x62 <__bad_interrupt>
  12:	27 c0       	rjmp	.+78     	; 0x62 <__bad_interrupt>
  14:	26 c0       	rjmp	.+76     	; 0x62 <__bad_interrupt>
  16:	25 c0       	rjmp	.+74     	; 0x62 <__bad_interrupt>
  18:	24 c0       	rjmp	.+72     	; 0x62 <__bad_interrupt>
  1a:	23 c0       	rjmp	.+70     	; 0x62 <__bad_interrupt>
  1c:	22 c0       	rjmp	.+68     	; 0x62 <__bad_interrupt>
  1e:	21 c0       	rjmp	.+66     	; 0x62 <__bad_interrupt>
  20:	20 c0       	rjmp	.+64     	; 0x62 <__bad_interrupt>
  22:	1f c0       	rjmp	.+62     	; 0x62 <__bad_interrupt>
  24:	1e c0       	rjmp	.+60     	; 0x62 <__bad_interrupt>
  26:	1d c0       	rjmp	.+58     	; 0x62 <__bad_interrupt>
  28:	1c c0       	rjmp	.+56     	; 0x62 <__bad_interrupt>
  2a:	1b c0       	rjmp	.+54     	; 0x62 <__bad_interrupt>
  2c:	1a c0       	rjmp	.+52     	; 0x62 <__bad_interrupt>
  2e:	19 c0       	rjmp	.+50     	; 0x62 <__bad_interrupt>
  30:	18 c0       	rjmp	.+48     	; 0x62 <__bad_interrupt>
  32:	17 c0       	rjmp	.+46     	; 0x62 <__bad_interrupt>
  34:	16 c0       	rjmp	.+44     	; 0x62 <__bad_interrupt>
  36:	15 c0       	rjmp	.+42     	; 0x62 <__bad_interrupt>
  38:	14 c0       	rjmp	.+40     	; 0x62 <__bad_interrupt>
  3a:	13 c0       	rjmp	.+38     	; 0x62 <__bad_interrupt>

0000003c <__ctors_end>:
  3c:	11 24       	eor	r1, r1
  3e:	1f be       	out	0x3f, r1	; 63
  40:	cf ef       	ldi	r28, 0xFF	; 255
  42:	d2 e0       	ldi	r29, 0x02	; 2
  44:	de bf       	out	0x3e, r29	; 62
  46:	cd bf       	out	0x3d, r28	; 61

00000048 <__do_copy_data>:
  48:	11 e0       	ldi	r17, 0x01	; 1
  4a:	a0 e0       	ldi	r26, 0x00	; 0
  4c:	b1 e0       	ldi	r27, 0x01	; 1
  4e:	e2 e1       	ldi	r30, 0x12	; 18
  50:	f1 e0       	ldi	r31, 0x01	; 1
  52:	02 c0       	rjmp	.+4      	; 0x58 <__do_copy_data+0x10>
  54:	05 90       	lpm	r0, Z+
  56:	0d 92       	st	X+, r0
  58:	a6 30       	cpi	r26, 0x06	; 6
  5a:	b1 07       	cpc	r27, r17
  5c:	d9 f7       	brne	.-10     	; 0x54 <__do_copy_data+0xc>
  5e:	09 d0       	rcall	.+18     	; 0x72 <main>
  60:	56 c0       	rjmp	.+172    	; 0x10e <_exit>

00000062 <__bad_interrupt>:
  62:	ce cf       	rjmp	.-100    	; 0x0 <__vectors>

00000064 <xmt_data>:
	#define xmt(val)   xmt_wait(); UDR0=val
#endif

void xmt_data(U8 data)
{
	xmt(data);
  64:	90 91 86 00 	lds	r25, 0x0086	; 0x800086 <__EEPROM_REGION_LENGTH__+0x7f0086>
  68:	95 ff       	sbrs	r25, 5
  6a:	fc cf       	rjmp	.-8      	; 0x64 <xmt_data>
  6c:	80 93 80 00 	sts	0x0080, r24	; 0x800080 <__EEPROM_REGION_LENGTH__+0x7f0080>
  70:	08 95       	ret

00000072 <main>:
	#endif
}

void main(void) __attribute__((noreturn));
void main(void)
{
  72:	a5 e0       	ldi	r26, 0x05	; 5
  74:	b0 e0       	ldi	r27, 0x00	; 0
  76:	ee e3       	ldi	r30, 0x3E	; 62
  78:	f0 e0       	ldi	r31, 0x00	; 0
  7a:	39 c0       	rjmp	.+114    	; 0xee <__prologue_saves__+0x18>

		//enable transmitter and receiver, normal uart mode
		USART0_CTRLB = USART_RXEN_bm | USART_TXEN_bm;
	#else

		UCSR0B = BIT(RXCIE0)|BIT(RXEN0)|BIT(TXEN0);//RX ISR en, RX en, TX en
  7c:	88 e9       	ldi	r24, 0x98	; 152
  7e:	80 93 85 00 	sts	0x0085, r24	; 0x800085 <__EEPROM_REGION_LENGTH__+0x7f0085>
		UCSR0C = BIT(UCSZ01)|BIT(UCSZ00);//Async, NoParity, 8DataBits, 1StopBit
  82:	86 e0       	ldi	r24, 0x06	; 6
  84:	80 93 84 00 	sts	0x0084, r24	; 0x800084 <__EEPROM_REGION_LENGTH__+0x7f0084>
		UBRR0H = 0;  //high byte must be written before low (pg138)
  88:	10 92 82 00 	sts	0x0082, r1	; 0x800082 <__EEPROM_REGION_LENGTH__+0x7f0082>
		UBRR0L = 77; //9600 bps @ 12MHz, 0.2% accuracy, U2Xn = 0
  8c:	8d e4       	ldi	r24, 0x4D	; 77
  8e:	80 93 81 00 	sts	0x0081, r24	; 0x800081 <__EEPROM_REGION_LENGTH__+0x7f0081>
  92:	7e 01       	movw	r14, r28
  94:	86 e0       	ldi	r24, 0x06	; 6
  96:	e8 0e       	add	r14, r24
  98:	f1 1c       	adc	r15, r1

	while(1)
	{
		//test function
		U8 ary1[] = {11,22,33,44,55}; //5 bytes
  9a:	85 e0       	ldi	r24, 0x05	; 5
  9c:	e0 e0       	ldi	r30, 0x00	; 0
  9e:	f1 e0       	ldi	r31, 0x01	; 1
  a0:	de 01       	movw	r26, r28
  a2:	11 96       	adiw	r26, 0x01	; 1
  a4:	01 90       	ld	r0, Z+
  a6:	0d 92       	st	X+, r0
  a8:	8a 95       	dec	r24
  aa:	e1 f7       	brne	.-8      	; 0xa4 <main+0x32>

		//direct index
		xmt_data(ary1[0]);
  ac:	8b e0       	ldi	r24, 0x0B	; 11
  ae:	da df       	rcall	.-76     	; 0x64 <xmt_data>
		xmt_data(ary1[1]);
  b0:	86 e1       	ldi	r24, 0x16	; 22
  b2:	d8 df       	rcall	.-80     	; 0x64 <xmt_data>
		xmt_data(ary1[2]);
  b4:	81 e2       	ldi	r24, 0x21	; 33
  b6:	d6 df       	rcall	.-84     	; 0x64 <xmt_data>
		xmt_data(ary1[3]);
  b8:	8c e2       	ldi	r24, 0x2C	; 44
  ba:	d4 df       	rcall	.-88     	; 0x64 <xmt_data>
		xmt_data(ary1[4]);
  bc:	87 e3       	ldi	r24, 0x37	; 55
  be:	d2 df       	rcall	.-92     	; 0x64 <xmt_data>
  c0:	8e 01       	movw	r16, r28
  c2:	0f 5f       	subi	r16, 0xFF	; 255
  c4:	1f 4f       	sbci	r17, 0xFF	; 255

		//loop not working
		for(U8 i=0; i<5; i++)
		{
			U8 x = ary1[i];
			xmt_data(x);
  c6:	f8 01       	movw	r30, r16
  c8:	81 91       	ld	r24, Z+
  ca:	8f 01       	movw	r16, r30
  cc:	cb df       	rcall	.-106    	; 0x64 <xmt_data>
		xmt_data(ary1[2]);
		xmt_data(ary1[3]);
		xmt_data(ary1[4]);

		//loop not working
		for(U8 i=0; i<5; i++)
  ce:	0e 15       	cp	r16, r14
  d0:	1f 05       	cpc	r17, r15
  d2:	c9 f7       	brne	.-14     	; 0xc6 <main+0x54>
  d4:	e2 cf       	rjmp	.-60     	; 0x9a <main+0x28>

000000d6 <__prologue_saves__>:
  d6:	2f 92       	push	r2
  d8:	3f 92       	push	r3
  da:	4f 92       	push	r4
  dc:	5f 92       	push	r5
  de:	6f 92       	push	r6
  e0:	7f 92       	push	r7
  e2:	8f 92       	push	r8
  e4:	9f 92       	push	r9
  e6:	af 92       	push	r10
  e8:	bf 92       	push	r11
  ea:	cf 92       	push	r12
  ec:	df 92       	push	r13
  ee:	ef 92       	push	r14
  f0:	ff 92       	push	r15
  f2:	0f 93       	push	r16
  f4:	1f 93       	push	r17
  f6:	cf 93       	push	r28
  f8:	df 93       	push	r29
  fa:	cd b7       	in	r28, 0x3d	; 61
  fc:	de b7       	in	r29, 0x3e	; 62
  fe:	ca 1b       	sub	r28, r26
 100:	db 0b       	sbc	r29, r27
 102:	0f b6       	in	r0, 0x3f	; 63
 104:	f8 94       	cli
 106:	de bf       	out	0x3e, r29	; 62
 108:	0f be       	out	0x3f, r0	; 63
 10a:	cd bf       	out	0x3d, r28	; 61
 10c:	09 94       	ijmp

0000010e <_exit>:
 10e:	f8 94       	cli

00000110 <__stop_program>:
 110:	ff cf       	rjmp	.-2      	; 0x110 <__stop_program>

 

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

Look at the do_copy_data for the T841 it uses correctly the LPM instruction to move data from flash to ram.

  52:	02 c0       	rjmp	.+4      	; 0x58 <__do_copy_data+0x10>
  54:	05 90       	lpm	r0, Z+
  56:	0d 92       	st	X+, r0

is the code fro the T1641 doing the same thing? I can't see that function.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

yes I noticed the t841 has the do_copy_data, I posted all the assembly from the t1614; it seems to be missing that important stuff. no lpm instruction found in the assembly for the t1614.

Last Edited: Mon. Dec 3, 2018 - 06:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
OPT='-D__AVR_ATtiny1614__ -D__AVR_DEVICE_NAME__=attiny1614 -D__AVR_DEV_LIB_NAME__=tn1614 -DF_CPU=12000000UL -Wall -Wno-volatile-register-var -gdwarf-2 -std=gnu99 -ffreestanding -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -finline-limit=3 -fno-inline-small-functions  -ffunction-sections  -fdata-sections  -mcall-prologues -flto'

OPT='-D__AVR_ATtiny1614__ -D__AVR_DEVICE_NAME__=attiny1614 -D__AVR_DEV_LIB_NAME__=tn1614 -DF_CPU=12000000UL -Wall -gdwarf-2 -std=gnu99 -ffreestanding -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums'

Can we see the actual compiler invocation that results from these definitions? For one thing:

-D__AVR_ATtiny1614__

looks very very wrong indeed! If that is how you set _AVR_ATTiny1614_ rather than using -mmcu= (which sets it automatically) then no wonder, at the link stage it does not know to use crt1614.o  !!

 

I know you said Linux but that doesn't mean you can't use an IDE. Either Eclipes or Code::Blocks (or Netbeans?) would know how to form the correct Makefile to invoke the tools correctly rather that you just randomly stabbing about in the dark and hoping to stumble upon something that works!

 

PS also take a look at this thread: https://www.avrfreaks.net/forum/... - I think that something like 1614 is also going to need to know about "device packs" too as I don't think it's generically supported.

Last Edited: Mon. Dec 3, 2018 - 11:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi Clawson,

I believe my compile scrips are correct, they are below.

been using bash scripts and PACKS in linux with Geany for a long time. Personal preference, I like Geany and bash.

I tried compiling it incorrectly on purpose as you have stated above and the compile gives warnings/errors if compiled with the wrong PACK or chip invocation.

My compilations have no warning or errors. t1614 has 0 bytes for .data + .bss + .noinit, t841 has 6 bytes

Tried with and without options "-ffunction-sections  -fdata-sections -finline-limit=3 -fno-inline-small-functions" but t1614 code seems to always have array problems, only thing that keeps the array around is having "static volatile" but that does not play nice with string functions.

I removed the redundant "-D__AVR_ATtinyXXXX__ -D__AVR_DEVICE_NAME__=attinyXXXX -D__AVR_DEV_LIB_NAME__=tnXXXX" stuff, yes I was already using -mmcu= and those defines were un-necessary and redundant, but the code compiled is the same. no change in result.

 

t1614

_________________________________________________________
STARTING COMPILE
COMPILE FINISHED
__________________________________________________________
HEX SIZE USAGE
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.2_1759) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

main.elf:     file format elf32-avr
AVR Memory Usage
----------------
Device: attiny1614

Program:     324 bytes (2.0% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)

   text       data        bss        dec        hex    filename
    329          0          0        329        149    main.elf
__________________________________________________________
 

#!/bin/bash

#variables
MCU=attiny1614
MCU_SIZE=attiny1614
OUT=t1614
TOOLCHAIN=/home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64
GCC=$TOOLCHAIN/bin
PAC=$TOOLCHAIN/PACKS/Atmel.ATtiny_DFP.1.3.172
PACB=$PAC/gcc/dev/attiny1614/
PACI=$PAC/include/
PACS=-B $PACB -I $PACI
CUR=$(pwd)

#options
OPT='-DF_CPU=12000000UL -Wall -Wno-volatile-register-var -gdwarf-2 -std=gnu99 -ffreestanding -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -finline-limit=3 -fno-inline-small-functions  -ffunction-sections  -fdata-sections  -mcall-prologues -flto'

#files to compile
FM=main

#make output directory
if [ -e "$OUT" ];
then
    echo found existing bin directory
else
	echo creating output directory
	mkdir $OUT
fi

#compile
reset
echo __________________________________________________________
echo STARTING COMPILE
cd $OUT
#=========================================================== -std=gnu99
#compile to object file (if not compiling correctly, echo the command below and make sure all variables are set)
$GCC/avr-gcc -g -mmcu=$MCU  -B $PACB -I $PACI  $OPT -Os -c "$CUR/$FM.c"
#compile objects to elf file
$GCC/avr-gcc -g -mmcu=$MCU -B $PACB -I $PACI -o $FM.elf $FM.o
#drump elf to hex file
$GCC/avr-objcopy -j .text -j .data -O ihex $FM.elf $FM.hex
#dump elf to eeprom file
$GCC/avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex $FM.elf $FM.eep
#dump elf to lss file
$GCC/avr-objdump -h -S $FM.elf > $FM.lss
#===========================================================
echo COMPILE FINISHED
echo __________________________________________________________
echo HEX SIZE USAGE
#display GCC version
$GCC/avr-gcc --version
#display code size
#https://www.avrfreaks.net/forum/where-does-avr-size-get-data-supported-devices
#$GCC/avr-size -C --mcu=$MCU_SIZE $FM.elf  #old method
$GCC/avr-objdump -Pmem-usage $FM.elf
$GCC/avr-size $FM.elf
echo __________________________________________________________
cd ..

t841

STARTING COMPILE
COMPILE FINISHED
__________________________________________________________
HEX SIZE USAGE
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.2_1759) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

main.elf:     file format elf32-avr
AVR Memory Usage
----------------
Device: attiny841

Program:     248 bytes (3.0% Full)
(.text + .data + .bootloader)

Data:          6 bytes (1.2% Full)
(.data + .bss + .noinit)

   text       data        bss        dec        hex    filename
    242          6          0        248         f8    main.elf
__________________________________________________________

#!/bin/bash

#variables
MCU=attiny841
MCU_SIZE=attiny841
OUT=t841
TOOLCHAIN=/home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64
GCC=$TOOLCHAIN/bin
PAC=$TOOLCHAIN/PACKS/Atmel.ATtiny_DFP.1.3.172
PACB=$PAC/gcc/dev/attiny841/
PACI=$PAC/include/
PACS=-B $PACB -I $PACI
CUR=$(pwd)

#options
OPT='-DF_CPU=12000000UL -Wall -Wno-volatile-register-var -gdwarf-2 -std=gnu99 -ffreestanding -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -finline-limit=3 -fno-inline-small-functions  -ffunction-sections  -fdata-sections  -mcall-prologues -flto'

#files to compile
FM=main

#make output directory
if [ -e "$OUT" ];
then
    echo found existing bin directory
else
	echo creating output directory
	mkdir $OUT
fi

#compile
reset
echo __________________________________________________________
echo STARTING COMPILE
cd $OUT
#=========================================================== -std=gnu99
#compile to object file (if not compiling correctly, echo the command below and make sure all variables are set)
$GCC/avr-gcc -g -mmcu=$MCU  -B $PACB -I $PACI  $OPT -Os -c "$CUR/$FM.c"
#compile objects to elf file
$GCC/avr-gcc -g -mmcu=$MCU -B $PACB -I $PACI -o $FM.elf $FM.o
#drump elf to hex file
$GCC/avr-objcopy -j .text -j .data -O ihex $FM.elf $FM.hex
#dump elf to eeprom file
$GCC/avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex $FM.elf $FM.eep
#dump elf to lss file
$GCC/avr-objdump -h -S $FM.elf > $FM.lss
#===========================================================
echo COMPILE FINISHED
echo __________________________________________________________
echo HEX SIZE USAGE
#display GCC version
$GCC/avr-gcc --version
#display code size
#https://www.avrfreaks.net/forum/where-does-avr-size-get-data-supported-devices
#$GCC/avr-size -C --mcu=$MCU_SIZE $FM.elf  #old method
$GCC/avr-objdump -Pmem-usage $FM.elf
$GCC/avr-size $FM.elf
echo __________________________________________________________
cd ..

 

Last Edited: Mon. Dec 3, 2018 - 01:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you tried moving the definition of ary1[] above main?

 

--Mike

 

 

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

yes Mike, that does work when the variable is global, problem does only occur when using array as local variable. It seems no local arrays work unless declared "static volatile"

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

What is a "U8"?

Oops, wrong question. I don't want to know hat a "U8" is.

I can also make some guess, about what it is probably supposed to mean, but I won't do that either.

Some 10 to 20 years ago, maybe longer names for fixed with integers have been standarized.

Standardisation is a good thing. Use those standards.

So use the names defined in stdint.h.

 

Also: One statement per line please.

I know the compiler don't care, but most mortals do.

 

I also have a strong suspicion that your problem has absolutely nothing to do with for loops.

 

Please excuse my language (or ignore if you like).

I guess i'm in a foul mood today, better go do something else.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

Last Edited: Mon. Dec 3, 2018 - 01:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does your map file have something like:

Archive member included to satisfy reference by file (symbol)

c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avrxmega3\libgcc.a(_exit.o)
                              C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o (exit)
c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avrxmega3\libgcc.a(_copy_data.o)
                              main.o (__do_copy_data)
c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avrxmega3\libgcc.a(_clear_bss.o)
                              main.o (__do_clear_bss)

If not then you aren't invoking the tools correctly.

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

Hi Paulvdh

post #6, entire source code is posted, U8 is #define U8 uint8_t

I'm not the only one who does this, it's a common nomenclature among some programmers.

#define I8  int8_t
#define I16 int16_t
#define I32 int32_t
#define I64 int64_t
#define U8  uint8_t
#define U16 uint16_t
#define U32 uint32_t
#define U64 uint64_t

I agree I dont think the problem is just for loops, it appears to be a local array issue, the for loop exhibits the issue everytime though.

 

Hi clawson,

I believe I am invoking the packs correctly as atmel/microchip has documented,

what else besides linking the correct pack and -mmcu= should I be doing?

I have posted my entire compile script for both chips, if a compile tool does not look like it is correctly being invoked please let me know.

I generated the map you requested and it is attached, here is how I generated it (modification from my above bash script in post #11)...

#compile objects to elf file
$GCC/avr-gcc -g -mmcu=$MCU  -Wl,-Map=main.map  -B $PACB -I $PACI -o $FM.elf $FM.o

same compile method used for both chips, correct packs passed to both, only difference is t1614 produces no local array data in (.data + .bss + .noinit), where t841, or any other attiny atmega chip does.

The only thing that makes the array produce data in (.data + .bss + .noinit) is having it "static volatile" or global instead of local. That seems like something to do with the compiler, but I have already tried turning off all my optimization switches, even tried -O1 -O2 instead of -Os ... but again, same compile method, same code, compiles fine for attiny and atmega (tried attiny44a, attiny841, atmega168pb) but has problems with tinyavr1 series (tried t1614 and t1617)

 

Archive member included to satisfy reference by file (symbol)

/home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
                              /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o (exit)

Memory Configuration

Name             Origin             Length             Attributes
text             0x0000000000000000 0x0000000000100000 xr
data             0x0000000000802000 0x000000000000ffa0 rw !x
eeprom           0x0000000000810000 0x0000000000010000 rw !x
fuse             0x0000000000820000 0x0000000000000009 rw !x
lock             0x0000000000830000 0x0000000000000400 rw !x
signature        0x0000000000840000 0x0000000000000400 rw !x
user_signatures  0x0000000000850000 0x0000000000000400 rw !x
*default*        0x0000000000000000 0xffffffffffffffff

Linker script and memory map

Address of section .data set to 0x803800
                0x0000000000008000                __RODATA_PM_OFFSET__ = 0x8000
LOAD /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
LOAD main.o
START GROUP
LOAD /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a
LOAD /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avrxmega3/libm.a
LOAD /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avrxmega3/libc.a
LOAD /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/libattiny1614.a
END GROUP
                0x0000000000100000                __TEXT_REGION_LENGTH__ = DEFINED (__TEXT_REGION_LENGTH__)?__TEXT_REGION_LENGTH__:0x100000
                0x000000000000ffa0                __DATA_REGION_LENGTH__ = DEFINED (__DATA_REGION_LENGTH__)?__DATA_REGION_LENGTH__:0xffa0
                0x0000000000010000                __EEPROM_REGION_LENGTH__ = DEFINED (__EEPROM_REGION_LENGTH__)?__EEPROM_REGION_LENGTH__:0x10000
                [0x0000000000000009]                __FUSE_REGION_LENGTH__ = DEFINED (__FUSE_REGION_LENGTH__)?__FUSE_REGION_LENGTH__:0x400
                0x0000000000000400                __LOCK_REGION_LENGTH__ = DEFINED (__LOCK_REGION_LENGTH__)?__LOCK_REGION_LENGTH__:0x400
                0x0000000000000400                __SIGNATURE_REGION_LENGTH__ = DEFINED (__SIGNATURE_REGION_LENGTH__)?__SIGNATURE_REGION_LENGTH__:0x400
                0x0000000000000400                __USER_SIGNATURE_REGION_LENGTH__ = DEFINED (__USER_SIGNATURE_REGION_LENGTH__)?__USER_SIGNATURE_REGION_LENGTH__:0x400
                0x0000000000008000                __RODATA_PM_OFFSET__ = DEFINED (__RODATA_PM_OFFSET__)?__RODATA_PM_OFFSET__:0x8000

.hash
 *(.hash)

.dynsym
 *(.dynsym)

.dynstr
 *(.dynstr)

.gnu.version
 *(.gnu.version)

.gnu.version_d
 *(.gnu.version_d)

.gnu.version_r
 *(.gnu.version_r)

.rel.init
 *(.rel.init)

.rela.init
 *(.rela.init)

.rel.text
 *(.rel.text)
 *(.rel.text.*)
 *(.rel.gnu.linkonce.t*)

.rela.text
 *(.rela.text)
 *(.rela.text.*)
 *(.rela.gnu.linkonce.t*)

.rel.fini
 *(.rel.fini)

.rela.fini
 *(.rela.fini)

.rel.rodata
 *(.rel.rodata)
 *(.rel.rodata.*)
 *(.rel.gnu.linkonce.r*)

.rela.rodata
 *(.rela.rodata)
 *(.rela.rodata.*)
 *(.rela.gnu.linkonce.r*)

.rel.data
 *(.rel.data)
 *(.rel.data.*)
 *(.rel.gnu.linkonce.d*)

.rela.data
 *(.rela.data)
 *(.rela.data.*)
 *(.rela.gnu.linkonce.d*)

.rel.ctors
 *(.rel.ctors)

.rela.ctors
 *(.rela.ctors)

.rel.dtors
 *(.rel.dtors)

.rela.dtors
 *(.rela.dtors)

.rel.got
 *(.rel.got)

.rela.got
 *(.rela.got)

.rel.bss
 *(.rel.bss)

.rela.bss
 *(.rela.bss)

.rel.plt
 *(.rel.plt)

.rela.plt
 *(.rela.plt)

.text           0x0000000000000000      0x122
 *(.vectors)
 .vectors       0x0000000000000000       0x7c /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
                0x0000000000000000                __vectors
                0x0000000000000000                __vector_default
 *(.vectors)
 *(.progmem.gcc*)
                0x000000000000007c                . = ALIGN (0x2)
                0x000000000000007c                __trampolines_start = .
 *(.trampolines)
 .trampolines   0x000000000000007c        0x0 linker stubs
 *(.trampolines*)
                0x000000000000007c                __trampolines_end = .
 *libprintf_flt.a:*(.progmem.data)
 *libc.a:*(.progmem.data)
 *(.progmem*)
                0x000000000000007c                . = ALIGN (0x2)
 *(.jumptables)
 *(.jumptables*)
 *(.lowtext)
 *(.lowtext*)
                0x000000000000007c                __ctors_start = .
 *(.ctors)
                0x000000000000007c                __ctors_end = .
                0x000000000000007c                __dtors_start = .
 *(.dtors)
                0x000000000000007c                __dtors_end = .
 SORT(*)(.ctors)
 SORT(*)(.dtors)
 *(.init0)
 .init0         0x000000000000007c        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
                0x000000000000007c                __init
 *(.init0)
 *(.init1)
 *(.init1)
 *(.init2)
 .init2         0x000000000000007c        0xc /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
 *(.init2)
 *(.init3)
 *(.init3)
 *(.init4)
 *(.init4)
 *(.init5)
 *(.init5)
 *(.init6)
 *(.init6)
 *(.init7)
 *(.init7)
 *(.init8)
 *(.init8)
 *(.init9)
 .init9         0x0000000000000088        0x8 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
 *(.init9)
 *(.text)
 .text          0x0000000000000090        0x4 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
                0x0000000000000090                __vector_22
                0x0000000000000090                __vector_28
                0x0000000000000090                __vector_1
                0x0000000000000090                __vector_24
                0x0000000000000090                __vector_12
                0x0000000000000090                __bad_interrupt
                0x0000000000000090                __vector_6
                0x0000000000000090                __vector_3
                0x0000000000000090                __vector_23
                0x0000000000000090                __vector_30
                0x0000000000000090                __vector_25
                0x0000000000000090                __vector_11
                0x0000000000000090                __vector_13
                0x0000000000000090                __vector_17
                0x0000000000000090                __vector_19
                0x0000000000000090                __vector_7
                0x0000000000000090                __vector_27
                0x0000000000000090                __vector_5
                0x0000000000000090                __vector_4
                0x0000000000000090                __vector_9
                0x0000000000000090                __vector_2
                0x0000000000000090                __vector_21
                0x0000000000000090                __vector_15
                0x0000000000000090                __vector_29
                0x0000000000000090                __vector_8
                0x0000000000000090                __vector_26
                0x0000000000000090                __vector_14
                0x0000000000000090                __vector_10
                0x0000000000000090                __vector_16
                0x0000000000000090                __vector_18
                0x0000000000000090                __vector_20
 .text          0x0000000000000094        0xe main.o
                0x0000000000000094                xmt_data
 .text          0x00000000000000a2        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
                0x00000000000000a2                . = ALIGN (0x2)
 *(.text.*)
 .text.startup  0x00000000000000a2       0x7c main.o
                0x00000000000000a2                main
 .text.libgcc.mul
                0x000000000000011e        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 .text.libgcc.div
                0x000000000000011e        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 .text.libgcc   0x000000000000011e        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 .text.libgcc.prologue
                0x000000000000011e        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 .text.libgcc.builtins
                0x000000000000011e        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 .text.libgcc.fmul
                0x000000000000011e        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 .text.libgcc.fixed
                0x000000000000011e        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
                0x000000000000011e                . = ALIGN (0x2)
 *(.fini9)
 .fini9         0x000000000000011e        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
                0x000000000000011e                exit
                0x000000000000011e                _exit
 *(.fini9)
 *(.fini8)
 *(.fini8)
 *(.fini7)
 *(.fini7)
 *(.fini6)
 *(.fini6)
 *(.fini5)
 *(.fini5)
 *(.fini4)
 *(.fini4)
 *(.fini3)
 *(.fini3)
 *(.fini2)
 *(.fini2)
 *(.fini1)
 *(.fini1)
 *(.fini0)
 .fini0         0x000000000000011e        0x4 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 *(.fini0)
                0x0000000000000122                _etext = .

.rodata         0x0000000000008122        0x5 load address 0x0000000000000122
 *(.rodata)
 .rodata        0x0000000000008122        0x5 main.o
 *(.rodata*)
 *(.gnu.linkonce.r*)

.data           0x0000000000803800        0x0 load address 0x0000000000000127
                [!provide]                        PROVIDE (__data_start, .)
 *(.data)
 .data          0x0000000000803800        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
 .data          0x0000000000803800        0x0 main.o
 .data          0x0000000000803800        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 *(.data*)
 *(.gnu.linkonce.d*)
                0x0000000000803800                . = ALIGN (0x2)
                0x0000000000803800                _edata = .
                [!provide]                        PROVIDE (__data_end, .)

.bss            0x0000000000803800        0x0
                [!provide]                        PROVIDE (__bss_start, .)
 *(.bss)
 .bss           0x0000000000803800        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
 .bss           0x0000000000803800        0x0 main.o
 .bss           0x0000000000803800        0x0 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/bin/../lib/gcc/avr/5.4.0/avrxmega3/libgcc.a(_exit.o)
 *(.bss*)
 *(COMMON)
                [!provide]                        PROVIDE (__bss_end, .)
                0x0000000000000127                __data_load_start = LOADADDR (.data)
                0x0000000000000127                __data_load_end = (__data_load_start + SIZEOF (.data))

.noinit         0x0000000000803800        0x0
                [!provide]                        PROVIDE (__noinit_start, .)
 *(.noinit*)
                [!provide]                        PROVIDE (__noinit_end, .)
                0x0000000000803800                _end = .
                [!provide]                        PROVIDE (__heap_start, .)

.eeprom         0x0000000000810000        0x0
 *(.eeprom*)
                0x0000000000810000                __eeprom_end = .

.fuse
 *(.fuse)
 *(.lfuse)
 *(.hfuse)
 *(.efuse)

.lock
 *(.lock*)

.signature
 *(.signature*)

.user_signatures
 *(.user_signatures*)

.stab
 *(.stab)

.stabstr
 *(.stabstr)

.stab.excl
 *(.stab.excl)

.stab.exclstr
 *(.stab.exclstr)

.stab.index
 *(.stab.index)

.stab.indexstr
 *(.stab.indexstr)

.comment        0x0000000000000000       0x30
 *(.comment)
 .comment       0x0000000000000000       0x30 main.o
                                         0x31 (size before relaxing)

.note.gnu.avr.deviceinfo
                0x0000000000000000       0x40
 .note.gnu.avr.deviceinfo
                0x0000000000000000       0x40 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o

.note.gnu.build-id
 *(.note.gnu.build-id)

.debug
 *(.debug)

.line
 *(.line)

.debug_srcinfo
 *(.debug_srcinfo)

.debug_sfnames
 *(.debug_sfnames)

.debug_aranges  0x0000000000000000       0x28
 *(.debug_aranges)
 .debug_aranges
                0x0000000000000000       0x28 main.o

.debug_pubnames
 *(.debug_pubnames)

.debug_info     0x0000000000000000     0x1d28
 *(.debug_info .gnu.linkonce.wi.*)
 .debug_info    0x0000000000000000     0x19ed /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
 .debug_info    0x00000000000019ed      0x33b main.o

.debug_abbrev   0x0000000000000000     0x19a6
 *(.debug_abbrev)
 .debug_abbrev  0x0000000000000000     0x1888 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
 .debug_abbrev  0x0000000000001888      0x11e main.o

.debug_line     0x0000000000000000      0x338
 *(.debug_line .debug_line.* .debug_line_end)
 .debug_line    0x0000000000000000      0x151 /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
 .debug_line    0x0000000000000151      0x1e7 main.o

.debug_frame    0x0000000000000000       0x44
 *(.debug_frame)
 .debug_frame   0x0000000000000000       0x44 main.o

.debug_str      0x0000000000000000      0xd8b
 *(.debug_str)
 .debug_str     0x0000000000000000      0xacf /home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64/PACKS/Atmel.ATtiny_DFP.1.3.172/gcc/dev/attiny1614/avrxmega3/crtattiny1614.o
 .debug_str     0x0000000000000acf      0x2bc main.o
                                        0x2f5 (size before relaxing)

.debug_loc      0x0000000000000000       0x7a
 *(.debug_loc)
 .debug_loc     0x0000000000000000       0x7a main.o

.debug_macinfo
 *(.debug_macinfo)

.debug_weaknames
 *(.debug_weaknames)

.debug_funcnames
 *(.debug_funcnames)

.debug_typenames
 *(.debug_typenames)

.debug_varnames
 *(.debug_varnames)

.debug_pubtypes
 *(.debug_pubtypes)

.debug_ranges   0x0000000000000000       0x18
 *(.debug_ranges)
 .debug_ranges  0x0000000000000000       0x18 main.o

.debug_macro
 *(.debug_macro)
OUTPUT(main.elf elf32-avr)
LOAD linker stubs

 

Last Edited: Mon. Dec 3, 2018 - 02:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've googled and cannot find  "avr8-gnu-toolchain-3.6.2.1759". Basically I was trying to work out which version of avr-gcc this is. Also I would like to know your AVR-LibC version. The fact is that there was a point where the handling of _do_copy_data and _do_clear_bss moved and I wonder if you have mismatched tools+lib ??

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

Seems to be a problem with the stack.  Local variables go there

and so your array should end up on the stack too.  A static array

will end up in "normal" RAM with a fixed address.

 

--Mike

 

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

]OK, I'll bite -- why would anyone create a local initialized array?  And then re-initialize every time through a while() loop?]

 

Remember that the newfangled ("Tiny-1 series"?) chips have a different memory map, and thus LD Rxx, Z+ is perfectly valid (AFAIK).  Now, you gurus can go back to the postings above and figure out what address is being used for the "load".

 

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

12oclocker wrote:
99c: ff ef ldi r31, 0xFF ; 255 99e: 4f 1a sub r4, r31 9a0: 5f 0a sbc r5, r31 9a2: 6f 0a sbc r6, r31 9a4: 7f 0a sbc r7, r31 gui_Hex(ary1[3]); gui_Hex(ary1[4]); //loop not working glcd_pos_chr(1,0); for(U8 i=0; i<5; i++) 9a6: 85 e0 ldi r24, 0x05 ; 5 9a8: 48 16 cp r4, r24 9aa: 51 04 cpc r5, r1 9ac: 61 04 cpc r6, r1 9ae: 71 04 cpc r7, r1 9b0: 41 f7 brne .-48 ; 0x982

I'm getting too old -- where are all these 32-bit operations coming from?

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

theusch wrote:
- where are all these 32-bit operations coming from?
While not shown I guess:

void gui_Hex(U32 dat);

 

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

hi guys, you are using old info, I created a simplified test program which exhibits the issue, all the gui_Hex stuff is gone, removed to prove to myself that code was not the issue.

Post #7 is the entire source code. Post #11 is the compile script.

attached is complete source and compile scripts that exhibit the issue.

When I first posted this I was working on a program, I scratched that program and just made a super simple test program to exhibit the issue.

You can ignore previous source code before post #7, all you need is post #7 source code and post #11 compile script to exhibit the issue (or the zip file I just attached)

EDIT* (forgot to pre-compile the code so you can see the lss output, did that and reattached files)

Attachment(s): 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As I can't use your scripts I just put that .c file into a project in AS7 and built it then stepped it in the simulator and before each call to xmt_data() I see R24 with the correct 11, 22, etc value so the problem is that I can't reproduce your fault.

 

My build commands were:

		Building file: D:/avr1614_prob/main.c
		Invoking: AVR/GNU C Compiler : 5.4.0
D:\avr1614_prob\main.c(64,6): warning: return type of 'main' is not 'int' [-Wmain]
		 void main(void)
		      ^
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.172\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=attiny1614 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.172\gcc\dev\attiny1614" -c -std=gnu99 -MD -MP -MF "main.d" -MT"main.d" -MT"main.o"   -o "main.o" "D:/avr1614_prob/main.c" 
		Finished building: D:/avr1614_prob/main.c
		Building target: Test1614.elf
		Invoking: AVR/GNU Linker : 5.4.0
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -o Test1614.elf  main.o   -Wl,-Map="Test1614.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=attiny1614 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.172\gcc\dev\attiny1614"  
		Finished building target: Test1614.elf
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures  "Test1614.elf" "Test1614.hex"
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "Test1614.elf" "Test1614.eep" || exit 0
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "Test1614.elf" > "Test1614.lss"
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "Test1614.elf" "Test1614.srec"
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "Test1614.elf"
		   text	   data	    bss	    dec	    hex	filename
		    287	      0	      0	    287	    11f	Test1614.elf
	Done executing task "RunCompilerTask".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	282 bytes   1.7 % Full
				Data Memory Usage 		:	0 bytes   0.0 % Full

So turn this around - use exactly those build commands with those options in your environment and see if you still see the problem.

 

Obviously your paths to your DFPs etc will likely be quite different.

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

Hi Clawson, I will try it, I know the "'main' is not 'int'" is because the freestanding switch is missing in your compile test, (I already tried leaving that out too and using a int main )

I will use your exact stuff above and give it a try...

 

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

Hi Clawson, I have bad news,

I compiled exactly as your switches above, and same result. (t1614 local arrays dont work)

Likewise, I used your switches for the t841, and same result (t841 compiles arrays OK)

I suspect your windows compiler is having the same trouble, I see "Data Memory Usage         :    0 bytes   0.0 % Full" 

when I expect to see something like "Data Memory Usage         :    6 bytes " as the t841 produces

maybe your simulator is working, but does the code actually work when flashed to the chip, can you post your lss file?

 

STARTING COMPILE
COMPILE FINISHED
__________________________________________________________
HEX SIZE USAGE
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.2_1759) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

main_clawson.elf:     file format elf32-avr
AVR Memory Usage
----------------
Device: attiny1614

Program:     294 bytes (1.8% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)

   text       data        bss        dec        hex    filename
    299          0          0        299        12b    main_clawson.elf
__________________________________________________________
 

 

#!/bin/bash

#variables
MCU=attiny1614
MCU_SIZE=attiny1614
OUT=t1614_clawson
TOOLCHAIN=/home/user/dev/lib_avr/avr8-gnu-toolchain-3.6.2.1759-linux_x86_64
GCC=$TOOLCHAIN/bin
PAC=$TOOLCHAIN/PACKS/Atmel.ATtiny_DFP.1.3.172
PACB=$PAC/gcc/dev/attiny1614/
PACI=$PAC/include/
PACS=-B $PACB -I $PACI
CUR=$(pwd)

#options
#OPT='-DF_CPU=12000000UL -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall'

#files to compile
FM=main_clawson

#make output directory
if [ -e "$OUT" ];
then
    echo found existing bin directory
else
	echo creating output directory
	mkdir $OUT
fi

#compile
reset
echo __________________________________________________________
echo STARTING COMPILE
cd $OUT
#=========================================================== -std=gnu99
#compile to object file (if not compiling correctly, echo the command below and make sure all variables are set)
$GCC/avr-gcc -x c -funsigned-char -funsigned-bitfields -DDEBUG -I $PACI -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=$MCU -B $PACB -c -std=gnu99 -MD -MP -MF "$FM.d" -MT"$FM.d" -MT"$FM.o"   -o "main.o" "$CUR/$FM.c" 

#compile objects to elf file
$GCC/avr-gcc -o $FM.elf  main.o   -Wl,-Map="$FM.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=attiny1614 -B $PACB
#$GCC/avr-gcc -g -mmcu=$MCU -Wl,-Map=main.map -B $PACB -I $PACI -o $FM.elf $FM.o  

#next
$GCC/avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures  "$FM.elf" "$FM.hex"
$GCC/avr-objcopy -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "$FM.elf" "$FM.eep"
$GCC/avr-objdump -h -S "$FM.elf" > "$FM.lss"
$GCC/avr-objcopy -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "$FM.elf" "$FM.srec"

#drump elf to hex file
#$GCC/avr-objcopy -j .text -j .data -O ihex $FM.elf $FM.hex
#dump elf to eeprom file
#$GCC/avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex $FM.elf $FM.eep
#dump elf to lss file
#$GCC/avr-objdump -h -S $FM.elf > $FM.lss
#===========================================================
echo COMPILE FINISHED
echo __________________________________________________________
echo HEX SIZE USAGE
#display GCC version
$GCC/avr-gcc --version
#display code size
#https://www.avrfreaks.net/forum/where-does-avr-size-get-data-supported-devices
#$GCC/avr-size -C --mcu=$MCU_SIZE $FM.elf  #old method
$GCC/avr-objdump -Pmem-usage $FM.elf
$GCC/avr-size $FM.elf
echo __________________________________________________________
cd ..

 

Last Edited: Mon. Dec 3, 2018 - 04:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As I say, this works when built with AS7. The first bit of code it hits to do with ary1[] is:

		U8 ary1[] = {11,22,33,44,55}; //5 bytes
  ec:	85 e0       	ldi	r24, 0x05	; 5
  ee:	ea e1       	ldi	r30, 0x1A	; 26
  f0:	f1 e8       	ldi	r31, 0x81	; 129
  f2:	de 01       	movw	r26, r28
  f4:	11 96       	adiw	r26, 0x01	; 1
  f6:	01 90       	ld	r0, Z+
  f8:	0d 92       	st	X+, r0
  fa:	8a 95       	dec	r24
  fc:	e1 f7       	brne	.-8      	; 0xf6 <main+0x52>

In the sim, if I breakpoint on the LD there I see:

So before the first LD/ST Z (R31:R30) contains 0x811A which according to the diagram Lee posted above is a map to flash address 0x011A. The destination X (R27:R26) is 0x3FF7 which is on the stack I believe.

 

So interesting if I use an "internal SRAM" window in the sim but move up to a "high address" at the 0x8000 offset I see:

 

So at 0x811A onwards are the 11, 22, 33, 44, 55 values (0x0B, 0x16, 0x21, 0x2c, 0x37) and that loop will copy the five bytes (0x05 count in R24) to 0x3FF7 onwards. After the loop completes I then see:

 

later on the code does:

			U8 x = ary1[i];
			xmt_data(x);
 104:	f8 01       	movw	r30, r16
 106:	81 91       	ld	r24, Z+
 108:	8f 01       	movw	r16, r30
 10a:	0e 94 4a 00 	call	0x94	; 0x94 <xmt_data>

and when it reaches here R31:R30=R17:R16 =0x3FF7 so on the first LD R24 gets 0x0B then 0x16 then 0x21 and so on. So this code is all working correctly.

 

I do wonder why you wouldn't use __flash but instead wastefully create a stack copy of the const flash data but I guess that's a question for another day?

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

12oclocker wrote:

Hi Paulvdh

post #6, entire source code is posted, U8 is #define U8 uint8_t

I'm not the only one who does this, it's a common nomenclature among some programmers.

#define I8  int8_t
#define I16 int16_t
#define I32 int32_t
#define I64 int64_t
#define U8  uint8_t
#define U16 uint16_t
#define U32 uint32_t
#define U64 uint64_t

I do the same thing.  If U8 confuses somebody, they probably shouldn't be programming micro controllers.

 

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

thanks clawson for all the great info!

The switches you provided DO PRODUCE DIFFERENT HEX! even though the data region does not show anything like the t841 chip does...

I flashed your HEX to the chip (IT WORKS)

I flash the other hex to the chip (IT DOES NOT WORK)

their is something going on with the compile switches, now I will compile and check each difference to figure out which one is causing the issue.

thank you again everyone, once I figure out which switch is causing the issue I will post it.

 

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

If using Linux and you have some aversion to IDEs then at the very least use Mfile and not some homegrown template!

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

clawson, I like to use bash sometimes instead of makefiles. I have used both, but sometimes I use bash. I prefer bash.

 

Last Edited: Mon. Dec 3, 2018 - 04:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well if you are going to use bash copy everything (and I  mean everything) that the Mfile template does to your bash script.

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

clawson wrote:

Well if you are going to use bash copy everything (and I  mean everything) that the Mfile template does to your bash script.

I have always read the atmel linux docs to compile, thus far no trouble, it worked for everything up until I reached t1614 tinyavr1 series.

their is no makefile template for t1614 series that I have found for linux. I am glad you posted your compile switch info it was a great help!

I am going to do some digging to see what switches are causing the issue.

I have marked your post #23 as the solution! thanks again!

Last Edited: Mon. Dec 3, 2018 - 04:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

12oclocker wrote:
it worked for everything up until I reached t1614 tinyavr1 series.

Even the old bit-pusher can look at

	//test function
		U8 ary1[] = {11,22,33,44,55}; //5 bytes
  9a:	85 e0       	ldi	r24, 0x05	; 5
  9c:	e0 e0       	ldi	r30, 0x00	; 0
  9e:	f1 e0       	ldi	r31, 0x01	; 1
  a0:	de 01       	movw	r26, r28
  a2:	11 96       	adiw	r26, 0x01	; 1
  a4:	01 90       	ld	r0, Z+
  a6:	0d 92       	st	X+, r0
  a8:	8a 95       	dec	r24
  aa:	e1 f7       	brne	.-8      	; 0xa4 <main+0x32>

..and see that R24 is the loop counter, and Z is loaded with 0x100 i.e. 256.  Given the memory map from the datasheet, is 0x100 where your loadable constants [why would anyone want to do that?!?]  are located?  I think not.

 

So you are using a roll-your-won toolchain and setup, and a new model of AVR, and wonder why it doesn't work?  If you do a vanilla setup in Studio7 for that chip target, what are the results?

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

It's not that I'm confused by "U8" conceptually, it's that if someone is writing "U8" instead of "uint8_t", they've introduced a possible source of error that I don't necessarily know about, and historically I've seen a lot of bugs come from hand-rolled typedefs and defines for base types, which is why we added the intX_t types in C99.

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

theusch, I cannot do a  vanilla setup in Studio7 because I use linux, sorry about that. I appreciate your help and info, avr linux setup is kinda like a "roll your own toolchain" anyways, windows toochain will always be better supported and easier to get rolling.

 

the_real_seebs, the reason I use U8 (and probably others) is because it is much quicker to type, and easier to spot syntax errors. unt8_t uint8_t look very similar, but I was typing fast and omitted the i on the first one. not going to happen with U8. everyone is going to have their own way of doing things, some people like to type uint8_t everytime, I like to type U8.

 

I have identified the switch issues, the problem was not explicitly removing the un-need info from the hex file during elf to hex generation... on the t841 chip the extra info was not in the elf, but on the t1614 chip it was, and it got output with the hex. the confusion of the lpm was a curveball, was never the issue, even though the data space shows 6 bytes for t841 and 0 for t1614, 0 could actually be correct as theusch stated in post #19 the new tinyavr1 series does thing a little different.

 

anyways thanks again everyone for helping me track down the issue ;-)