First and easiest what i would do in such case is to start debugger, before starting programm fill whole stack with 0xff or 0xa5 or whatever, start program, wait for a some time, stop it and check your stack. so, u can see how much of stack was used. of course, if programm crashes u can not get access to stack. by this way u can more or less evaluate the use of stack. repeat it for several times to get ''the worst'' use of stack.
I have done that and the worst case seems to be stack goes from 0x1FF to 0x166. That should be ok? I have also tried to use static memory models. When using memory long I get error ''segment .share size overflow (64)'' from linker.
Posted on April 19, 2006 at 11:43Bood, looking at your map file, the compiler calculates a maximun theoretical stack usage of 215 bytes (you measured much less with the method suggested by Luter). Since you have nothing but the stack in page 1 (all your variables are in page0), there should be no stack corruption (assuming, of course, that your ST7 has enough RAM). The problem probably comes from the fact that you are using printf within an interrupt routine; this is a very bad practice for a number of reasons. Try to move printf into main (set a flag in your interrupt and then test this flag and execute printf if it is true) and the problem should go away. More generally, this syle of programming is not very suitable for ST7 (and small micros in general): - using float is big and slow (replace with look up tables when possible) - using printf is big and slow (replace with own subroutine, or with the ''light'' version of printf if possible) - using printf (or any other ''big function'') into interrupt routine is definitely to be avoided Regards, Luca (Cosmic)
It seems that the error only occurs when printing float values in the interrupt routine. I will follow your advice, I understand this is not the best for a small micro, but still I wonder why it dont work when all memory handle seems ok. BR Bood
..still I wonder why it dont work when all memory handle seems ok.
printf uses resources that are not saved by default when entering the interrupt routine; you could force the compiler to save all that stuff (notably, the LREG), but, as using printf under interrups is wrong anyway (no predictable execution time), you'd better remove it altogether. Regards, Luca