硬汉嵌入式论坛

 找回密码
 立即注册
查看: 265|回复: 2
收起左侧

HAL_CRC_Accumulate的初始值怎么设置的

[复制链接]

11

主题

36

回帖

69

积分

初级会员

积分
69
发表于 2024-3-29 14:05:15 | 显示全部楼层 |阅读模式
如题
环境:
STM32CubeMX+Keil MDK
STM32Cube_FW_F4_V1.27.1
裸机 HAL库
HAL_CRC_Calculate 这个函数我知道是直接只计算所传参数数据的CRC

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


[C] 纯文本查看 复制代码
// 附:部分代码

/**
  * @brief  CRC 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_t  IDR;        /*!< 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;



/**
  * @brief  Compute the 32-bit CRC value of a 32-bit data buffer
  *         starting with the previously computed CRC as initialization value.
  * @param  hcrc CRC handle
  * @param  pBuffer pointer to the input data buffer.
  * @param  BufferLength 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[index];
  }
  temp = hcrc->Instance->DR;

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

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

/**
  * @brief  Compute the 32-bit CRC value of a 32-bit data buffer
  *         starting with hcrc->Instance->INIT as initialization value.
  * @param  hcrc CRC handle
  * @param  pBuffer pointer to the input data buffer.
  * @param  BufferLength 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[index];
  }
  temp = hcrc->Instance->DR;

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

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


回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106726
QQ
发表于 2024-3-30 09:14:15 | 显示全部楼层
CRC函数HAL_CRC_Calculate和HAL_CRC_Accumulate使用方法对比
https://www.armbbs.cn/forum.php? ... 2953&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

11

主题

36

回帖

69

积分

初级会员

积分
69
 楼主| 发表于 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



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-2 06:28 , Processed in 0.161939 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表