I've been trying to troubleshoot a mysterious problem for a few days now, and I hope someone here can give me some ideas. We are using UV3 and C51 (ver 7.50) to develop an application for Cypress FX2 LP which is a 8051 variant with 16KB RAM (which may be shared for code and data). For applications of up to about 11KB in code size, everything works fine. When the program exceeds 11KB, strange problems pop up. Calling some (valid!) functions trigger a system reset. Adding a line to a function that no one ever calls, and the system goes into infinite reboot loop. Adding a dummy file with some uncalled functions, same thing happens. Adding a redundant function call that does nothing and everything goes back no normal, until the next time some other line changes. To make a long story short - total chaos! I can't understand the logic of any of this, and it happens only beyond a certain program size. The program compiles and links with no errors (except "uncalled segment" warning if 'dummy' uncalled functions are inserted). The problem is very distrurbing and very chaotic - the program may run fine up to a certain point, then reboots with no apparent cause at all. Comment out an unused function and all goes well. Another thing I noticed - if I tell the linker to move the program in memory, the fault point shifts randomly to someplace else. We've ruled out a H/W problem or a defective CPU. Has anyone ever encountered something so odd, and can you give me any ideas on how to troubleshoot? Thanks in advance, Ran Shalgi Siano Mobile Silicon
Ok, found my problem. I did have a warning: "MULTIPLE CALL TO SEGMENT...". This was a function that is called by an ISR, and also called at startup. There would not be a case of it being called in both contexts simultaneously. According to http://www.keil.com/support/docs/805.htm, one resolution is this: "If you are 100% sure that two copies of the function will never execute at the same time (if the function is called from the main code and interrupts are disabled) and that there is no memory used by the function (only registers are used), then you may simply choose to ignore this warning." Apparently, with version 7.5 of the compiler, this is no longer true. Even though the two weren't called at the same time, and no memory was used by the function, somehow the generated code messed up register R7 on other function calls that are unrelated. Adding the "reentrant" keyword to the function got rid of the warning and all the problems.
Thanks for all the ideas and suggestions. My problem is still unresolved and seems to be different than what you describe: 1. I have no "multiple call" warnings. 2. The problem happens even when only a single process ("main") calls the function, with all ISRs disabled. 3. The system reboots when the function is called. It's not that I'm getting into the function and getting erronous values - the first line of the function never gets executed.
just a question: since no one states it, are you all using the Cypress chip? Please repost and indicate the derivative you use Erik