Adapting Mega code to Due

Hi, I am trying to rewrite a sketch that was written for a Mega to work on a DUE, aside from the EEPROM/Flash hardware differences and the size of the sketch I though it should be relatively straight forward. Such is not the case and it has been a struggle from the start. Now I have come to a series of errors that I can’t seem to figure out if it is because of a referenced address locations or in the code itself. Any help offered would be greatly appreciated !

iAqua_test.ino (257 KB)

errors 060415.txt (17.9 KB)

It seems like "DueFlashStorage" has been #defined to be something else. Are you sure that library is working in a small test sketch? Then try to #include all the other libraries in your test.

That does seem to be an exceptionally large program for fish feeding. Is it an industrial aquarium?

The following code you have at line starting 410 I think is only for AVR, not SAM:

int freeRam ()
{
  // Returns available SRAM
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

You might like to use the following for the DUE:

 extern char _end; // for free memory function:"
 extern "C" char *sbrk(int i);
 char *ramstart = (char *)0x20070000;
 char *ramend = (char *)0x20088000;

void setup()
{

 char *heapend = sbrk(0);
 register char * stack_ptr asm("sp");
 struct mallinfo mi = mallinfo();

 printf("Dynamic ram used:\t\t%d\n",mi.uordblks);
 printf("Program static ram used:\t%d\n",&_end - ramstart);
 printf("Stack ram used:\t\t%d\n",ramend - stack_ptr);
 printf("Free memory estimate:\t%d\n\n",stack_ptr - heapend + mi.fordblks);
}

Paul

oops, you’ll need this too:

#include	<malloc.h>
#include	<stdlib.h>
#include	<stdio.h>