Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Re: [AVR-Chat] Debugging ATMega16

Re: [AVR-Chat] Debugging ATMega16

2005-04-14 by Ivan Vernot


----- Original Message -----
From: "Chuck Hackett" <egroupscdh@WhiteTrout.net>
To: <AVR-Chat@yahoogroups.com>
Sent: Friday, April 15, 2005 6:15 AM
Subject: [AVR-Chat] Debugging ATMega16


>
> I'm debugging a program that I did not create. I'm using AVRStudio.
General
> questions:
>
> 1) Is there a way to display the current call-chain (i.e.: stack trace)
Not with the JTAGICE (you need the ICE50 for that - but there have been
people in this group saying they the ICE50 is very unstable/buggy)

> 2) What's the easiest way to determine if the stack is overwriting static
data
Easy? Nothing is easy in embeede systems ;-)
What I do is write a sentile byte at the end of memoery (bottom of stack)
and the check if the the sentile byte has been overwritten.
This can be done by sprinkling checks around 'suspicions call paths' or, as
a firts pass each time though the main loop (I am assuming you are not using
a multi-trasking executive). This is by no means foolproof but its better
than nothing.
If you are really stuck (and pretty certain that you are over writing the
stack) you might setup a timer ISR and check the sentinal byte 'at regular
intervals'.
The problem with this, of course, is that it is quite invasive to your code
and may change timing enough to change the symptoms. Good Luck!

A better approach might be to strip back the code and re-test in smaller
chunks


> 3) AVRStudio is displaying things (watch window, etc.) in decimal and
ASCII.
> Can I add/change it to hex through a global setting? Or, how does one
view
> variable data in hex?

Right click on the watch window and select 'Display All Values in Hex' (NB:
this is a 'toggle selection')

>
> Program specific (gcc 3.4.3)

Sorry can't help - I am a happy Imagecraft C User.

Cheers,
Ivan Vernot
www.realtimedesigns.com.au
>

> When I added a call to "fdevopen( uart_putchar, NULL, 0 );" (see
"uart_putchar"
> below) to allow using the (existing, written for ImageCraft's compiler)
> "printf"'s the symptoms changed in strange ways (program not getting as
far as
> it did, new interrupts occurring) depending on parts I commented out of
> "sendchar" (see below). If I used "Code 1" (non-interrupt driven) the
code
> executed differently than if I used "Code 2" (interrupt driven) even
though
> neither "sendchar" or "uart_putchar" were never executed (I had a
breakpoint
> there).
>
> To better describe the symptoms I would have to go into greater depth but
> without you having to get too deep into the code - are there bugs that
show
> up/change when the code size changes (see "Size" info below)?
>
> Thanks in advance for any assistance.
>
> Cheers,
>
> Chuck Hackett
> "Good judgment comes from experience, experience comes from bad judgment"
> 7.5" gauge Union Pacific Northern (4-8-4) 844
> http://www.whitetrout.net/Chuck
>
>
> ---------- Code ----------
>
> int sendchar( int data )
> {
> unsigned char tmphead;
>
> //* Code 1
> loop_until_bit_is_set(UCSRA, UDRE);
> UDR = data;
> //* End Code 1
>
> //* Code 2
> /* calculate buffer index */
> tmphead = ( USART_TxHead + 1 ) & USART_TX_BUFFER_MASK;
> /* wait for free space in buffer */
> while ( tmphead == USART_TxTail );
> /* store data in buffer */
> USART_TxBuf[tmphead] = (unsigned char)data;
> USART_TxHead = tmphead; /* store new index */
>
> UCSRB |= (1< > //* End Code 2
>
> return data;
> }
>
> /*
> * Redirect STDIO to USART
> */
> int uart_putchar(char c)
> {
>
> if (c == '\n')
> sendchar('\r');
> sendchar( c );
> return 0;
> }
>
> ------ Size info from gcc tools ------
>
> Size after:
> easyavr_acix.elf :
> section size addr
> .text 12352 0
> .data 210 8388704
> .bss 379 8388914
> .noinit 0 8389293
> .eeprom 0 8454144
> .debug_aranges 20 0
> .debug_pubnames 1409 0
> .debug_info 2946 0
> .debug_abbrev 349 0
> .debug_line 4053 0
> .debug_str 1239 0
> Total 22957
>
>
> AVR Memory Usage:
> -----------------
> Device: atmega16
>
> Program: 12562 bytes (76.7% Full)
> (.text + .data + .bootloader)
>
> Data: 589 bytes (57.5% Full)
> (.data + .bss + .noinit)
>
>
> -------- end --------
>
>
> > Process Exit Code: 0
>
>
>
>
>
> Yahoo! Groups Links
>
> <*> To visit your group on the web, go to:
> http://groups.yahoo.com/group/AVR-Chat/
>
> <*> To unsubscribe from this group, send an email to:
> AVR-Chat-unsubscribe@yahoogroups.com
>
> <*> Your use of Yahoo! Groups is subject to:
> http://docs.yahoo.com/info/terms/
>
>
>
>
>


MSGTAG has notified the sender that you have read this message.

Re: [AVR-Chat] Debugging ATMega16

2005-04-14 by Ivan Vernot

Arghh, I am lost without the spell checker!! (sorry) Why is it that OE does not automatically spell check some emails (I have is set to spell check before sending but clearly the previous email did not get checked.
FWIW - Corrections are below.
I
----- Original Message -----
Show quoted textHide quoted text
Sent: Friday, April 15, 2005 9:38 AM
Subject: Re: [AVR-Chat] Debugging ATMega16


----- Original Message -----
From: "Chuck Hackett" <egroupscdh@WhiteTrout.net>
To: <AVR-Chat@yahoogroups.com>
Sent: Friday, April 15, 2005 6:15 AM
Subject: [AVR-Chat] Debugging ATMega16


>
> I'm debugging a program that I did not create. I'm using AVRStudio.
General
> questions:
>
> 1) Is there a way to display the current call-chain (i.e.: stack trace)
Not with the JTAGICE (you need the ICE50 for that - but there have been
people in this group saying they the ICE50 is very unstable/buggy)

> 2) What's the easiest way to determine if the stack is overwriting static
data
Easy? Nothing is easy in embedded systems ;-)
What I do, is write a sentinel byte at the end of memory (bottom of stack)
and then check if the sentinel byte has been overwritten.
This can be done by sprinkling checks around 'suspicions call paths' or, as
a first pass, each time though the main loop (I am assuming you are not using
a multi-tasking executive). This is by no means foolproof but its better
than nothing...
If you are really stuck (and pretty certain that you _are_ over writing the
stack) you might setup a timer ISR and check the sentinel byte 'at regular
intervals' in the ISR.
The problem with this, of course, is that it is quite invasive to your code
and may change timing enough to change the symptoms. Good Luck!

A better approach might be to strip back the code and re-test in smaller
chunks


> 3) AVRStudio is displaying things (watch window, etc.) in decimal and
ASCII.
> Can I add/change it to hex through a global setting? Or, how does one
view
> variable data in hex?

Right-click on the watch window and select 'Display All Values in Hex' (NB:
this is a 'toggle selection')

>
> Program specific (gcc 3.4.3)

Sorry can't help - I am a happy Imagecraft C User.

Cheers,
Ivan Vernot
www.realtimedesigns.com.au
>;

> When I added a call to "fdevopen( uart_putchar, NULL, 0 );" (see
"uart_putchar"
> below) to allow using the (existing, written for ImageCraft's compiler)
> "printf"'s the symptoms changed in strange ways (program not getting as
far as
> it did, new interrupts occurring) depending on parts I commented out of
> "sendchar" (see below). If I used "Code 1" (non-interrupt driven) the
code
> executed differently than if I used "Code 2" (interrupt driven) even
though
> neither "sendchar" or "uart_putchar" were never executed (I had a
breakpoint
> there).
>
> To better describe the symptoms I would have to go into greater depth but
> without you having to get too deep into the code - are there bugs that
show
> up/change when the code size changes (see "Size" info below)?
>
> Thanks in advance for any assistance.
>
> Cheers,
>
> Chuck Hackett
> "Good judgment comes from experience, experience comes from bad judgment"
> 7.5" gauge Union Pacific Northern (4-8-4) 844
> http://www.whitetrout.net/Chuck
>
>
> ---------- Code ----------
>
> int sendchar( int data )
> {
> unsigned char tmphead;
>
> //* Code 1
> loop_until_bit_is_set(UCSRA, UDRE);
> UDR = data;
> //* End Code 1
>
> //* Code 2
> /* calculate buffer index */
> tmphead = ( USART_TxHead + 1 ) & USART_TX_BUFFER_MASK;
> /* wait for free space in buffer */
> while ( tmphead == USART_TxTail );
> /* store data in buffer */
> USART_TxBuf[tmphead] = (unsigned char)data;
> USART_TxHead = tmphead; /* store new index */
>
> UCSRB |= (1<> //* End Code 2
>
> return data;
> }
>
> /*
> * Redirect STDIO to USART
> */
> int uart_putchar(char c)
> {
>
> if (c == '\n')
> sendchar('\r');
> sendchar( c );
> return 0;
> }
>
> ------ Size info from gcc tools ------
>
> Size after:
> easyavr_acix.elf :
> section size addr
> .text 12352 0
> .data 210 8388704
> .bss 379 8388914
> .noinit 0 8389293
> .eeprom 0 8454144
> .debug_aranges 20 0
> .debug_pubnames 1409 0
> .debug_info 2946 0
> .debug_abbrev 349 0
> .debug_line 4053 0
> .debug_str 1239 ; 0
> Total 22957
>
>
> AVR Memory Usage:
> -----------------
> Device: atmega16
>
> Program: 12562 bytes (76.7% Full)
> (.text + .data + .bootloader)
>
> Data: 589 bytes (57.5% Full)
> (.data + .bss + .noinit)
>
>
> -------- end --------
>
>
> > Process Exit Code: 0
>
>
>
>
>
> Yahoo! Groups Links
>
> <*> To visit your group on the web, go to:
> http://groups.yahoo.com/group/AVR-Chat/
>
> <*> To unsubscribe from this group, send an email to:
> AVR-Chat-unsubscribe@yahoogroups.com
>
> <*> Your use of Yahoo! Groups is subject to:
> http://docs.yahoo.com/info/terms/
>
>
>
>
>


MSGTAG has notified the sender that you have read this message.

MSGTAG has notified the sender that you have read this message.

Re: [AVR-Chat] Debugging ATMega16

2005-04-15 by John Samperi

At 09:43 AM 15/04/2005, you wrote:
>Arghh, I am lost without the spell checker!!
>What I do, is write a sentinel (was sentile) byte at the end of memory

Well....I knew what you meant 8-) but then again I'm the world's
pest smeller. After having used Eudora for about 10 years, I felt
sorry for them and gave them some money, so as of yesterday, I
now have a functioning spiel checker so I KNOW there are no
smelling mistakes in my email.

I usually clear all memory at start up (assembler person here), so
if I don't see lots of 00 bytes towards the top of ram then I know
something is fishy. Studio does have some form of stack monitor
but it only "works" with some tools not all IIRC.

>Sorry can't help - I am a happy Imagecraft C User.

You will be absolutely ecstatic to know that, earlier this week,
I installed the ICCavr thingy from the CD we got at the seminar.
Now that I have a Mega64 (or 128) board and a JTAGICE I may be
able to get the 'Hello world!" program working in C. :-)

Regards

John Samperi

******************************************************
                         Ampertronics Pty. Ltd.
   11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
          Tel. (02) 9674-6495       Fax (02) 9674-8745
                Email: samperi@ampertronics.com.au
                  Website  http://www.ampertronics.com.au
* Electronic Design   * Custom Products   * Contract Assembly
******************************************************

RE: [AVR-Chat] Debugging ATMega16

2005-04-15 by Chuck Hackett

> From: Ivan Vernot
> 
> > ....
> > 1) Is there a way to display the current call-chain (i.e.: stack trace)
> Not with the JTAGICE (you need the ICE50 for that - but there have been
> people in this group saying they the ICE50 is very unstable/buggy)

Strange, I thought stack trace back was a standard feature of symbolic
debuggers.  Is there something about AVRs that makes this difficult?

> > 2) What's the easiest way to determine if the stack is overwriting static
> data
> Easy? Nothing is easy in embeede systems ;-)
> What I do is write a sentile byte at the end of memoery (bottom of stack)
> and the check if the the sentile byte has been overwritten.

That was my thought but, since I'm new to AVR I thought I'd ask.

> > ....
> > 3) AVRStudio is displaying things (watch window, etc.) in decimal and
> ASCII.
> > Can I add/change it to hex through a global setting?  Or, how does one
> view
> > variable data in hex?
> 
> Right click on the watch window and select 'Display All Values in Hex' (NB:
> this is a 'toggle selection')

Thanks for that ...

BTW: I checked out your web site.  Can you briefly describe the "RTD Serial
Protocol Analyser" and "RTD SIP Simulator/Analyser" programs you have on your
download page?  RTD => as in Temperature Sensor?

I've been to Australia twice - great place you have there ...

Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Compilers (was: Debugging ATMega16)

2005-04-15 by Chuck Hackett

Well, I discovered part of my problem.  The program I'm working with was
originally written for the ImageCraft C compiler and I'm using WinAVR(gcc).  I
tried to convert everything as well as I could but apparently something I don't
understand is going on because I downloaded the trial version of ImageCraft V7
today and the program ran the first time!  I'm thinking that it has something to
do with the differences in support for stdout (usart) but I haven't nailed it
down.

So, I'm re-evaluating what compiler to use.  I realize that this issue is
somewhat "religious" in nature but I have to ask.  Considering:

CodeVision

ImageCraft

WinAVR

Which would/did you pick and why?  What, in your mind, are the advantages and
disadvantages of each?  Features, library completeness, documentation, help
system, support, usefulness of available user forums, etc.

I know WinAVR is free but the cost of ImageCraft ($199) and CodeVision ($150)
seem reasonable if justified in support, features, etc.

BTW: I'm programming in a Windows XP environment and have AVRSTudio and an
STK500 and JTAG ICE-Cube.  I want to be able to use the full AVR line from TINY
to MEGA.  I'll do 90% in C but may need bits of code in assembler some day.

Thanks in advance for any guidance you may be able to provide.

Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Re: [AVR-Chat] Debugging ATMega16

2005-04-16 by Ivan Vernot


----- Original Message -----
From: "John Samperi" <samperi@ampertronics.com.au>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, April 16, 2005 9:02 AM
Subject: Re: [AVR-Chat] Debugging ATMega16


>
> >Sorry can't help - I am a happy Imagecraft C User.
>
> You will be absolutely ecstatic

Well I suspect that Les Grant might me more excited than I (he's the local
Imagecraft disty) ;-)

> to know that, earlier this week,
> I installed the ICCavr thingy from the CD we got at the seminar.

Welcome to the dark side.... (muhaaa...) (hehe)

> Now that I have a Mega64 (or 128) board and a JTAGICE I may be
> able to get the 'Hello world!" program working in C. :-)

easy.. done if four lines
void main(void)
{
puts("Hello World");
}
done!
but - oh wait...

Need to setup
- I/O
- Timers
- ISRs
- UARTs
- ADCs
- Implement the int putch(int ch) function (so puts() works)
- Enable the watchdog .. etc, etc,etc

If won't take long to fill that 64K you have John. ;-)

Just joking, I think you will be pleasantly surprised how compact the code
ends up.

A couple of hits,
1. It is a good idea to look at the generated output listings to get an idea
of how different C statements affect code generation
A few to look at are -
while() vs for()
++i vs i--
arry[idx] vs *(ptr+idx)
switch vs multiple ifs

2. Don't look at the output listing (yes I know that it contradicts 1. ) as
it will constantly frustrate you how dumb the complier can be
("Why is if reloading R6 again - it R6 _already_ contains the value that is
needed? I wouldn't do that in ASM!)

Be content (trust ;-)) that in the big picture (ie over the entire
application) the code size of a reasonably written C program is within
5%-20% (depending on who you believe) of a reasonably written ASM program.

Oh oh - I've really opened myself up for flaming here ;-)
So I'll stop right now before I get myself into a 'religious' C vs ASM war.
;-)

Cheers,
Ivan

PS. If you get stuck let me know if I can be of help.






>
> Regards
>
> John Samperi
>
> ******************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495 Fax (02) 9674-8745
> Email: samperi@ampertronics.com.au
> Website http://www.ampertronics.com.au
> * Electronic Design * Custom Products * Contract Assembly
> ******************************************************
>
>
>
>
>
> Yahoo! Groups Links
>
> <*> To visit your group on the web, go to:
> http://groups.yahoo.com/group/AVR-Chat/
>
> <*> To unsubscribe from this group, send an email to:
> AVR-Chat-unsubscribe@yahoogroups.com
>
> <*> Your use of Yahoo! Groups is subject to:
> http://docs.yahoo.com/info/terms/
>
>
>
>
>


MSGTAG has notified the sender that you have read this message.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.