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.

Compiler/MSP430F5659: the question about stack calculation

Part Number: MSP430F5659

Tool/software: TI C/C++ Compiler

Hi, sir

I have transplanted UCOS II systerm to MSP430F5659 for developing multiple application funtions. However, I found the program  operate abnomally after I added some appilcation codes. I guessed that the reason is stack overflow. So, I  check Enable stack usage analysis check box in the Options of IAR compiler to gernerate a map file about stack.  The map file is following 

                ****************************************
                *                                      *
                *             STACK USAGE              *
                *                                      *
                ****************************************

  Call Graph Root Category  Max Use  Total Use
  ------------------------  -------  ---------
  interrupt                     56        204
  Program entry                528        528
  Uncalled function          1 404      6 214


Program entry
  "__program_start": 0x00008000

  Maximum call chain                            *?* 528  bytes
    (** call graph contains indirect calls (example: "_LocaleEncoding")
                            functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "__program_start"                                 0
    "main"                                            4
    "Init_App"                                        6
    "msgInit"                                        32
    "logSysMsgWithTime"                              52
    "DBWriteSysInfoNoInfoType"                      152
    "DBWrite"                                        20
    "writeSoe"                                       32
    "DBCWriteData"                                   38
    "ReadData"                                       32
    "FlashRead"                                      30
    "df_read"                                        28
    "read_buffer"                                    24
    "dataflash_wait_busy"                            12
    "dataflash_read_status"                           6
    "FlashSPIRead"                                   20
    "F5659SpiSend8"                                  36
    "F5659SpiWaiteIdle"                               4

interrupt
  "ADC12_ISR": 0x00008044

  Maximum call chain                               32  bytes

    "ADC12_ISR"                                    20
    "memcpy"                                       12

interrupt
  "Port3_ISR": 0x000081e8

  Maximum call chain                                8  bytes

    "Port3_ISR"                                     8

interrupt
  "USCI_B2_ISR": 0x00008226

  Maximum call chain                                8  bytes

    "USCI_B2_ISR"                                   8

interrupt
  "USCI_B1_ISR": 0x00008206

  Maximum call chain                                8  bytes

    "USCI_B1_ISR"                                   8

interrupt
  "PORT1_ISR": 0x00008296

  Maximum call chain                               56  bytes

    "PORT1_ISR"                                    20
    "RF_Frame_Receive"                              4
    "SetRFMode"                                     8
    "SpiWriteCfg"                                  20
    "SPI_Send_Byte"                                 4

interrupt
  "TIMER2_A1_ISR": 0x00008360

  Maximum call chain                                8  bytes

    "TIMER2_A1_ISR"                                 8

interrupt
  "TIMER1_A1_ISR": 0x00008344

  Maximum call chain                                8  bytes

    "TIMER1_A1_ISR"                                 8

interrupt
  "TIMER0_A1_ISR": 0x00008328

  Maximum call chain                                8  bytes

    "TIMER0_A1_ISR"                                 8

interrupt
  "TIMER2_A0_ISR": 0x000082ce

  Maximum call chain                                4  bytes

    "TIMER2_A0_ISR"                                 4

interrupt
  "TIMER1_A0_ISR": 0x000082c2

  Maximum call chain                               24  bytes

    "TIMER1_A0_ISR"                                20
    "RunSoftTime"                                   4

interrupt
  "TIMER0_A0_ISR": 0x000082c0

  Maximum call chain                                4  bytes

    "TIMER0_A0_ISR"                                 4

interrupt
  "USCI_A2_ISR": 0x0000845c

  Maximum call chain                               12  bytes

    "USCI_A2_ISR"                                  12

interrupt
  "USCI_A1_ISR": 0x000083ec

  Maximum call chain                               12  bytes

    "USCI_A1_ISR"                                  12

interrupt
  "USCI_A0_ISR": 0x0000837c

  Maximum call chain                               12  bytes

    "USCI_A0_ISR"                                  12

Uncalled function
  "StartupTask": 0x000265bc

  Maximum call chain                            *?* 180  bytes
    (** call graph contains functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "StartupTask"                                    72
    "OSTaskCreateExt"                                58
    "OS_TCBInit"                                     46
    "?OneBitMask32"                                   4

Uncalled function
  "OS_TaskStat": 0x0002510a

  Maximum call chain                                *?* 94  bytes
    (** call graph contains functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "OS_TaskStat"                                       20
    "OS_TaskStatStkChk"                                 36
    "OSTaskStkChk"                                      38
    "OS_CPU_SR_Save"                            - no info -

Uncalled function
  "OS_TaskIdle": 0x0002ff74

  Maximum call chain                            *?* 16  bytes
    (** call graph contains functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "OS_TaskIdle"                                   12
    "OSTaskIdleHook"                                 4

Uncalled function
  "OSTimeTick": 0x00026c02

  Maximum call chain                            *?* 108  bytes
    (** call graph contains functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "OSTimeTick"                                     20
    "OSTimeTickHook"                                  4
    "OSTmrSignal"                                     8
    "OSSemPost"                                      20
    "OS_EventTaskRdy"                                36
    "OS_EventTaskRemoveMulti"                        20

Uncalled function
  "OSIntExit": 0x0002cb20

  Maximum call chain                            *?* 12  bytes
    (** call graph contains functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "OSIntExit"                                      8
    "OS_SchedNew"                                    4

Uncalled function
  "OSTaskSwHook": 0x00030800

  Maximum call chain                                4  bytes

    "OSTaskSwHook"                                  4

Uncalled function
  "OSTmr_Task": 0x0002a2ac

  Maximum call chain                            *?* 74  bytes
    (** call graph contains indirect calls (example: "OSTmr_Task")
                            functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "OSTmr_Task"                                    30
    "OSTmr_Unlink"                                  28
    "?DivMod32u"                                    16

Uncalled function
  "Time1sCall": 0x0002c5e6

  Maximum call chain                            *?* 112  bytes
    (** call graph contains functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "Time1sCall"                                     30
    "OSFlagPost"                                     46
    "OS_FlagTaskRdy"                                 28
    "OS_FlagUnlink"                                   8

Uncalled function
  "time100mscall": 0x0002c446

  Maximum call chain                            *?* 112  bytes
    (** call graph contains functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "time100mscall"                                  30
    "OSFlagPost"                                     46
    "OS_FlagTaskRdy"                                 28
    "OS_FlagUnlink"                                   8

Uncalled function
  "Time10msCall": 0x0002c516

  Maximum call chain                            *?* 112  bytes
    (** call graph contains functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "Time10msCall"                                   30
    "OSFlagPost"                                     46
    "OS_FlagTaskRdy"                                 28
    "OS_FlagUnlink"                                   8

Uncalled function
  "Com2task": 0x00030682

  Maximum call chain                            *?* 1 404  bytes
    (** call graph contains recursive functions (example: "CSecAppSev::ProcControl()")
                            indirect calls (example: "_LocaleEncoding")
                            functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "Com2task"                                          8
    "ComApp"                                           12
    "DFE_WHTask"                                       22
    "DFEWHPriOnRx"                                     12
    "DFEWHSearchComFrame"                              20
    "DFEWHAppLayerPro"                                 12
    "ProcCallAllData"                                  12
    "ProcSystemInfo"                                  134
    "ReadSysInfoFrmFlash"                              36
    "ProcSysInfoToFlash"                               20
    "WriteSysInfoToFlash"                             780
    "sprintf"                                          16
    "_PrintfLarge"                                    148
    "_PutstrLarge"                                    116
    "__data20_malloc"                                  20
    "__data20_findmem"                                 12
    "__data20_free"                                    24


Uncalled function
  "Periodtask": 0x00028434

  Maximum call chain                            *?* 1 178  bytes
    (** call graph contains indirect calls (example: "_LocaleEncoding")
                            functions with no stack usage info (example: "OS_CPU_SR_Save") **)

    "Periodtask"                                       22
    "WriteSysInfoToFlashPeriod"                        20
    "ProcSysInfoToFlash"                               20
    "WriteSysInfoToFlash"                             780
    "sprintf"                                          16
    "_PrintfLarge"                                    148
    "_PutstrLarge"                                    116
    "__data20_malloc"                                  20
    "__data20_findmem"                                 12
    "__data20_free"                                    24

The following functions make up recursion nest 0, which has no maximum recursion depth specified:

  "CPriDLink::CallAppProc()": 0x00029794
  "CPriDLink::DLSendProc(INT16U)": 0x0001c548

The following functions make up recursion nest 1, which has no maximum recursion depth specified:

  "CSecAppSev::ProcControl()": 0x0000d6f6
  "CSecAppSev::SecAppProc(unsigned char *, INT16U, INT16U, unsigned char *, INT16U *, INT16U *)": 0x0000e622
  "CSecDLink::CallUData()": 0x0002c308

The following functions appear to be called, but have no stack
usage information:

  "OSCtxSw": 0x0002a48a
  "OSIntCtxSw": 0x0002a4ce
  "OSStartHighRdy": 0x0002a46e
  "OS_CPU_SR_Restore": 0x0002a466
  "OS_CPU_SR_Save": 0x0002a45e

The following functions perform unknown indirect calls:

  "OSTmr_Task": 0x0002a2ac
  "_LocaleEncoding": 0x000306de
  "localeconv": 0x000304d0
  "operator new(unsigned long)": 0x0002fbf4

    The question is how I could calculate the size of stack that I need to set by the map file ?

     Another question  is that the IAR compiler  showed 3 warnings when I execute compilation(Enable stack usage analysis check box selected).


How could I eliminate the warnings?

Best regards

Jent

  • Hi Jent,

    The "Max Use" case should define the maximum amount of stack used at any given time, based on this it appears that you should allocate at least 2 KB. Have you made any changes to project settings or the command linker file? I am not familiar with IAR map files or warnings, you may want to consider contacting IAR support for further assistance.

    Regards,
    Ryan
  • Hi Jent,

    the MSP430 Compiler User's guide provides some help how to check for STACK overflow. Please find the link below:
    www.ti.com/.../slau132p.pdf

    In chapter 6.1.5 some information about STACK and allocation are mentioned it also links to section 2.14 using hook option to check for STACK overflow. Honeslty I never used it by my own but maybe it helps you to find out if really a STACK overflow caused your problem.

**Attention** This is a public forum