diff --git a/src/system/newlib_stubs.c b/src/system/newlib_stubs.c index feeb8b80..faf8c28c 100644 --- a/src/system/newlib_stubs.c +++ b/src/system/newlib_stubs.c @@ -31,8 +31,19 @@ #define MICRO_TO_NANO 1000 void _exit(int status) { + extern void flush_output_streams(); + flush_output_streams(); + extern void ser_output_flush(); + ser_output_flush(); + rtos_suspend_all(); if(status != 0) dprintf(3, "Error %d\n", status); // kprintf + uint32_t start_time = millis(); + static const uint32_t max_flush_time = 50; + while (vexSerialWriteFree(1) != 2048 || millis() - start_time > max_flush_time) { + vexBackgroundProcessing(); + } vexSystemExitRequest(); + while (1) vexBackgroundProcessing(); } int usleep( useconds_t period ) { diff --git a/src/system/newlib_stubs_support.cpp b/src/system/newlib_stubs_support.cpp new file mode 100644 index 00000000..21967b5d --- /dev/null +++ b/src/system/newlib_stubs_support.cpp @@ -0,0 +1,8 @@ +#include +#include + +// called by _exit in newlib_stubs.c +extern "C" void flush_output_streams() { + fflush(stdout); + std::cout.flush(); +} \ No newline at end of file