Propeller Tool V1.3
Paul M
Posts: 95
Yesterday I downloaded and installed Propeller Tool V1.3. I tried compiling a fairly large and complex application which was successful. However, after downloading to the prop the application did not run. I reverted to V1.2.7 and everything was OK.
After some investgation I traced the problem to the "Stack_Length" object which has been updated for Proptool V1.3. The updates include:
1. The return value from the GetLength method has been changed to a Long from a string pointer.
2. Serial transmission of the stack length now uses "Parallax Serial Terminal.spin" rather than just inline code to transmit on the chosen pin.
I am surprised that this has slipped through the net as these changes will clearly break existing code; 1. because the return type has changed, and 2. because "Parallax Serial Terminal.spin" starts a new cog (which may not be available) and, by the way, never stops it, nor indeed is the any way of doing so.
As it turns out, although several objects referenced the Stack_Length object, my application did not make use of the GetLength call nor was I using the serial output feature and yet my code would not run.
In short, the problem appears to be with "Parallax Serial Terminal.spin"; removing all references to it in 2Stack_Length.spin" fixes the problem. I don't understand why, but simply having the reference to the object in the OBJ block without any calls to its methods, also causes the problem.
Surely a library object should not modified such that it breaks existing applications?? - even if it did actually work!
Paul
After some investgation I traced the problem to the "Stack_Length" object which has been updated for Proptool V1.3. The updates include:
1. The return value from the GetLength method has been changed to a Long from a string pointer.
2. Serial transmission of the stack length now uses "Parallax Serial Terminal.spin" rather than just inline code to transmit on the chosen pin.
I am surprised that this has slipped through the net as these changes will clearly break existing code; 1. because the return type has changed, and 2. because "Parallax Serial Terminal.spin" starts a new cog (which may not be available) and, by the way, never stops it, nor indeed is the any way of doing so.
As it turns out, although several objects referenced the Stack_Length object, my application did not make use of the GetLength call nor was I using the serial output feature and yet my code would not run.
In short, the problem appears to be with "Parallax Serial Terminal.spin"; removing all references to it in 2Stack_Length.spin" fixes the problem. I don't understand why, but simply having the reference to the object in the OBJ block without any calls to its methods, also causes the problem.
Surely a library object should not modified such that it breaks existing applications?? - even if it did actually work!
Paul
Comments
That makes sense.
But If I compile with 'F8 View Info' the object takes up 272 Longs of Program RAM and 55 Longs of Variable space.
There is no compiler error - so where do I start looking?
I have added just the reference in my main code and this also causes it to fail.
It doesn't matter where the reference is added in the list of objects
I have changed the reference name and renamed the object .spin file but this does not help.
I can add additional references to other objects without any problems.
I have added the reference to a smaller application without any problems.
Anyone?
- How does it fail (what doesn't happen)? Is it always the same location or is it random? Could give a hint re: memory corruption.
- Are all stacks big enough? Even if you think they are, make them bigger for now.
- Are all access ops within range? I know it's a pain to verify ...
Let's start with that list.But I would advise breaking your complex application into its constitutent parts, and see if these work individually, then start putting them back together.
Since this erro has not been reported before, there is a good chance its something in the way you app is put together, reather than the tool.
I agree, not due to V1.3 of the tool; as I said, referencing the PST object anywhere in the application causes the problem and it also occurs with V1.2.7.
I have started trying to eliminate parts of the code but as you will probably agree this is a painful process - not least because of the long(relatively) compile and download times.
Sorry, don't understand "access ops" ??
Depending on which parts of the main loop I eliminate, the code stops running at different times - sometimes the display never comes up at all, sometimes it is updated a few dozen times before the crash.
I have tried eliminating the VGA object altogether but it still stops; I can tell because the serial data also stops.
Sometimes the propeller reboots - again I can tell this because I have a different code loaded in eeprom.
All I really know is that adding a reference to the PST object causes the problem.
I'll have to get back to this next week - thanks again for the suggestions.
I have got to the point where adding a single line of code, e.g. X:=1 will cause the crash. I can add the code anywhere with the same results.I assume this means that valid program RAM is very close to its maximum limit and is somehow being corrupted at run time; however, the compiler reports plenty of spare RAM.
Any ideas?
Is this a very big programs? How many free longs do you have?
It definately crashes; quite often the prop reboots - I have loaded a different program into eeprom so I can tell when this happens
I have only 2 objects running spin in new cogs and I have checked the stack space for these objects - they have 2-3 times more than reported by the stack length object.
It is a large program; when compiled with F8 the compiler reports 474 free longs and the code will crash.
removing just one line will result in 475 free longs and will run.
I have used both Version 1.2.7 and 1.3 of the proptool; 1.3 uses less program space so code that won't run under 1.2.7 will under 1.3. However, as soon as the free space drops below 475 the problem occurs with V1.3 also. This presumably is further evidence that it is memory corruption.
As you can tell I don't understand this very well - I looked at the manual p.80 "The Need for Stack Space" - does this imply that the main code uses some of the free ram for its stack?
Is one of your objects relying on a certain amount of free space (hardwired addresses in high memory maybe)? IIRC one of the settings objects from the OBEX uses memory from top of RAM downwards as cache.
As far as I am aware I'm not accessing any high memory using hardcoded addresses.
Does the fact that the 'bug' causes the propeller to reboot narrow down the possible cause?
Also, does the order of declaration/order of "first use" of objects affect their position in memory?
If you are using CogNew to start up other Spin cogs, that's another area I'd double-check for enough stack space...
You do know about the issue where an FTDI serial chip that is connected to the Prop, but not connected to the PC can cause a reboot, right? Are you connected to a PC when this happens?
From experience the order of objects in the OBJ block defines where the object start and stop in memory. However, the VAR blocks are ordered from smallest to biggest and the DAT block is left as is. I'm not sure how the VARs behave across multiple OBJs. I'm fairly sure that the DAT blocks are static. I assume (and it appears to me ) that the VARs are lumped together regardless of the object. I'm not sure though, never tested the assumption.
I've found the problem.
My main routine declared a number of local variables, including an array. The array was never used but was declared as 400 longs. When I moved the array to the VAR section it became clear that I was running out of stack for the main method - it actually required 87 longs.
At the risk of boring you all, I am now a bit confused.
Judging by the output of F8 for the following short code: - local variables are created on the stack and do not form part of the object's variable space?
- local variables are created when the method is called, whether they are used or not?
- number of free longs is independent of number of local variables?
What is confusing is that in my original (large) code adding local variables or changing the local array size in the main method does change the reported number of free longs, but not in a consistent way:
with 5 local variables free longs: 329
with 6 local variables free longs: 328
adding local array ARR[2] free longs:326
adding local array ARR[4] free longs:318
adding local array ARR[6] free longs:314
adding local array ARR[25] free longs:297
adding local array ARR[250] free longs:282
and finally, if the array is the last local variable declared the compiler just seems to ignore it.
Is this expected behaviour?
Should not the compiler take account of local variables for the main method since it has to run and the variables will always be created?
That definitely sounds like trouble....
It's probably not a good idea to declare huge local variables like that. It makes determining how much free stack space you need difficult...
I think it's much better to have big arrays in var or dat.
If I had a dollar for every time that happened...
Thanks for that, I'm sure it must be something to do with this. My short example does not behave in the same way but is probably not a fair test.
Although I'm glad it happened, this all came about due to an updated library object in proptool V1.3 that is not backward compatible.
To wrap this up, am I alone in thinking this shouldn't happen?
I think it's a good thing you found that local 400 item array.
The Stack Length object: it has a changed return value and now uses the Parallax Serial Terminal object (see my very first post)
Absolutely! Lesson learned as I said. Perhaps the modified object should just have been renamed to ...V2 or something.
It's been that way for decades. In the Windows world they call it "dll hell". Linux has similar dependency problems that the distributions package managers try to solve for you but can still bite you when developing your own code or building things from sources.
One just has to learn to be vigalent and ask "what changed" when updates cause things to break.
-Phil