查看Keil的编译结果发现总共6160个字节。计算结果如下,
代码如下
#include "ac780x_crc.h"
#include "ac780x.h"
#include "ac780x_debugout.h"
#include "string.h"
#include "ac780x_eflash.h"
#define TestSize 1024 ///< 4K
#define TestAddressStart 0x08000000
uint8_t Data[9000]; // 共6140 Bytes
uint32_t tmpResult = 0; /* CRC计算结果 */
uint32_t tmpCRCType = CRC_PROTOCOL_32BIT; /* CRC 支持16位和32位长度多项式 */
/**
* @prototype main(void)
*
* @param[in] void
* @return void
*
* @brief main entry.
* main函数.
*/
int main(void)
{
CRC_ConfigType CRCConfig;
memset(&CRCConfig, 0, sizeof(CRCConfig));
CRCConfig.crcProtocolType = (CRC_ProtocolType)tmpCRCType;
uint32_t CRCSeed = 0;
InitDebug(); // Initialize debug UART 1
// printf("AC7801: CRC_Demo\r\n");
// if (tmpCRCType > 1)
// {
// printf("tmpCRCType: 0: CRC-CCITT; 1: CRC-32! \r\n");
// return -1;
// }
EFLASH_UnlockCtrl();
EFLASH_Read(TestAddressStart, (uint32_t *)Data, TestSize);
EFLASH_Read(TestAddressStart + TestSize, (uint32_t *)Data + 256, TestSize);
EFLASH_Read(TestAddressStart + TestSize * 2, (uint32_t *)Data + 256 * 2, TestSize);
EFLASH_Read(TestAddressStart + TestSize * 3, (uint32_t *)Data + 256 * 3, TestSize);
EFLASH_Read(TestAddressStart + TestSize * 4, (uint32_t *)Data + 256 * 4, TestSize);
EFLASH_Read(TestAddressStart + TestSize * 5, (uint32_t *)Data + 256 * 5, TestSize);
EFLASH_Read(TestAddressStart + TestSize * 6, (uint32_t *)Data + 256 * 6, 20);
EFLASH_LockCtrl();
printf("0x8000000 ");
unsigned i = 0;
while (i < 6160)
{
printf("%02x", Data[i]);
i++;
if (i % 16 == 0)
{
printf("\r\n0x%7x ", 0x8000000 + i);
}
}
printf("\r\n");
// CRCDataLength = strlen((char *)CRCMsg); // Length of data
if (tmpCRCType == CRC_PROTOCOL_32BIT) // CRC32 configuration
{
CRCConfig.poly = 0x4C11DB7; // CRC-32 Poly: 0x4C11DB7
CRCSeed = 0xFFFFFFFF; // CRC-CCITT seed: 0xFFFFFFFF
CRCConfig.finalXOR = ENABLE;
CRCConfig.readTransposeType = CRC_READ_TRANSPOSE_BITS_BYTES;
CRCConfig.writeBytesNumOnce = CRC_WRITE_1_BYTE_ONCE;
CRCConfig.writeTransposeType = CRC_WRITE_TRANSPOSE_BITS;
}
// else // CRC16 configuration
// {
// CRCConfig.poly = 0x1021; // CRC-CCITT Poly: 0x1021
// CRCSeed = 0xFFFF; // CRC-CCITT seed: 0xFFFF
// CRCConfig.finalXOR = ENABLE; // disable final xor
// CRCConfig.readTransposeType = CRC_READ_TRANSPOSE_NONE;
// CRCConfig.writeTransposeType = CRC_WRITE_TRANSPOSE_BITS_BYTES;
// }
CRC_Init(&CRCConfig);
// if (CRCConfig.crcProtocolType == CRC_PROTOCOL_16BIT)
// {
// tmpResult = CRC_Check(CRCSeed, &CRCMsg[0], CRCDataLength);
// printf("CRC-CCITT, Poly:0x%X\r\n", CRCConfig.poly);
// }
// else
{
tmpResult = CRC_Check(CRCSeed, &Data[0], 6156);
printf("CRC-32, Poly:0x%X\r\n", CRCConfig.poly);
}
printf("CRC result is: 0x%X\r\n", tmpResult);
while (1)
;
}
发现去掉Flash内容后四位的值都是正确的,加上后四位值就不对了,这个据说是Flash的CRC值,但是跟计算出来的去掉4位的值不同。后续有空再慢慢研究。