Re: avr-gcc and char strings
Senthil Kumar Selvaraj <[email protected]>
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Dec 04, 2014 at 03:45:20AM +0530, Andreas Höschler wrote: > Hi Wouter, > > here is the assembler file generated with > > avr-gcc -mmcu=atmega2560 -Wall -O2 -S -I /usr/local/avr/include -I./ -o toggle_led.out main.c > > > Thanks!! > > Andreas > + > > Could you post the assembler output? IIRC --save-temps or -S should be added to the gcc command line. > > Wouter > > Op 3 dec. 2014 22:12 schreef "Andreas Höschler" <[email protected]<mailto:[email protected]>>: > Hi all, > > I am close to tearing my hair out. After having established the avr tool chain I tried out a very simple C-program (see below) on an SainSmart Mega2560 board programmed into the chip by making use of /Applications/Arduino.app//Contents/Resources/Java/hardware/tools/avr/bin/avrdude: > > #define F_CPU 16000000UL /* 16 MHz CPU clock */ > #include "Global.h" > #include <util/delay.h> > #include <avr/io.h> > #include <avr/interrupt.h> > #include <inttypes.h> > > > > char String[] = "Hello world!!"; > > > > void USARTInit0(uint16_t baud) > { > // Set Baud rate > int value = (F_CPU / 16 / baud) - 1; > UBRR0H = (uint8_t)(value>>8); > UBRR0L = (uint8_t)value; > > > > // 8N1 > UCSR0C = 0x06; // (3<<UCSZ00); > > > > // Enable receiver and transmitter > UCSR0B = (1<<RXEN0) | (1<<TXEN0); > } > > > > void TxByte0 (uint8_t data) > { > // Wait for empty transmit buffer > while ( !(UCSR0A & (1 << UDRE0)) ); > // Putting data into the buffer, forces transmission > UDR0 = data; > } > > > > int main (void) > { > DDRB = 0xff; // all outputs > > > > USARTInit0(38400); // 9600 19200 38400 > > > > while (1) > { > TxByte0('A'); > TxByte0('B'); > TxByte0('C'); > TxByte0('\n'); > > > > char *s = String; > while (*s != 0) > { > TxByte0(*s); > s++; > } > > > > _delay_ms(500); > } > return (0); > } > > > > This program produces the following output > > ... > ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC > ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC > ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC > ... > > > > telling me that sending single chars works but sending strings fails (does not seem to have anything to do with the serial communication but rather be some kind of memory management problem!??). Older versions of the toolchain did not tell the linker where to place globals in data memory (i.e. did not pass -Tdata) - that would obviously break globals. Can you try making String local and see if that helps? Can you also send the output ELF (or atleast disassembly (objdump -S) and sections (objdump -h))? Regards Senthil > > To be sure the problem is not caused by my own gcc build I changed my Makefile to > > > # AVR-GCC Makefile > PROJECT=toggle_led > SOURCES=main.c > HEADERS= > CC=/Applications/Arduino.app//Contents/Resources/Java/hardware/tools/avr/bin/avr-gcc > OBJCOPY=avr-objcopy > MMCU=atmega2560 > > > > CFLAGS=-mmcu=$(MMCU) -Wall -O2 -I /usr/local/avr/include > > $(PROJECT).hex: $(PROJECT).out > $(OBJCOPY) -j .text -O ihex $(PROJECT).out $(PROJECT).hex > > > > $(PROJECT).out: $(SOURCES) > $(CC) $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES) > > > > program: $(PROJECT).hex > avrdude -p $(MMCU) -c avrispmkII -P usb -e -U flash:w:$(PROJECT).hex > clean: > rm -f $(PROJECT).out > rm -f $(PROJECT).hex > > > > > and thus built the program with a gcc from a respected source (avr-gcc coming with Arduino.app). But the problem persists!? I already discussed this problem on avrfreaks forum. All agree that the above code should work but it does not!?? :-() > > Could this be a problem of the board/chip? I am using a SainSmart Mega2560 board (which seems to be a clone of the original Arduino product)! Or am I doing anything wrong?? > > > > Clueless!?? :-( Hints are greatly appreciated!! > > Thanks a lot, > > > > Andreas > > > > > > _______________________________________________ > AVR-GCC-list mailing list > [email protected]<mailto:[email protected]> > https://lists.nongnu.org/mailman/listinfo/avr-gcc-list > >