Setting up your runtime environment
You can set up the runtime environment based on some basic project settings. It is also often convenient to let the C-SPY debugger manage things like standard streams, file I/O, and various other system interactions. This basic runtime environment can be used for simulation before you have any target hardware.
Before you build your project, choose Project>Options>General Options to open the Options dialog box.
On the Library Configuration page, verify the following settings:
Library—choose which library configuration to use. Typically, choose None, Normal,Full, or Custom. For library support for C++17, choose Libc++, which uses the Full library configuration.
For information about the various library configurations, see Runtime library configurations.
On the Library Options 1 page, select Auto with multibyte support or Auto without multibyte support for both Printf formatter and Scanf formatter. This means that the linker will automatically choose the appropriate formatters based on information from the compiler. For more information about the available formatters and how to choose one manually, see Formatters for printf and Formatters for scanf, respectively.
To enable C-SPY emulated I/O, choose Project>Options>General Options>Library Configuration and select Semihosted (
‑‑semihosted) or IAR breakpoint (‑‑semihosting=iar_breakpoint).Note
For some Cortex-M devices it is also possible to direct
stdout/stderrvia SWO. This can significantly improvestdout/stderrperformance compared to semihosting. For hardware requirements, see SWO Configuration dialog box.Danger
To enable
stdoutvia SWO on the command line, use the linker option‑‑redirect __iar_sh_stdout=__iar_sh_stdout_swo.Caution
To enable
stdoutvia SWO in the IDE, select the Semihosted option and the stdout/stderr via SWO option.See Briefly about C-SPY emulated I/O and The semihosting mechanism.
On some systems, terminal output might be slow because the host computer and the target system must communicate for each character.
For this reason, a replacement for the
__writefunction called__write_bufferedis included in the runtime library. This module buffers the output and sends it to the debugger one line at a time, speeding up the output.Note
This function uses about 80 bytes of RAM memory.
Caution
To use this feature in the IDE, choose Project>Options>General Options>Library Options 1 and select the option Buffered terminal output.
Danger
To enable this function on the command line, add this to the linker command line:
‑‑redirect __write=__write_buffered
Some math functions are available in different versions—default versions, smaller than the default versions, and larger but more accurate than default versions. Consider which versions you should use.
For more information, see Math functions.
When you build your project, a suitable prebuilt library and library configuration file are automatically used based on the project settings you made.
For information about which project settings affect the choice of library file, see Runtime library configurations.
You have now set up a runtime environment that can be used while developing your application source code.