Hi,I am trying to implement a nios system(cyclone III) with 16-bit DDR2 SDRAM and 16-bit Flash device. While try to erase the flash device using the routine listed below
unsigned int32 flashoffset;
unsigned int16 noofblockstoerase;
unsigned int16 erasesize;
flashutils_eraseflash(flashoffset,noofblockstoerase*erasesize); it could only erase 64K locations. I assumed that the argument passed was only the lower 16 bits of the noofblockstoerase*erasesize value, as only a 16-bit RAM is connected. Please let me know if there is a solution where, even if i dont explicitly declare a variable it would still work as normally as 32-bit RAM.
Not sure what your problem is?The flash sector size could well be 64k bytes (except maybe for 'boot' sectors at one end of the device), so you can only erase multiples of that size. As a general point, don't use int16 (or short) unless you really want wrapping at 2^16, are saving space in a structure, or mapping actual hardware registers into a structure. All you do is cause the compiler to generate extra instructions every time you do any maths. In the above, both your int16 items will be promoted to 'int' (32 bits) before the multiply - so that shouldn't be relevant. The size of the flash chips data bus is mostly irrelevant - apart from the problems in generating the required single cycles during the programming operation.
The actual problem is that, when i dont declare a 32 bit int variable to store the result of noofblockstoeras e*erasesize and use it asflashutils_eraseflash(flashoffset,noofblockstoeras e*erasesize); the flash erase is executed only till 2^16 locations, even when i try erasing a larger block, but this works when i explicitly declare a 32 bit int variable to store the multiplied value. This may cause problems in my software application where i havent declared variables explicitly.
hmmm.... the multiply SHOULD be done (in C) as if the two variables are 'int'.So using an extra variable shouldn't matter. Something very strange must be going on with the generated code. I'd also verify what happens if you pass a length of zero - it is possible that causes a single flash sector be erased! I am presuming that the 'noofblockstoeras e*erasesize' is a typo! (no space). I also don't quite understand your comment about 'explicitly declaring variables'.
Sorry for the confusion, 'explicitly declaring variables' just means that i had declared a variableunsigned int 32 tempnoofblockstobeerased; tempnoofblockstobeerased = noofblockstoerase*erasesize; flashutils_eraseflash(flashoffset,tempnoofblockstobeerased); This works. the other one is just a typo..
Try adding -Wall (and maybe -Werror) to the compiler options - it might show something that is wrong.I normally use -O2 -pipe -Wall -Wshadow -Wcast-qual -Wmissing-prototypes -Wpointer-arith -Wwrite-strings -fmessage-length=0 -Werror The only troublesome one is -Wsign-compare (migth be included by -Wall) since 'fixing' things is difficult without a cast, and I try to limit the number of casts since they can hide bigger problems.