Stack corruption?
Moderator: Benj
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Stack corruption?
Hi,
I'm nearly finished with a program, but now I get unpredictable results. That can be due to stack corruption? The msg file shows:
Building CASM file
Serious Warning: Possible sw stack corruption, function 'FCD_PWM0_Enable' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCM_RS232_Output' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_PWM0_Disable' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'delay_us' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Memory Usage Report
===================
RAM available:256 bytes, used:256 bytes (100.0%), free:0 bytes (0.0%),
Heap size:0 bytes, Heap max single alloc:0 bytes
ROM available:4096 words, used:3781 words (92.4%), free:315 words (7.6%)
PWM0 and delay_us are Flowcode functions., RS232 is a macro of myself which I do not you recursively.
Can someone tell if if this warnings can indeed give stack corruptions?
Kind regards
Jan Lichtenbelt
I'm nearly finished with a program, but now I get unpredictable results. That can be due to stack corruption? The msg file shows:
Building CASM file
Serious Warning: Possible sw stack corruption, function 'FCD_PWM0_Enable' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCM_RS232_Output' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_PWM0_Disable' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'delay_us' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Memory Usage Report
===================
RAM available:256 bytes, used:256 bytes (100.0%), free:0 bytes (0.0%),
Heap size:0 bytes, Heap max single alloc:0 bytes
ROM available:4096 words, used:3781 words (92.4%), free:315 words (7.6%)
PWM0 and delay_us are Flowcode functions., RS232 is a macro of myself which I do not you recursively.
Can someone tell if if this warnings can indeed give stack corruptions?
Kind regards
Jan Lichtenbelt
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Stack corruption?
Hi jan
Did you configure the soft stack option in compiler? If.yes this might have causing the trouble. Can you just try with defult compiler option then? Let us know what you are getting!
Did you configure the soft stack option in compiler? If.yes this might have causing the trouble. Can you just try with defult compiler option then? Let us know what you are getting!
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Stack corruption?
Hi Enamul
I did use the standard compiler option. I do not know what soft option is and if that is standard or not?
Kind regrads
Jan Lichtenbelt
I did use the standard compiler option. I do not know what soft option is and if that is standard or not?
Kind regrads
Jan Lichtenbelt
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Stack corruption?
Hi Jan,
It's hard to say exactly without seeing your program and working out what can be called and when.
The compiler messages are basically saying this.
There is a function named .... which is called in the main program loop and also via an interrupt. Should the interrupt kick in while you are already inside the function then this will potentially cause RAM corruption and may even have effects on the program counter etc which may cause resets or other weirdness.
To answer this you need to know: is the function called from anywhere in the main loop while the interrupt is potentially active?
If no then there shouldn't be any problems.
If yes then maybe disable the interrupt before calling the function and re-enable after coming back out or maybe find a way of moving the function call from the interrupt routine and into the main by using a trigger variable.
It's hard to say exactly without seeing your program and working out what can be called and when.
The compiler messages are basically saying this.
There is a function named .... which is called in the main program loop and also via an interrupt. Should the interrupt kick in while you are already inside the function then this will potentially cause RAM corruption and may even have effects on the program counter etc which may cause resets or other weirdness.
To answer this you need to know: is the function called from anywhere in the main loop while the interrupt is potentially active?
If no then there shouldn't be any problems.
If yes then maybe disable the interrupt before calling the function and re-enable after coming back out or maybe find a way of moving the function call from the interrupt routine and into the main by using a trigger variable.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Stack corruption?
Hi Jan,
In that case you can simply post the program and our compiler experts Ben or David can have a look..
In that case you can simply post the program and our compiler experts Ben or David can have a look..
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Stack corruption?
Hi Enamul and Ben
Thanks for help.
1) I deleted the us delay, but the warning resists?????
2) It is correct that I use the PWM enable and PWM disable in the main program and in an interrupt, but they can never happen at the same time.
3) Also the macro RS232_output are in the main program and in an interrupt. But at this stage of development, the interrupt will never get active.
That makes me conclude that there is an other problem which causes my unexpeceted results.
Can the maximum use of RAM be a problem?
RAM available:256 bytes, used:256 bytes (100.0%), free:0 bytes (0.0%)
or the nearly maximum of the ROM?
ROM available:4096 words, used:3878 words (94.7%), free:218 words (5.3%)
Kind regards
Jan Lichtenbelt
Thanks for help.
1) I deleted the us delay, but the warning resists?????
2) It is correct that I use the PWM enable and PWM disable in the main program and in an interrupt, but they can never happen at the same time.
3) Also the macro RS232_output are in the main program and in an interrupt. But at this stage of development, the interrupt will never get active.
That makes me conclude that there is an other problem which causes my unexpeceted results.
Can the maximum use of RAM be a problem?
RAM available:256 bytes, used:256 bytes (100.0%), free:0 bytes (0.0%)
or the nearly maximum of the ROM?
ROM available:4096 words, used:3878 words (94.7%), free:218 words (5.3%)
Kind regards
Jan Lichtenbelt
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Stack corruption?
Hi Jan,
Is there any functions or component macros being called in the interrupt that could potentially be calling the delay function?1) I deleted the us delay, but the warning resists?????
As long as the function cannot collide with itself then there is no problem in calling these functions inside an interrupt.2) It is correct that I use the PWM enable and PWM disable in the main program and in an interrupt, but they can never happen at the same time.
Again this is fine.3) Also the macro RS232_output are in the main program and in an interrupt. But at this stage of development, the interrupt will never get active.
Personally this would worry me a bit, is there any way for you to remove or re-use any variables to raise the free percentage and see if things improve at all.RAM available:256 bytes, used:256 bytes (100.0%), free:0 bytes (0.0%)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Stack corruption?
Dear Ben,
I have still problems. If I use the macro RS232_output (see attached file) it works correctly in this simple test program. But as said, my real program has RAM and ROM nearly used completely (not 100% any more). In that case the variable RC_Time_On will loss its value and become 0 after the first call of the macro RS232_output.
I used the new PIC_CAL_String.c ( http://www.matrixmultimedia.com/mmforum ... =29&t=7903 )
What can be the reason?
Kind regards
Jan Lichtenbelt
I have still problems. If I use the macro RS232_output (see attached file) it works correctly in this simple test program. But as said, my real program has RAM and ROM nearly used completely (not 100% any more). In that case the variable RC_Time_On will loss its value and become 0 after the first call of the macro RS232_output.
I used the new PIC_CAL_String.c ( http://www.matrixmultimedia.com/mmforum ... =29&t=7903 )
What can be the reason?
Kind regards
Jan Lichtenbelt
- Attachments
-
- Test_RS232_error.fcf
- (15 KiB) Downloaded 258 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Stack corruption?
Hi Jan,
I noticed that the variable in the prog is RC_Time and the variable in the variable window is RC_Tiem. Not sure how this is possible but could this be the cause of the problem?
I noticed that the variable in the prog is RC_Time and the variable in the variable window is RC_Tiem. Not sure how this is possible but could this be the cause of the problem?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Stack corruption?
Sorry, my fault. Here the improved version V2
- Attachments
-
- Test_RS232_error_V2.fcf
- (15 KiB) Downloaded 264 times
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Stack corruption?
Hi
Can anybody tell me why in this simple program the RAM uses already 201 bytes! If I look in the assembler file, there are a lot of variables which seems to me are unnecessary in this list (see attachment). Can I prevent these variables?
Kind regards
Jan Lichtenbelt
Can anybody tell me why in this simple program the RAM uses already 201 bytes! If I look in the assembler file, there are a lot of variables which seems to me are unnecessary in this list (see attachment). Can I prevent these variables?
Kind regards
Jan Lichtenbelt
- Attachments
-
- Test_RS232_error_V2.asm
- (42.89 KiB) Downloaded 255 times
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Stack corruption?
For the interested people.
I found that the unexpected change of the value of a variable was not due to a stack problem but due to a not correct end of an interrupt disable. That means probably that thare was an intterupt call which changed the value of the variable of interest.
Kind regards
Jan Lichtenbelt
I found that the unexpected change of the value of a variable was not due to a stack problem but due to a not correct end of an interrupt disable. That means probably that thare was an intterupt call which changed the value of the variable of interest.
Kind regards
Jan Lichtenbelt
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Stack corruption?
Hi Jan,
I looked at the programs you sent (the FCF and the ASM files) and it looks like all those extra variables are being used for things like string concatenation and similar. It might be possible for you to pass things straight to the RS232 rather then combining into a string before sending, not really sure how much this would optimise the code as the macro itself could get a bit more messy and take up more ROM memory. If your struggling for space then you can post up the file and I will see if I can spot any easy way to optimise and cut down on RAM usage.
I looked at the programs you sent (the FCF and the ASM files) and it looks like all those extra variables are being used for things like string concatenation and similar. It might be possible for you to pass things straight to the RS232 rather then combining into a string before sending, not really sure how much this would optimise the code as the macro itself could get a bit more messy and take up more ROM memory. If your struggling for space then you can post up the file and I will see if I can spot any easy way to optimise and cut down on RAM usage.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 130
- Joined: Sat Feb 26, 2011 4:26 am
- Location: South Africa
- Has thanked: 25 times
- Been thanked: 11 times
- Contact:
Re: Stack corruption?
Hi Ben / Jan
In a previous post called "Checksum freezes Pic" I pasted a simple hardware / software RS232 program with the same error message when compiling. JonnyW gave me some good advice & I got rid of the freezing part but not the error messages please let me know if you know what might be causing this stack corruption error.
In a previous post called "Checksum freezes Pic" I pasted a simple hardware / software RS232 program with the same error message when compiling. JonnyW gave me some good advice & I got rid of the freezing part but not the error messages please let me know if you know what might be causing this stack corruption error.