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.

CCS/TMS570LC4357: Code stopped working (sprintf)

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

This code stops working (crashes, stops at "b   dataEntry") when you create a HalCoGen project with FreeRTOS (you don't have to use FreeRTOS for this to occur):

uint32_t id = 0x14FF01EF;
float internalVoltage = 22750.0;
int8_t intTempC = 25;

char buffer[150];
int len = sprintf(buffer, "(0x%08x) internal voltage: %4.2f internal temp: %d\r\n", (int)id, internalVoltage, intTempC);
puts(buffer);

I tracked it down to "HL_sys_core.asm". The section at line 162-167, switches from this (no FreeRTOS):

userSp  .word 0x08000000+0x00001000
svcSp   .word 0x08000000+0x00001000+0x00000100
fiqSp   .word 0x08000000+0x00001000+0x00000100+0x00000100
irqSp   .word 0x08000000+0x00001000+0x00000100+0x00000100+0x00000100
abortSp .word 0x08000000+0x00001000+0x00000100+0x00000100+0x00000100+0x00000100
undefSp .word 0x08000000+0x00001000+0x00000100+0x00000100+0x00000100+0x00000100+0x00000100

to this (with FreeRTOS):

userSp  .word 0x08000000+0x00000300
svcSp   .word 0x08000000+0x00000300+0x00000100
fiqSp   .word 0x08000000+0x00000300+0x00000100+0x00000100
irqSp   .word 0x08000000+0x00000300+0x00000100+0x00000100+0x00000100
abortSp .word 0x08000000+0x00000300+0x00000100+0x00000100+0x00000100+0x00000100
undefSp .word 0x08000000+0x00000300+0x00000100+0x00000100+0x00000100+0x00000100+0x00000100

I cannot find these values or any mention of them in any of the PDFs or in the forums. The function is "Initialize Stack Pointers" -- which makes sense why it's affecting sprintf.

How can you set these values so that sprintf works as well as FreeRTOS?

  • If the stack is overflow, a data abort will be generated. 

  • How do you detect a stack overflow? How do you set these values or do you have to just set the stack size?

    I found Tips for Using Printf

    It states: "Make sure the stack is large enough. Depending on the version of the compiler, calling one of the *printf functions requires more than 400 bytes of stack. Make sure the stack is in valid read/write data memory." -- FreeRTOS is setting the stack to 300 and you need 400... but I don't know how to bump it up after sys core changes it.

  • The Stack Usage View in Code Composer Studio (available in CCS 6.2 and higher) provides a static view of stack usage for your application. The information is generated on project build and displayed as a function call tree with stack usages for each function in a horizontal bar graph. 

    In CCS project linker configuration, you can set the stack size. CCS project property --> CCS Build -->ARM Linker-->Basic Options

    The stack size in map file is what you define in linker cmd file: staring address, and length. It is define where the stack is located.

    The _coreInitStackPointer_() in sys_core.asm defines stack size for each mode (User, SVC, IRQ,....)

    --stack_size in CCS linker option should match the total size defined in _coreInitStackPointer_() function.

  • Chris Dickerson said:
    but I don't know how to bump it up after sys core changes it.

    If the sprintf function is called from a FreeRTOS task, then the stack size is specified when the task is created - see How big should the stack be? from the FreeRTOS FAQ.

  • I know about running IN a task, the problem is using sprintf in a notification from CAN... which lies outside a task.