Skip to content

Commit 4c2ea49

Browse files
committed
Fix issue with main task stack usage too high after previous change
1 parent b034fd4 commit 4c2ea49

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Platform/RepRap.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,7 @@ void RepRap::Spin() noexcept
730730
// Check if we need to send diagnostics
731731
if (diagnosticsDestination != MessageType::NoDestinationMessage)
732732
{
733-
String<GCodeReplyLength> buf;
734-
Diagnostics(diagnosticsDestination, buf.GetRef());
733+
GenerateDeferredDiagnostics(diagnosticsDestination); // call out to separate function to keep stack usage under control
735734
diagnosticsDestination = MessageType::NoDestinationMessage;
736735
}
737736

@@ -808,6 +807,13 @@ void RepRap::Spin() noexcept
808807
RTOSIface::Yield();
809808
}
810809

810+
// 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.
811+
__attribute__((noinline)) void RepRap::GenerateDeferredDiagnostics(MessageType destination) noexcept
812+
{
813+
String<GCodeReplyLength> buf;
814+
Diagnostics(destination, buf.GetRef());
815+
}
816+
811817
void RepRap::Timing(const StringRef& reply) noexcept
812818
{
813819
reply.lcatf("Slowest loop: %.2fms; fastest: %.2fms", (double)(slowLoop * StepClocksToMillis), (double)(fastLoop * StepClocksToMillis));

src/Platform/RepRap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class RepRap final INHERIT_OBJECT_MODEL
178178
ReadWriteLock *_ecv_null GetObjectLock(unsigned int tableNumber) const noexcept override;
179179

180180
private:
181+
__attribute__((noinline)) void GenerateDeferredDiagnostics(MessageType destination) noexcept;
181182

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

0 commit comments

Comments
 (0)