Arduino Mega Crashes At 41%

Hi Guys, just a quick question on something I'm stuck with on a mega 2560. When I go above a certain program size (41%) the IOs seem to become corrupt. I have a button press which stop detecting and an ssd1306 display that stop functioning. Any idea where to even start looking for the cause of the issue?

Could be that although you have plenty of flash left, you've run out of RAM. What does the compiler tell you?

Yes. have a look at 64K problems: pins_arduino.h _PGM arrays pushed out of range of pgm_read_byte()

Whandall:
Yes. have a look at 64K problems: pins_arduino.h _PGM arrays pushed out of range of pgm_read_byte()

Wow! I've had this problem for years!!!!! This info solved it (although I did it a different way):

I put this into "Arduino.h":

// https://github.com/arduino/Arduino/issues/2226
// hacked 03 May 2017 RAK
#ifndef _PGM_RB
 #ifdef pgm_read_byte_far
  #define _PGM_RB pgm_read_byte_far
  #define _PGM_RW pgm_read_word_far
  #define _PGM_RD pgm_read_dword_far
 #else
  #define _PGM_RB pgm_read_byte_near
  #define _PGM_RW pgm_read_word_near
  #define _PGM_RD pgm_read_dword_near
 #endif
#endif

...as well as all libraries that use "pgm_read_xxx".

Thanks so much! Karma++ for you and Bill!

(edit to add): I should probably add "pgm_read_float" to this.........

Hi Guys,

I'm new to all this and having difficulty understanding how to use (what I think) is some sort of 'diff' code posted by westFW on the link above.

Is it possible to get a fixed version of the pins_arduino.h file?

Thanks in advance,
E

employee:
Hi Guys,

I'm new to all this and having difficulty understanding how to use (what I think) is some sort of 'diff' code posted by westFW on the link above.

Is it possible to get a fixed version of the pins_arduino.h file?

Thanks in advance,
E

I did this: In Arduino.h I made new definitions for the pgm_read_xxx functions:

// https://github.com/arduino/Arduino/issues/2226
// hacked 03 May 2017 RAK
#ifndef _PGM_RB
#ifdef pgm_read_byte_far
#define _PGM_RB pgm_read_byte_far
#define _PGM_RW pgm_read_word_far
#define _PGM_RD pgm_read_dword_far
#define _PGM_RF pgm_read_float_far
#else
#define _PGM_RB pgm_read_byte_near
#define _PGM_RW pgm_read_word_near
#define _PGM_RD pgm_read_dword_near
#define _PGM_RF pgm_read_float_near
#endif
#endif

Then anywhere in any code or library that uses "pgm_read_byte" (or "pgm_read_word" or "dword" or "float") I replaced them with "_PGM_RB" or "RW" or "RD" or "RF" as appropriate.

Thinking about it, I wonder if I can do an "undef" and then "define" of the real names in order to solve this even easier. I'm going to try it.

(edit to add): Yes it works!