diff --git a/Marlin/src/gcode/calibrate/M100.cpp b/Marlin/src/gcode/calibrate/M100.cpp index a6f4f8f5d2e70c8cad1d9873d17a9bcefe7cb991..452dfd033c570d0b30d1cefb81789d66382dace1 100644 --- a/Marlin/src/gcode/calibrate/M100.cpp +++ b/Marlin/src/gcode/calibrate/M100.cpp @@ -51,7 +51,7 @@ * Also, there are two support functions that can be called from a developer's C code. * * uint16_t check_for_free_memory_corruption(PGM_P const free_memory_start); - * void M100_dump_routine(PGM_P const title, char *start, char *end); + * void M100_dump_routine(PGM_P const title, const char * const start, const char * const end); * * Initial version by Roxy-3D */ @@ -151,8 +151,8 @@ inline int32_t count_test_bytes(const char * const start_free_memory) { // Start and end the dump on a nice 16 byte boundary // (even though the values are not 16-byte aligned). // - start_free_memory = (char*)((ptr_int_t)((uint32_t)start_free_memory & 0xFFFFFFF0)); // Align to 16-byte boundary - end_free_memory = (char*)((ptr_int_t)((uint32_t)end_free_memory | 0x0000000F)); // Align end_free_memory to the 15th byte (at or above end_free_memory) + 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) // Dump command main loop while (start_free_memory < end_free_memory) { @@ -177,15 +177,16 @@ inline int32_t count_test_bytes(const char * const start_free_memory) { } } - void M100_dump_routine(PGM_P const title, char *start, char *end) { + void M100_dump_routine(PGM_P const title, const char * const start, const char * const end) { serialprintPGM(title); SERIAL_EOL(); // // Round the start and end locations to produce full lines of output // - start = (char*)((ptr_int_t)((uint32_t)start & 0xFFFFFFF0)); // Align to 16-byte boundary - end = (char*)((ptr_int_t)((uint32_t)end | 0x0000000F)); // Align end_free_memory to the 15th byte (at or above end_free_memory) - dump_free_memory(start, end); + 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) + ); } #endif // M100_FREE_MEMORY_DUMPER @@ -211,7 +212,7 @@ inline int check_for_free_memory_corruption(PGM_P const title) { // idle(); serial_delay(20); #if ENABLED(M100_FREE_MEMORY_DUMPER) - M100_dump_routine(PSTR(" Memory corruption detected with end_free_memory<Heap\n"), (char*)0x1B80, (char*)0x21FF); + M100_dump_routine(PSTR(" Memory corruption detected with end_free_memory<Heap\n"), (const char*)0x1B80, (const char*)0x21FF); #endif } diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 92928cf8b3350c1edc592c857e6c9ce89a15142a..d835ce65558ecfbedb98e0e2c533d0bef5282e45 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -209,7 +209,7 @@ void GcodeSuite::dwell(millis_t time) { // Placeholders for non-migrated codes // #if ENABLED(M100_FREE_MEMORY_WATCHER) - extern void M100_dump_routine(PGM_P const title, char *start, char *end); + extern void M100_dump_routine(PGM_P const title, const char * const start, const char * const end); #endif /** @@ -865,7 +865,7 @@ void GcodeSuite::process_next_command() { SERIAL_ECHOLN(current_command); #if ENABLED(M100_FREE_MEMORY_DUMPER) SERIAL_ECHOPAIR("slot:", queue.index_r); - M100_dump_routine(PSTR(" Command Queue:"), queue.command_buffer, queue.command_buffer + sizeof(queue.command_buffer)); + M100_dump_routine(PSTR(" Command Queue:"), &queue.command_buffer[0][0], &queue.command_buffer[BUFSIZE - 1][MAX_CMD_SIZE - 1]); #endif }