Pages: 1 [2] 3   Go Down
Author Topic: Help create maxSize sketch  (Read 1396 times)
0 Members and 1 Guest are viewing this topic.
Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8975
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This works to fill 32254 of the 32256 bytes available on the UNO:
Code:
#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;
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: January 17, 2013, 07:04:31 pm by retrolefty » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 17, 2013, 08:07:00 pm by Coding Badly » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


I can't help with mega1280 boards.
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 76
Posts: 2247
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have whipped up a quick sketch I'll let you play with,

at the moment, it creates a 30k progmem block.

Code:
#define nothing

template< uint64_t C, typename T >
  struct LargeStruct{
    T Data;
    LargeStruct< C - 1, T > Next;
};
template< typename T > struct LargeStruct< 0, T >{ };

typedef LargeStruct< 150, uint32_t > Container; //600 bytes

PROGMEM LargeStruct< 50, Container > l_Struct; //Fills to 30k bytes


void setup()
  {
    volatile int i = ( int ) &l_Struct;
  }

void loop()
  {
   
  }
Binary sketch size: 30,748 bytes (of a 258,048 byte maximum)
Logged


SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6806
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had:
Code:
/*
 * These were used to fill up flash to debug some issues with
 * optiboot uploads of large sketches.
 */

#define FLASH_STRING(name, str) PGM_P name = str;

#define make64bytes(a) FLASH_STRING(__flash1 ## a, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

#define make256bytes(a) make64bytes(x ## a);     make64bytes(x1 ## a); \
    make64bytes(x2 ## a);    make64bytes(x3 ## a)

#define make1kbytes(a) make256bytes(x1 ## a);     make256bytes(x2 ## a); \
    make256bytes(x3 ## a);     make256bytes(x4 ## a)

#define make4kbytes(a) make1kbytes(x1 ## a);     make1kbytes(x2 ## a); \
    make1kbytes(x3 ## a);     make1kbytes(x4 ## a)

#define make16kbytes(a) make4kbytes(x1 ## a);     make4kbytes(x2 ## a); \
    make4kbytes(x3 ## a);     make4kbytes(x4 ## a)

make16kbytes(foo);
make16kbytes(bar);

#if 0
make4kbytes(bar);
make256bytes(baz);
make256bytes(baz1);
make256bytes(baz2);
#endif
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 76
Posts: 2247
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure if this will even work ( didn't upload ), but this fills every single byte free on the mega

Code:
#define nothing

template< uint64_t C, typename T >
  struct LargeStruct{
    T Data;
    LargeStruct< C - 1, T > Next;
};
template< typename T > struct LargeStruct< 0, T >{ };

typedef LargeStruct< 80, uint64_t > Container; //640 bytes

PROGMEM LargeStruct< 50, Container > l_Struct;  //32k
PROGMEM LargeStruct< 50, Container > l_Struct1;   //32k
PROGMEM LargeStruct< 50, Container > l_Struct2;   //32k
PROGMEM LargeStruct< 50, Container > l_Struct3;   //32k
PROGMEM LargeStruct< 50, Container > l_Struct4;   //32k
PROGMEM LargeStruct< 50, Container > l_Struct5;  //32k
PROGMEM LargeStruct< 50, Container > l_Struct6;   //32k
PROGMEM LargeStruct< 50, Container > l_Struct7;   //32k

PROGMEM LargeStruct< 431, uint16_t > l_Struct8; //862 bytes
void setup()
  {
    volatile int i = ( int ) &l_Struct;
    volatile int i1 = ( int ) &l_Struct1;
    volatile int i2 = ( int ) &l_Struct2;
    volatile int i3 = ( int ) &l_Struct3;
    volatile int i4 = ( int ) &l_Struct4;
    volatile int i5 = ( int ) &l_Struct5;
    volatile int i6 = ( int ) &l_Struct6;
    volatile int i7 = ( int ) &l_Struct7;    
    volatile int i8 = ( int ) &l_Struct8;  
  }

void loop(){}
Binary sketch size: 258,048 bytes (of a 258,048 byte maximum)
« Last Edit: January 17, 2013, 08:39:19 pm by pYro_65 » Logged


Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So many different methods, most using features and functions I've yet to learn about.

I think what I have (below) will hold me for awhile as I await a mega1284P chip coming on a slow ship from China. It really is shame about the state of the mega boards bootloaders (present 2560 and older 1280) still having problems with WDT interrupts, !!! monitor trigger, and possibly a problem loading near max size sketches. I've been lead to believe that the next IDE release may indeed include an updated bootloader for the mega2560 but I suspect the legacy mega1280 will propably spin in the wind, just for the lack of someone recompiling the new 2560 bootloader for the 1280.  smiley-cry

Code:
#include <avr/pgmspace.h>   //To store arrays into flash rather then SRAM
// Simple sketch to create large sketch sizes for testing purposes
/*
  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 1500 for 328P chip, 4000 for 1280P chip?,
 3600 for 644P chip, xxxx for 1284P,  etc.
*/
const int arraysize= 1500;  // value to mostly fill avalible flash capacity

long myInts0[arraysize] PROGMEM = {};  //Store initilized array into flash memory
long myInts1[arraysize] PROGMEM = {};
long myInts2[arraysize] PROGMEM = {};
long myInts3[arraysize] PROGMEM = {};

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  int i = random(0,arraysize);      // Work around any optimization for constant values
  Serial.print(myInts0[i]);         //  Access some random element so the array can't be optimized away.
  Serial.print(myInts1[i]);         //  Access some random element so the array can't be optimized away.
  Serial.print(myInts2[i]);         //  Access some random element so the array can't be optimized away.
  Serial.print(myInts3[i]);         //  Access some random element so the array can't be optimized away.
}

// 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
}


Lefty
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is that what that PROGMEM syntax is actually doing ?
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 76
Posts: 2247
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is that what that PROGMEM syntax is actually doing ?

What is your question referencing?

PROGMEM is causing variables marked with it to have their data stored in flash and as a result are constant, as opposed to normal variables which reside in sram.
Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Potential auto-sizing version...

Code:
struct
{
  uint8_t Data[ FLASHEND - _VECTORS_SIZE - 572 ];
}
BigOne PROGMEM;

int main( void )
{
  volatile int i = ( int ) &BigOne;

  return( 0 );
}
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6806
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think AVR arrays are limited to 32k bytes in size, at least in the compiler version Arduino uses.
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 76
Posts: 2247
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes that is why my version used a few declarations instead of one, 500 max nested template instantiations and a max variable size of ( ( 1<< 16 ) / 2 ) - 1

There is compiler options to enlarge both I think.
Logged


Pages: 1 [2] 3   Go Up
Jump to: