Skip to content

Commit f370dcf

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

12 files changed

Lines changed: 620 additions & 7 deletions

ARM.CMSIS-Compiler.pdsc

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<releases>
1616
<release version="2.2.0-dev">
1717
Active Development ...
18+
Add components that enable stdio retarget to UART
1819
AC6:
1920
- Corrected _sys_read return value when rt_fs_read returns with error (#62)
2021
IAR:
@@ -108,6 +109,11 @@
108109
<require condition="CORE"/>
109110
<require condition="CortexDevice_ITM"/>
110111
</condition>
112+
<condition id="CORE UART_CMSIS">
113+
<description>CMSIS-Compiler CORE component and CMSIS-Driver USART</description>
114+
<require condition="CORE"/>
115+
<require Cclass="CMSIS Driver" Cgroup="USART"/>
116+
</condition>
111117

112118
<condition id="ARMCC CORE">
113119
<description>ARMCC and CORE component</description>
@@ -155,6 +161,13 @@
155161
<require condition="CORE"/>
156162
<require Cclass="CMSIS" Cgroup="RTOS2"/>
157163
</condition>
164+
165+
<condition id="STDIO UART CMSIS">
166+
<description>STDIO retarget to CMSIS Driver UART</description>
167+
<accept Cclass="CMSIS-Compiler" Cgroup="STDERR" Csub="UART" Cvariant="CMSIS"/>
168+
<accept Cclass="CMSIS-Compiler" Cgroup="STDIN" Csub="UART" Cvariant="CMSIS"/>
169+
<accept Cclass="CMSIS-Compiler" Cgroup="STDOUT" Csub="UART" Cvariant="CMSIS"/>
170+
</condition>
158171
</conditions>
159172
<taxonomy>
160173
<description Cclass="CMSIS-Compiler" doc="documentation/html/index.html">Compiler Specific Interfaces</description>
@@ -215,28 +228,36 @@
215228

216229
<components>
217230
<!-- Core -->
218-
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.1.1" condition="ARMCC CortexDevice">
231+
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.2.0" condition="ARMCC CortexDevice">
219232
<description>Standard C Library Retarget Core</description>
220233
<files>
221234
<file category="sourceC" name="source/core/armcc/retarget_io.c"/>
235+
<file category="sourceC" name="source/core/stdio_cmsis_uart.c" condition="STDIO UART CMSIS"/>
236+
<file category="header" name="config/stdio_cmsis_uart_config.h" attr="config" version="1.0.0" condition="STDIO UART CMSIS"/>
222237
</files>
223238
</component>
224-
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.1.0" condition="GCC CortexDevice">
239+
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.2.0" condition="GCC CortexDevice">
225240
<description>Standard C Library Retarget Core</description>
226241
<files>
227242
<file category="sourceC" name="source/core/gcc/retarget_syscalls.c"/>
243+
<file category="sourceC" name="source/core/stdio_cmsis_uart.c" condition="STDIO UART CMSIS"/>
244+
<file category="header" name="config/stdio_cmsis_uart_config.h" attr="config" version="1.0.0" condition="STDIO UART CMSIS"/>
228245
</files>
229246
</component>
230-
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.1.0" condition="CLANG CortexDevice">
247+
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.2.0" condition="CLANG CortexDevice">
231248
<description>Standard C Library Retarget Core</description>
232249
<files>
233250
<file category="sourceC" name="source/core/clang/retarget_syscalls.c"/>
251+
<file category="sourceC" name="source/core/stdio_cmsis_uart.c" condition="STDIO UART CMSIS"/>
252+
<file category="header" name="config/stdio_cmsis_uart_config.h" attr="config" version="1.0.0" condition="STDIO UART CMSIS"/>
234253
</files>
235254
</component>
236-
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.2.0" condition="IAR CortexDevice">
255+
<component Cclass="CMSIS-Compiler" Cgroup="CORE" Cversion="1.3.0" condition="IAR CortexDevice">
237256
<description>Standard C Library Retarget Core</description>
238257
<files>
239258
<file category="sourceC" name="source/core/iar/retarget_io.c"/>
259+
<file category="sourceC" name="source/core/stdio_cmsis_uart.c" condition="STDIO UART CMSIS"/>
260+
<file category="header" name="config/stdio_cmsis_uart_config.h" attr="config" version="1.0.0" condition="STDIO UART CMSIS"/>
240261
</files>
241262
</component>
242263

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

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

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

382433
<!-- TTY -->
383434
<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_ */
40 Bytes
Binary file not shown.
2.29 KB
Loading

documentation/doxygen/src/rt_io.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ The following subcomponents are available:
3939
**Breakpoint** | When the I/O stream is used, the application stops with [BKPT](https://developer.arm.com/documentation/100073/latest/The-Arm-C-and-C---Libraries/Support-for-building-an-application-with-the-C-library/Using-the-C-and-C---libraries-with-an-application-in-a-semihosting-environment?lang=en) instruction. No additional code is required.
4040
**Event Recorder** | STDOUT and STDERR can be redirected using the [Event Recorder](https://arm-software.github.io/CMSIS-View/main/evr.html) (especially interesting for targets without ITM (such as Cortex-M0/M0+/M23)).
4141
**ITM** | Use [Instrumentation Trace Macrocell (ITM)](https://developer.arm.com/documentation/ddi0314/h/Instrumentation-Trace-Macrocell?lang=en) for I/O communication via the debugger (only available for Cortex-M3/M4/M7/M33/M55/M85 processors).<br/> Usually, data is shown in a dedicated window.<br/> No additional code is required to output or input data through the ITM channel. However, you have to configure the ITM channel for tracing.
42-
**Custom** | Retarget I/O stream to a user defined interface (such as UART or other application specific interface).<br/>See \subpage custom_subcomponent for further details.
42+
**UART** | Retarget I/O streams to UART. Default implementation variant uses CMSIS-Driver USART.
43+
**Custom** | Retarget I/O stream to a user defined interface (such as custom UART implementation or other application specific interface).<br/>See \subpage custom_subcomponent for further details.
4344

4445

4546
> **Note**

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

0 commit comments

Comments
 (0)