Skip to content

Commit

Permalink
Fix issue with main task stack usage too high after previous change
Browse files Browse the repository at this point in the history
  • Loading branch information
dc42 committed Feb 11, 2025
1 parent b034fd4 commit 4c2ea49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Platform/RepRap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,7 @@ void RepRap::Spin() noexcept
// Check if we need to send diagnostics
if (diagnosticsDestination != MessageType::NoDestinationMessage)
{
String<GCodeReplyLength> buf;
Diagnostics(diagnosticsDestination, buf.GetRef());
GenerateDeferredDiagnostics(diagnosticsDestination); // call out to separate function to keep stack usage under control
diagnosticsDestination = MessageType::NoDestinationMessage;
}

Expand Down Expand Up @@ -808,6 +807,13 @@ void RepRap::Spin() noexcept
RTOSIface::Yield();
}

// Send diagnostics to the specified destination. This is in a separate function so that the large string doesn't take up main task stack space all the time.
__attribute__((noinline)) void RepRap::GenerateDeferredDiagnostics(MessageType destination) noexcept
{
String<GCodeReplyLength> buf;
Diagnostics(destination, buf.GetRef());
}

void RepRap::Timing(const StringRef& reply) noexcept
{
reply.lcatf("Slowest loop: %.2fms; fastest: %.2fms", (double)(slowLoop * StepClocksToMillis), (double)(fastLoop * StepClocksToMillis));
Expand Down
1 change: 1 addition & 0 deletions src/Platform/RepRap.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class RepRap final INHERIT_OBJECT_MODEL
ReadWriteLock *_ecv_null GetObjectLock(unsigned int tableNumber) const noexcept override;

private:
__attribute__((noinline)) void GenerateDeferredDiagnostics(MessageType destination) noexcept;

#ifndef DUET_NG // Duet 2 doesn't currently need this feature, so omit it to save memory
struct DebugLogRecord
Expand Down

0 comments on commit 4c2ea49

Please sign in to comment.