尊敬的 TI 专家:
我正在尝试在 MSP432E401Y 上实现硬件 CRC。 我需要使用 CRC_polynomial _CRC_16_CCITT 标准来匹配我在 MSP430上计算的硬件 CRC (只有一个标准)。 我正在对4个字节的数据进行计算、每次添加1个字节的数据。 种子(初始值)为0xFFFF。
我在下面附上了代码、这是用于在 MSP432上进行硬件 CRC 计算的标准示例代码。 我只将 src 更改为 4个字节、 src_size 和 CRC 驱动程序用于满足我的需求的参数。
/*
* Copyright (c) 2019, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== crc.c ========
*/
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
/* Driver Header files */
#include <ti/drivers/UART.h>
#include <ti/drivers/CRC.h>
/* Driver configuration */
#include "ti_drivers_config.h"
/* Expected CRC for CRC_32_IEEE with full endianness reversal */
static const uint32_t expectedCrc = 0x4C4B4461;
/* Example test vector */
static const size_t srcSize = 4;
static const uint8_t src [] = {
0x12, 0x34, 0x56, 0x78
};
static const char preOpMessage[] = "Performing CRC_32_IEEE with endianness reversal... ";
static const char postOpMessage[] = "Check successful.\r\n";
/* ======== mainThread ======== */
void *mainThread(void *arg0)
{
int_fast16_t status;
uint16_t result;
CRC_Handle handle;
CRC_Params params;
UART_Handle uart;
UART_Params uartParams;
/* Initialize the drivers */
CRC_init();
UART_init();
/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uart = UART_open(CONFIG_UART_0, &uartParams);
if (uart == NULL) {
/* UART_open() failed */
while (1);
}
UART_write(uart, preOpMessage, sizeof(preOpMessage));
/* Set data processing options, including endianness control */
CRC_Params_init(¶ms);
params.byteSwapInput = CRC_BYTESWAP_UNCHANGED;
params.returnBehavior = CRC_RETURN_BEHAVIOR_BLOCKING;
params.polynomial = CRC_POLYNOMIAL_CRC_16_CCITT;
params.dataSize = CRC_DATA_SIZE_8BIT;
params.seed = 0xFFFF;
//params.programmablePoly = 0x1021;
//params.programmablePolyOrder = 3;
/* Open the driver using the settings above */
handle = CRC_open(CONFIG_CRC_0, ¶ms);
if (handle == NULL)
{
/* If the handle is already open, execution will stop here */
while(1);
}
/* Calculate the CRC of all 32 bytes in the source array */
status = CRC_calculateFull(handle, src, srcSize, &result);
if (status != CRC_STATUS_SUCCESS)
{
/* If the CRC engine is busy or if an error occurs execution will stop here */
while(1);
}
/* This is another way of achieving the same result; for instance
* if data is arriving in blocks (over UART) this method may be preferable.
* CRC_reset() may be used to clear an ongoing partial if the result is no
* longer needed. CRC_finalise() also resets the state. */
status = CRC_addData(handle, src, srcSize/2);
if (status != CRC_STATUS_SUCCESS)
{
/* If the CRC engine is busy or if an error occurs execution will stop here */
while(1);
}
status = CRC_addData(handle, &src[srcSize/2], srcSize/2);
/* Extract the result from the internal state */
CRC_finalize(handle, &result);
if (status != CRC_STATUS_SUCCESS)
{
/* If the CRC engine is busy or if an error occurs execution will stop here */
while(1);
}
UART_write(uart, postOpMessage, sizeof(postOpMessage));
/* Close the driver to allow other users to access this driver instance */
CRC_close(handle);
UART_close(uart);
return NULL;
}
我将使用此在线 CRC 计算 器在线 CRC-8 CRC-16 CRC-32计算器(crccalc.com)交叉校验我的结果、结果应在第一行(CRC-16/CCITT-false)。
数据:0x12、0x34、0x56、0x78
我从代码 0xFFEC 获取的结果
来自在线计算器的结果:0x30EC
下面是在线计算器结果的快照。

无论我尝试哪种数据组合、较低字节(本例中为 EC)都是正确的、但较高字节是 FF 或其他一些错误值。
我在 MSP432上实现 CRC 驱动程序时是否出错?
我们非常感谢您的任何帮助。
谢谢。


