Skip to content

Commit f6f0fd6

Browse files
committed
[rtt] Fix finding wrong identifier marker
1 parent 593abe7 commit f6f0fd6

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/modm/platform/uart/rtt/rtt.cpp.in

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ namespace modm::platform
1818

1919
struct RttBuffer
2020
{
21-
const char* name{nullptr};
22-
uint8_t* buffer{nullptr};
23-
const uint32_t size{0};
24-
volatile uint32_t head{0};
25-
volatile uint32_t tail{0};
26-
uint32_t flags{0};
21+
const char* name;
22+
uint8_t* const buffer;
23+
const uint32_t size;
24+
volatile uint32_t head;
25+
volatile uint32_t tail;
26+
const uint32_t flags;
2727

2828
bool write(uint8_t data)
2929
{
@@ -66,22 +66,30 @@ static uint8_t rx_data_buffer_{{loop.index0}}[{{size}}];
6666
%#
6767
struct RttControlBlock
6868
{
69-
const char identifier[16]{"modm.rtt.modm"};
70-
const int32_t tx_buffer_count{ {{ buffer_tx | length }} };
71-
const int32_t rx_buffer_count{ {{ buffer_rx | length }} };
72-
RttBuffer tx_buffers[{{ buffer_tx | length }}] = {
69+
const char identifier[16];
70+
const int32_t tx_buffer_count;
71+
const int32_t rx_buffer_count;
72+
RttBuffer tx_buffers[{{ buffer_tx | length }}];
73+
RttBuffer rx_buffers[{{ buffer_rx | length }}];
74+
} modm_packed;
75+
76+
// Explicitly constructed as constinit to force *only* copying via .data section.
77+
// This prevents the "modm.rtt.modm" identifier leaking into the stack and being
78+
// found by OpenOCD accidentally instead of the real RTT control block.
79+
static constinit RttControlBlock rtt_control{
80+
"modm.rtt.modm",
81+
{{ buffer_tx | length }},
82+
{{ buffer_rx | length }},
83+
{
7384
%% for size in buffer_tx
74-
{"tx{{loop.index0}}", {% if size %}tx_data_buffer_{{loop.index0}}{% else %}nullptr{% endif %}, {{size}} },
85+
{"tx{{loop.index0}}", {% if size %}tx_data_buffer_{{loop.index0}}{% else %}nullptr{% endif %}, {{size}}, 0,0,0 },
7586
%% endfor
76-
};
77-
RttBuffer rx_buffers[{{ buffer_rx | length }}] = {
87+
},{
7888
%% for size in buffer_rx
79-
{"rx{{loop.index0}}", {% if size %}rx_data_buffer_{{loop.index0}}{% else %}nullptr{% endif %}, {{size}} },
89+
{"rx{{loop.index0}}", {% if size %}rx_data_buffer_{{loop.index0}}{% else %}nullptr{% endif %}, {{size}}, 0,0,0 },
8090
%% endfor
81-
};
82-
} modm_packed;
83-
84-
static RttControlBlock rtt_control;
91+
}
92+
};
8593

8694

8795
Rtt::Rtt(uint8_t channel)

0 commit comments

Comments
 (0)