Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
742 Views

CFM byte order confusion

Hi folks, 

Sometime ago I posted a question to ask if it were possible to remotely update a MAX10 SC variant. I have now come to the conclusion it is but I need a little advice I am uncertain of the byte order and revesing of bit positions in bytes before writing to flash for both CFM and UFM. I shall explain what I have done so far based upon AN 741 and the example code: 

 

1). I have generated a a .map and rpd files for my design using the convert program files application. This generates 3 .rpd files. a complete .rpd and two others, one for the CFM and one for the UFM. 

2). I then obtain the start addresses of these sections from the memory map in qsys (but also) from the BSP linker info. My CFM starts at 0x08000 and goes to 0x0397FF and the UFM section starts at 0x0000 up to 0x7fff. 

3). My application code then erases all the sectors (excluding five, as this is not enabled in the BSP). I do this using the following code structure: 

 

//remove protection from UFM1 

IOWR(HEADFLASH_CSR_BASE, 1, 0xfeffffff); 

//start erase 

IOWR(HEADFLASH_CSR_BASE, 1, 0xfeafffff); 

 

 

while(result != 0x10) 

result = (IORD(HEADFLASH_CSR_BASE, 0) & 0x13); 

if (result == 0x00) 

term_sendLine("Erase failed"); 

return ERR_FLASH_ERASE; 

term_sendLine("UFM1 Erased"); 

 

This is working, as if I load a .pof into the device and read the device, there is something present. If I then run the flash erase code for all sectors I get the same result as when I do an erase using the programmer. All good so far. 

 

4. I then program the CFM section, to do this I take the first 4 bytes from the CFM rpd file and reverse the bit order of each byte, i then arrange these into a word using the following code: 

 

wordArray[0] = (block[0] << 24) + (block[1] << 16) + (block[2] << 8) + block[3]; 

 

Such that the first byte from the file goes into the MSByte position of the word and block[0] is effectively the first byte out of the rpd file, block[3] being the 4th byte out of the rpd file. 

 

I then write this word to flash (at the CFM start address of) using 

 

for(wordIndex = 0; wordIndex < 4; wordIndex ++) 

IOWR_32DIRECT(HEADFLASH_DATA_BASE,address,wordArray[wordIndex]); 

while((IORD(HEADFLASH_CSR_BASE, 0) & 0x0b) == 0x02); 

if((IORD(HEADFLASH_CSR_BASE, 0) & 0x0b) == 0x00) 

//term_sendLine("flash write error"); 

return ERR_OK; 

address += 4; 

 

(ignore return ERR_OK it isn't really ok). 

 

5). I repeat this process for the UFM section. 

 

I can see that the device has programmed with something, as when I then read again using the programmer, then checksum is no longer the same as an erased device, and it is different after just programming CFM and programming CFM and UFM. So my flash write is doing something at least. 

 

But it wont boot from reset!!! 

 

So the question is this as follows. 

 

a). Am i reversing the bytes and converting to a word correctly? (ie byte order in the word after bit reversing). 

b). Does the UFM section also need the bits reversing for each byte of the word and is the byte order in the word the same as that used for the CFM. 

c). I tried reading back from the flash using a simple (IORD(HEADFLASH_DATA_BASE, 0x8000)) but it didn't seem to be the data I put in, am I even doing this correctly? 

 

Please help.....many thanks 

Mr confused!
0 Kudos
0 Replies