| View previous topic :: View next topic |
| Author |
Message |
jaka
Joined: 04 May 2014 Posts: 45 Location: Finland
|
| Worst case stack usage |
Posted: Mon Mar 02, 2026 4:49 am |
|
|
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
|
|
Posted: Mon Mar 02, 2026 8:57 am |
|
|
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: 45 Location: Finland
|
|
Posted: Mon Mar 02, 2026 11:32 am |
|
|
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
} |
|
|
 |
|