CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Worst case stack usage

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jaka



Joined: 04 May 2014
Posts: 46
Location: Finland

View user's profile Send private message

Worst case stack usage
PostPosted: Mon Mar 02, 2026 4:49 am     Reply with quote

I need to conduct worst case stack / heap usage analysis for a CCS project and prove that an overflow can't occur. I am using PIC18F26K83.

Normally, I check the list or .STA file but for this project they show that stack is not used at all. Can that be true? Is there some other way to analyze stack usage?

The top of the .lst file says:
Code:
CCS PCH C Compiler, Version 5.116, 63210               02-maalis-26 12.26

               Filename:   (filename removed)

               ROM used:   18472 bytes (28%)
                           Largest free fragment is 21840
               RAM used:   690 (17%) at main() level
                           752 (18%) worst case
               Stack used: 0 locations
               Stack size: 31


And some snippets from .STA file:
Code:
ROM used:   18472/65536 (28%)
            21884/65536 (33%) including unused fragments

            1.1 Average locations per line
            9.9 Average locations per statement

RAM used:   690/4095 (17%) at main() level
            752/4095 (18%) worst case

Stack used: 0 worst case (0 in main + 0 for interrupts)
Stack size: 31

...

Program metrics:
    Functions               76
    Statements              1868
    Comments                8458
    Volume (V)              145135
    Difficulty (D)          411.9
    Effort to implement (E) 59779021
    Time to implement (T)   922 hours, 31 minutes
    Est Delivered Bugs (B)  51
    Cyclomatic Complexity   384
    Maintainability (MI)    49

 Segment     Used  Free
-----------  ----  ----
00000-00002     4  0 
00004-00006     0  4 
00008-00060    90  0 
00062-05550  18332  3412 
05552-05552     2  0 
05554-05554     2  0 
05556-05556     2  0 
05558-0AAA6     0  21840 
0AAA8-0AAA8     2  0 
0AAAA-0AAAA     2  0 
0AAAC-0AAAC     2  0 
0AAAE-0FFBE     0  21778 
0FFC0-0FFDE    32  0 
0FFE0-0FFFC     0  30 
0FFFE-0FFFE     2  0 


My code uses only one interrupt, I2C1 interrupt. The code flow is also tried to be kept deterministic, with all functions always running at specific order. But still, zero stack usage seems odd?
Ttelmah



Joined: 11 Mar 2010
Posts: 20043

View user's profile Send private message

PostPosted: Mon Mar 02, 2026 8:57 am     Reply with quote

Show the lines where you declare the interrupt handler.
For 'straight line' code, it is possible to have no stack usage, but the
interrupt if the handler is properly declared, will be using stack space.
So show how this is declared.
jaka



Joined: 04 May 2014
Posts: 46
Location: Finland

View user's profile Send private message

PostPosted: Mon Mar 02, 2026 11:32 am     Reply with quote

My interrupt is declared like this:

Code:
#INT_I2C1
void i2c1_interrupt(void) {
 
   code removed, actual code is very similar
   as in ex_i2c_slave_k42.c

}
jaka



Joined: 04 May 2014
Posts: 46
Location: Finland

View user's profile Send private message

PostPosted: Mon Mar 02, 2026 11:38 am     Reply with quote

Hmm.. just tried to compile the ex_i2c_slave_k42.c and that is showing:
Stack used: 2 locations (0 in main + 2 for interrupts)

I need to do some experimenting which is causing the stack analysis to fail on my main project. I suspect the ClassB tests..

edit:
It was the ClassB tests, now I am getting this on my main project:
Stack used: 6 locations (5 in main + 1 for interrupts)
which seems plausible to me
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group