Skip to content

Commit 727797a

Browse files
committed
factorysetup: use Segger RTT instead of USB for communications
Simplifies the factory setup process by only requiring a Segger JLink device. We also take the attestation sighash salt from the host for flexibility.
1 parent 26bda5c commit 727797a

21 files changed

+5121
-38
lines changed

external/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,13 @@ add_library(ctaes
251251
ctaes/ctaes.c
252252
)
253253
target_include_directories(ctaes SYSTEM PUBLIC ctaes)
254+
255+
add_library(rtt
256+
SEGGER_RTT_V796b/RTT/SEGGER_RTT.c
257+
)
258+
target_compile_options(rtt PRIVATE "-Wno-cast-qual")
259+
# Define RTT config vars. The default DOWN buffer size (buffer for reading from host) is 64, which
260+
# is too small for our need. The default UP buffer size (buffer for writing to host) is 1024, but
261+
# we define it anyway here in case the default changes.
262+
target_compile_definitions(rtt PUBLIC "BUFFER_SIZE_DOWN=(1024)" "BUFFER_SIZE_UP=(1024)")
263+
target_include_directories(rtt SYSTEM PUBLIC SEGGER_RTT_V796b/RTT SEGGER_RTT_V796b/Config)

external/SEGGER_RTT_V796b/Config/SEGGER_RTT_Conf.h

Lines changed: 425 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*********************************************************************
2+
* SEGGER Microcontroller GmbH *
3+
* Solutions for real time microcontroller applications *
4+
**********************************************************************
5+
* *
6+
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
7+
* *
8+
* www.segger.com Support: support@segger.com *
9+
* *
10+
**********************************************************************
11+
12+
--------- END-OF-HEADER --------------------------------------------
13+
File : Main_RTT_MenuApp.c
14+
Purpose : Sample application to demonstrate RTT bi-directional functionality
15+
*/
16+
17+
#define MAIN_C
18+
19+
#include <stdio.h>
20+
21+
#include "SEGGER_RTT.h"
22+
23+
volatile int _Cnt;
24+
volatile int _Delay;
25+
26+
static char r;
27+
28+
/*********************************************************************
29+
*
30+
* main
31+
*/
32+
void main(void) {
33+
34+
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
35+
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
36+
do {
37+
r = SEGGER_RTT_WaitKey();
38+
SEGGER_RTT_Write(0, &r, 1);
39+
r++;
40+
} while (1);
41+
}
42+
43+
/*************************** End of file ****************************/
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*********************************************************************
2+
* SEGGER Microcontroller GmbH *
3+
* Solutions for real time microcontroller applications *
4+
**********************************************************************
5+
* *
6+
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
7+
* *
8+
* www.segger.com Support: support@segger.com *
9+
* *
10+
**********************************************************************
11+
--------- END-OF-HEADER --------------------------------------------
12+
File : Main_RTT_MenuApp.c
13+
Purpose : Sample application to demonstrate RTT bi-directional functionality
14+
*/
15+
16+
#define MAIN_C
17+
18+
#include <stdio.h>
19+
20+
#include "SEGGER_RTT.h"
21+
22+
volatile int _Cnt;
23+
volatile int _Delay;
24+
25+
/*********************************************************************
26+
*
27+
* main
28+
*/
29+
void main(void) {
30+
int r;
31+
int CancelOp;
32+
33+
do {
34+
_Cnt = 0;
35+
36+
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
37+
SEGGER_RTT_WriteString(0, "Press <1> to continue in blocking mode (Application waits if necessary, no data lost)\r\n");
38+
SEGGER_RTT_WriteString(0, "Press <2> to continue in non-blocking mode (Application does not wait, data lost if fifo full)\r\n");
39+
do {
40+
r = SEGGER_RTT_WaitKey();
41+
} while ((r != '1') && (r != '2'));
42+
if (r == '1') {
43+
SEGGER_RTT_WriteString(0, "\r\nSelected <1>. Configuring RTT and starting...\r\n");
44+
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
45+
} else {
46+
SEGGER_RTT_WriteString(0, "\r\nSelected <2>. Configuring RTT and starting...\r\n");
47+
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
48+
}
49+
CancelOp = 0;
50+
do {
51+
//for (_Delay = 0; _Delay < 10000; _Delay++);
52+
SEGGER_RTT_printf(0, "Count: %d. Press <Space> to get back to menu.\r\n", _Cnt++);
53+
r = SEGGER_RTT_HasKey();
54+
if (r) {
55+
CancelOp = (SEGGER_RTT_GetKey() == ' ') ? 1 : 0;
56+
}
57+
//
58+
// Check if user selected to cancel the current operation
59+
//
60+
if (CancelOp) {
61+
SEGGER_RTT_WriteString(0, "Operation cancelled, going back to menu...\r\n");
62+
break;
63+
}
64+
} while (1);
65+
SEGGER_RTT_GetKey();
66+
SEGGER_RTT_WriteString(0, "\r\n");
67+
} while (1);
68+
}
69+
70+
/*************************** End of file ****************************/
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*********************************************************************
2+
* SEGGER Microcontroller GmbH *
3+
* Solutions for real time microcontroller applications *
4+
**********************************************************************
5+
* *
6+
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
7+
* *
8+
* www.segger.com Support: support@segger.com *
9+
* *
10+
**********************************************************************
11+
12+
--------- END-OF-HEADER --------------------------------------------
13+
File : Main_RTT_MenuApp.c
14+
Purpose : Sample application to demonstrate RTT bi-directional functionality
15+
*/
16+
17+
#define MAIN_C
18+
19+
#include <stdio.h>
20+
21+
#include "SEGGER_RTT.h"
22+
23+
volatile int _Cnt;
24+
25+
/*********************************************************************
26+
*
27+
* main
28+
*/
29+
void main(void) {
30+
31+
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
32+
33+
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n\r\n");
34+
SEGGER_RTT_WriteString(0, "###### Testing SEGGER_printf() ######\r\n");
35+
36+
SEGGER_RTT_printf(0, "printf Test: %%c, 'S' : %c.\r\n", 'S');
37+
SEGGER_RTT_printf(0, "printf Test: %%5c, 'E' : %5c.\r\n", 'E');
38+
SEGGER_RTT_printf(0, "printf Test: %%-5c, 'G' : %-5c.\r\n", 'G');
39+
SEGGER_RTT_printf(0, "printf Test: %%5.3c, 'G' : %-5c.\r\n", 'G');
40+
SEGGER_RTT_printf(0, "printf Test: %%.3c, 'E' : %-5c.\r\n", 'E');
41+
SEGGER_RTT_printf(0, "printf Test: %%c, 'R' : %c.\r\n", 'R');
42+
43+
SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\" : %s.\r\n", "RTT");
44+
SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\\r\\nRocks.\" : %s.\r\n", "RTT\r\nRocks.");
45+
46+
SEGGER_RTT_printf(0, "printf Test: %%u, 12345 : %u.\r\n", 12345);
47+
SEGGER_RTT_printf(0, "printf Test: %%+u, 12345 : %+u.\r\n", 12345);
48+
SEGGER_RTT_printf(0, "printf Test: %%.3u, 12345 : %.3u.\r\n", 12345);
49+
SEGGER_RTT_printf(0, "printf Test: %%.6u, 12345 : %.6u.\r\n", 12345);
50+
SEGGER_RTT_printf(0, "printf Test: %%6.3u, 12345 : %6.3u.\r\n", 12345);
51+
SEGGER_RTT_printf(0, "printf Test: %%8.6u, 12345 : %8.6u.\r\n", 12345);
52+
SEGGER_RTT_printf(0, "printf Test: %%08u, 12345 : %08u.\r\n", 12345);
53+
SEGGER_RTT_printf(0, "printf Test: %%08.6u, 12345 : %08.6u.\r\n", 12345);
54+
SEGGER_RTT_printf(0, "printf Test: %%0u, 12345 : %0u.\r\n", 12345);
55+
SEGGER_RTT_printf(0, "printf Test: %%-.6u, 12345 : %-.6u.\r\n", 12345);
56+
SEGGER_RTT_printf(0, "printf Test: %%-6.3u, 12345 : %-6.3u.\r\n", 12345);
57+
SEGGER_RTT_printf(0, "printf Test: %%-8.6u, 12345 : %-8.6u.\r\n", 12345);
58+
SEGGER_RTT_printf(0, "printf Test: %%-08u, 12345 : %-08u.\r\n", 12345);
59+
SEGGER_RTT_printf(0, "printf Test: %%-08.6u, 12345 : %-08.6u.\r\n", 12345);
60+
SEGGER_RTT_printf(0, "printf Test: %%-0u, 12345 : %-0u.\r\n", 12345);
61+
62+
SEGGER_RTT_printf(0, "printf Test: %%u, -12345 : %u.\r\n", -12345);
63+
SEGGER_RTT_printf(0, "printf Test: %%+u, -12345 : %+u.\r\n", -12345);
64+
SEGGER_RTT_printf(0, "printf Test: %%.3u, -12345 : %.3u.\r\n", -12345);
65+
SEGGER_RTT_printf(0, "printf Test: %%.6u, -12345 : %.6u.\r\n", -12345);
66+
SEGGER_RTT_printf(0, "printf Test: %%6.3u, -12345 : %6.3u.\r\n", -12345);
67+
SEGGER_RTT_printf(0, "printf Test: %%8.6u, -12345 : %8.6u.\r\n", -12345);
68+
SEGGER_RTT_printf(0, "printf Test: %%08u, -12345 : %08u.\r\n", -12345);
69+
SEGGER_RTT_printf(0, "printf Test: %%08.6u, -12345 : %08.6u.\r\n", -12345);
70+
SEGGER_RTT_printf(0, "printf Test: %%0u, -12345 : %0u.\r\n", -12345);
71+
SEGGER_RTT_printf(0, "printf Test: %%-.6u, -12345 : %-.6u.\r\n", -12345);
72+
SEGGER_RTT_printf(0, "printf Test: %%-6.3u, -12345 : %-6.3u.\r\n", -12345);
73+
SEGGER_RTT_printf(0, "printf Test: %%-8.6u, -12345 : %-8.6u.\r\n", -12345);
74+
SEGGER_RTT_printf(0, "printf Test: %%-08u, -12345 : %-08u.\r\n", -12345);
75+
SEGGER_RTT_printf(0, "printf Test: %%-08.6u, -12345 : %-08.6u.\r\n", -12345);
76+
SEGGER_RTT_printf(0, "printf Test: %%-0u, -12345 : %-0u.\r\n", -12345);
77+
78+
SEGGER_RTT_printf(0, "printf Test: %%d, -12345 : %d.\r\n", -12345);
79+
SEGGER_RTT_printf(0, "printf Test: %%+d, -12345 : %+d.\r\n", -12345);
80+
SEGGER_RTT_printf(0, "printf Test: %%.3d, -12345 : %.3d.\r\n", -12345);
81+
SEGGER_RTT_printf(0, "printf Test: %%.6d, -12345 : %.6d.\r\n", -12345);
82+
SEGGER_RTT_printf(0, "printf Test: %%6.3d, -12345 : %6.3d.\r\n", -12345);
83+
SEGGER_RTT_printf(0, "printf Test: %%8.6d, -12345 : %8.6d.\r\n", -12345);
84+
SEGGER_RTT_printf(0, "printf Test: %%08d, -12345 : %08d.\r\n", -12345);
85+
SEGGER_RTT_printf(0, "printf Test: %%08.6d, -12345 : %08.6d.\r\n", -12345);
86+
SEGGER_RTT_printf(0, "printf Test: %%0d, -12345 : %0d.\r\n", -12345);
87+
SEGGER_RTT_printf(0, "printf Test: %%-.6d, -12345 : %-.6d.\r\n", -12345);
88+
SEGGER_RTT_printf(0, "printf Test: %%-6.3d, -12345 : %-6.3d.\r\n", -12345);
89+
SEGGER_RTT_printf(0, "printf Test: %%-8.6d, -12345 : %-8.6d.\r\n", -12345);
90+
SEGGER_RTT_printf(0, "printf Test: %%-08d, -12345 : %-08d.\r\n", -12345);
91+
SEGGER_RTT_printf(0, "printf Test: %%-08.6d, -12345 : %-08.6d.\r\n", -12345);
92+
SEGGER_RTT_printf(0, "printf Test: %%-0d, -12345 : %-0d.\r\n", -12345);
93+
94+
SEGGER_RTT_printf(0, "printf Test: %%x, 0x1234ABC : %x.\r\n", 0x1234ABC);
95+
SEGGER_RTT_printf(0, "printf Test: %%+x, 0x1234ABC : %+x.\r\n", 0x1234ABC);
96+
SEGGER_RTT_printf(0, "printf Test: %%.3x, 0x1234ABC : %.3x.\r\n", 0x1234ABC);
97+
SEGGER_RTT_printf(0, "printf Test: %%.6x, 0x1234ABC : %.6x.\r\n", 0x1234ABC);
98+
SEGGER_RTT_printf(0, "printf Test: %%6.3x, 0x1234ABC : %6.3x.\r\n", 0x1234ABC);
99+
SEGGER_RTT_printf(0, "printf Test: %%8.6x, 0x1234ABC : %8.6x.\r\n", 0x1234ABC);
100+
SEGGER_RTT_printf(0, "printf Test: %%08x, 0x1234ABC : %08x.\r\n", 0x1234ABC);
101+
SEGGER_RTT_printf(0, "printf Test: %%08.6x, 0x1234ABC : %08.6x.\r\n", 0x1234ABC);
102+
SEGGER_RTT_printf(0, "printf Test: %%0x, 0x1234ABC : %0x.\r\n", 0x1234ABC);
103+
SEGGER_RTT_printf(0, "printf Test: %%-.6x, 0x1234ABC : %-.6x.\r\n", 0x1234ABC);
104+
SEGGER_RTT_printf(0, "printf Test: %%-6.3x, 0x1234ABC : %-6.3x.\r\n", 0x1234ABC);
105+
SEGGER_RTT_printf(0, "printf Test: %%-8.6x, 0x1234ABC : %-8.6x.\r\n", 0x1234ABC);
106+
SEGGER_RTT_printf(0, "printf Test: %%-08x, 0x1234ABC : %-08x.\r\n", 0x1234ABC);
107+
SEGGER_RTT_printf(0, "printf Test: %%-08.6x, 0x1234ABC : %-08.6x.\r\n", 0x1234ABC);
108+
SEGGER_RTT_printf(0, "printf Test: %%-0x, 0x1234ABC : %-0x.\r\n", 0x1234ABC);
109+
110+
SEGGER_RTT_printf(0, "printf Test: %%p, &_Cnt : %p.\r\n", &_Cnt);
111+
112+
SEGGER_RTT_WriteString(0, "###### SEGGER_printf() Tests done. ######\r\n");
113+
do {
114+
_Cnt++;
115+
} while (1);
116+
}
117+
118+
/*************************** End of file ****************************/
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*********************************************************************
2+
* SEGGER Microcontroller GmbH *
3+
* Solutions for real time microcontroller applications *
4+
**********************************************************************
5+
* *
6+
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
7+
* *
8+
* www.segger.com Support: support@segger.com *
9+
* *
10+
**********************************************************************
11+
12+
--------- END-OF-HEADER --------------------------------------------
13+
File : Main_RTT_SpeedTestApp.c
14+
Purpose : Sample program for measuring RTT performance.
15+
*/
16+
17+
#include "RTOS.h"
18+
#include "BSP.h"
19+
20+
#include "SEGGER_RTT.h"
21+
#include <stdio.h>
22+
23+
OS_STACKPTR int StackHP[128], StackLP[128]; /* Task stacks */
24+
OS_TASK TCBHP, TCBLP; /* Task-control-blocks */
25+
26+
static void HPTask(void) {
27+
while (1) {
28+
//
29+
// Measure time needed for RTT output
30+
// Perform dummy write with 0 characters, so we know the overhead of toggling LEDs and RTT in general
31+
//
32+
// Set BP here. Then start sampling on scope
33+
BSP_ClrLED(0);
34+
SEGGER_RTT_Write(0, 0, 0);
35+
BSP_SetLED(0);
36+
BSP_ClrLED(0);
37+
SEGGER_RTT_Write(0, "01234567890123456789012345678901234567890123456789012345678901234567890123456789\r\n", 82);
38+
BSP_SetLED(0);
39+
// Set BP here. Then stop sampling on scope
40+
OS_Delay(200);
41+
}
42+
}
43+
44+
static void LPTask(void) {
45+
while (1) {
46+
BSP_ToggleLED(1);
47+
OS_Delay (500);
48+
}
49+
}
50+
51+
/*********************************************************************
52+
*
53+
* main
54+
*
55+
*********************************************************************/
56+
57+
int main(void) {
58+
OS_IncDI(); /* Initially disable interrupts */
59+
OS_InitKern(); /* Initialize OS */
60+
OS_InitHW(); /* Initialize Hardware for OS */
61+
BSP_Init(); /* Initialize LED ports */
62+
BSP_SetLED(0);
63+
/* You need to create at least one task before calling OS_Start() */
64+
OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);
65+
OS_CREATETASK(&TCBLP, "LP Task", LPTask, 50, StackLP);
66+
OS_Start(); /* Start multitasking */
67+
return 0;
68+
}
69+

external/SEGGER_RTT_V796b/LICENSE.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
SEGGER Microcontroller GmbH
3+
The Embedded Experts
4+
5+
(c) 1995 - 2021 SEGGER Microcontroller GmbH
6+
www.segger.com Support: support@segger.com
7+
8+
SEGGER RTT Real Time Transfer for embedded targets
9+
10+
11+
All rights reserved.
12+
13+
SEGGER strongly recommends to not make any changes
14+
to or modify the source code of this software in order to stay
15+
compatible with the RTT protocol and J-Link.
16+
17+
Redistribution and use in source and binary forms, with or
18+
without modification, are permitted provided that the following
19+
condition is met:
20+
21+
- Redistributions of source code must retain the above copyright
22+
notice, this condition and the following disclaimer.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25+
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28+
DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR
29+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
31+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
36+
DAMAGE.

external/SEGGER_RTT_V796b/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
RTT
2+
===
3+
4+
SEGGER RTT Sources
5+
6+
https://www.segger.com/products/debug-probes/j-link/technology/about-real-time-transfer
7+
https://wiki.segger.com/RTT
8+
9+
## Included files
10+
11+
* `RTT/`
12+
* `SEGGER_RTT.c` - Main module for RTT.
13+
* `SEGGER_RTT.h` - Main header for RTT.
14+
* `SEGGER_RTT_ASM_ARMv7M.S` - Assembly-optimized implementation of RTT functions for ARMv7M processors.
15+
* `SEGGER_RTT_Printf.c` - Simple implementation of printf (`SEGGER_RTT_Printf()`) to write formatted strings via RTT.
16+
* `Syscalls/`
17+
* `SEGGER_RTT_Syscalls_*.c` - Low-level syscalls to retarget `printf()` to RTT with different toolchains.
18+
* `Config/`
19+
* `SEGGER_RTT_Conf.h` - RTT configuration file.
20+
* `Examples/`
21+
* `Main_RTT_InputEchoApp.c` - Example application which echoes input on Channel 0.
22+
* `Main_RTT_MenuApp.c` - Example application to demonstrate RTT bi-directional functionality.
23+
* `Main_RTT_PrintfTest.c` - Example application to test RTT's simple printf implementation.
24+
* `Main_RTT_SpeedTestApp.c` - Example application to measure RTT performance. (Requires embOS)

0 commit comments

Comments
 (0)