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.

Compiled C++ program will not load properly when IOStream.h is included.

Other Parts Discussed in Thread: TM4C123GH6PM

I am exploring the use of iostream on TivaC Launchpad (TM4C123GH6PM microcontroller) but could not get the program to load for stepping through.

It just loads and automatically runs (hang?) without clicking the run button.

Clicking the suspend button causes a new file to be popped up - "copy_decompress_rle.c" and the following statement highlighted within the file

"while(run_len--) WRITE8_ADV(outbuf, ch);"

Clicking the restart button makes the program run automatically again as before, instead of pausing at "void main(void){".

But if I comment out the statements "#include <iostream.h>" and "cout<<"Hello World!"<<endl;", the program will load and I can then step though the code. 

The test program is very simple:

#include <stdint.h>
#include <iostream.h>

void main(void) {

uint16_t ui16Cnt = 0;

ui16Cnt++;

cout<<"Hello World!"<<endl;

while(1){
}

}

The project was created using File>New>CCS Project, and then renaming "main.c" as main.cpp. Code composer studio is version 6.0.1.00040

1. Can anyone advise why the program will load and automatically run? How to prevent auto run so that I can use the debugger?  

2. Also, is there a workbook to guide the development of c++ projects in CCS? A workbook similar to the excellent workbook for C projects in CCS will save many of us a lot of trial,  error and frustrations. 

Thanks in advance,

John

 

  • John Chee said:
    1. Can anyone advise why the program will load and automatically run? How to prevent auto run so that I can use the debugger?  

    What is happening is that the program is failing during the run-time start code such that main isn't reached.

    If you want to single step the run-time start up code to investigate such failure, under the CCS Project Properties -> Debug -> Auto Run and Launch Options -> Auto Run Options untick the "On a program load or restart" and "On a reset" checkboxes. This means that when starting a debug session the debugger stops at the reset vector rather than attempting to run to main. This gives the ability to single step though the run-time start up code.

    John Chee said:
    The project was created using File>New>CCS Project, and then renaming "main.c" as main.cpp. Code composer studio is version 6.0.1.00040

    With your example program I was able to repeat the failure of the program not reaching main. When I paused the program noticed that was running C++ initializers for iostream. The iostream initialization uses new to dynamically allocate memory from the heap.

    When a new project is created in CCS the heap size is set to zero, which causes the iostream initialization to fail. By setting the heap size to 2048, under CCS Project Properties -> CCS Build -> ARM Linker -> Basic Options, the program then ran to main and write to the cout stream worked (appeared in the CCS CIO console).

    [I haven't determined the minimum heap size required for using iostream - the setting of 2048 bytes was just an initial guess]

  • Dear Chester,
    Thank you very much! Your advise works!

    Best regards,
    John