Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
1224 Discussions

UP SD Card Random Read Error - Fixed

Altera_Forum
Honored Contributor II
1,065 Views

I have noticed that when reading with the SD card core, bit 5 in the ASR (which indicates a data error) would be set on some sectors even though the data was read properly. At first I thought it was random, but upon further observation I noticed that it was repeatable. Some sectors would always indicate a read error and other sectors would indicate that there was no error. 

 

After some exploration with Signaltap, I found that when the CRC is generated, the core is not including the last data bit of the sector in the CRC calculation. So if the last bit in the sector is a 0, the CRC would be calculated properly and no error was indicated. This is because when calculating the CRC, a 0 only shifts the result so it will match the CRC from the SD card. When the last bit is a 1, that bit should get XORed into the CRC which would create a new value. Since that last bit was not included in the CRC calculation, the CRC from the SD card does not match the calculated value and the error is indicated even though the data was read properly. 

 

So to fix the core, edit the file Altera_UP_SD_Card_Buffer.vhd and look around line# 253 for this line: 

 

to_crc_generator <= shift_register(16) when (current_state = s_RECEIVING_DATA) else 

from_mem_1_bit when (current_state = s_SEND_DATA) else 

'0'; 

 

and change it to: 

 

to_crc_generator <= shift_register(16) when (current_state = s_RECEIVING_DATA) or (current_state = s_RECEIVING_STOP_BIT) else 

from_mem_1_bit when (current_state = s_SEND_DATA) else 

'0'; 

 

That will fix the problem.
0 Kudos
0 Replies
Reply