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.

CC1110 IDATA Stack Overflow After 3-4 hours Of Run Time



The following function is called to do 527 ADC conversions.  After each conversion, an interrupt occurs during which the ADC result goes through a bit resolution function and then is stored into an array called tempSamp defined as a float type.  The array was defined and initialized to zero in xdata memory prior to starting main().

  for (bufferNum = 1; bufferNum < 528; bufferNum++)

  { cycle = 0;

    ADCCON1 |= ADCCON1_ST | BIT1 | BIT0;  //Execute ADC conversion

     while( cycle == 0 );  }

The program runs between 3-4 hours without any problems but then an idata stack overflow occurs and the program stops.  If I run the device like I want out of debug mode, it also stops after 3-4 hours probably because of the idata overflow issue (although I don’t know for sure because of not being in debug mode).   I have read in a different forum that it is not a good idea to define a large array in a function.  From debug mode, I know for certain that the stack clears after the ADC function for a couple of hours.

I don’t externally reset the device without restarting the debug session, the power supply remains sufficient, I don’t enter any PM modes, and haven’t experienced known problems with the debug signals.

Any thoughts about why the stack would clear 3-4 hours and then stop clearing when the code is just going through a big loop?  

Is watchdog reset mode my best bet or is there a way I can make sure the idata stack is cleared after the ADC function?

IDATA Stack size setting: 0x80

XDATA Stack size setting: 0x1FF

-JD

################################################################################
#                                                                              #
#      IAR Universal Linker V5.4.1.30                                          #
#                                                                              #
#           Link time     =  12/Mar/2013  09:45:36                             #
#           Target CPU    =  x51                                               #
#           List file     =                               		       #
#           Output file 1 =  						       #
#                            Format: debug                                     #
#                            UBROF version 10.0.6                              #
#                            Using library modules for C-SPY (-rt)             #
#           Command line  =  "-IC:\Program Files (x86)\IAR Systems\Embedded Wo #
#                            rkbench 6.4 Baseline\8051\CONFIG\"                #
#                            -D_NR_OF_BANKS=0 -D_CODEBANK_END=0                #
#                            -D_CODEBANK_START=0                               #
#                            -o                                                #
#                            -l                                                #
#                            -xms                                              #
#                            "-IC:\Program Files (x86)\IAR Systems\Embedded Wo #
#                            rkbench 6.4 Baseline\8051\LIB\"                   #
#                            -f                                                #
#                            "C:\Program Files (x86)\IAR Systems\Embedded Work #
#                            bench 6.4 Baseline\8051\config\devices\Texas Inst #
#                            ruments\lnk51ew_CC1110F32.xcl"                    #
#                            (-D_IDATA0_START=0x00 -D_IDATA0_END=0xFF          #
#                            -D_PDATA0_START=0xF000 -D_PDATA0_END=0xF0FF       #
#                            -D_IXDATA0_START=0x00F000                         #
#                            -D_IXDATA0_END=0x00FDA1                           #
#                            -D_XDATA0_START=0x00F000 -D_XDATA0_END=0x00FDA1   #
#                            -D_CODE0_START=0x000000 -D_CODE0_END=0x007FFF     #
#                            -D?REGISTER_BANK=0x0 -D_REGISTER_BANK_START=0x0   #
#                            -D_BREG_START=0x00 -D?VB=0x20 -D?ESP=0x9B         #
#                            -Z(BIT)BREG=_BREG_START -Z(BIT)BIT_N=0-7F         #
#                            -Z(DATA)REGISTERS+8=_REGISTER_BANK_START          #
#                            -Z(DATA)BDATA_Z,BDATA_N,BDATA_I=20-2F             #
#                            -Z(DATA)VREG+_NR_OF_VIRTUAL_REGISTERS=08-7F       #
#                            -Z(DATA)PSP,XSP=08-7F -Z(DATA)DOVERLAY=08-7F      #
#                            -Z(DATA)DATA_I,DATA_Z,DATA_N=08-7F                #
#                            -U(IDATA)0-7F=(DATA)0-7F                          #
#                            -Z(IDATA)IDATA_I,IDATA_Z,IDATA_N=08-_IDATA0_END   #
#                            -Z(IDATA)ISTACK+_IDATA_STACK_SIZE#08-_IDATA0_END  #
#                            -Z(IDATA)IOVERLAY=08-FF -Z(CODE)INTVEC=0          #
#                            -Z(CODE)CSTART=_CODE0_START-_CODE0_END            #
#                            -Z(CODE)BIT_ID,BDATA_ID,DATA_ID,IDATA_ID,IXDATA_I #
#                            D,PDATA_ID,XDATA_ID=_CODE0_START-_CODE0_END       #
#                            -Z(CODE)RCODE,DIFUNCT,CODE_C,CODE_N,NEAR_CODE=_CO #
#                            DE0_START-_CODE0_END                              #
#                            -Z(CODE)CHECKSUM#_CODE0_END                       #
#                            -Z(XDATA)PDATA_Z,PDATA_I=_PDATA0_START-_PDATA0_EN #
#                            D                                                 #
#                            -P(XDATA)PDATA_N=_PDATA0_START-_PDATA0_END        #
#                            -Z(XDATA)PSTACK+_PDATA_STACK_SIZE=_PDATA0_START-_ #
#                            PDATA0_END                                        #
#                            -Z(XDATA)EXT_STACK+_EXTENDED_STACK_SIZE=_EXTENDED #
#                            _STACK_START                                      #
#                            -Z(XDATA)XSTACK+_XDATA_STACK_SIZE=_XDATA0_START-_ #
#                            XDATA0_END                                        #
#                            -Z(XDATA)IXDATA_Z,IXDATA_I=_IXDATA0_START-_IXDATA #
#                            0_END                                             #
#                            -P(XDATA)IXDATA_N=_IXDATA0_START-_IXDATA0_END     #
#                            -Z(XDATA)XDATA_Z,XDATA_I=_XDATA0_START-_XDATA0_EN #
#                            D                                                 #
#                            -P(XDATA)XDATA_N=_XDATA0_START-_XDATA0_END        #
#                            -Z(XDATA)XDATA_HEAP+_XDATA_HEAP_SIZE=_XDATA0_STAR #
#                            T-_XDATA0_END                                     #
#                            -Z(CONST)XDATA_ROM_C=_XDATA0_START-_XDATA0_END    #
#                            -cx51 -Z(XDATA)XDATA_SCRATCH=0xFDA2-0xFEFF)       #
#                            -D?DPMASK=0x01 -D_NR_OF_VIRTUAL_REGISTERS=20      #
#                            -D?DPS=0x92 -D?PBANK=0x93 -D?DPL1=0x84            #
#                            -D?DPH1=0x85 -rt -s __program_start               #
#                            "C:\Program Files (x86)\IAR Systems\Embedded Work #
#                            bench 6.4 Baseline\8051\LIB\DLIB\dl-pli-nlxd-2e16 #
#                            inc.r51"                                          #
#                            -D_IDATA_STACK_SIZE=0x80                          #
#                            -D_EXTENDED_STACK_START=0x00                      #
#                            -D_EXTENDED_STACK_SIZE=0x00                       #
#                            -D_PDATA_STACK_SIZE=0x40                          #
#                            -D_XDATA_STACK_SIZE=0x1FF                         #
#                            -D_XDATA_HEAP_SIZE=0xFF -D_FAR_HEAP_SIZE=0xFF     #
#                            -D_HUGE_HEAP_SIZE=0xFF -D_FAR22_HEAP_SIZE=0xFF    #
#                                                                              #
#                           Copyright (C) 1987-2012 IAR Systems AB.            #
################################################################################





                ****************************************
                *                                      *
                *           CROSS REFERENCE            *
                *                                      *
                ****************************************

       Program entry at : CODE      000000DF  Relocatable, from module : CSTARTUP




                ****************************************
                *                                      *
                *            RUNTIME MODEL             *
                *                                      *
                ****************************************

  __Heap_Handler             = Basic
  __SystemLibrary            = DLib
  __calling_convention       = xdata_reentrant
  __code_model               = near
  __core                     = plain
  __data_model               = large
  __dlib_file_descriptor     = 0
  __dlib_full_locale_support = 0
  __dptr_size                = 16
  __dptr_visibility          = separate
  __extended_stack           = disabled
  __location_for_constants   = data
  __number_of_dptrs          = 2
  __rt_version               = 1

                ****************************************
                *                                      *
                *    AUTOMATIC SYMBOL REDIRECTIONS     *
                *                                      *
                ****************************************

                  There are no automatic symbol redirections.



                ****************************************
                *                                      *
                *              MODULE MAP              *
                *                                      *
                ****************************************


  DEFINED ABSOLUTE ENTRIES
    *************************************************************************

  DEFINED ABSOLUTE ENTRIES
  PROGRAM MODULE, NAME : ?ABS_ENTRY_MOD

Absolute parts
           ENTRY                   ADDRESS         REF BY
           =====                   =======         ======
           _FAR22_HEAP_SIZE        000000FF 
           _HUGE_HEAP_SIZE         000000FF 
           _FAR_HEAP_SIZE          000000FF 
           _XDATA_HEAP_SIZE        000000FF 
           _XDATA_STACK_SIZE       000001FF 
           _PDATA_STACK_SIZE       00000040 
           _EXTENDED_STACK_SIZE    00000000 
           _EXTENDED_STACK_START   00000000 
           _IDATA_STACK_SIZE       00000080 
           ?DPH1                   00000085        ?XSTACK_RESTORE_DPTRS_1 (?XSTACK_RESTORE_DPTR)
                                                   ?XSTACK_SAVE_DPTRS_1 (?XSTACK_SAVE_DPTR)
                                                   Dma_channel_init(DMA_DESC *, uint16 *, uint16 *, uint16, uint8, uint16, uint16, uint8, uint8, uint8, uint16) (MainTX_v18a1e)
                                                   InitFlash(PT, PT, PT, PT) (MainTX_v18a1e)
                                                   Segment part 1 (?XSTACK_DISP8)
                                                   __call_ctors (?cppinit)
                                                   __call_dtors (?cppinit)
                                                   __record_needed_destruction (?cppinit)
                                                   main (MainTX_v18a1e)
           ?DPL1                   00000084        ?XSTACK_RESTORE_DPTRS_1 (?XSTACK_RESTORE_DPTR)
                                                   ?XSTACK_SAVE_DPTRS_1 (?XSTACK_SAVE_DPTR)
                                                   Dma_channel_init(DMA_DESC *, uint16 *, uint16 *, uint16, uint8, uint16, uint16, uint8, uint8, uint8, uint16) (MainTX_v18a1e)
                                                   InitFlash(PT, PT, PT, PT) (MainTX_v18a1e)
                                                   Segment part 1 (?XSTACK_DISP8)
                                                   __call_ctors (?cppinit)
                                                   __call_dtors (?cppinit)
                                                   __record_needed_destruction (?cppinit)
                                                   main (MainTX_v18a1e)
           ?PBANK                  00000093 
           ?DPS                    00000092        ?FUNC_ENTER_XDATA (?FUNC_ENTER_XDATA)
                                                   ?FUNC_LEAVE_XDATA (?FUNC_LEAVE_XDATA)
                                                   ?INTERRUPT_ENTER_XSP (?INTERRUPT_ENTER_XSP)
                                                   ?INTERRUPT_LEAVE_XSP (?INTERRUPT_LEAVE_XSP)
                                                   ?MOVE_LONG8_XDATA_XDATA_2DPTR (?MOVE_LONG8_XDATA_XDATA_2DPTR)
                                                   ?RESET_DPS (CSTARTUP)
							...
                                                   __DebugBreak (?__dbg_break)
                                                   __call_ctors (?cppinit)
                                                   __call_dtors (?cppinit)
                                                   __low_level_init (?low_level_init)
                                                   __record_needed_destruction (?cppinit)
                                                   main (MainTX_v18a1e)
           _NR_OF_VIRTUAL_REGISTERS
                                   00000020 
           ?DPMASK                 00000001        ?FUNC_ENTER_XDATA (?FUNC_ENTER_XDATA)
                                                   ?FUNC_LEAVE_XDATA (?FUNC_LEAVE_XDATA)
                                                   ?INTERRUPT_ENTER_XSP (?INTERRUPT_ENTER_XSP)
                                                   ?INTERRUPT_LEAVE_XSP (?INTERRUPT_LEAVE_XSP)
                                                   ?RESET_DPS (CSTARTUP)
           ?ESP                    0000009B 
           ?VB                     00000020        ?FUNC_ENTER_XDATA (?FUNC_ENTER_XDATA)
                                                   ?FUNC_LEAVE_XDATA (?FUNC_LEAVE_XDATA)
                                                   ?INTERRUPT_ENTER_XSP (?INTERRUPT_ENTER_XSP)
                                                   ?INTERRUPT_LEAVE_XSP (?INTERRUPT_LEAVE_XSP)
                                                   main (MainTX_v18a1e)
           _BREG_START             00000000 
           _REGISTER_BANK_START    00000000 
           ?REGISTER_BANK          00000000        Segment part 6 (CSTARTUP)
           _CODE0_END              00007FFF 
           _CODE0_START            00000000 
           _XDATA0_END             0000FDA1 
           _XDATA0_START           0000F000 
           _IXDATA0_END            0000FDA1 
           _IXDATA0_START          0000F000 
           _PDATA0_END             0000F0FF 
           _PDATA0_START           0000F000 
           _IDATA0_END             000000FF 
           _IDATA0_START           00000000 
           _CODEBANK_START         00000000 
           _CODEBANK_END           00000000 
           _NR_OF_BANKS            00000000 
    *************************************************************************

...

                ****************************************
                *                                      *
                *      SEGMENTS IN ADDRESS ORDER       *
                *                                      *
                ****************************************


SEGMENT              SPACE    START ADDRESS   END ADDRESS     SIZE  TYPE  ALIGN
=======              =====    =============   ===========     ====  ====  =====
INTVEC               CODE          00000000 - 00000085          86   com    0
CSTART               CODE          00000086 - 000000F6          71   rel    0
PDATA_ID             CODE               000000F7                     dse    0
IXDATA_ID            CODE               000000F7                     dse    0
IDATA_ID             CODE               000000F7                     dse    0
BDATA_ID             CODE               000000F7                     dse    0
BIT_ID               CODE               000000F7                     dse    0
DATA_ID              CODE               000000F7                     dse    0
XDATA_ID             CODE          000000F7 - 00000172          7C   rel    0
RCODE                CODE          00000174 - 00000B91         A1E   rel    1
DIFUNCT              CODE          00000B92 - 00000B93           2   rel    0
CODE_N               CODE               00000B94                     dse    0
CODE_C               CODE               00000B94                     dse    0
NEAR_CODE            CODE          00000B94 - 0000743F        68AC   rel    0
CODE_AN              CODE          00007C00 - 00007FFF         400   rel    0
REGISTERS            DATA          00000000 - 00000007           8   rel    0
BREG                 BIT        00000020.0  -  00000020.7        8   rel    0
VREG                 DATA          00000021 - 00000040          20   rel    0
PSP                  DATA               00000041                     dse    0
XSP                  DATA          00000041 - 00000042           2   rel    0
SFR_AN               DATA          00000080 - 00000080           1   rel    0
                     DATA          00000088 - 00000088           1 
                     DATA          0000008D - 0000008D           1 
                     DATA          0000008F - 00000091           3 
                     DATA          0000009A - 0000009E           5 
                     DATA          000000A0 - 000000A0           1 
                     DATA          000000A8 - 000000A8           1 
                     DATA          000000AB - 000000AE           4 
                     DATA          000000B4 - 000000B5           2 
                     DATA          000000B8 - 000000B8           1 
                     DATA          000000BA - 000000BE           5 
                     DATA          000000C0 - 000000C0           1 
                     DATA          000000C6 - 000000C6           1 
                     DATA          000000CB - 000000CB           1 
                     DATA          000000CD - 000000CD           1 
                     DATA          000000D1 - 000000D6           6 
                     DATA          000000D8 - 000000D8           1 
                     DATA          000000DA - 000000DB           2 
                     DATA          000000E1 - 000000E1           1 
                     DATA          000000E4 - 000000E5           2 
                     DATA          000000E9 - 000000E9           1 
                     DATA          000000F2 - 000000F7           6 
                     DATA          000000FD - 000000FF           3 
XSTACK               XDATA         0000F000 - 0000F1FE         1FF   rel    0
XDATA_Z              XDATA         0000F1FF - 0000FC44         A46   rel    0
XDATA_I              XDATA         0000FC45 - 0000FCC0          7C   rel    0
ISTACK               IDATA         00000080 - 000000FF          80   rel    0

                ****************************************
                *                                      *
                *        END OF CROSS REFERENCE        *
                *                                      *
                ****************************************

 29 759 bytes of CODE  memory (+ 1 024 absolute )
     42 bytes of DATA  memory (+    51 absolute )
  3 265 bytes of XDATA memory
    128 bytes of IDATA memory
      8 bits  of BIT   memory

Errors: none
Warnings: none

  • Hello JDBC,

    I am not sure of this, but I would recommend you to try to run the code with integers instead of floats to try to verify of this is causing the problem or not. The 8051 processor do not have floating point instructions so all operations must be emulated which might give rise to a "bloated" use of the system resources.

    Try to use scaled integers instead of floats. You can use "scaled" long integers ( 4 bytes ) and use integer operations on that. For example if you had the value 2.5 you can just multiply it with 10 and get 25 for use with arithmetic's and then reformat it later if you are to display it on a LCD.

    As you stated, it is a good idea to not define large arrays inside functions. If you do not have deterministic knowledge on when and how often the function is called the application might suddenly expand and fill up the allocated available stack resources in RAM and you might end up with a overflow (usually in XDATA for this specific case).

    BR. Eirik

  • Thank you Eirik.  I came to that same conclusion a few days ago too and have been meaning to update the forum.  The issue had to do with storing the ADC result as a float and entering multiple functions within functions with a large array.  Since I combined the functions into one and made the ADC result an uint16, I haven't had any more issues.  I also think it had to do with going through the ADC loop too quickly and needing to allow enough time between conversions.  Hopefully this will help others with similar issues in the future.

    Thanks again for the expertise!

    JDBC

  • Glad to hear it. Good luck on wards. 

    BR. Eirik