LinY 发表于 2024-3-29 14:05:15

HAL_CRC_Accumulate的初始值怎么设置的

如题
环境:
STM32CubeMX+Keil MDK
STM32Cube_FW_F4_V1.27.1
裸机 HAL库
HAL_CRC_Calculate 这个函数我知道是直接只计算所传参数数据的CRC

HAL_CRC_Accumulate 这个函数我知道是在原有crc计算值的基础上再计算所传参数数据的CRC
老版本有hcrc->Instance->Init,但是这个版本看提示在



// 附:部分代码

/**
* @briefCRC Handle Structure definition
*/
typedef struct
{
CRC_TypeDef               *Instance;   /*!< Register base address      */

HAL_LockTypeDef             Lock;      /*!< CRC Locking object         */

__IO HAL_CRC_StateTypeDef   State;       /*!< CRC communication state      */

} CRC_HandleTypeDef;

/**
* @brief CRC calculation unit
*/

typedef struct
{
__IO uint32_t DR;         /*!< CRC Data register,             Address offset: 0x00 */
__IO uint8_tIDR;      /*!< CRC Independent data register, Address offset: 0x04 */
uint8_t       RESERVED0;/*!< Reserved, 0x05                                    */
uint16_t      RESERVED1;/*!< Reserved, 0x06                                    */
__IO uint32_t CR;         /*!< CRC Control register,          Address offset: 0x08 */
} CRC_TypeDef;



/**
* @briefCompute the 32-bit CRC value of a 32-bit data buffer
*         starting with the previously computed CRC as initialization value.
* @paramhcrc CRC handle
* @parampBuffer pointer to the input data buffer.
* @paramBufferLength input data buffer length (number of uint32_t words).
* @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
*/
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
{
uint32_t index;      /* CRC input data buffer index */
uint32_t temp = 0U;/* CRC output (read from hcrc->Instance->DR register) */

/* Change CRC peripheral state */
hcrc->State = HAL_CRC_STATE_BUSY;

/* Enter Data to the CRC calculator */
for (index = 0U; index < BufferLength; index++)
{
    hcrc->Instance->DR = pBuffer;
}
temp = hcrc->Instance->DR;

/* Change CRC peripheral state */
hcrc->State = HAL_CRC_STATE_READY;

/* Return the CRC computed value */
return temp;
}

/**
* @briefCompute the 32-bit CRC value of a 32-bit data buffer
*         starting with hcrc->Instance->INIT as initialization value.
* @paramhcrc CRC handle
* @parampBuffer pointer to the input data buffer.
* @paramBufferLength input data buffer length (number of uint32_t words).
* @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
*/
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
{
uint32_t index;      /* CRC input data buffer index */
uint32_t temp = 0U;/* CRC output (read from hcrc->Instance->DR register) */

/* Change CRC peripheral state */
hcrc->State = HAL_CRC_STATE_BUSY;

/* Reset CRC Calculation Unit (hcrc->Instance->INIT is
*written in hcrc->Instance->DR) */
__HAL_CRC_DR_RESET(hcrc);

/* Enter 32-bit input data to the CRC calculator */
for (index = 0U; index < BufferLength; index++)
{
    hcrc->Instance->DR = pBuffer;
}
temp = hcrc->Instance->DR;

/* Change CRC peripheral state */
hcrc->State = HAL_CRC_STATE_READY;

/* Return the CRC computed value */
return temp;
}

eric2013 发表于 2024-3-30 09:14:15

CRC函数HAL_CRC_Calculate和HAL_CRC_Accumulate使用方法对比
https://www.armbbs.cn/forum.php?mod=viewthread&tid=112953&fromuid=58
(出处: 硬汉嵌入式论坛)

LinY 发表于 2024-4-1 11:37:05

eric2013 发表于 2024-3-30 09:14
CRC函数HAL_CRC_Calculate和HAL_CRC_Accumulate使用方法对比
https://www.armbbs.cn/forum.php?mod=viewth ...

这个已经看过了
我也理解这2个方法 一个是从头算,一个是从上一次的结果值去算。
我举个例 我想达到的效果
我有2个数组,各有20个元素,分别记为A0-A19,B0-B19
我假定先去计算A0-A9 然后B0-B9 然后在A0-A9的结果值基础上再去计算A10-19 接着在B0-B19的基础上去算B10-B19
我现在就是想要设置HAL_CRC_Accumulate运算前的上一次结果值,这个可以设置么?还是说只能通过__HAL_CRC_DR_RESET(hcrc);设为0xFFFFFFFF



页: [1]
查看完整版本: HAL_CRC_Accumulate的初始值怎么设置的