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.