Yahoo Groups archive

AVR-Chat

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

Thread

Debugging ATMega16

Debugging ATMega16

2005-04-14 by Chuck Hackett

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)
2) What's the easiest way to determine if the stack is overwriting static data
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?

Program specific (gcc 3.4.3)

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<<UDRIE);            /* enable UDRE interrupt */
//* 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

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.