Embedded Studio Library IO

From SEGGER Wiki
Revision as of 14:03, 24 January 2022 by Johannes (talk | contribs)
Jump to: navigation, search

The debugger and the Runtime Library of Embedded Studio support different mechanisms for debug input and output. The mechanism to be used in a project can easily be selected in the project options at Library -> Library I/O and does not require any additional file or configuration.

Library I/O Mechanisms

There are different mechanisms for different application requirements.

RTT

Use SEGGER Real-Time Transfer (RTT), which enables super fast output without halting the system. The target application writes the output string to a buffer in RAM. The J-Link reads the buffer while the target is running.

Suitable for applications with real-time requirements.

Available on all Cortex-M based systems.

SWO

The target application writes the output string to the ITM stimulus ports. The J-Link reads the SWO pin while the target is running.

Suitable for applications with real-time requirements.

Available on all Cortex-M based systems with a SWO pin.

SEMIHOST

Halt the target CPU for I/O operations. On halt, the debugger reads and executes the operation command and parameters.

Available on all targets (Cortex-M, Cortex-A, Cortex-R, RISC-V)

SEMIHOST host-formatted

With host formatting printf output is processed by the debugger instead of on the target. The debugger reads the format string and the parameters from the target and feeds it to its formatter to be printed. No code for formatting is required on the target, saving 1 - 3 kiloBytes of ROM.

Recommended for minimum size.

None

No I/O mechanism implemented. Use user-supplied I/O mechanisms, such as output on a UART.

User-supplied I/O

Note: This section applies to Embedded Studio V6.10 and later.

When no standard I/O mechanism is implemented, the user can supply an implementation of the low-level routines to do output and optionally input.

The functions to be implemented are:

 int __SEGGER_RTL_X_file_write(__SEGGER_RTL_FILE *stream, const char *s, unsigned len);  // Write data to file stream.     >= 0: OK. < 0: Error.
 int __SEGGER_RTL_X_file_read(__SEGGER_RTL_FILE * stream, char * s, unsigned len);       // Read data from file stream.    >= 0: OK. < 0: Failed to read.
 int __SEGGER_RTL_X_file_bufsize(__SEGGER_RTL_FILE *stream);                             // Get stream buffer size.        == 1: Unbuffered I/O. > 1: Size of buffer.
 int __SEGGER_RTL_X_file_unget(__SEGGER_RTL_FILE *stream, int c);                        // Push character back to stream. >= 0: OK. < 0: Error.
 int __SEGGER_RTL_X_file_stat(__SEGGER_RTL_FILE *stream);                                // Get file status.               >= 0: OK. < 0: Invalid file stream.

The default implementations are:

 int __SEGGER_RTL_X_file_write(__SEGGER_RTL_FILE *stream, const char *s, unsigned len) {
   while (len > 0) {
     UART_SendByte(*s++); // Output any stream to UART.
     --len;
   }
   return 0;
 }
 int __SEGGER_RTL_X_file_read(__SEGGER_RTL_FILE * stream, char * s, unsigned len) {
   return EOF; // Read not implemented
 }
 int __SEGGER_RTL_X_file_bufsize(__SEGGER_RTL_FILE *stream) {
   return 1; // 1 for unbuffered I/O. Otherwise 80.
 }
 int __SEGGER_RTL_X_file_unget(__SEGGER_RTL_FILE *stream, int c) {
   return EOF; // Unget not implemented.
 }
 int __SEGGER_RTL_X_file_stat(__SEGGER_RTL_FILE *stream) {
   return 0;  // Assume only stdout/stdin/stderr is used and always valid.
 }