ARM Technical Support Knowledge Articles

Why the simulation stalls when printf() is used in my C code?

Applies to: Cortex-M0, Cortex-M0Plus, Cortex-M3, Cortex-M4, Cortex-M7

Scenario

The intended audience of the knowledge article are software developers having issues when using printf() on ARM cores.

The symptoms of the issue are as follows:

The above issue can occur under the following circumstances:

Answer

The ARM compiler produces an assembly code which tries to load the width and precision values from a specific memory address located in the stack area, regardless of those values being given to the printf() format specifier or not. If the stack memory area has not been initialised this can potentially result in loading X values into the registers of the processor, which ultimately can cause the simulation to stall.

It is important to state that the stall issue is caused by the X values, therefore the same assembly code cannot cause any issues in real life systems, it only affects RTL simulation.

Workaround

The easiest workaround for the issue is explicitly specifying the width or precision in the format specifier, for example

printf("Example string : %1d",example_int)

Another way to work around the issue is adding the following code to the beginning of the C code.

#if defined ( __CC_ARM )
#if (__ARMCC_VERSION < 400000)
#else
// Insist on keeping widthprec, to avoid X propagation by benign code in C-lib
#pragma import _printf_widthprec
#endif
#endif

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential