Skip to content

Commit 08c06de

Browse files
committed
Add segger RTT as a logger output implementation
1 parent f044cdc commit 08c06de

19 files changed

Lines changed: 5199 additions & 0 deletions

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/internal/tools.cmake)
3838
add_subdirectory(Drivers)
3939
add_subdirectory(Middlewares/ST)
4040
add_subdirectory(Middlewares/Third_Party/FatFs)
41+
add_subdirectory(Middlewares/Third_Party/RTT)
4142

4243
add_library(daisy STATIC
4344
${MODULE_DIR}/daisy_field.cpp
@@ -112,6 +113,7 @@ target_link_libraries(daisy PUBLIC
112113
STM32_USB_DEVICE_LIBRARY
113114
STM32_USB_HOST_LIBRARY
114115
FatFs
116+
RTT
115117
)
116118

117119
# There is a abstract `IReader` interface that allows that can be swappped out
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enable_language(C ASM)
2+
add_library(RTT STATIC
3+
RTT/SEGGER_RTT.c
4+
RTT/SEGGER_RTT_printf.c
5+
RTT/SEGGER_RTT_ASM_ARMv7M.S
6+
)
7+
8+
target_include_directories(RTT PUBLIC
9+
Config
10+
RTT
11+
)

Middlewares/Third_Party/RTT/Config/SEGGER_RTT_Conf.h

Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*********************************************************************
2+
* SEGGER Microcontroller GmbH *
3+
* The Embedded Experts *
4+
**********************************************************************
5+
* *
6+
* (c) 1995 - 2021 SEGGER Microcontroller GmbH *
7+
* *
8+
* www.segger.com Support: support@segger.com *
9+
* *
10+
**********************************************************************
11+
* *
12+
* SEGGER RTT * Real Time Transfer for embedded targets *
13+
* *
14+
**********************************************************************
15+
* *
16+
* All rights reserved. *
17+
* *
18+
* SEGGER strongly recommends to not make any changes *
19+
* to or modify the source code of this software in order to stay *
20+
* compatible with the RTT protocol and J-Link. *
21+
* *
22+
* Redistribution and use in source and binary forms, with or *
23+
* without modification, are permitted provided that the following *
24+
* condition is met: *
25+
* *
26+
* o Redistributions of source code must retain the above copyright *
27+
* notice, this condition and the following disclaimer. *
28+
* *
29+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
30+
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
31+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
32+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
33+
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
34+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
35+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
36+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
37+
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
38+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
39+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
40+
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
41+
* DAMAGE. *
42+
* *
43+
**********************************************************************
44+
* *
45+
* RTT version: 7.54 *
46+
* *
47+
**********************************************************************
48+
49+
--------- END-OF-HEADER --------------------------------------------
50+
File : Main_RTT_MenuApp.c
51+
Purpose : Sample application to demonstrate RTT bi-directional functionality
52+
*/
53+
54+
#define MAIN_C
55+
56+
#include <stdio.h>
57+
58+
#include "SEGGER_RTT.h"
59+
60+
volatile int _Cnt;
61+
volatile int _Delay;
62+
63+
static char r;
64+
65+
/*********************************************************************
66+
*
67+
* main
68+
*/
69+
void main(void) {
70+
71+
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
72+
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
73+
do {
74+
r = SEGGER_RTT_WaitKey();
75+
SEGGER_RTT_Write(0, &r, 1);
76+
r++;
77+
} while (1);
78+
}
79+
80+
/*************************** End of file ****************************/
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*********************************************************************
2+
* SEGGER Microcontroller GmbH *
3+
* The Embedded Experts *
4+
**********************************************************************
5+
* *
6+
* (c) 1995 - 2021 SEGGER Microcontroller GmbH *
7+
* *
8+
* www.segger.com Support: support@segger.com *
9+
* *
10+
**********************************************************************
11+
* *
12+
* SEGGER RTT * Real Time Transfer for embedded targets *
13+
* *
14+
**********************************************************************
15+
* *
16+
* All rights reserved. *
17+
* *
18+
* SEGGER strongly recommends to not make any changes *
19+
* to or modify the source code of this software in order to stay *
20+
* compatible with the RTT protocol and J-Link. *
21+
* *
22+
* Redistribution and use in source and binary forms, with or *
23+
* without modification, are permitted provided that the following *
24+
* condition is met: *
25+
* *
26+
* o Redistributions of source code must retain the above copyright *
27+
* notice, this condition and the following disclaimer. *
28+
* *
29+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
30+
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
31+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
32+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
33+
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
34+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
35+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
36+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
37+
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
38+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
39+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
40+
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
41+
* DAMAGE. *
42+
* *
43+
**********************************************************************
44+
* *
45+
* RTT version: 7.54 *
46+
* *
47+
**********************************************************************
48+
49+
--------- END-OF-HEADER --------------------------------------------
50+
File : Main_RTT_MenuApp.c
51+
Purpose : Sample application to demonstrate RTT bi-directional functionality
52+
*/
53+
54+
#define MAIN_C
55+
56+
#include <stdio.h>
57+
58+
#include "SEGGER_RTT.h"
59+
60+
volatile int _Cnt;
61+
volatile int _Delay;
62+
63+
/*********************************************************************
64+
*
65+
* main
66+
*/
67+
void main(void) {
68+
int r;
69+
int CancelOp;
70+
71+
do {
72+
_Cnt = 0;
73+
74+
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
75+
SEGGER_RTT_WriteString(0, "Press <1> to continue in blocking mode (Application waits if necessary, no data lost)\r\n");
76+
SEGGER_RTT_WriteString(0, "Press <2> to continue in non-blocking mode (Application does not wait, data lost if fifo full)\r\n");
77+
do {
78+
r = SEGGER_RTT_WaitKey();
79+
} while ((r != '1') && (r != '2'));
80+
if (r == '1') {
81+
SEGGER_RTT_WriteString(0, "\r\nSelected <1>. Configuring RTT and starting...\r\n");
82+
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
83+
} else {
84+
SEGGER_RTT_WriteString(0, "\r\nSelected <2>. Configuring RTT and starting...\r\n");
85+
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
86+
}
87+
CancelOp = 0;
88+
do {
89+
//for (_Delay = 0; _Delay < 10000; _Delay++);
90+
SEGGER_RTT_printf(0, "Count: %d. Press <Space> to get back to menu.\r\n", _Cnt++);
91+
r = SEGGER_RTT_HasKey();
92+
if (r) {
93+
CancelOp = (SEGGER_RTT_GetKey() == ' ') ? 1 : 0;
94+
}
95+
//
96+
// Check if user selected to cancel the current operation
97+
//
98+
if (CancelOp) {
99+
SEGGER_RTT_WriteString(0, "Operation cancelled, going back to menu...\r\n");
100+
break;
101+
}
102+
} while (1);
103+
SEGGER_RTT_GetKey();
104+
SEGGER_RTT_WriteString(0, "\r\n");
105+
} while (1);
106+
}
107+
108+
/*************************** End of file ****************************/
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*********************************************************************
2+
* SEGGER Microcontroller GmbH *
3+
* The Embedded Experts *
4+
**********************************************************************
5+
* *
6+
* (c) 1995 - 2021 SEGGER Microcontroller GmbH *
7+
* *
8+
* www.segger.com Support: support@segger.com *
9+
* *
10+
**********************************************************************
11+
* *
12+
* SEGGER RTT * Real Time Transfer for embedded targets *
13+
* *
14+
**********************************************************************
15+
* *
16+
* All rights reserved. *
17+
* *
18+
* SEGGER strongly recommends to not make any changes *
19+
* to or modify the source code of this software in order to stay *
20+
* compatible with the RTT protocol and J-Link. *
21+
* *
22+
* Redistribution and use in source and binary forms, with or *
23+
* without modification, are permitted provided that the following *
24+
* condition is met: *
25+
* *
26+
* o Redistributions of source code must retain the above copyright *
27+
* notice, this condition and the following disclaimer. *
28+
* *
29+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
30+
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
31+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
32+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
33+
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
34+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
35+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
36+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
37+
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
38+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
39+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
40+
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
41+
* DAMAGE. *
42+
* *
43+
**********************************************************************
44+
* *
45+
* RTT version: 7.54 *
46+
* *
47+
**********************************************************************
48+
49+
--------- END-OF-HEADER --------------------------------------------
50+
File : Main_RTT_MenuApp.c
51+
Purpose : Sample application to demonstrate RTT bi-directional functionality
52+
*/
53+
54+
#define MAIN_C
55+
56+
#include <stdio.h>
57+
58+
#include "SEGGER_RTT.h"
59+
60+
volatile int _Cnt;
61+
62+
/*********************************************************************
63+
*
64+
* main
65+
*/
66+
void main(void) {
67+
68+
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
69+
70+
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n\r\n");
71+
SEGGER_RTT_WriteString(0, "###### Testing SEGGER_printf() ######\r\n");
72+
73+
SEGGER_RTT_printf(0, "printf Test: %%c, 'S' : %c.\r\n", 'S');
74+
SEGGER_RTT_printf(0, "printf Test: %%5c, 'E' : %5c.\r\n", 'E');
75+
SEGGER_RTT_printf(0, "printf Test: %%-5c, 'G' : %-5c.\r\n", 'G');
76+
SEGGER_RTT_printf(0, "printf Test: %%5.3c, 'G' : %-5c.\r\n", 'G');
77+
SEGGER_RTT_printf(0, "printf Test: %%.3c, 'E' : %-5c.\r\n", 'E');
78+
SEGGER_RTT_printf(0, "printf Test: %%c, 'R' : %c.\r\n", 'R');
79+
80+
SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\" : %s.\r\n", "RTT");
81+
SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\\r\\nRocks.\" : %s.\r\n", "RTT\r\nRocks.");
82+
83+
SEGGER_RTT_printf(0, "printf Test: %%u, 12345 : %u.\r\n", 12345);
84+
SEGGER_RTT_printf(0, "printf Test: %%+u, 12345 : %+u.\r\n", 12345);
85+
SEGGER_RTT_printf(0, "printf Test: %%.3u, 12345 : %.3u.\r\n", 12345);
86+
SEGGER_RTT_printf(0, "printf Test: %%.6u, 12345 : %.6u.\r\n", 12345);
87+
SEGGER_RTT_printf(0, "printf Test: %%6.3u, 12345 : %6.3u.\r\n", 12345);
88+
SEGGER_RTT_printf(0, "printf Test: %%8.6u, 12345 : %8.6u.\r\n", 12345);
89+
SEGGER_RTT_printf(0, "printf Test: %%08u, 12345 : %08u.\r\n", 12345);
90+
SEGGER_RTT_printf(0, "printf Test: %%08.6u, 12345 : %08.6u.\r\n", 12345);
91+
SEGGER_RTT_printf(0, "printf Test: %%0u, 12345 : %0u.\r\n", 12345);
92+
SEGGER_RTT_printf(0, "printf Test: %%-.6u, 12345 : %-.6u.\r\n", 12345);
93+
SEGGER_RTT_printf(0, "printf Test: %%-6.3u, 12345 : %-6.3u.\r\n", 12345);
94+
SEGGER_RTT_printf(0, "printf Test: %%-8.6u, 12345 : %-8.6u.\r\n", 12345);
95+
SEGGER_RTT_printf(0, "printf Test: %%-08u, 12345 : %-08u.\r\n", 12345);
96+
SEGGER_RTT_printf(0, "printf Test: %%-08.6u, 12345 : %-08.6u.\r\n", 12345);
97+
SEGGER_RTT_printf(0, "printf Test: %%-0u, 12345 : %-0u.\r\n", 12345);
98+
99+
SEGGER_RTT_printf(0, "printf Test: %%u, -12345 : %u.\r\n", -12345);
100+
SEGGER_RTT_printf(0, "printf Test: %%+u, -12345 : %+u.\r\n", -12345);
101+
SEGGER_RTT_printf(0, "printf Test: %%.3u, -12345 : %.3u.\r\n", -12345);
102+
SEGGER_RTT_printf(0, "printf Test: %%.6u, -12345 : %.6u.\r\n", -12345);
103+
SEGGER_RTT_printf(0, "printf Test: %%6.3u, -12345 : %6.3u.\r\n", -12345);
104+
SEGGER_RTT_printf(0, "printf Test: %%8.6u, -12345 : %8.6u.\r\n", -12345);
105+
SEGGER_RTT_printf(0, "printf Test: %%08u, -12345 : %08u.\r\n", -12345);
106+
SEGGER_RTT_printf(0, "printf Test: %%08.6u, -12345 : %08.6u.\r\n", -12345);
107+
SEGGER_RTT_printf(0, "printf Test: %%0u, -12345 : %0u.\r\n", -12345);
108+
SEGGER_RTT_printf(0, "printf Test: %%-.6u, -12345 : %-.6u.\r\n", -12345);
109+
SEGGER_RTT_printf(0, "printf Test: %%-6.3u, -12345 : %-6.3u.\r\n", -12345);
110+
SEGGER_RTT_printf(0, "printf Test: %%-8.6u, -12345 : %-8.6u.\r\n", -12345);
111+
SEGGER_RTT_printf(0, "printf Test: %%-08u, -12345 : %-08u.\r\n", -12345);
112+
SEGGER_RTT_printf(0, "printf Test: %%-08.6u, -12345 : %-08.6u.\r\n", -12345);
113+
SEGGER_RTT_printf(0, "printf Test: %%-0u, -12345 : %-0u.\r\n", -12345);
114+
115+
SEGGER_RTT_printf(0, "printf Test: %%d, -12345 : %d.\r\n", -12345);
116+
SEGGER_RTT_printf(0, "printf Test: %%+d, -12345 : %+d.\r\n", -12345);
117+
SEGGER_RTT_printf(0, "printf Test: %%.3d, -12345 : %.3d.\r\n", -12345);
118+
SEGGER_RTT_printf(0, "printf Test: %%.6d, -12345 : %.6d.\r\n", -12345);
119+
SEGGER_RTT_printf(0, "printf Test: %%6.3d, -12345 : %6.3d.\r\n", -12345);
120+
SEGGER_RTT_printf(0, "printf Test: %%8.6d, -12345 : %8.6d.\r\n", -12345);
121+
SEGGER_RTT_printf(0, "printf Test: %%08d, -12345 : %08d.\r\n", -12345);
122+
SEGGER_RTT_printf(0, "printf Test: %%08.6d, -12345 : %08.6d.\r\n", -12345);
123+
SEGGER_RTT_printf(0, "printf Test: %%0d, -12345 : %0d.\r\n", -12345);
124+
SEGGER_RTT_printf(0, "printf Test: %%-.6d, -12345 : %-.6d.\r\n", -12345);
125+
SEGGER_RTT_printf(0, "printf Test: %%-6.3d, -12345 : %-6.3d.\r\n", -12345);
126+
SEGGER_RTT_printf(0, "printf Test: %%-8.6d, -12345 : %-8.6d.\r\n", -12345);
127+
SEGGER_RTT_printf(0, "printf Test: %%-08d, -12345 : %-08d.\r\n", -12345);
128+
SEGGER_RTT_printf(0, "printf Test: %%-08.6d, -12345 : %-08.6d.\r\n", -12345);
129+
SEGGER_RTT_printf(0, "printf Test: %%-0d, -12345 : %-0d.\r\n", -12345);
130+
131+
SEGGER_RTT_printf(0, "printf Test: %%x, 0x1234ABC : %x.\r\n", 0x1234ABC);
132+
SEGGER_RTT_printf(0, "printf Test: %%+x, 0x1234ABC : %+x.\r\n", 0x1234ABC);
133+
SEGGER_RTT_printf(0, "printf Test: %%.3x, 0x1234ABC : %.3x.\r\n", 0x1234ABC);
134+
SEGGER_RTT_printf(0, "printf Test: %%.6x, 0x1234ABC : %.6x.\r\n", 0x1234ABC);
135+
SEGGER_RTT_printf(0, "printf Test: %%6.3x, 0x1234ABC : %6.3x.\r\n", 0x1234ABC);
136+
SEGGER_RTT_printf(0, "printf Test: %%8.6x, 0x1234ABC : %8.6x.\r\n", 0x1234ABC);
137+
SEGGER_RTT_printf(0, "printf Test: %%08x, 0x1234ABC : %08x.\r\n", 0x1234ABC);
138+
SEGGER_RTT_printf(0, "printf Test: %%08.6x, 0x1234ABC : %08.6x.\r\n", 0x1234ABC);
139+
SEGGER_RTT_printf(0, "printf Test: %%0x, 0x1234ABC : %0x.\r\n", 0x1234ABC);
140+
SEGGER_RTT_printf(0, "printf Test: %%-.6x, 0x1234ABC : %-.6x.\r\n", 0x1234ABC);
141+
SEGGER_RTT_printf(0, "printf Test: %%-6.3x, 0x1234ABC : %-6.3x.\r\n", 0x1234ABC);
142+
SEGGER_RTT_printf(0, "printf Test: %%-8.6x, 0x1234ABC : %-8.6x.\r\n", 0x1234ABC);
143+
SEGGER_RTT_printf(0, "printf Test: %%-08x, 0x1234ABC : %-08x.\r\n", 0x1234ABC);
144+
SEGGER_RTT_printf(0, "printf Test: %%-08.6x, 0x1234ABC : %-08.6x.\r\n", 0x1234ABC);
145+
SEGGER_RTT_printf(0, "printf Test: %%-0x, 0x1234ABC : %-0x.\r\n", 0x1234ABC);
146+
147+
SEGGER_RTT_printf(0, "printf Test: %%p, &_Cnt : %p.\r\n", &_Cnt);
148+
149+
SEGGER_RTT_WriteString(0, "###### SEGGER_printf() Tests done. ######\r\n");
150+
do {
151+
_Cnt++;
152+
} while (1);
153+
}
154+
155+
/*************************** End of file ****************************/

0 commit comments

Comments
 (0)