Data in program memory breaks simulator but works on real 3216

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

Hi everybody

 

I'm working on a project with an ATtiny3216 that involves a lot of lookup tables and for the past few days now I've been stumped with this problem.

Storing my data in flash causes the simulator to no longer function properly and no longer hit my breakpoints however on a real chip everything works as expected. I want to (for now) store 8192 bytes of data, reducing this to 7168 bytes makes it function properly again. When you pause the simulator it seems to be executing the data in the array! It's great that it works on a real chip but I'd really like to know if I'm doing something wrong here or if the simulator is at fault?

 

Out of curiosity I've tried changing where the data is stored in program memory but I've not been successful in that. I'm using Atmel Studio 7 with the built in simulator.

 

Example code: 

#include <avr/interrupt.h>

uint16_t dummyCounter;
int8_t dummyValue;
const __flash int8_t data[8192] = {};	//Works on real hardware but not the simulator
//const __flash int8_t data[7168] = {};   //Works on simulator and real hardware

//Set breakpoint in ISR to test.
ISR(TCB0_INT_vect) {
        TCB0.INTFLAGS = TCB_CAPT_bm;
	dummyCounter++;
	dummyValue = data[dummyCounter];
}

int main(void)
{
	TCB0.CTRLA = TCB_ENABLE_bm;
	TCB0.CCMP = 600;
	TCB0.INTCTRL = TCB_CAPT_bm;
	sei();

	while (1)
	{

	}
}

To see this behavior set a breakpoint in the ISR and switch which line is commented out to see the difference.

This topic has a solution.
Last Edited: Sun. Dec 8, 2019 - 12:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have that much flash space? The only obvious difference is array size.

 

Also, dummyCounter and dummyValue MUST be spec'd as "volatile".

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

The ATtiny 3216 has 32KB of flash so it should be more than sufficient, I have also tested that the chip is actually able to read the data, it's just the simulator that's not playing along!

 

You're right about the dummy variables, it doesn't have any effect on the problem though sadly. Thanks for taking a look!

Last Edited: Fri. Dec 6, 2019 - 08:32 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> the simulator

 

That doesn't narrow it down- Atmel Studio? MPLABX? Something else?

 

That code simulates ok in MPLABX, and the only limit to the array size in this case is flash size.

 

You also do not need the __flash attribute, as flash can be read without lpm on the avr0/1. The use of 'const' gets the var into the .rodata section, which is flash, and any access uses its data space mapped address.

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

I should've included what environment I am using (Atmel Studio 7), I've added it now.

 

Removing the __flash does indeed make it function in both the simulator and on real hardware.

I also noticed in the map file it is now putting the data at a different adress, it is still a mystery to me why with __flash it would work on one but not the other.

 

Thank you for the information, I clearly have a lot more reading to do on the subject.

Last Edited: Sat. Dec 7, 2019 - 12:15 AM