Pumpkin, Inc.

Pumpkin User Forums

AVR simulator: excessive stack overflow

For issues specific to Atmel's AVR and MegaAVR microcontrollers, including Atmel AVRStudio and ImageCraft's ICCAVR C compiler.

AVR simulator: excessive stack overflow

Postby alexswiss » Thu Dec 07, 2006 1:10 am

I am using the winAVR with AVR studio 4.12.
The simulator seems to run fine with Salvo light and step through the code, it all seems to run like I would at the top level.
It enables an ADC and then wait for the interrupt to read the result.

However, after some time, the simulator crashes at 26000us with excessive stack overflow.

If I remove the OStaskcreate call, it runs forever and so it is not a simulator limitation.

Any help would be much appreciated.

Alex
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include "isr.h"
//#include "eeprom.h"

#include "salvo.h"

#define TASK_MEASURE_P OSTCBP(1) /* task #1 */
#define PRIO_MEASURE 10 /* task priorities*/
#define BINSEM_ADCRDY_P OSECBP(1) /* binSem #1 */

#define PORT PORTD


#define Init() do { TCCR1B = 0x00; /* Stop Timer1 */
TCNT1H = 0x00; /* Clear Timer1 */
OCR1AH = 0x00; /* Set Compare A to 39 */
OCR1AL = 0x26; /* ((4MHz/1024)/39) = 10ms (9.984ms) timer */
TIMSK = 0x40; /* Compare A Interrupt enable */
TCCR1B = 0x0D; /* Start Timer1 with clk/1024 */
} while (0)

/*
* Bits that are set inside interrupt routines, and watched outside in
* the program's main loop.
*/
volatile struct
{
uint8_t tmr_int: 1;
uint8_t adc_int: 1;
uint8_t rx_int: 1;
}
intflags;

unsigned int counter;
char temp;

/* global variables for main program */
/* Store all monitored paramters */
unsigned int voltage;
signed int temperature;
unsigned int rssi[3];
unsigned int bias[3];


/*
* Last value read from ADC.
*/
volatile uint16_t adcval;


_OSLabel(TaskMeasurel)


void TaskMeasure( void )
{
ADCSRA = (1<<ADEN) | (0<< ADSC) | (0<<ADFR) | (0<<ADIF) | (0<<ADIE) | (0b111);


for (;;) {
/* Measure Voltage */
ADMUX = (0<<REFS1) | (1<< REFS0) | (1<<ADLAR) | (0 << MUX3) | (0 << MUX2) |(0 << MUX1) |(1 << MUX0);
/* write ADSCR to start conversion */
ADCSRA |= _BV(ADSC);// | _BV(ADIE);
// OS_WaitBinSem(BINSEM_ADCRDY_P, OSNO_TIMEOUT, TaskMeasurel);
/* return from interrupt with new measurement */
// voltage = adcval;
OS_Yield (TaskMeasurel);

}
}


int main( void )
{

/* Initialize the processor */
Init ();


/* Initialize the OS */
OSInit();

/* Create all tasks */
//OSCreateTask(TaskMeasure, TASK_MEASURE_P, PRIO_MEASURE);

/* Create semaphores */

OSCreateBinSem(BINSEM_ADCRDY_P, 0);



/* Enable interrupt processing */

OSEi();

/* Run the scheduler */

for (;;)
OSSched();
}

#include "isr.h"
#include <salvo.h>
#define BINSEM_ADCRDY_P OSECBP(1) /* binSem #1 */

#if defined(USE_INTERRUPTS)

#if defined(SYSY) /* AVR + AVR-GCC */

SIGNAL(SIG_OUTPUT_COMPARE1A)
{
OSTimer();
}

/* Other interrupts handlers are here */

SIGNAL(SIG_ADC)
{
ADCSRA &= ~_BV(ADIE); // disable interrupt
// OSSignalBinSem(BINSEM_ADCRDY_P);
}


#else /* SYS* not defined */
#error Undefined Salvo test system (SYS*). Definition required.

#endif

#endif

#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_CONFIG OSA

#define OSEVENTS 1
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 3

#define USE_INTERRUPTS TRUE
#define SYSY TRUE

[This message has been edited by alexswiss (edited December 07, 2006).]

alexswiss
 
Posts: 4
Joined: Thu Dec 07, 2006 12:00 am
Location: Switzerland

Re: AVR simulator: excessive stack overflow

Postby aek » Thu Dec 07, 2006 2:39 am

Code looks fine -- which compiler? AVR-GCC?

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: AVR simulator: excessive stack overflow

Postby aek » Thu Dec 07, 2006 2:39 am

And which part?

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: AVR simulator: excessive stack overflow

Postby alexswiss » Fri Dec 08, 2006 4:34 am

Thanks. I sent it.

Alex

alexswiss
 
Posts: 4
Joined: Thu Dec 07, 2006 12:00 am
Location: Switzerland

Re: AVR simulator: excessive stack overflow

Postby alexswiss » Fri Dec 08, 2006 12:19 pm

Yes, winavr gcc-avr.

I assume when you ask which part, you mean where the code explodes.

It dies in part of the salvo code that I don't have source to.
The part to uncomment to see it die is the
OStaskcreate.

Just some random address as far as I can tell.

Otherwise, the code step through the code exactly as I would expect. Post a request to measure the ADC and wait for interrupt and then read the value from the global variable.

Only after it does it a bunch of times, it dies.

Mysterious.

Alex

[This message has been edited by alexswiss (edited December 08, 2006).]

alexswiss
 
Posts: 4
Joined: Thu Dec 07, 2006 12:00 am
Location: Switzerland

Re: AVR simulator: excessive stack overflow

Postby aek » Fri Dec 08, 2006 12:24 pm

No, I mean which AVR is your target processor?

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: AVR simulator: excessive stack overflow

Postby alexswiss » Fri Dec 08, 2006 12:30 pm

atmega8 at 4MHz
alexswiss
 
Posts: 4
Joined: Thu Dec 07, 2006 12:00 am
Location: Switzerland

Re: AVR simulator: excessive stack overflow

Postby aek » Fri Dec 08, 2006 12:35 pm

please zip the whole project and email it to support -- we'll take a look at it.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: AVR simulator: excessive stack overflow

Postby aek » Sat Dec 09, 2006 3:13 am

It's not a Salvo issue, it appears ...

When I disable your ADC ISR by commenting out the | _BV(ADIE) line in TaskMeasure(), it never crashes.

If I enable the ADC ISR via that line in TaskMeasure(), it never reaches it. Instead, the application resets and restarts in main. This usually means that the code vectored to an unsupported / empty ISR due to an interrupt.

However, I also noticed that OSTimer() is never being called (even when I disable the ADC ISR).

This tells me that Init() is not correct for the ATmega8. It is correct for the AT90S8515, which is what the project in http://www.pumpkininc.com/salvo/lite/avr/3.2/tu5_WinAVR.zip was built for.

So fix the Init() for at ATmega8, get the calls to OSTimer() to work, and then figure out why the ADC ISR is never reached if it is enabled.

IOW, there is some code in your app that is correct for the AT90S8515 but not for the ATmega8. Since the example project doesn't crash when built for an ATmega8 (it runs forever, but it doesn't call OSTimer()), this points to a need for slightly different Init() code for the ATmega8.

When you have a good Init() for the ATMega8 please post it here ...

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: AVR simulator: excessive stack overflow

Postby aek » Thu Dec 14, 2006 9:34 am

Hi Alex.

I am able to reproduce the problem -- it is very strange. I think it's a simulator issue ...

1) Do you have an actual part to test on? Like an ATmega8? If possible, can you put a very simple Salvo program on it and see if it runs?

2) Here's what I have found. On an extremely simple application, like

code:
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>

#include "salvo.h"

#define TASK_MEASURE_P OSTCBP(1) /* task #1 */
#define PRIO_MEASURE 10 /* task priorities*/
#define BINSEM_ADCRDY_P OSECBP(1) /* binSem #1 */

_OSLabel(TaskMeasurel)

void TaskMeasure( void )
{
for (;;)
{
OS_Yield(TaskMeasurel);
}
}


int main( void )
{
OSInit();

OSCreateTask(TaskMeasure, TASK_MEASURE_P, PRIO_MEASURE);

for (;;)
{
OSSched();
}
}


the following behavior is observed in the simulator when a breakpoint is placed on the OS_Yield() call with a "Break execution after 10000" property:
code:

Target RAM comment
------- ------ --------
ATmega8515 544 bytes works forever
ATmega8 1 kByte crash after 511
ATmega88 1 kByte crash after 511
ATmega16 1 kByte crash after 511
ATmega32 2 kByte crash after 1023
ATmega64 4 kByte works forever


By "crash" I mean that you get an error like

code:
14-Dec-2006 22:45:36  AVR Simulator: Excessive stack overflow, stop sim

By "works forever" I mean that the application never resets -- it just keeps going (properly).

In the simulator, there is no indication as to why the crash happens. The SP is fine, all the other registers are fine, RAM is fine, SR is fine, etc. It simply dies. Note that it dies at exactly 2xRAM size. This makes me think that it is related to the simulator ... at this point I have run out of ideas.

I can check if it crashes in another simulator (IAR) next ...

------------------

[This message has been edited by aek (edited December 14, 2006).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Next

Return to Atmel AVR and MegaAVR

Who is online

Users browsing this forum: No registered users and 2 guests

cron