@@ -18,12 +18,12 @@ namespace modm::platform
18
18
19
19
struct RttBuffer
20
20
{
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;
27
27
28
28
bool write(uint8_t data)
29
29
{
@@ -66,22 +66,30 @@ static uint8_t rx_data_buffer_{{loop.index0}}[{{size}}];
66
66
%#
67
67
struct RttControlBlock
68
68
{
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
+ {
73
84
%% 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 },
75
86
%% endfor
76
- };
77
- RttBuffer rx_buffers[{{ buffer_rx | length }}] = {
87
+ },{
78
88
%% 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 },
80
90
%% endfor
81
- };
82
- } modm_packed;
83
-
84
- static RttControlBlock rtt_control;
91
+ }
92
+ };
85
93
86
94
87
95
Rtt::Rtt(uint8_t channel)
0 commit comments