Help create maxSize sketch

So I would like a general purpose sketch that can fill the flash memory on a sketch to near maximum size just to test reliablity of uploading large sketches. So I though maybe just a modified blink sketch with just a array defined with different sizes for the various AVR chips, see code comments below. I know the exact size has to take into consideration the size of the bootloader so it doesn't have to be exactly full size minus bootloader size, just use numbers that allow for a maximum size bootloader perhaps?

However I need to force the array to be created and initilized in flash and I've not done that before, so can someone show me how to create the array declaration such that it gets stored into Flash? Thanks.

Lefty

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// make size = to xxxx for 328 chip, yyyy for 1280 chip, zzzz for 2560 chip, etc.
const int size= 6000;  // value to fill avalible flash capacity
long myInts[size];  // How to force array to be stored in flash?

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

It might be sufficient to declare the array PROGMEM.

 #include <avr/pgmspace.h>
// make size = to xxxx for 328 chip, yyyy for 1280 chip, zzzz for 2560 chip, etc.
const int size= 6000;  // value to fill avalible flash capacity
long myInts[size] PROGMEM;

johnwasser:
It might be sufficient to declare the array PROGMEM.

 #include <avr/pgmspace.h>

// make size = to xxxx for 328 chip, yyyy for 1280 chip, zzzz for 2560 chip, etc.
const int size= 6000;  // value to fill avalible flash capacity
long myInts[size] PROGMEM;

Thanks, it compiles but that doesn't seem to effect the sketch size when verified so it's not going to flash, just SRAM I believe.

Lefty

This works:

#include <avr/pgmspace.h>

#define TEN_VALUES 1,2,3,4,5,6,7,8,9,10
#define HUNDRED_VALUES TEN_VALUES, TEN_VALUES, TEN_VALUES, TEN_VALUES, TEN_VALUES, TEN_VALUES, TEN_VALUES, TEN_VALUES, TEN_VALUES, TEN_VALUES
#define THOUSAND_VALUES HUNDRED_VALUES, HUNDRED_VALUES, HUNDRED_VALUES, HUNDRED_VALUES, HUNDRED_VALUES, HUNDRED_VALUES, HUNDRED_VALUES, HUNDRED_VALUES, HUNDRED_VALUES, HUNDRED_VALUES

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// make size = to xxxx for 328 chip, yyyy for 1280 chip, zzzz for 2560 chip, etc.
const int arraysize= 6000;  // value to fill avalible flash capacity
long myInts[arraysize] PROGMEM = {
  THOUSAND_VALUES, THOUSAND_VALUES, THOUSAND_VALUES, THOUSAND_VALUES, THOUSAND_VALUES, THOUSAND_VALUES };

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  int i = random(0,arraysize);  // Work around any optimization for constant values
  Serial.print(myInts[i]);         //  Access some random element so the array can't be optimized away.
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Binary sketch size: 27,018 bytes (of a 32,256 byte maximum)

Yes, it works but I don't have a clue what size array it is building based on the arraysize integer and all those defines are very confusing to me?

Care to explain?

Thanks;
Lefty

I don't have a clue what size array it is building

The TEN_VALUES name resolves to, not surprisingly, 10 values.

The HUNDRED_VALUES name resolves to 100 values (10 instances of 10 values).

The THOUSAND_VALUES name resolves to 1000 values.

PaulS:

I don't have a clue what size array it is building

The TEN_VALUES name resolves to, not surprisingly, 10 values.

The HUNDRED_VALUES name resolves to 100 values (10 instances of 10 values).

The THOUSAND_VALUES name resolves to 1000 values.

Ok, but in context of what I was trying to build is there not a simpler way to specify how large an array to build, so that it can be easily adjusted at compile time for different size chips by changing just a single value?

Lefty

Ok the below seems to work fine by just adjusting the arraysize constant without needing all those defines.
If I make arraysize too big for the board selected it complains when verifying so that seems to be a good way to go? Is there something fundamentally wrong with the below?

Lefty

#include <avr/pgmspace.h>

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// make arraysize = to xxxx for 328 chip, yyyy for 1280 chip, zzzz for 2560 chip, etc.
const int arraysize= 7000;  // value to fill avalible flash capacity

long myInts[arraysize] PROGMEM = {arraysize};
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  int i = random(0,arraysize);  // Work around any optimization for constant values
  Serial.print(myInts[i]);         //  Access some random element so the array can't be optimized away.
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

I (sort of) have one of those. Be back in a minute...

TinyISP_31K.ino (195 KB)

Error 503 Service Unavailable
Service Unavailable
Guru Meditation:
XID: 1098813109
Varnish cache server

Argh! Stupid Guru!

Be back in a few minutes...

maybe declare the progmem array volatile?

This will have to do...
http://www.zygomorphic.com/Arduino/TinyISP_31K.ino

I believe avrdude skips blocks of 0xFF so I filled the array (RandomJunk) with random data.

Commenting-out elements to trim the array is a bit crude but it works.

The only point of the calculation is to force the compiler to include the array.

long myInts[arraysize] PROGMEM = {arraysize};

I'm not sure what advantage there is in initializing the first element of the array to the size of the array.

PaulS:

long myInts[arraysize] PROGMEM = {arraysize};

I'm not sure what advantage there is in initializing the first element of the array to the size of the array.

It's not like I know what I'm doing, but it lets me change one variable, arraysize, to fill to different sketch sizes. It compiles and uploads, unless arraysize is too big and then it complains.

So simplify it for me.

Lefty

So simplify it for me.

There's nothing wrong with it. It's just strange to create an array with 7000 elements in it, and initialize the first one to 7000 and the other 6,999 to 0.

This works to fill 32254 of the 32256 bytes available on the UNO:

#include <avr/pgmspace.h>

// make size = to xxxx for 328 chip, yyyy for 1280 chip, zzzz for 2560 chip, etc.
const int arraysize= 7733;  // value to fill avalible flash capacity
volatile long myInts[arraysize] PROGMEM;

void setup() {   
}

// the loop routine runs over and over again forever:
void loop() {
  int i = random(0,arraysize);  // Work around any optimization for constant values
  use(myInts[i]);         //  Access some random element so the array can't be optimized away.
  delay(1000);               // wait for a second
}

long use(long x) {
  return x;
}

Thanks guys.

Interesting side effect I can compile sizes that are under the max avalible flash size for the board selected, but the upload will upchuck with an AVRDUDE error. If I lower if a few KB then it both compiles and uploads and runs fine.

Really doesn't matter, I just wanted an easy way to create large sketch sizes for testing purposes and what I got works well enough as is.

Lefty

retrolefty:
Interesting side effect I can compile sizes that are under the max avalible flash size for the board selected, but the upload will upchuck with an AVRDUDE error. If I lower if a few KB then it both compiles and uploads and runs fine.

I had the same problem. Turned out to be an old bug in Optiboot. Installing the latest version solved the problem.

I figured it was bootloader related. The worst are my older mega1280 boards (one arduino mega1280 and one early Seeeduino mega1280 board), I can't go much above 69KB before AVRDUDE pukes after uploading all the data. I haven't been able to locate a optiboot for the mega1280 board nor the changes to the boards.txt if would take to run it if I located it. Now my 644P loads up real close to the flash limit without complaint.

Is the Optiboot that is distributed with IDE 1.0.3 the latest all fixed version?

Lefty

retrolefty:
Is the Optiboot that is distributed with IDE 1.0.3 the latest all fixed version?

Yes. The most recent version was introduced with IDE 1.0. The Optiboot version to look for is 4.4.