Skip to content

Commit 6c7cdfa

Browse files
committed
WIP Refactor RTT implementation
1 parent 5925bb0 commit 6c7cdfa

File tree

13 files changed

+184
-262
lines changed

13 files changed

+184
-262
lines changed

examples/blue_pill_f103/rtt/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<extends>modm:blue-pill-f103</extends>
33
<options>
44
<option name="modm:build:build.path">../../../build/blue_pill_f103/rtt</option>
5-
<option name="modm:platform:rtt:buffer.rx">16</option>
5+
<option name="modm:rtt:buffer.rx">16</option>
66
</options>
77
<modules>
88
<module>modm:platform:rtt</module>

examples/blue_pill_f103/servo_pwm/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<extends>modm:blue-pill-f103</extends>
33
<options>
44
<option name="modm:build:build.path">../../../build/blue_pill_f103/servo_pwm</option>
5-
<option name="modm:platform:rtt:buffer.tx">128</option>
5+
<option name="modm:rtt:buffer.tx">128</option>
66
</options>
77
<modules>
88
<module>modm:build:scons</module>

examples/nucleo_f429zi/spi_flash_fatfs/project.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<extends>modm:nucleo-f429zi</extends>
33
<options>
44
<option name="modm:build:build.path">../../../build/nucleo_f429zi/spi_flash_fatfs</option>
5-
<option name="modm:platform:rtt:buffer.tx">4096</option>
65
</options>
76
<modules>
87
<module>modm:build:scons</module>

examples/nucleo_l476rg/rtt/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<extends>modm:nucleo-l476rg</extends>
33
<options>
44
<option name="modm:build:build.path">../../../build/nucleo_l476rg/rtt</option>
5-
<option name="modm:platform:rtt:buffer.rx">16</option>
5+
<option name="modm:rtt:buffer.rx">16</option>
66
</options>
77
<modules>
88
<module>modm:platform:rtt</module>

examples/stm32f3_discovery/rtt/project.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<extends>modm:disco-f303vc</extends>
33
<options>
44
<option name="modm:build:build.path">../../../build/stm32f3_discovery/rtt</option>
5-
<option name="modm:platform:rtt:buffer.rx">16</option>
5+
<option name="modm:rtt:buffer.tx">512, 0, 1024</option>
6+
<option name="modm:rtt:buffer.rx">16, 32, 0</option>
67
</options>
78
<modules>
89
<module>modm:platform:rtt</module>

ext/segger/SEGGER_RTT_Conf.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
# define SEGGER_RTT_MAX_INTERRUPT_PRIORITY ((1ul << __NVIC_PRIO_BITS) - 1ul)
4545
#endif
4646

47+
// Non-standard useful functions
48+
unsigned SEGGER_RTT_GetBytesInDownBuffer(unsigned BufferIndex);
49+
4750
// RTT lock configuration for GCC
4851
#if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__))
4952

ext/segger/rtt_modm_port.cpp.in

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
99
*/
1010

11-
#include "SEGGER_RTT.h"
11+
#include <SEGGER_RTT.h>
1212
%#
1313
%% for index in range(buffer_tx[1:] | length)
1414
%% if buffer_tx[index+1]
@@ -35,12 +35,46 @@ static void modm_rtt_init()
3535
%% endfor
3636
}
3737
%#
38+
/*********************************************************************
39+
*
40+
* SEGGER_RTT_GetBytesInBuffer()
41+
*
42+
* Function description
43+
* Returns the number of bytes currently used in the down buffer.
44+
*
45+
* Parameters
46+
* BufferIndex Index of the down buffer.
47+
*
48+
* Return value
49+
* Number of bytes that are used in the buffer.
50+
*/
51+
unsigned SEGGER_RTT_GetBytesInDownBuffer(unsigned BufferIndex) {
52+
unsigned RdOff;
53+
unsigned WrOff;
54+
unsigned r;
55+
volatile SEGGER_RTT_CB* pRTTCB;
56+
//
57+
// Avoid warnings regarding volatile access order. It's not a problem
58+
// in this case, but dampen compiler enthusiasm.
59+
//
60+
// Access RTTCB uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly
61+
pRTTCB = (volatile SEGGER_RTT_CB*)((uintptr_t)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF);
62+
RdOff = pRTTCB->aDown[BufferIndex].RdOff;
63+
WrOff = pRTTCB->aDown[BufferIndex].WrOff;
64+
if (RdOff <= WrOff) {
65+
r = WrOff - RdOff;
66+
} else {
67+
r = pRTTCB->aDown[BufferIndex].SizeOfBuffer - (WrOff - RdOff);
68+
}
69+
return r;
70+
}
71+
%#
3872
%% if with_printf
3973
#include <modm/ext/printf/printf.h>
4074

4175
static void output_gadget(char c, void* BufferIndex)
4276
{
43-
SEGGER_RTT_WriteSkipNoLock((unsigned) BufferIndex, &c, 1);
77+
SEGGER_RTT_PutCharSkipNoLock((unsigned) BufferIndex, c);
4478
}
4579

4680
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...)

src/modm/platform/uart/rtt/module.lb

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,22 @@ def init(module):
1414
module.name = ":platform:rtt"
1515
module.description = FileReader("module.md")
1616

17+
1718
def prepare(module, options):
1819
if not options[":target"].has_driver("core:cortex-m*"):
1920
return False
2021

21-
module.add_list_option(
22-
NumericOption(name="buffer.tx", description="Transmit buffer sizes",
23-
minimum=0, maximum="64Ki"), default=512)
24-
module.add_list_option(
25-
NumericOption(name="buffer.rx", description="Receive buffer sizes",
26-
minimum=0, maximum="64Ki"), default=0)
22+
module.add_alias(
23+
Alias(name="buffer.tx", destination=":rtt:buffer.tx",
24+
description="Moved to the `modm:rtt` module"))
25+
module.add_alias(
26+
Alias(name="buffer.rx", destination=":rtt:buffer.rx",
27+
description="Moved to the `modm:rtt` module"))
2728

28-
module.depends(":architecture:uart")
29+
module.depends(":architecture:uart", ":architecture:fiber", ":rtt")
2930
return True
3031

31-
def validate(env):
32-
if len(env["buffer.tx"]) != len(env["buffer.rx"]):
33-
raise ValidateException("There must be the same number of TX buffers as RX buffers!")
3432

3533
def build(env):
3634
env.outbasepath = "modm/src/modm/platform/rtt"
37-
env.substitutions = {
38-
"buffer_tx": env["buffer.tx"],
39-
"buffer_rx": env["buffer.rx"],
40-
}
41-
env.template("rtt.hpp.in")
42-
env.template("rtt.cpp.in")
35+
env.copy("rtt.hpp")

src/modm/platform/uart/rtt/module.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ buffer sizes indexed by channel. Here is an example of three channels:
3232
<!-- Channel0: TX only with 256B buffer -->
3333
<!-- Channel1: RX only with 128B buffer -->
3434
<!-- Channel2: TX with 512B and RX with 64B buffer -->
35-
<option name="modm:platform:rtt:buffer.tx">256, 0, 512</option>
36-
<option name="modm:platform:rtt:buffer.rx">0, 128, 64</option>
35+
<option name="modm:rtt:buffer.tx">256, 0, 512</option>
36+
<option name="modm:rtt:buffer.rx">0, 128, 64</option>
3737
```
3838

3939
You can set the buffer size to `0` if you don't want to use this channel

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

Lines changed: 0 additions & 153 deletions
This file was deleted.

0 commit comments

Comments
 (0)