Sending strings via UART fails on ATMega2560

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

Hi all,

 

I have jsut established serial communication on an ATMega2560 board. Sending and receiving (even interrupt driven) single characters works great. However, when I try to send a string like so 

 

char String[]  = "Hello world!!"; 

 

 

while (1)                 
  {            
   TxByte0('A');
   TxByte0('B');
   TxByte0('C');
   TxByte0('\n');
   
   putString_in_serial_trans_buffer0(String);
   
   delay_ms(500);            
  }

 

with 

 

void TxByte0 (uint8_t data)
{
    while ( !(UCSR0A & (1 << UDRE0)) );
   UDR0 = data;
}

 

void putString_in_serial_trans_buffer0(const char *s)
{
  while (*s)
    {
      if (*s == '\n') TxByte0('\r');
      else TxByte0(*s);
      s++;
    }
}

 

I get 

 

...

ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC

...

 

So sending chars works but sending strings for whatever reason does not! :-(

 

Any idea?

 

Thanks a lot!

 

Andreas

 

 

 

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

Hmmm--is this CodeVision?  (my hint was "delay_ms()")

 

Tell toolchain and version.  If an older version of CV, the "const" might be taken for "flash".  Remove the const; what happens?  Post smallest complete test program that demonstrates the symptoms.

(You are replacing line feed with carriage return?  How will you get to the next line?)

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

Hi theusch,

 

thanks for your response. Tool chain is 

 

avr-gcc -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/local/avr/libexec/gcc/avr/4.5.1/lto-wrapper
Target: avr
Configured with: ../gcc-4.5.1/configure --target=avr --prefix=/usr/local/avr --with-gnu-ld --with-gnu-as --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --disable-nls --disable-libssp --with-dwarf2
Thread model: single

gcc version 4.5.1 (GCC) 

 

 

built and running on MacOSX. The shortest complete program is

 

#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;
    
    // potentially doubling the speed by setting U2X0 bit
    // UCSR0A = (0<<RXC0) | (0<<TXC0) | (0<<UDRE0) | (0<<FE0) | (0<<DOR0) | (0<<UPE0) | (0<<U2X0) | (0<<MPCM0);
    
    // 8N1
    //   UCSR0C = (0<<UMSEL01) | (0<<UMSEL00) | (0<<UPM01) | (0<<UPM00) | (0<<USBS0) | (1<<UCSZ01) | (1<<UCSZ00) | (0<<UCPOL0);
    UCSR0C = 0x06; // (3<<UCSZ00);   
    
    // Enable receiver and transmitter
    //   UCSR0B = (0<<RXCIE0) | (0<<TXCIE0) | (0<<UDRIE0) | (0<<RXEN0) | (1<<TXEN0) | (0<<UCSZ02) | (0<<RXB80) | (0<<TXB80);
    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
   
   sbi (UCSR0B, RXCIE0);    // enable RX interrupt  
   sei();              // enabling interrupts   
   

while (1)                 
  {            
   TxByte0('A');
   TxByte0('B');
   TxByte0('C');
   TxByte0('\n');
      
   char *s = String;   
   while (*s != 0)
     {
      TxByte0(*s);
      s++;
    }
      
   delay_ms(500);            
  }
      return (0);
  }

 

The result of this is 

 

...

ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC

...

 

Thanks,

 

 Andreas

 

 

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

Additional info! My Makefile looks like so:

 

# AVR-GCC Makefile
PROJECT=toggle_led
SOURCES=main.c Serial.c
HEADERS=Serial.h
CC=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

 

I have built my tool chain on MacOSX like so:

 

 

    PREFIX=/usr/local/avr

    export PREFIX

    PATH=$PATH:$PREFIX/bin

    export PATH

 

We download http://ftp.gnu.org/gnu/binutils/...

We download http://www.smartsoft.de/Download...

 

    cd /usr/src

    gunzip binutils-2.20.1-patches.tar.gz

    tar xvf binutils-2.20.1-patches.tar

 

    mkdir avr

    cd avr

    bunzip2 binutils-2.20.1.tar.bz2

    gnutar xvf binutils-2.20.1.tar

    cd binutils-2.20.1

 

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-300-binutils-2.20.1-avr-size

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-301-binutils-2.20.1-avr-coff

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-302-binutils-2.20.1-new-sections

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-303-binutils-2.20.1-as-dwarf

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-304-binutils-2.20.1-dwarf2-AVRStudio-workaround

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-305-binutils-2.20.1-assembler-options

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-400-binutils-2.20.1-xmega

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-401-binutils-2.20.1-new-devices

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-402-binutils-2.20.1-avrtiny10

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-403-binutils-2.20.1-xmega128a1u-64a1u

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-404-binutils-2.20.1-atxmega16x1-32x1

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-405-binutils-2.20.1-atxmega128b1

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-406-binutils-2.20.1-atxmega256a3bu

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-407-binutils-2.20.1-at90pwm161

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-408-binutils-2.20.1-atmega16hvb-32hvb

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-409-binutils-2.20.1-atmega32_5_50_90_pa

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-410-binutils-2.20.1-attiny1634

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-411-binutils-2.20.1-atmega48pa

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-500-binutils-2.20.1-bug13789

    patch -p0 < /usr/src/binutils-2.20.1-patches/patch-Makefile.in

 

    CFLAGS="-Wno-error -g -O2" ./configure --target=avr --program-prefix="avr-" --prefix=$PREFIX --disable-nls

    make

    make install

 

We download https://gmplib.org/download/gmp/... from https://gmplib.org/#DOWNLOAD

 

    cd /usr/src

    bunzip2 gmp-6.0.0a.tar.bz2

    tar xvf gmp-6.0.0a.tar

    cd gmp-6.0.0

    ./configure

    make

    make check

    make install 

 

We download mpfr from http://www.mpfr.org!

We download http://www.smartsoft.de/Download...!

 

    cd /usr/src/

    gunzip mpfr-3.1.2-patches.tar.gz

    tar xvf mpfr-3.1.2-patches.tar

 

    bunzip2 mpfr-3.1.2.tar.bz2

    tar xvf mpfr-3.1.2.tar

    cd mpfr-3.1.2

    patch -N -Z -p1 < /usr/src/mpfr-3.1.2-patches/allpatches

    ./configure

    make

    make check

    make install 

 

We download mpc from http://www.multiprecision.org/?p....

 

    cd /usr/src/

    gunzip mpc-1.0.2.tar.gz

    tar xvf mpc-1.0.2.tar

    cd mpc-1.0.2

    ./configure

    make

    make install 

 

We download http://gcc.cybermirror.org/relea...

We download http://www.smartsoft.de/Download...

 

    cd /usr/src/

    gunzip gcc-4.5.1-patches.tar.gz

    tar xvf gcc-4.5.1-patches.tar

 

    cd /usr/src/avr

    mkdir avrgcc

    bunzip2 gcc-4.5.1.tar.bz2

    tar xvf gcc-4.5.1.tar

    cd gcc-4.5.1

 

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-200-gcc-4.5.1-libiberty-Makefile.in

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-300-gcc-4.5.1-fixedpoint-3-4-2010

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-301-gcc-4.5.1-xmega-v14

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-302-gcc-4.5.1-avrtiny10

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-303-gcc-4.5.1-osmain

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-304-gcc-4.5.1-builtins-v6

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-305-gcc-4.5.1-avrtiny10-non-fixedpoint

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-306-gcc-4.5.1-option-list-devices

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-400-gcc-4.5.1-new-devices

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-401-gcc-4.5.1-atmega32_5_50_90_pa

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-402-gcc-4.5.1-attiny1634

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-403-gcc-4.5.1-atmega48pa

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-500-gcc-4.5.1-bug13473

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-501-gcc-4.5.1-bug13579

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-502-gcc-4.5.1-bug-18145-v4

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-503-gcc-4.5.1-avrtiny10-bug-12510

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-504-gcc-4.5.1-bug12915

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-505-gcc-4.5.1-bug13932

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-506-gcc-4.5.1-bug13789

    patch -p0 < /usr/src/gcc-4.5.1-patches/patch-599-gcc-4.5.1-bug46779

    cd ..

    cd avrgcc

    ../gcc-4.5.1/configure --target=avr --prefix=$PREFIX --with-gnu-ld --with-gnu-as --enable-languages="c,c++" --with-gmp=/usr/local --with-mpfr=/usr/local --disable-nls --disable-libssp --with-dwarf2

    make 

    make install

 

We download http://download.savannah.gnu.org...

 

    cd /usr/src/avr

    bunzip2 avr-libc-1.8.1.tar.bz2

    tar xvf avr-libc-1.8.1.tar

    cd avr-libc-1.8.1

    ./configure --host=avr --prefix=$PREFIX --build=`./config.guess`

    make

    make install

 

Any idea??

 

Thanks,

 

 Andreas

 

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

???

Functions

<util/delay.h>: Convenience functions for busy-wait delay loops

Functions

void _delay_ms (double __ms)

 

That's _delay_ms().  But your code uses delay_ms() with no underscore; strange.

 

Any idea??

 

Dunno.  Any warnings during build?  The program is small enough that you could generate the machine code file for inspection.

 

 

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:

???

Functions

<util/delay.h>: Convenience functions for busy-wait delay loops

Functions

void _delay_ms (double __ms)

 

That's _delay_ms().  But your code uses delay_ms() with no underscore; strange.

 

 

Sorry, I forgot to add this non-sense function to the code excerpt:

 

void delay_ms(uint16_t ms)
{
    while ( ms )
   {
    _delay_ms(1);
    ms--;
   }
}

 

 

But I doubt this is related to the problem!??

 

The serial transmit stuff works as cen be seen via the char send statements. It's accessing the string that causes the problem. But why and how?

 

Andreas

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  sbi (UCSR0B, RXCIE0);     // enable RX interrupt

So where's your ISR?

ISR(USART0_RX_vect)

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

What if you change

char String[]  = "Hello world!!"; 

to

uint8_t  String[]  = "Hello world!!"; 

 

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

Post the .lss

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

My first step would be to install a proven gcc from a respected source.

I am sure that you might have a full set of patches,   but then again,   you might not.

 

Then you should build a proven example,   and verify that everything is working properly.

 

The CODE that you have posted does not have an ISR(),   and is not buildable.

Please post a compilable minimal program that exhibits your problem.

 

David.

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

Hi all,

 

the following code should build (no ISR needed)!?

 

#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);

  }

 

My first step would be to install a proven gcc from a respected source.

 

Good idea! I changed my Makefile like so 

 

CC=/Applications/Arduino.app//Contents/Resources/Java/hardware/tools/avr/bin/avr-gcc

 

 

and rebuild the project. The problem remains!?

...

ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC

...

 

What if you change

char String[]  = "Hello world!!"; 

to

uint8_t  String[]  = "Hello world!!"; 

 

I tried that:

 

#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>

 

uint8_t  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');

            

      uint8_t *s = String;   

      while (*s != 0)

        {

         TxByte0(*s);

         s++;

        }

      

      _delay_ms(500);            

     }

   return (0);

  }

 

Same problem! I now use the avr-gcc and avrdude coming with Arduino.app (consider this a respected source). And the problem persists!??

 

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)!

 

Still clueless!?? :-(

 

Thanks a lot,

 

 Andreas

 

 

 

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

Well,   your program looks as if it should run.

 

I built it with AS4.19 and uploaded with avrdude to a Funduino Mega2560 (a Mega clone).

 

It worked just fine.

 

I would guess that you could have simply written:

void setup(void)
{
    Serial.begin(38400);
}

void loop(void)
{
    Serial.print('A');
    Serial.print('B');
    Serial.print('C');
    Serial.print('\n');
    Serial.print("Hello World !!");
}

and the Arduino would have done the business.

 

As far as I know,   there are proven packages for the Mac.    You can just build AVR-GCC programs as if you are on a regular Linux system.

 

There are also packages that enable you to run a regular Windows Studio 4.19 project.

I don't know about AS6.2 running on a Mac.    Since it is a bit flaky on Windoze,    I would be wary of running it in a Virtual Machine.   And even more wary of any Emulator.

 

But there are several Mac users here.   I am sure that they can help.

 

I would guess that you have not got the correct gcc and ld and objcopy commands.

 

David.

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

I repeat:

joeymorin wrote:
Post the .lss

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

joeymorin wrote:

I repeat:

joeymorin wrote:

Post the .lss

 

 

Hi Joey,

 

please excuse my ignorance. But what is that? All I have in my project dir is

 

-rw-r--r--   1 ahoesch  20           160 Feb 18  2010 Global.h
-rw-r--r--   1 ahoesch  other        491 Dec  3 23:12 Makefile
-rw-r--r--   1 ahoesch  20          4785 Dec  2 22:06 Serial.c
-rw-r--r--   1 ahoesch  20           590 Dec  2 21:32 Serial.h
-rw-r--r--   1 ahoesch  other          0 Nov 27 22:25 a.out
-rw-r--r--   1 ahoesch  20          1118 Dec  3 23:11 main.c
-rw-r--r--   1 ahoesch  other       1931 Dec  3 23:14 toggle_led.out

 

Thanks,

 

  Andreas

 

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

It is the listing file and shows the actual instructions that your AVR will execute.  Basically it's (sort of) a readable version the .hex file.

 

Your Makefile generates an intermediate file before spitting out the .hex file:

$(PROJECT).out: $(SOURCES)
    $(CC) $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES)

You can generate the listing file from that .out file like this:

avr-objdump -S <the_dot_out_file> > listing_file.lss

Or you could add the appropriate lines to your Makefile:

OBJDUMP=avr-objdump
DUMPFLAGS=-S

$(PROJECT).out: $(SOURCES)
    $(CC) $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES)
    $(OBJDUMP) $(DUMPFLAGS) $(PROJECT).out > $(PROJECT).lss

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Thu. Dec 4, 2014 - 03:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the following code should build (no ISR needed)!?

 

#define F_CPU 16000000UL  /* 16 MHz CPU clock */

#include "Global.h"  <== ???

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

Yes,   I should have mentioned that I commented out the "Global.h"

There did not appear to be any "global" variables that were referenced (apart from String[] )

There was no interrupt code in the source that I built.

 

I am convinced that the OP's problems come down to inappropriate GCC commands.

 

Not only do you have to find, patch, build all the GCC tools from scratch,   you also need to use the correct switches and arguments when you invoke them.    This requires quite a lot of experience (and enthusiasm).

 

It is pretty obvious that the "Hello World" has not been copied to SRAM by the crts0.o startup code.

Hence the UART just spits out whatever values happen to reside in SRAM at the location that should have been initialised.

 

THere is a similar thread where another OP has deliberately removed the C startup initialisation (for a bootloader) and then worried because his SRAM strings were not present.

 

David.

Last Edited: Thu. Dec 4, 2014 - 02:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes,   I should have mentioned that I commented out the "Global.h"

There did not appear to be any "global" variables that were referenced (apart from String[] )

Well, belts and suspenders -- OP should give us (especially in this situation) an exact complete program.  There is the possibility that macros or code in Global.h "overload" other operations.  (there is a current thread about redefining printf() for example)

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

Hi all,

 

thanks a lot for all you hints. I got this sorted out with help from the avr-gcc mailing list. My avr-gcc seems ok. The problem was the "-j .text" option given to avr-objcopy. Replacing 

 

$(PROJECT).hex: $(PROJECT).out

    $(OBJCOPY) -j .text -O ihex $(PROJECT).out $(PROJECT).hex

 

in my Makefile with

 

$(PROJECT).hex: $(PROJECT).out

    $(OBJCOPY) -R .eeprom -O ihex $(PROJECT).out $(PROJECT).hex

 

did the trick! :-)

 

The program is behaving correctly now!! Thanks a lot for your time and thoughts!!

 

Andreas

 

 

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

You GCC gurus will need to figure out why that helps.  Was the initial value of Hello world!! in EEPROM?

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

-j explicitly copies a section excluding unspecified sections.

-R explicitly removes a section.

 

So the OP is going to come back shortly with all sorts of other problems.

The GCC tools have a myriad of switches and options.   If you decide to hand-roll them,  you have to accept the consequences.

 

This is why most IDEs or commandline packages come with a skeleton Makefile.   Or a utility to configure one for yourself.

 

David.

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

ahoesch wrote:

    $(OBJCOPY) -j .text -O ihex $(PROJECT).out $(PROJECT).hex
    $(OBJCOPY) -R .eeprom -O ihex $(PROJECT).out $(PROJECT).hex

Had not looked closely at your Makefile :(

 

From the objcopy manpage:

               [-j sectionname|--only-section=sectionname]
               [-R sectionname|--remove-section=sectionname]

By including only .text, you left out .data. 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Thu. Dec 4, 2014 - 05:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

By including only .text, you left out .data. 

Which is about the oldest error in the book!

 

This is what happens when people roll their own Makefiles rather using an IDE of a template Makefile from a recognised source. As OP seems intent on using the command line rather than an IDE then I'd highly recommend:

 

http://www.sax.de/~joerg/mfile/

 

The template that provides has already considered the -j/-R issue.

 

Whether you use -j or -R is a good question. -j very specifically ensures that only the named sections go into the .hex but if you add something like ".myflashection" to the flash image then you have to remember to add it as a -j. -R could be better as it is used to specifically say what you don't want in the .hex but that could mean that if you add ".myRAMsection" it could end up going into the .hex where it's not wanted if you forget to list that in a -R.

 

Oh and if you are going the -R route then don't forget "-R .fuse -R .lock -R .signature" in current builds of code where those sections could easily be present.

 

But really, to save yourself a lot of hassle, get an IDE that already knows all about this stuff and hides the issue from you.

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

I dropped the code into AS6 & ran on my Arduino Mega2560.

 

Had to remove "Global.h", change "uint8_t" to "char", added a "TxByte0('\r');

 

I use Putty for my terminal.  Program runs fine.  Strings are as they should be.

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

jstampfl wrote:
change "uint8_t" to "char"
unsigned char actually.

 

Or just add #include <stdint.h>

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Or just add #include <stdint.h>

it's a pretty rare piece of AVR code that does not #include <avr/io.h> and that includes <stdint.h>. So uint8_t etc. should just be available anyway.

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

True enough!

 

Why @jstampfl felt the need to switch from uint8_t to char is mysterious...

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

mysterious to me also.

 

I tried to recreate, but when I put the code in AS6 and deleted "Global.h".  Compiled cleanly.  Why it was giving an error on the statements I changed I don't know.  But the first attempt to compile I was getting an error on those statements.

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

Figured out what happened.  After I dropped the code into AS6, I had 3 errors compiling.  The second & third errors were complaining about the uint8_t which I changed to char and those errors went away.  The first error was a funny listing saying something was expected.  Turned out that the first "/*" was missing the "/".  Replaced the "/" and all was well, but I didn't think about changiing back the char to uint8_t.