Skip to content

Commit 27d488e

Browse files
committed
Add standard stream to CMSIS-Driver USART retarget implementation
1 parent 683a6af commit 27d488e

9 files changed

Lines changed: 613 additions & 2 deletions

ARM.CMSIS-Compiler.pdsc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@
108108
<require condition="CORE"/>
109109
<require condition="CortexDevice_ITM"/>
110110
</condition>
111+
<condition id="CORE UART_CMSIS">
112+
<description>CMSIS-Compiler CORE component and CMSIS-Driver USART</description>
113+
<require condition="CORE"/>
114+
<require Cclass="CMSIS Driver" Cgroup="USART"/>
115+
</condition>
111116

112117
<condition id="ARMCC CORE">
113118
<description>ARMCC and CORE component</description>
@@ -155,6 +160,13 @@
155160
<require condition="CORE"/>
156161
<require Cclass="CMSIS" Cgroup="RTOS2"/>
157162
</condition>
163+
164+
<condition id="STDIO UART CMSIS">
165+
<description>STDIO retarget to CMSIS Driver UART</description>
166+
<accept Cclass="CMSIS-Compiler" Cgroup="STDERR" Csub="UART" Cvariant="CMSIS"/>
167+
<accept Cclass="CMSIS-Compiler" Cgroup="STDIN" Csub="UART" Cvariant="CMSIS"/>
168+
<accept Cclass="CMSIS-Compiler" Cgroup="STDOUT" Csub="UART" Cvariant="CMSIS"/>
169+
</condition>
158170
</conditions>
159171
<taxonomy>
160172
<description Cclass="CMSIS-Compiler" doc="documentation/html/index.html">Compiler Specific Interfaces</description>
@@ -219,24 +231,32 @@
219231
<description>Standard C Library Retarget Core</description>
220232
<files>
221233
<file category="sourceC" name="source/core/armcc/retarget_io.c"/>
234+
<file category="sourceC" name="source/core/stdio_cmsis_uart.c" condition="STDIO UART CMSIS"/>
235+
<file category="header" name="config/stdio_cmsis_uart_config.h" attr="config" version="1.0.0" condition="STDIO UART CMSIS"/>
222236
</files>
223237
</component>
224238
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.1.0" condition="GCC CortexDevice">
225239
<description>Standard C Library Retarget Core</description>
226240
<files>
227241
<file category="sourceC" name="source/core/gcc/retarget_syscalls.c"/>
242+
<file category="sourceC" name="source/core/stdio_cmsis_uart.c" condition="STDIO UART CMSIS"/>
243+
<file category="header" name="config/stdio_cmsis_uart_config.h" attr="config" version="1.0.0" condition="STDIO UART CMSIS"/>
228244
</files>
229245
</component>
230246
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.1.0" condition="CLANG CortexDevice">
231247
<description>Standard C Library Retarget Core</description>
232248
<files>
233249
<file category="sourceC" name="source/core/clang/retarget_syscalls.c"/>
250+
<file category="sourceC" name="source/core/stdio_cmsis_uart.c" condition="STDIO UART CMSIS"/>
251+
<file category="header" name="config/stdio_cmsis_uart_config.h" attr="config" version="1.0.0" condition="STDIO UART CMSIS"/>
234252
</files>
235253
</component>
236254
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.2.0" condition="IAR CortexDevice">
237255
<description>Standard C Library Retarget Core</description>
238256
<files>
239257
<file category="sourceC" name="source/core/iar/retarget_io.c"/>
258+
<file category="sourceC" name="source/core/stdio_cmsis_uart.c" condition="STDIO UART CMSIS"/>
259+
<file category="header" name="config/stdio_cmsis_uart_config.h" attr="config" version="1.0.0" condition="STDIO UART CMSIS"/>
240260
</files>
241261
</component>
242262

@@ -304,6 +324,16 @@
304324
<file category="sourceC" name="source/stderr/stderr_itm.c"/>
305325
</files>
306326
</component>
327+
<component Cclass="CMSIS-Compiler" Cgroup="STDERR" Csub="UART" Cvariant="CMSIS" Capiversion="1.1.0" Cversion="1.0.0" condition="CORE UART_CMSIS">
328+
<description>Redirect STDERR to a CMSIS-Driver USART</description>
329+
<RTE_Components_h>
330+
#define RTE_CMSIS_Compiler_STDERR /* CMSIS-Compiler STDERR */
331+
#define RTE_CMSIS_Compiler_STDERR_UART_CMSIS /* CMSIS-Compiler STDERR: UART: CMSIS */
332+
</RTE_Components_h>
333+
<files>
334+
<file category="header" name="config/stderr_cmsis_uart_config.h" attr="config" version="1.0.0"/>
335+
</files>
336+
</component>
307337

308338
<!-- STDIN -->
309339
<component Cclass="CMSIS-Compiler" Cgroup="STDIN" Csub="Custom" Capiversion="1.1.0" Cversion="1.1.0" custom="1" condition="CORE">
@@ -336,6 +366,16 @@
336366
<file category="sourceC" name="source/stdin/stdin_itm.c"/>
337367
</files>
338368
</component>
369+
<component Cclass="CMSIS-Compiler" Cgroup="STDIN" Csub="UART" Cvariant="CMSIS" Capiversion="1.1.0" Cversion="1.0.0" condition="CORE UART_CMSIS">
370+
<description>Retrieve STDIN from a CMSIS-Driver USART</description>
371+
<RTE_Components_h>
372+
#define RTE_CMSIS_Compiler_STDIN /* CMSIS-Compiler STDIN */
373+
#define RTE_CMSIS_Compiler_STDIN_UART_CMSIS /* CMSIS-Compiler STDIN: UART: CMSIS */
374+
</RTE_Components_h>
375+
<files>
376+
<file category="header" name="config/stdin_cmsis_uart_config.h" attr="config" version="1.0.0"/>
377+
</files>
378+
</component>
339379

340380
<!-- STDOUT -->
341381
<component Cclass="CMSIS-Compiler" Cgroup="STDOUT" Csub="Custom" Capiversion="1.1.0" Cversion="1.1.0" custom="1" condition="CORE">
@@ -378,6 +418,16 @@
378418
<file category="sourceC" name="source/stdout/stdout_itm.c"/>
379419
</files>
380420
</component>
421+
<component Cclass="CMSIS-Compiler" Cgroup="STDOUT" Csub="UART" Cvariant="CMSIS" Capiversion="1.1.0" Cversion="1.0.0" condition="CORE UART_CMSIS">
422+
<description>Redirect STDOUT to a CMSIS-Driver USART</description>
423+
<RTE_Components_h>
424+
#define RTE_CMSIS_Compiler_STDOUT /* CMSIS-Compiler STDOUT */
425+
#define RTE_CMSIS_Compiler_STDOUT_UART_CMSIS /* CMSIS-Compiler STDOUT: UART: CMSIS */
426+
</RTE_Components_h>
427+
<files>
428+
<file category="header" name="config/stdout_cmsis_uart_config.h" attr="config" version="1.0.0"/>
429+
</files>
430+
</component>
381431

382432
<!-- TTY -->
383433
<component Cclass="CMSIS-Compiler" Cgroup="TTY" Csub="Custom" Capiversion="1.1.0" Cversion="1.1.0" custom="1" condition="ARMCC CORE">

config/stderr_cmsis_uart_config.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*---------------------------------------------------------------------------
2+
* Copyright (c) 2026 Arm Limited (or its affiliates).
3+
* All rights reserved.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the License); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* --------------------------------------------------------------------------
19+
*
20+
* Purpose: Configure STDERR to CMSIS-Driver USART retarget implementation
21+
* Revision: V1.0.0
22+
*
23+
* --------------------------------------------------------------------------*/
24+
25+
#ifndef STDERR_CMSIS_UART_CONFIG_H_
26+
#define STDERR_CMSIS_UART_CONFIG_H_
27+
28+
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
29+
//------ With VS Code: Open Preview for Configuration Wizard -------------------
30+
31+
// <o>UART STDERR Buffer Size
32+
// <i> UART STDERR buffer is used to store STDERR data before sending it via UART
33+
// <i> Default: 0 (unbuffered)
34+
#ifndef STDERR_UART_BUFFER_SIZE
35+
#define STDERR_UART_BUFFER_SIZE 0
36+
#endif
37+
38+
// <s>UART STDERR Buffer Section Name
39+
// <i> Specify the memory section name for UART STDERR buffer
40+
// <i> Default: .stderr_uart_buf
41+
#ifndef STDERR_UART_BUFFER_SECTION
42+
#define STDERR_UART_BUFFER_SECTION ".stderr_uart_buf"
43+
#endif
44+
45+
// <o>UART STDERR Buffer Alignment
46+
// <i> Define the STDERR buffer alignment in bytes
47+
// <i> Default: 32
48+
#ifndef STDERR_UART_BUFFER_ALIGNMENT
49+
#define STDERR_UART_BUFFER_ALIGNMENT 32
50+
#endif
51+
52+
// <q>Convert LF to CRLF
53+
// <i> If enabled, LF characters are preceded by CR characters on output
54+
// <i> Default: 0
55+
#ifndef STDERR_CR_LF
56+
#define STDERR_CR_LF 0
57+
#endif
58+
59+
#endif /* STDERR_CMSIS_UART_CONFIG_H_ */

config/stdin_cmsis_uart_config.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*---------------------------------------------------------------------------
2+
* Copyright (c) 2026 Arm Limited (or its affiliates).
3+
* All rights reserved.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the License); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* --------------------------------------------------------------------------
19+
*
20+
* Purpose: Configure STDIN to CMSIS-Driver USART retarget implementation
21+
* Revision: V1.0.0
22+
*
23+
* --------------------------------------------------------------------------*/
24+
25+
#ifndef STDIN_CMSIS_UART_CONFIG_H_
26+
#define STDIN_CMSIS_UART_CONFIG_H_
27+
28+
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
29+
//------ With VS Code: Open Preview for Configuration Wizard -------------------
30+
31+
// <o>UART STDIN Buffer Size
32+
// <i> UART STDIN buffer is used to store STDIN data received via UART
33+
// <i> Default: 64
34+
#ifndef STDIN_UART_BUFFER_SIZE
35+
#define STDIN_UART_BUFFER_SIZE 64
36+
#endif
37+
38+
// <s>UART STDIN Buffer Section Name
39+
// <i> Specify the memory section name for UART STDIN buffer
40+
// <i> Default: .stdin_uart_buf
41+
#ifndef STDIN_UART_BUFFER_SECTION
42+
#define STDIN_UART_BUFFER_SECTION ".stdin_uart_buf"
43+
#endif
44+
45+
// <o>UART STDIN Buffer Alignment
46+
// <i> Define the STDIN buffer alignment in bytes
47+
// <i> Default: 32
48+
#ifndef STDIN_UART_BUFFER_ALIGNMENT
49+
#define STDIN_UART_BUFFER_ALIGNMENT 32
50+
#endif
51+
52+
// <q>Echo Input Characters
53+
// <i> If enabled, received characters are echoed to STDOUT
54+
// <i> Default: 0
55+
#ifndef STDIN_ECHO
56+
#define STDIN_ECHO 0
57+
#endif
58+
59+
#endif /* STDIN_CMSIS_UART_CONFIG_H_ */

config/stdio_cmsis_uart_config.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*---------------------------------------------------------------------------
2+
* Copyright (c) 2026 Arm Limited (or its affiliates).
3+
* All rights reserved.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the License); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* --------------------------------------------------------------------------
19+
*
20+
* Purpose: STDIO to CMSIS Driver USART Retarget Configuration
21+
* Revision: V1.0.0
22+
*
23+
* --------------------------------------------------------------------------*/
24+
25+
#ifndef STDIO_CMSIS_UART_CONFIG_H_
26+
#define STDIO_CMSIS_UART_CONFIG_H_
27+
28+
#ifdef CMSIS_target_header
29+
#include CMSIS_target_header
30+
#else
31+
#define RETARGET_STDIO_UART 0
32+
#endif
33+
34+
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
35+
//------ With VS Code: Open Preview for Configuration Wizard -------------------
36+
37+
// <y>Connect to hardware via Driver_USART#
38+
// <i> Select driver control block for hardware interface
39+
// <i> Default: 0
40+
#ifndef STDIO_UART_DRIVER
41+
#define STDIO_UART_DRIVER RETARGET_STDIO_UART
42+
#endif
43+
44+
// <o>UART baudrate
45+
// <i> Specifies the baudrate for UART communication
46+
// <i> Common values: 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
47+
// <i> Default: 115200
48+
#ifndef STDIO_UART_BAUDRATE
49+
#define STDIO_UART_BAUDRATE 115200
50+
#endif
51+
52+
#endif /* STDIO_CMSIS_UART_CONFIG_H_ */

config/stdout_cmsis_uart_config.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*---------------------------------------------------------------------------
2+
* Copyright (c) 2026 Arm Limited (or its affiliates).
3+
* All rights reserved.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the License); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* --------------------------------------------------------------------------
19+
*
20+
* Purpose: Configure STDOUT to CMSIS-Driver USART retarget implementation
21+
* Revision: V1.0.0
22+
*
23+
* --------------------------------------------------------------------------*/
24+
25+
#ifndef STDOUT_CMSIS_UART_CONFIG_H_
26+
#define STDOUT_CMSIS_UART_CONFIG_H_
27+
28+
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
29+
//------ With VS Code: Open Preview for Configuration Wizard -------------------
30+
31+
// <o>UART STDOUT Buffer Size
32+
// <i> UART STDOUT buffer is used to store STDOUT data before sending it via UART
33+
// <i> Default: 0 (unbuffered)
34+
#ifndef STDOUT_UART_BUFFER_SIZE
35+
#define STDOUT_UART_BUFFER_SIZE 0
36+
#endif
37+
38+
// <s>UART STDOUT Buffer Section Name
39+
// <i> Specify the memory section name for UART STDOUT buffer
40+
// <i> Default: .stdout_uart_buf
41+
#ifndef STDOUT_UART_BUFFER_SECTION
42+
#define STDOUT_UART_BUFFER_SECTION ".stdout_uart_buf"
43+
#endif
44+
45+
// <o>UART STDOUT Buffer Alignment
46+
// <i> Define the buffer alignment in bytes
47+
// <i> Default: 32
48+
#ifndef STDOUT_UART_BUFFER_ALIGNMENT
49+
#define STDOUT_UART_BUFFER_ALIGNMENT 32
50+
#endif
51+
52+
// <q>Convert LF to CRLF
53+
// <i> If enabled, LF characters are preceded by CR characters on output
54+
// <i> Default: 0
55+
#ifndef STDOUT_CR_LF
56+
#define STDOUT_CR_LF 0
57+
#endif
58+
59+
#endif /* STDOUT_CMSIS_UART_CONFIG_H_ */

gen_pack.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ DEFAULT_ARGS=(-c "v")
2929
# Default: empty (all folders)
3030
#
3131
PACK_DIRS="
32+
config
3233
documentation
3334
example
3435
include

source/core/armcc/retarget_io.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023-2025 ARM Limited or its affiliates. All rights reserved.
2+
* Copyright (C) 2023-2026 ARM Limited or its affiliates. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -32,14 +32,23 @@
3232

3333
#ifdef RTE_CMSIS_Compiler_STDERR
3434
#include "retarget_stderr.h"
35+
#ifdef RTE_CMSIS_Compiler_STDERR_UART_CMSIS
36+
#include "stderr_cmsis_uart_config.h"
37+
#endif
3538
#endif
3639

3740
#ifdef RTE_CMSIS_Compiler_STDIN
3841
#include "retarget_stdin.h"
42+
#ifdef RTE_CMSIS_Compiler_STDIN_UART_CMSIS
43+
#include "stdin_cmsis_uart_config.h"
44+
#endif
3945
#endif
4046

4147
#ifdef RTE_CMSIS_Compiler_STDOUT
4248
#include "retarget_stdout.h"
49+
#ifdef RTE_CMSIS_Compiler_STDOUT_UART_CMSIS
50+
#include "stdout_cmsis_uart_config.h"
51+
#endif
4352
#endif
4453

4554
#ifdef RTE_CMSIS_Compiler_TTY

0 commit comments

Comments
 (0)