2016-03-25 01:19:46 -05:00
|
|
|
/**
|
2016-03-24 13:01:20 -05:00
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2016-03-24 13:01:20 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2016-03-24 13:01:20 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-17 00:33:00 -05:00
|
|
|
#include "../../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(M100_FREE_MEMORY_WATCHER)
|
|
|
|
|
|
|
|
#include "../gcode.h"
|
2018-04-21 19:41:26 -05:00
|
|
|
#include "../queue.h"
|
2017-09-06 06:28:31 -05:00
|
|
|
#include "../../libs/hex_print_routines.h"
|
|
|
|
|
2020-01-02 19:01:38 -06:00
|
|
|
#include "../../MarlinCore.h" // for idle()
|
2017-09-17 00:33:00 -05:00
|
|
|
|
2016-03-25 01:19:46 -05:00
|
|
|
/**
|
|
|
|
* M100 Free Memory Watcher
|
2016-12-15 09:21:32 -06:00
|
|
|
*
|
2016-03-25 01:19:46 -05:00
|
|
|
* This code watches the free memory block between the bottom of the heap and the top of the stack.
|
|
|
|
* This memory block is initialized and watched via the M100 command.
|
2016-12-15 09:21:32 -06:00
|
|
|
*
|
2017-04-10 19:19:22 -05:00
|
|
|
* M100 I Initializes the free memory block and prints vitals statistics about the area
|
|
|
|
*
|
|
|
|
* M100 F Identifies how much of the free memory block remains free and unused. It also
|
|
|
|
* detects and reports any corruption within the free memory block that may have
|
|
|
|
* happened due to errant firmware.
|
|
|
|
*
|
|
|
|
* M100 D Does a hex display of the free memory block along with a flag for any errant
|
|
|
|
* data that does not match the expected value.
|
|
|
|
*
|
|
|
|
* M100 C x Corrupts x locations within the free memory block. This is useful to check the
|
|
|
|
* correctness of the M100 F and M100 D commands.
|
2016-12-15 09:21:32 -06:00
|
|
|
*
|
2017-04-13 18:07:10 -05:00
|
|
|
* Also, there are two support functions that can be called from a developer's C code.
|
|
|
|
*
|
2019-05-09 21:57:44 -05:00
|
|
|
* uint16_t check_for_free_memory_corruption(PGM_P const free_memory_start);
|
2019-12-15 20:21:56 -06:00
|
|
|
* void M100_dump_routine(PGM_P const title, const char * const start, const char * const end);
|
2017-04-13 18:07:10 -05:00
|
|
|
*
|
2017-03-18 10:15:54 -05:00
|
|
|
* Initial version by Roxy-3D
|
2016-03-25 01:19:46 -05:00
|
|
|
*/
|
2018-02-05 21:54:50 -06:00
|
|
|
#define M100_FREE_MEMORY_DUMPER // Enable for the `M100 D` Dump sub-command
|
2017-04-10 19:19:22 -05:00
|
|
|
#define M100_FREE_MEMORY_CORRUPTOR // Enable for the `M100 C` Corrupt sub-command
|
2015-07-05 19:42:13 -05:00
|
|
|
|
2017-04-15 19:14:40 -05:00
|
|
|
#define TEST_BYTE ((char) 0xE5)
|
|
|
|
|
2019-05-09 21:57:44 -05:00
|
|
|
#if defined(__AVR__) || IS_32BIT_TEENSY
|
|
|
|
|
|
|
|
extern char __bss_end;
|
2019-06-12 03:12:03 -05:00
|
|
|
char *end_bss = &__bss_end,
|
|
|
|
*free_memory_start = end_bss, *free_memory_end = 0,
|
|
|
|
*stacklimit = 0, *heaplimit = 0;
|
2019-05-09 21:57:44 -05:00
|
|
|
|
|
|
|
#define MEMORY_END_CORRECTION 0
|
|
|
|
|
|
|
|
#elif defined(TARGET_LPC1768)
|
|
|
|
|
2019-06-12 03:12:03 -05:00
|
|
|
extern char __bss_end__, __StackLimit, __HeapLimit;
|
2019-05-09 21:57:44 -05:00
|
|
|
|
2019-06-12 03:12:03 -05:00
|
|
|
char *end_bss = &__bss_end__,
|
|
|
|
*stacklimit = &__StackLimit,
|
2019-07-28 14:48:29 -05:00
|
|
|
*heaplimit = &__HeapLimit;
|
2019-05-09 21:57:44 -05:00
|
|
|
|
|
|
|
#define MEMORY_END_CORRECTION 0x200
|
|
|
|
|
2019-06-12 03:12:03 -05:00
|
|
|
char *free_memory_start = heaplimit,
|
|
|
|
*free_memory_end = stacklimit - MEMORY_END_CORRECTION;
|
2019-05-09 21:57:44 -05:00
|
|
|
|
|
|
|
#elif defined(__SAM3X8E__)
|
|
|
|
|
2019-06-12 03:12:03 -05:00
|
|
|
extern char _ebss;
|
2019-05-09 21:57:44 -05:00
|
|
|
|
2019-06-12 03:12:03 -05:00
|
|
|
char *end_bss = &_ebss,
|
|
|
|
*free_memory_start = end_bss,
|
|
|
|
*free_memory_end = 0,
|
|
|
|
*stacklimit = 0,
|
|
|
|
*heaplimit = 0;
|
2019-05-09 21:57:44 -05:00
|
|
|
|
|
|
|
#define MEMORY_END_CORRECTION 0x10000 // need to stay well below 0x20080000 or M100 F crashes
|
|
|
|
|
2019-07-28 14:48:29 -05:00
|
|
|
#elif defined(__SAMD51__)
|
|
|
|
|
|
|
|
extern unsigned int __bss_end__, __StackLimit, __HeapLimit;
|
|
|
|
extern "C" void * _sbrk(int incr);
|
|
|
|
|
|
|
|
void *end_bss = &__bss_end__,
|
|
|
|
*stacklimit = &__StackLimit,
|
|
|
|
*heaplimit = &__HeapLimit;
|
|
|
|
|
|
|
|
#define MEMORY_END_CORRECTION 0x400
|
|
|
|
|
|
|
|
char *free_memory_start = (char *)_sbrk(0) + 0x200, // Leave some heap space
|
|
|
|
*free_memory_end = (char *)stacklimit - MEMORY_END_CORRECTION;
|
|
|
|
|
2019-05-09 21:57:44 -05:00
|
|
|
#else
|
|
|
|
#error "M100 - unsupported CPU"
|
|
|
|
#endif
|
2015-07-05 19:42:13 -05:00
|
|
|
|
|
|
|
//
|
2017-04-10 19:19:22 -05:00
|
|
|
// Utility functions
|
2015-07-05 19:42:13 -05:00
|
|
|
//
|
|
|
|
|
2020-04-21 12:30:58 -05:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wreturn-local-addr"
|
|
|
|
|
|
|
|
// Location of a variable in its stack frame.
|
|
|
|
// The returned address will be above the stack (after it returns).
|
|
|
|
char *top_of_stack() {
|
2017-04-10 19:19:22 -05:00
|
|
|
char x;
|
|
|
|
return &x + 1; // x is pulled on return;
|
|
|
|
}
|
|
|
|
|
2020-04-21 12:30:58 -05:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
2017-04-10 19:19:22 -05:00
|
|
|
// Count the number of test bytes at the specified location.
|
2019-05-09 21:57:44 -05:00
|
|
|
inline int32_t count_test_bytes(const char * const start_free_memory) {
|
2017-09-30 16:06:43 -05:00
|
|
|
for (uint32_t i = 0; i < 32000; i++)
|
2019-05-09 21:57:44 -05:00
|
|
|
if (char(start_free_memory[i]) != TEST_BYTE)
|
2017-04-10 19:19:22 -05:00
|
|
|
return i - 1;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// M100 sub-commands
|
|
|
|
//
|
|
|
|
|
|
|
|
#if ENABLED(M100_FREE_MEMORY_DUMPER)
|
|
|
|
/**
|
|
|
|
* M100 D
|
2019-05-09 21:57:44 -05:00
|
|
|
* Dump the free memory block from brkval to the stack pointer.
|
2017-04-10 19:19:22 -05:00
|
|
|
* malloc() eats memory from the start of the block and the stack grows
|
|
|
|
* up from the bottom of the block. Solid test bytes indicate nothing has
|
|
|
|
* used that memory yet. There should not be anything but test bytes within
|
|
|
|
* the block. If so, it may indicate memory corruption due to a bad pointer.
|
|
|
|
* Unexpected bytes are flagged in the right column.
|
|
|
|
*/
|
2019-06-12 03:12:03 -05:00
|
|
|
inline void dump_free_memory(char *start_free_memory, char *end_free_memory) {
|
2017-04-10 19:19:22 -05:00
|
|
|
//
|
|
|
|
// Start and end the dump on a nice 16 byte boundary
|
|
|
|
// (even though the values are not 16-byte aligned).
|
|
|
|
//
|
2019-12-15 20:21:56 -06:00
|
|
|
start_free_memory = (char*)(ptr_int_t(uint32_t(start_free_memory) & ~0xFUL)); // Align to 16-byte boundary
|
|
|
|
end_free_memory = (char*)(ptr_int_t(uint32_t(end_free_memory) | 0xFUL)); // Align end_free_memory to the 15th byte (at or above end_free_memory)
|
2017-04-10 19:19:22 -05:00
|
|
|
|
|
|
|
// Dump command main loop
|
2019-05-09 21:57:44 -05:00
|
|
|
while (start_free_memory < end_free_memory) {
|
|
|
|
print_hex_address(start_free_memory); // Print the address
|
2017-04-10 19:19:22 -05:00
|
|
|
SERIAL_CHAR(':');
|
2020-03-13 23:18:16 -05:00
|
|
|
LOOP_L_N(i, 16) { // and 16 data bytes
|
2017-04-10 19:19:22 -05:00
|
|
|
if (i == 8) SERIAL_CHAR('-');
|
2019-05-09 21:57:44 -05:00
|
|
|
print_hex_byte(start_free_memory[i]);
|
2017-04-10 19:19:22 -05:00
|
|
|
SERIAL_CHAR(' ');
|
2015-10-03 01:08:58 -05:00
|
|
|
}
|
2018-11-23 21:05:59 -06:00
|
|
|
serial_delay(25);
|
2017-04-10 19:19:22 -05:00
|
|
|
SERIAL_CHAR('|'); // Point out non test bytes
|
2020-03-13 23:18:16 -05:00
|
|
|
LOOP_L_N(i, 16) {
|
2019-05-09 21:57:44 -05:00
|
|
|
char ccc = (char)start_free_memory[i]; // cast to char before automatically casting to char on assignment, in case the compiler is broken
|
2019-07-01 15:33:15 -05:00
|
|
|
ccc = (ccc == TEST_BYTE) ? ' ' : '?';
|
2017-04-15 19:14:40 -05:00
|
|
|
SERIAL_CHAR(ccc);
|
|
|
|
}
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_EOL();
|
2019-05-09 21:57:44 -05:00
|
|
|
start_free_memory += 16;
|
2018-11-23 21:05:59 -06:00
|
|
|
serial_delay(25);
|
2017-04-10 19:19:22 -05:00
|
|
|
idle();
|
2015-10-03 01:08:58 -05:00
|
|
|
}
|
2017-04-10 19:19:22 -05:00
|
|
|
}
|
2017-04-13 18:07:10 -05:00
|
|
|
|
2019-12-15 20:21:56 -06:00
|
|
|
void M100_dump_routine(PGM_P const title, const char * const start, const char * const end) {
|
2018-09-30 23:44:33 -05:00
|
|
|
serialprintPGM(title);
|
|
|
|
SERIAL_EOL();
|
2017-09-06 06:28:31 -05:00
|
|
|
//
|
|
|
|
// Round the start and end locations to produce full lines of output
|
|
|
|
//
|
2019-12-15 20:21:56 -06:00
|
|
|
dump_free_memory(
|
|
|
|
(char*)(ptr_int_t(uint32_t(start) & ~0xFUL)), // Align to 16-byte boundary
|
|
|
|
(char*)(ptr_int_t(uint32_t(end) | 0xFUL)) // Align end_free_memory to the 15th byte (at or above end_free_memory)
|
|
|
|
);
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
2017-04-16 17:33:22 -05:00
|
|
|
|
2017-04-10 19:19:22 -05:00
|
|
|
#endif // M100_FREE_MEMORY_DUMPER
|
|
|
|
|
2018-09-30 23:44:33 -05:00
|
|
|
inline int check_for_free_memory_corruption(PGM_P const title) {
|
|
|
|
serialprintPGM(title);
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-05-09 21:57:44 -05:00
|
|
|
char *start_free_memory = free_memory_start, *end_free_memory = free_memory_end;
|
|
|
|
int n = end_free_memory - start_free_memory;
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
SERIAL_ECHOPAIR("\nfmc() n=", n);
|
2019-05-09 21:57:44 -05:00
|
|
|
SERIAL_ECHOPAIR("\nfree_memory_start=", hex_address(free_memory_start));
|
2019-06-12 03:12:03 -05:00
|
|
|
SERIAL_ECHOLNPAIR(" end_free_memory=", hex_address(end_free_memory));
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2019-05-09 21:57:44 -05:00
|
|
|
if (end_free_memory < start_free_memory) {
|
|
|
|
SERIAL_ECHOPGM(" end_free_memory < Heap ");
|
2017-09-06 06:28:31 -05:00
|
|
|
// SET_INPUT_PULLUP(63); // if the developer has a switch wired up to their controller board
|
|
|
|
// safe_delay(5); // this code can be enabled to pause the display as soon as the
|
|
|
|
// while ( READ(63)) // malfunction is detected. It is currently defaulting to a switch
|
|
|
|
// idle(); // being on pin-63 which is unassigend and available on most controller
|
|
|
|
// safe_delay(20); // boards.
|
|
|
|
// while ( !READ(63))
|
|
|
|
// idle();
|
2018-11-23 21:05:59 -06:00
|
|
|
serial_delay(20);
|
2017-09-06 06:28:31 -05:00
|
|
|
#if ENABLED(M100_FREE_MEMORY_DUMPER)
|
2019-12-15 20:21:56 -06:00
|
|
|
M100_dump_routine(PSTR(" Memory corruption detected with end_free_memory<Heap\n"), (const char*)0x1B80, (const char*)0x21FF);
|
2017-09-06 06:28:31 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan through the range looking for the biggest block of 0xE5's we can find
|
|
|
|
int block_cnt = 0;
|
|
|
|
for (int i = 0; i < n; i++) {
|
2019-05-09 21:57:44 -05:00
|
|
|
if (start_free_memory[i] == TEST_BYTE) {
|
|
|
|
int32_t j = count_test_bytes(start_free_memory + i);
|
2017-09-06 06:28:31 -05:00
|
|
|
if (j > 8) {
|
|
|
|
// SERIAL_ECHOPAIR("Found ", j);
|
2019-05-09 21:57:44 -05:00
|
|
|
// SERIAL_ECHOLNPAIR(" bytes free at ", hex_address(start_free_memory + i));
|
2017-09-06 06:28:31 -05:00
|
|
|
i += j;
|
|
|
|
block_cnt++;
|
|
|
|
SERIAL_ECHOPAIR(" (", block_cnt);
|
|
|
|
SERIAL_ECHOPAIR(") found=", j);
|
2019-05-09 21:57:44 -05:00
|
|
|
SERIAL_ECHOLNPGM(" ");
|
2017-09-06 06:28:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERIAL_ECHOPAIR(" block_found=", block_cnt);
|
|
|
|
|
2019-05-09 21:57:44 -05:00
|
|
|
if (block_cnt != 1)
|
2017-09-06 06:28:31 -05:00
|
|
|
SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
|
|
|
|
|
|
|
|
if (block_cnt == 0) // Make sure the special case of no free blocks shows up as an
|
2020-01-08 18:31:57 -06:00
|
|
|
block_cnt = -1; // error to the calling code!
|
2017-09-06 06:28:31 -05:00
|
|
|
|
|
|
|
SERIAL_ECHOPGM(" return=");
|
|
|
|
if (block_cnt == 1) {
|
2020-01-08 18:31:57 -06:00
|
|
|
SERIAL_CHAR('0'); // If the block_cnt is 1, nothing has broken up the free memory
|
|
|
|
SERIAL_EOL(); // area and it is appropriate to say 'no corruption'.
|
2017-09-06 06:28:31 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SERIAL_ECHOLNPGM("true");
|
|
|
|
return block_cnt;
|
|
|
|
}
|
|
|
|
|
2017-04-10 19:19:22 -05:00
|
|
|
/**
|
|
|
|
* M100 F
|
|
|
|
* Return the number of free bytes in the memory pool,
|
|
|
|
* with other vital statistics defining the pool.
|
|
|
|
*/
|
2019-05-09 21:57:44 -05:00
|
|
|
inline void free_memory_pool_report(char * const start_free_memory, const int32_t size) {
|
2017-09-30 16:06:43 -05:00
|
|
|
int32_t max_cnt = -1, block_cnt = 0;
|
2019-05-09 11:45:55 -05:00
|
|
|
char *max_addr = nullptr;
|
2017-04-10 19:19:22 -05:00
|
|
|
// Find the longest block of test bytes in the buffer
|
2017-09-30 16:06:43 -05:00
|
|
|
for (int32_t i = 0; i < size; i++) {
|
2019-05-09 21:57:44 -05:00
|
|
|
char *addr = start_free_memory + i;
|
2017-04-10 19:19:22 -05:00
|
|
|
if (*addr == TEST_BYTE) {
|
2017-09-30 16:06:43 -05:00
|
|
|
const int32_t j = count_test_bytes(addr);
|
2017-04-10 19:19:22 -05:00
|
|
|
if (j > 8) {
|
|
|
|
SERIAL_ECHOPAIR("Found ", j);
|
2017-04-12 19:39:26 -05:00
|
|
|
SERIAL_ECHOLNPAIR(" bytes free at ", hex_address(addr));
|
2017-04-10 19:19:22 -05:00
|
|
|
if (j > max_cnt) {
|
|
|
|
max_cnt = j;
|
|
|
|
max_addr = addr;
|
|
|
|
}
|
|
|
|
i += j;
|
|
|
|
block_cnt++;
|
|
|
|
}
|
2017-04-10 15:20:20 -05:00
|
|
|
}
|
2015-10-03 01:08:58 -05:00
|
|
|
}
|
2017-04-10 19:19:22 -05:00
|
|
|
if (block_cnt > 1) {
|
|
|
|
SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
|
|
|
|
SERIAL_ECHOPAIR("\nLargest free block is ", max_cnt);
|
2017-04-12 19:39:26 -05:00
|
|
|
SERIAL_ECHOLNPAIR(" bytes at ", hex_address(max_addr));
|
2017-04-10 19:19:22 -05:00
|
|
|
}
|
2018-09-30 23:44:33 -05:00
|
|
|
SERIAL_ECHOLNPAIR("check_for_free_memory_corruption() = ", check_for_free_memory_corruption(PSTR("M100 F ")));
|
2017-04-10 19:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(M100_FREE_MEMORY_CORRUPTOR)
|
|
|
|
/**
|
|
|
|
* M100 C<num>
|
|
|
|
* Corrupt <num> locations in the free memory pool and report the corrupt addresses.
|
|
|
|
* This is useful to check the correctness of the M100 D and the M100 F commands.
|
|
|
|
*/
|
2019-05-09 21:57:44 -05:00
|
|
|
inline void corrupt_free_memory(char *start_free_memory, const uint32_t size) {
|
|
|
|
start_free_memory += 8;
|
|
|
|
const uint32_t near_top = top_of_stack() - start_free_memory - 250, // -250 to avoid interrupt activity that's altered the stack.
|
2017-06-27 02:36:19 -05:00
|
|
|
j = near_top / (size + 1);
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM("Corrupting free memory block.\n");
|
2017-09-30 16:06:43 -05:00
|
|
|
for (uint32_t i = 1; i <= size; i++) {
|
2019-05-09 21:57:44 -05:00
|
|
|
char * const addr = start_free_memory + i * j;
|
2017-06-27 02:36:19 -05:00
|
|
|
*addr = i;
|
|
|
|
SERIAL_ECHOPAIR("\nCorrupting address: ", hex_address(addr));
|
2015-10-03 01:08:58 -05:00
|
|
|
}
|
2017-06-27 02:36:19 -05:00
|
|
|
SERIAL_EOL();
|
2015-10-03 01:08:58 -05:00
|
|
|
}
|
2017-04-10 19:19:22 -05:00
|
|
|
#endif // M100_FREE_MEMORY_CORRUPTOR
|
2015-07-05 19:42:13 -05:00
|
|
|
|
2017-04-10 19:19:22 -05:00
|
|
|
/**
|
|
|
|
* M100 I
|
|
|
|
* Init memory for the M100 tests. (Automatically applied on the first M100.)
|
|
|
|
*/
|
2019-05-09 21:57:44 -05:00
|
|
|
inline void init_free_memory(char *start_free_memory, int32_t size) {
|
2017-04-10 19:19:22 -05:00
|
|
|
SERIAL_ECHOLNPGM("Initializing free memory block.\n\n");
|
2015-07-05 19:42:13 -05:00
|
|
|
|
2017-04-10 19:19:22 -05:00
|
|
|
size -= 250; // -250 to avoid interrupt activity that's altered the stack.
|
2017-04-13 18:07:10 -05:00
|
|
|
if (size < 0) {
|
|
|
|
SERIAL_ECHOLNPGM("Unable to initialize.\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-07-05 19:42:13 -05:00
|
|
|
|
2019-05-09 21:57:44 -05:00
|
|
|
start_free_memory += 8; // move a few bytes away from the heap just because we don't want
|
2017-04-13 18:07:10 -05:00
|
|
|
// to be altering memory that close to it.
|
2019-05-09 21:57:44 -05:00
|
|
|
memset(start_free_memory, TEST_BYTE, size);
|
2017-04-10 19:19:22 -05:00
|
|
|
|
|
|
|
SERIAL_ECHO(size);
|
|
|
|
SERIAL_ECHOLNPGM(" bytes of memory initialized.\n");
|
|
|
|
|
2017-09-30 16:06:43 -05:00
|
|
|
for (int32_t i = 0; i < size; i++) {
|
2019-05-09 21:57:44 -05:00
|
|
|
if (start_free_memory[i] != TEST_BYTE) {
|
|
|
|
SERIAL_ECHOPAIR("? address : ", hex_address(start_free_memory + i));
|
|
|
|
SERIAL_ECHOLNPAIR("=", hex_byte(start_free_memory[i]));
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_EOL();
|
2017-04-10 19:19:22 -05:00
|
|
|
}
|
2015-10-03 01:08:58 -05:00
|
|
|
}
|
2015-07-05 19:42:13 -05:00
|
|
|
}
|
|
|
|
|
2017-04-10 19:19:22 -05:00
|
|
|
/**
|
|
|
|
* M100: Free Memory Check
|
|
|
|
*/
|
2017-09-17 00:33:00 -05:00
|
|
|
void GcodeSuite::M100() {
|
2017-04-10 15:20:20 -05:00
|
|
|
|
2019-05-09 21:57:44 -05:00
|
|
|
char *sp = top_of_stack();
|
|
|
|
if (!free_memory_end) free_memory_end = sp - MEMORY_END_CORRECTION;
|
|
|
|
SERIAL_ECHOPAIR("\nbss_end : ", hex_address(end_bss));
|
2019-06-12 03:12:03 -05:00
|
|
|
if (heaplimit) SERIAL_ECHOPAIR("\n__heaplimit : ", hex_address(heaplimit));
|
2019-05-09 21:57:44 -05:00
|
|
|
SERIAL_ECHOPAIR("\nfree_memory_start : ", hex_address(free_memory_start));
|
|
|
|
if (stacklimit) SERIAL_ECHOPAIR("\n__stacklimit : ", hex_address(stacklimit));
|
2019-06-12 03:12:03 -05:00
|
|
|
SERIAL_ECHOPAIR("\nfree_memory_end : ", hex_address(free_memory_end));
|
|
|
|
if (MEMORY_END_CORRECTION) SERIAL_ECHOPAIR("\nMEMORY_END_CORRECTION: ", MEMORY_END_CORRECTION);
|
2019-05-09 21:57:44 -05:00
|
|
|
SERIAL_ECHOLNPAIR("\nStack Pointer : ", hex_address(sp));
|
2017-04-10 15:20:20 -05:00
|
|
|
|
2017-04-10 19:19:22 -05:00
|
|
|
// Always init on the first invocation of M100
|
|
|
|
static bool m100_not_initialized = true;
|
2017-05-20 03:03:08 -05:00
|
|
|
if (m100_not_initialized || parser.seen('I')) {
|
2017-04-10 19:19:22 -05:00
|
|
|
m100_not_initialized = false;
|
2019-05-09 21:57:44 -05:00
|
|
|
init_free_memory(free_memory_start, free_memory_end - free_memory_start);
|
2017-04-10 19:19:22 -05:00
|
|
|
}
|
2017-04-10 15:20:20 -05:00
|
|
|
|
2017-04-10 19:19:22 -05:00
|
|
|
#if ENABLED(M100_FREE_MEMORY_DUMPER)
|
2017-05-20 03:03:08 -05:00
|
|
|
if (parser.seen('D'))
|
2019-05-09 21:57:44 -05:00
|
|
|
return dump_free_memory(free_memory_start, free_memory_end);
|
2017-04-10 19:19:22 -05:00
|
|
|
#endif
|
2017-04-10 15:20:20 -05:00
|
|
|
|
2017-05-20 03:03:08 -05:00
|
|
|
if (parser.seen('F'))
|
2019-05-09 21:57:44 -05:00
|
|
|
return free_memory_pool_report(free_memory_start, free_memory_end - free_memory_start);
|
2017-04-10 19:19:22 -05:00
|
|
|
|
|
|
|
#if ENABLED(M100_FREE_MEMORY_CORRUPTOR)
|
|
|
|
|
2017-05-20 03:03:08 -05:00
|
|
|
if (parser.seen('C'))
|
2019-05-09 21:57:44 -05:00
|
|
|
return corrupt_free_memory(free_memory_start, parser.value_int());
|
2017-04-10 19:19:22 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
2017-09-17 00:33:00 -05:00
|
|
|
|
|
|
|
#endif // M100_FREE_MEMORY_WATCHER
|