This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCSTUDIO: How to set "--printf_support=minimal"? (Using sprintf() function causes stack overflow)

Part Number: CCSTUDIO
Other Parts Discussed in Thread: MSPM0L1305

Tool/software:

Hi,

Background:

I am currently developing a firmware using CCS1271 with a custom board which features an MSPM0L1305 microcontroller.

As shown in the snapshot below, a function that calls the sprintf() function multiple times potentially takes up too much stack space and the moment it overflows, variables residing in other sections get corrupted resulting in the program failure.

Question:

I have been looking into the previous Q/A's relevant to this topic in this forum and it looks like others have already gone through similar issues. I came down to the following two potential solutions:

  • Increase the stack size
  • Use --printf_support=minimal

@Ki provided a detailed guideline regarding increasing the stack size (CCSTUDIO: Changing stack size through "Properties > Arm Linker > Basic Options" doesn't seem to work), and now I am having trouble finding the place to set "--printf_support=minimal" option in my environment. I went through every single menu in the project properties but couldn't find where to set it.

I also found the following information which may be implying that I don't have the option to control the "--printf_support" setting.

Can anyone share some insights into this?

My goal is to try and see if setting the option "--printf_support" to "minimal" would significantly decrease the inclusive size of stack usage and prevent stack overflow.

Thank you,

Kyungjae Lee

  • The tiarmclang compiler does not support the option --printf_support.  Instead, it automatically chooses the smallest variant of the printf routines that can support the format specifiers (%s, %d, etc.) seen in the program.  For details, please see the Printf Support Optimization part of the tiarmclang online manual

    I understand your overall goal is to ...

    decrease the inclusive size of stack usage and prevent stack overflow

    Unfortunately, there is problem which prevents this outcome.  Because of the already known issue EXT_EP-10804, even the minimal variant of the printf functions use a large amount of stack.

    Thanks and regards,

    -George

  • Hi George,

    I really appreciate the answer. If there is no way I can meet my project requirements other than using the 'sprintf()' function, would migrating to an MCU with larger SRAM be the only option? Or, since this is a known issue, is there any suggested solution to work around using the 'sprintf()' function?

    Thank you,

    Kyungjae Lee

  • If you only use sprintf to convert a number to a string, consider changing your code to use a different function.  The function ltoa is not part of the C/C++ standards.  But it is commonly supplied with many compilers, including tiarmclang.  For the details, please see the source file ltoa.c in a directory location similar to ...

    C:\ti\ccs1200\ccs\tools\compiler\ti-cgt-armllvm_3.2.2.LTS\lib\src

    Thanks and regards,

    -George

  • I ended up implementing a couple of custom functions to replace the 'sprintf()' function instead of using 'ltoa()' function. I saw in another thread that the compiler's support for this function may be discontinued in the future without notification and I didn't want to risk it.

    Thank you,

    Kyungjae Lee