Sowmya Radhakrishnan

Issue faced while reading from NAND Flash of MC1322x ARM7 Zigbee Chip

Discussion created by Sowmya Radhakrishnan on Oct 9, 2009
Latest reply on Oct 9, 2009 by David Payne

I am facing a strange issue while using the Freescale's NVM library of MC1322x ARM7 Chip to read from/write to Flash. I am not sure what is it that I am doing incorrectly in s/w and would like some help.

 

I have a piece of code that looks something like this:

 

main() 

{

  unsigned char temp1, temp2;

  unsigned char temp3 = 0x45;

 

  //power on NVM

  NVM_Erase(0x0001C000); //Erase sector starting at 0x0001C000

 

  NVM_Read(&temp1, 0x0001C000, 0x01); //Reading one byte starting at address 0x0001C000                                                          //and copying information to temp1

  NVM_Write(&temp3, 0x0001C000, 0x01); //Write 0x45 at address 0x0001C000

}

 

When I executed this, and stepped in, I was hoping to get temp1 as 0xFF (since I did an erase). Strangely, I get temp1 as 0x45! I noticed that whatever value I set to temp3, is what I get when I watch temp1 in the watch window. I know for sure, that the NVM Address actually holds 0xFF, and I can't figure out how it gets temp3's value.

 

I tried making these variables static or global but the result remains the same.

 

I tried doing read and write in different functions but the result remains the same.

 

I slightly altered the code and did this:

 

main() 

{

  unsigned char temp1, temp2;

  unsigned char temp3 = 0x45;

 

  //power on NVM

 

  NVM_Read(&temp1, 0x0001C000, 0x01); //Reading one byte starting at address 0x0001C000                                                          //and copying information to temp1

  NVM_Write(&temp3, 0x0001C000, 0x01); //Write 0x45 at address 0x0001C000

 

  NVM_Erase(0x0001C000); //Erase sector starting at 0x0001C000

}

 

Now, when I read temp1, I got 0xFF!

 

The conclusion is that the NVM Read function gives the value, that is actually planned to be written into it. (in the first case, even though the NVM Write was never executed, temp1 still always read temp3's value). In the second case, given that the erase code comes after write, temp1 reads 0xFF.

 

I don't understand this strange correlation, and NVM_Read reading a value, even before NVM_Write is executed!! Given that NVM Read and Write is pure assembly code, I find it difficult to interpret it.

 

Any help deeply appreciated!!!

Outcomes