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.

MSP430FR2675: How to enable printf output to console in CCS 10?

Part Number: MSP430FR2675
Other Parts Discussed in Thread: MSP-FET, MSP-TS430PT48A, MSP430FR2633, CAPTIVATE-PGMR, CAPTIVATE-FR2633, , MSP430FR5969, MSP430FR2355

I'm using CCS 10.3.  I changed the --print_support option to nofloat, and my project builds without any errors or warnings.  However, I'm not seeing any output from my printf statements in the CCS console.  Breakpoint functionality in CCS is poor at best (i.e. some breakpoints don't get hit, even with no optimizations; breakpoint counters never halt execution), so I really need to get this console output working, so that I can get some idea as to what my application is doing.

Please describe in detail how to get/view console output from printf statements.  I'm using MSP-FET and MSP-TS430PT48A.

If you're going to only point me to a document, please at least point me to the correct section.  I need a single answer that resolves this, not something that go on for weeks on end without resolution, like my other ticket here.

  • Hi,

    You should include stdio.h head file in your project first. Then you can call the printf() function in your code.

    Best regards,

    Cash Hao

  • I'm already including stdio.h.  As I stated, my code compiles without any errors or warnings.  I need help getting the printf output to appear in the CCS console view.

  • Hi,

    Could you share your code here? And you said "some breakpoints don't get hit". I am thinking the code might cause the problem.

    Best regards,

    Cash Hao

  • Have you tried an fflush()?

    And then be patient.

  • Oddly, when I run the Hello World starter project in the debugger, I am able to see the "Hellow World!" output to the console.  Although it does unexpectedly break on line 114 in `__TI_writemsg()`.  If I resume program execution that's when I see the console output.  

    However, when I start with the empty project, and add the two lines of code to match the implementation of `main()` in the hello world project, the console output does not work.

    This leads me to believe that something needs to be configured in the project settings.

  • I tried running `fflush(stdio)`, calling `printf` a second time, and even adding additional (more than one) newline ('\n') character at the end of my print strings.  No joy.

    Then I tried switching to use `assert()` to perform my unit tests.  The debugger stopped at the same odd place that it did with the Hello World project, as if it was going to work, but instead, after continuing program execution, this error was printed to the console:

    Invalid CIO command (255) in the CIO buffer at address (0x8000) was not recognized. Please check the device and program memory maps.

    Increasing the heap from 160 bytes to 1024 bytes had no effect.

  • Oddly, when I run the Hello World starter project in the debugger, I am able to see the "Hellow World!" output to the console.  Although it does unexpectedly break on line 114 in `__TI_writemsg()`. 

    I can repeat that behaviour with a MSP430FR2633 in a CAPTIVATE-FR2633, using a CAPTIVATE-PGMR as a debugger.

    In the project configured as:

    • CCS 10.4.0.00006
    • TI compiler v21.6.0.LTS
    • --printf_support=nofloat
    • --heap_size=300
    • --stack_size=300

    When start the debugging session and halted at the start of main() then the FRCTL0 registers shows NWAITS as one wait state:

    If attempt to step over the printf() call then end up in trgmsg.c:

    The way printf() works with the TI compiler is that the debugger sets a breakpoint on the C$$IO$$ symbol which is inside the __TI_writmsg function in trgmsg.c, and after the breakpoint is hit the debugger is supposed to read the printf() output from the CIO buffer, display it on the Console and then continue the target automatically.

    In the above noticed that the breakpoint is reported at address 0x00E39C where as the actual address of the C$$IO$$ symbol is 0x00E3AC in the above example program.

    Looking at the MSP430FR2633 Device Erratasheet (Rev. S) noticed the following:

    After the program was halted at the start of main, in the Registers view manually set the FRCTL0 register to 0xA500 to set NWAITS to zero. Now, when step over printf() call get the output on the console and no spurious halt in trgmsg.c:

    Since the change in behaviour occurred when just changed the NWAITS from 1 to 0, i.e. no change to the compiled program nor CCS project settings, it just suggest errara EEM23 is the cause of the problem.

    I don't have a MSP430FR2675 to repeat the test with, but that device has the same EEM23 errata listed.

  • I don't have a MSP430FR2675 to repeat the test with, but that device has the same EEM23 errata listed.

    I had the same code and project options for a MSP430FR5969 which originally wasn't showing the problem, even though the MSP430FR5969 also has EEM23 listed. Noticed a difference in the reset state of the devices:

    • In the MSP430FR2633 the initial state of NWAITS was 1.
    • In the MSP430FR5969 the initial state of NWAITS was 0.

    For the MSP430FR5969 if used the debugger to set NWAITS to 1 at the start of main, then attempting to set over the printf() call then could repeat the same issue of stopping unexpectedly in trgmsg.c; stopped with the PC at 0x0064A8 where the address of the C$$IO$$ symbol was 0x0064B8.

    If the MSP430FR2675 only needs to operate with a Processor frequency (MCLK frequency) <= 8 MHz, then a work-around could be to set NWAITS to zero to avoid EEM23 when debugging.

  • This leads me to believe that something needs to be configured in the project settings.

    In the past found that insufficient heap space would cause printf() to silently produce no output on the CCS console, when the malloc() call inside setvbuf() which is called when printf attempts to generate output failed to allocate space for the output buffer (BUFSIZ is set to 256 bytes).

    Based on tests 300 bytes of heap should be sufficient for printf to work.

    On both MSP430FR2355 and MSP430FR2675 the default linker command files place the .sysmem (used for malloc) and .cio sections in FRAM:

            GROUP(READ_WRITE_MEMORY)
            {
                .TI.persistent : {}              /* For #pragma persistent            */
                .cio           : {}              /* C I/O Buffer                      */
                .sysmem        : {}              /* Dynamic memory allocation area    */
            } PALIGN(0x0400), RUN_START(fram_rw_start) RUN_END(fram_rx_start)

    What I found with a printf test on a MSP430FR2355 is that when a project is created the default is that that under the CCS Project Properties "Enable FRAM Write Protection (FRWP)" is ticked:

    With "Enable FRAM Write Protection (FRWP)" ticked then printf output from a MSP430FR2355 worked.

    When "Enable FRAM Write Protection (FRWP)" was unticked then printf output didn't work; single stepping showed that malloc() was returning NULL even though the 300 bytes of heap set in the linker options should have been sufficient. With "Enable FRAM Write Protection (FRWP)" unticked then the SYSCFG0 register was set such all of the FRAM program memory was write-protected, with caused printf to produce no output.

    Where with "Enable FRAM Write Protection (FRWP)" ticked, SYSCFG0 was set such that the lower 1Kbyte of program FRAM which contained the .cio and .sysmem sections was writable and the rest of program FRAM was write protected.

    While I don't have a MSP430FR2675 to test it, I think the same applies to that device. I.e. under Project Properties check what "Enable FRAM Write Protection (FRWP)" is set to.

  • Chester, thanks for the great info.  By setting FRCTL0 to 0xA500 (NWAITS = 0) and increasing the heap size to 300 I was able to get my console demo application to work and mimmick the "Hello World!" output to the console that the HelloWorld demo produces. 

    Unfortunately, I'm still having problems with my work project application.  I attempted running the DCO at 8 MHz and then 1 MHz, as well as increasing the heap to 1024 bytes, but no joy.  I also enabled the setting for Enable FRM Write Protection (FRWP), but that resulted in a bunch of linker errors.

  • also enabled the setting for Enable FRM Write Protection (FRWP), but that resulted in a bunch of linker errors.

    In the project properties under CCS Build -> MSP430 Linker -> File Search Path -> Include library file or command file as input (--library, -l) can you check that frwp_init.a is in the list:

    If I take a project for a MSP430FR2675 which was successfully linking with FRWP enabled, and remove the frwp_init.a file from the list then get your linker errors.

    The frwp_init.a library is ccs/ccs_base/msp430/lib/FR2xx/frwp_init.a with the CCS 10.4 installation, i.e. not part of the compiler run time library.

    Without frwp_init.a being specified, the linker falls-back to trying to link a different library for the __mpu_init function which is incompatible with a MSP430FR2675, as tries to access FRAM MPU registers which don't exist in a MSP430FR2675.

**Attention** This is a public forum