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.

Starterware/EK-TM4C1294XL: Inclusion of C++ libraries causes the PC to jump to Fault ISR even before entry to main

Part Number: EK-TM4C1294XL

Tool/software: Starterware

Hi,

In a simple non RTOS program which needs to work with strings and write bytes into EEPROM, I wanted to convert my C program to a C++.

So I included with #include <iostream>

But on launching debugger the program did not come to main..

I debugged in the starter portion. I found that on reaching initialization of user defines structures and variables the prgram crashed into fault ISR. 

But on removing inclusion of iostream, this behavior vanished and the program executed correctly.

So without knowing why I increased stack size to 1024 and arbitrarily set heap size to 100000.

Now the program worked correctly!

Please help me understand the problem and the correct way to migrate to C++

Thank you

Best Regards

Pavitra

  • Hi,
    I found another post with similar problem where the program hangs before reaching the main when iostream is added in the startup. The solution was also to increase the stack size and heap. As far as why adding iostream will cause the stack to overflow I don't know and need some investigation.
  • Pavitra Ramanujam said:
    So I included with #include <iostream>

    EEEP! That's a bit like deciding to load your car with the contents of a shipping container. iostream is not a small addition.

    Robert

  • Pavitra Ramanujam said:
    So without knowing why I increased stack size to 1024 and arbitrarily set heap size to 100000.

    Now the program worked correctly!

    Had a look at the memory requirements for <iostream> using a TM4C129NCPDT using the TI v17.3.0 compiler with the following simple test program:

    #include <iostream>
    
    int main(void)
    {
        std::cout << "Hello World" << std::endl;
    
        return 0;
    }

    To find the stack usage made the linker fill the stack with a initial value, and then used the memory browser to find the maximum usage.

    To find the heap usage made use of the undocumented run-time library memmap() function mentioned in RM48L952ZWT: How to do Heap Profiling (but with a modification to store the heap usage in global variables for inspection by the debugger rather than calling printf)

    With the test program the results were:

    a) On entry to main() the maximum stack size was 416 bytes, and 7300 bytes of heap were used.

    b) After the use of std::cout the maximum stack size was still 416 bytes, and 7564 bytes of heap were used.

    This gives an idea of the stack and heap required to use iostream, but of course the actual usage may be more depending upon which features are used.

    For reference, the project is attached TM4C1294_io_stream.zip

  • Robert Adsett72 said:
    iostream is not a small addition

    Indeed, my above simple example used 125373 bytes of flash of which 92220 bytes were from the single unified_locale.obj object file from the compiler run-time library rtsv7M4_T_le_v4SPD16_eabi.lib

    There is outstanding compiler defect CODEGEN-1458 on the subject of "Consider splitting up unified_locale.cpp to save code space".