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.

How to access stack pointer (SP) for MSP430FG4619 with IAR in C file?

Other Parts Discussed in Thread: MSP430FG4619

For CCS I found this intrinsics to be able to get the SP in C:

"unsigned short _get_SP_register(void);"

Is it the same intrinsics in IAR?

  • Hi Tony,

    Thank you so much for sharing your code.

    Highly appreciated.

    In the MSP430FG4619 family we have around 1% that resets, most likely because of stack overflow or DCO / FLL error so I would like to monitor the stack pointer.

    Or maybe it’s a DCO / FLL failure?

    May I ask what dos this code do?

    How can this be erased by mistake?

     

    if (CALBC1_8MHZ != 0xff){     // erased by mistake?

     BCSCTL1 = CALBC1_8MHZ;       // Set DCO to factory calibrate 8MHz 

        DCOCTL = CALDCO_8MHZ;


    Med venlig hilsen/ Regards

    Steffen kristensen

    Embedded Systems Director

    Larsen & Brusgaard

  • Steffen Kristensen said:

    In the MSP430FG4619 family we have around 1% that resets, most likely because of stack overflow or DCO / FLL error so I would like to monitor the stack pointer.

    If you are using a modern version of the IAR tools, you can use the new "stack usage" feature. It calculates the amount of stack that an application is using, so that you can be certain that you don't run out of stack. This is done by the linker using stack usage information the compiler provides.

    Of course, there are some limitations to this system. It doesn't handle function pointers, multithreading, or assembly libraries without "cfi" directives.

    You can enable this in "Options -> Linker -> Stack Usage" and inspect the result in the linker map file.

        -- Anders Lindgren, IAR Systems

  • The DCO calibration values are stored in the "information memory A" region of flash memory on the MCU. The can be accidentally erased by the debugger; normally it's set to leave InfoMem A untouched, but there's an option to clear the whole flash memory. The bootstrap loader can mass erase the flash in a similar way. Also it's possible to erase it if your firmware uses the flash controller to write to InfoMem A.
  • Thank you for the information. I now have the latest version with "Stack usage".
    I'm unsure in what file the stack information is saved?
  • It's included in the linker list file (also known as the "map" file).

    -- Anders

**Attention** This is a public forum