   Serial.begin(UART_BAUD_RATE);
   Serial << F("YaesuTest: starting ...") << endl;
   
- #if defined (__AVR__)
-  Serial << F("Free SRAM: ") << availableMemory() << endl;
- #endif // (__AVR__)
+  Serial << F("Free SRAM: ") << getFreeRAM() << endl;
 #endif // DEBUG
 
   // set the data rate for the SoftwareSerial port(s)

#endif // (__AVR__)

// local prototypes
#if defined (__AVR__)
static int availableMemory();
#endif // (__AVR__)

void setup() {


/** 
 *  Try to inquire max. available memory by allocating until heap is exhausted.
 */
static int getFreeRAM() {

  char top;
  
#ifndef __arm__
  extern char *__brkval;
  extern char __bss_end;
#endif  // __arm__

  // see also:
  // https://forum.pjrc.com/threads/23256-Get-Free-Memory-for-Teensy-3-0
#ifdef __arm__
   uint32_t stackTop;
    uint32_t heapTop;

    // current position of the stack.
    stackTop = (uint32_t) &stackTop;

    // current position of heap.
    void* hTop = malloc(1);
    heapTop = (uint32_t) hTop;
    free(hTop);

    // The difference is the free, available ram.
    return stackTop - heapTop;
#else  // __arm__
  return __brkval ? &top - __brkval : &top - &__bss_end;
#endif  // __arm__
}

