We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I am developing a firmware for EZUSB FX based board. I am facing a small problem. I am not able to initialize a Global variable in my firmware. Even though I assign the global variable with 0 initial value, But the variable does not take that value. I am using SMALL memory model for my development. my declerations looks like this :- BYTE GlobalCount = 0; and in my sof() I am using this variable and updating it and reusing it again in next sof(). Please advise .. Rahul Gupta
GlobalCount is initialized to 0 in my startup code, main(), and even in TD_POLL(polling function). Sounds like the compiler and startup code are doing their jobs. But in SOF() (interrupt routine) it was not zero and had some garbage value. Sounds like it's getting trashed somewhere else in your program. Jon
As, in code Posted above I never touch the GlobalCount in any of my functions. There should be any corruption. Is there any other way I can achieve the desiref functionality ??? Thanks Rahul Gupta
oops! it's really bad! :-( :-( try to understand where this memory location was overwrited. 1. Check .m51, where var is located. 2 is there any array before or after this var? array index may be wrong, for example char x[7]; x[i]= 0; with i>= 7; use x[8] and x[i&7] instead, especially for receiver buffer! 3 did you use any pointer operation, like char *x; *x= value; x may be wrong. 4 did you use sprintf ? If format is wrong, it may put data outside the buffer
On Analysing the problem further, This is the behaviour I have observed .... If I remove the code line viz. glbCount = glbCount + 0x10; in the Code attached below. The glbCount is initialized to 0. But if this line of code is there then I my glbCount can start It seems this particular line of code is corrupting the Initial value. If it is ... what is the alternate way to achieve the desired functionality ??? TIA Rahul Gupta static BYTE glbCount = 0; // global //Interrupt Routine void ISR_Sof(void) interrupt 0 { BYTE i = 0; for (i=0;i<16;i++) { IN8DATA = glbCount; } glbCount = glbCount + 0x10; EZUSB_IRQ_CLEAR(); USBIRQ = bmSOF; // Clear SOF IRQ }
On Analysing the problem further, This is the behaviour I have observed .... If I remove the code line viz. glbCount = glbCount + 0x10; in the Code attached below. The glbCount is initialized to 0. But if this line of code is there then the glbCount can take any garbage value and increment subsiquently ... It seems this particular line of code is corrupting the Initial value. If it is ... what is the alternate way to achieve the desired functionality ??? Attaching code for reference ... Please Advise !! static BYTE glbCount = 0; // global //Interrupt Routine void ISR_Sof(void) interrupt 0 { BYTE i = 0; for (i=0;i<16;i++) { IN8DATA = glbCount; } glbCount = glbCount + 0x10; EZUSB_IRQ_CLEAR(); USBIRQ = bmSOF; // Clear SOF IRQ }
The code you have posted #includes files I don't have, calls functions that aren't defined and runs on hardware I don't have. You need to strip the program right down to a main function, ISR and variable declarations. If that still doesn't work, post it. If it does work, add your other code back in bit by bit until the problem reappears. You will then have a pretty good idea where the problem lies.
This code is taken from an example supplied with the Cypress development toolkit. I have only changed the code in Sof() function. The main functions etc .. is the minimal code for initialization and support for a ISO endpoint and bringing up the board. Thanks Rahul