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.

CCSV4 vsnprintf and MSP430F2418

Other Parts Discussed in Thread: MSP430F2418, MSP430F5438A

Hi,

I'm trying to print out on the UART of an MSP430F2418 debug messages of my code. I am formatting those messages using vsnprintf, but whenever I'm trying to print a message which contains some formatting, e.g: %f %d or %lX, my program silently fails.

I'm using pretty much the same code on an MSP430F5438A and I had the same problem, but I fixed it by allocating more stack and heap size.

However, for the 2418 it doesn't work, the program keeps failing over and over again, most probably due to a stack overflow or due to lack of memory for the heap.

I'm using the following settings:

I include <stdio.h> in the file i use to call vsnprintf.

I put a "\n" at the end of each line I want to print to clear the buffer.

Compiler options:

--silicon_version=mspx --large_memory_model --printf_support=full


Linker options:

--use_hw_mpy=F5 --stack_size=1024 --heap_size=1024 --rom_model

In my linker script I allocate the RAM as follows:

    //------------------------------------------------------------------------
    //  Declare RAM usage
    //------------------------------------------------------------------------
    .bss     : {} run = RAM, RUN_START(bss_start), SIZE(bss_size)
    .cio     : {} run = RAM
    .sysmem  : {} run = RAM, RUN_START(sysmem_start), SIZE(sysmem_size)
    .stack   : {} run = RAM(HIGH), RUN_START(stack_start), SIZE(stack_size)

 


Does anyone have any idea why this happens?

 

 

 

 

  • Sonia,

    what is meant by the program "silently fails"? Crash? No output? Or..?
    Also, can you output at least simple strings or formatted integer values? (%u, %i, etc.)?

    As for %d, %g, etc., you may have good reasons for this but I would probably recommend avoiding trying to print such values on an MSP430 as they are quite taxing in terms of CPU time and memory consumption since you won't be able to use the smaller, more optimized printf() implementation of the runtime library. You could always generate the float-value strings on your host side if that's something under your control.

    Thanks and Regards,
    Andreas

  • As Andreas already stated, printing of float values consumes a LOT of stack space.

    Now the 5438 has 16k while the 2418 has only 8k. Depending on your other program code, there might be not enough ram left. 8K is plenty anyways (I wrote complex programs with only 256 bytes, but then even a simple printf was almost too much).

    The MSP has no memory management unit, so if the stack overflows into data region, it just does that, no matter what you 'defined'. No exceptions, no memory violation etc. That's only for the compiler to warn you if you if you request to much statically allocated stack space (such as a large local array) and maybe as a hint for the debugger.

    (hey, that would be an idea: causing an NMI when certain memory locations are accessed. very useful for detecting stack over/underflows in a multitasking kernel)

    Sonia Marginean said:
    --use_hw_mpy=F5

    Are you sure that is correct? i don't know the compiler/linker you're using, but it looks like this option is meant for enabling the 54xx hardware 32 bit multiplier. I doubt the 2418 has one. But I might be wrong. Only that you mentioned using a 5438 before.

     

**Attention** This is a public forum