# HG changeset patch # User Daniel O'Connor # Date 1365945741 -34200 # Node ID cf9eb08b8b23d1a0f8f42c8e9539bc74847e8fd8 # Parent cc998b0b2baee433f875bf2a0f28502a75437327 CRC a word at a time rather than the whole block (since we are reading/writing a word at a time). diff -r cc998b0b2bae -r cf9eb08b8b23 flash.c --- a/flash.c Sun Apr 14 16:07:29 2013 +0930 +++ b/flash.c Sun Apr 14 22:52:21 2013 +0930 @@ -346,8 +346,10 @@ assert(len % 4 == 0); flashstartread(addr); + CRC_ResetDR(); for (int i = len; i > 0; i--) { *data = flashreadbyte(); + CRC_CalcCRC(*data); data++; } @@ -358,16 +360,13 @@ flashstopread(); - /* Calculate CRC */ - CRC_ResetDR(); - ramcrc = CRC_CalcBlockCRC((uint32_t *)_data, len / 4); - - /* printf("RAM CRC 0x%08x Flash CRC 0x%08x\r\n", (uint)ramcrc, (uint)flashcrc); */ - - if (ramcrc == flashcrc) - return 1; - else - return 0; + ramcrc = CRC_GetCRC(); + + /* printf("RAM CRC 0x%08x Flash CRC 0x%08x\r\n", (uint)ramcrc, (uint)flashcrc); */ + if (ramcrc == flashcrc) + return 1; + else + return 0; } void @@ -392,20 +391,22 @@ /* Erase sector */ flash4kerase(addr); + CRC_ResetDR(); + /* Write data */ for (uint i = 0; i < len / 2; i++) { if (i == 0) flashstartwrite(addr, *data); else flashwriteword(*data); + CRC_CalcCRC(*data); data++; } /* Calculate CRC */ - CRC_ResetDR(); - crc = CRC_CalcBlockCRC((uint32_t *)_data, len / 4); - - printf("CRC is 0x%08x\r\n", (uint)crc); + crc = CRC_GetCRC(); + + //printf("CRC is 0x%08x\r\n", (uint)crc); /* Write CRC */ flashwriteword(crc);