OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4265|回复: 7

硬件CRC校验和软件CRC的问题

[复制链接]

74

主题

182

帖子

0

精华

高级会员

Rank: 4

积分
588
金钱
588
注册时间
2014-10-15
在线时间
137 小时
发表于 2023-5-24 20:24:56 | 显示全部楼层 |阅读模式
1金钱
我有一块STM32F303的板子,里面有CRC的例程。
代码如下:
  1. #include "main.h"

  2. /** @addtogroup STM32F3xx_HAL_Examples
  3.   * @{
  4.   */

  5. /** @addtogroup CRC_Example
  6.   * @{
  7.   */

  8. /* Private typedef -----------------------------------------------------------*/
  9. /* Private define ------------------------------------------------------------*/
  10. #define BUFFER_SIZE    114

  11. /* Private macro -------------------------------------------------------------*/
  12. /* Private variables ---------------------------------------------------------*/
  13. /* CRC handler declaration */
  14. CRC_HandleTypeDef   CrcHandle;

  15. /* Used for storing CRC Value */
  16. __IO uint32_t uwCRCValue = 0;

  17. static const uint32_t aDataBuffer[BUFFER_SIZE] =
  18. {
  19.   0x00001021, 0x20423063, 0x408450a5, 0x60c670e7, 0x9129a14a, 0xb16bc18c,
  20.   0xd1ade1ce, 0xf1ef1231, 0x32732252, 0x52b54294, 0x72f762d6, 0x93398318,
  21.   0xa35ad3bd, 0xc39cf3ff, 0xe3de2462, 0x34430420, 0x64e674c7, 0x44a45485,
  22.   0xa56ab54b, 0x85289509, 0xf5cfc5ac, 0xd58d3653, 0x26721611, 0x063076d7,
  23.   0x569546b4, 0xb75ba77a, 0x97198738, 0xf7dfe7fe, 0xc7bc48c4, 0x58e56886,
  24.   0x78a70840, 0x18612802, 0xc9ccd9ed, 0xe98ef9af, 0x89489969, 0xa90ab92b,
  25.   0x4ad47ab7, 0x6a961a71, 0x0a503a33, 0x2a12dbfd, 0xfbbfeb9e, 0x9b798b58,
  26.   0xbb3bab1a, 0x6ca67c87, 0x5cc52c22, 0x3c030c60, 0x1c41edae, 0xfd8fcdec,
  27.   0xad2abd0b, 0x8d689d49, 0x7e976eb6, 0x5ed54ef4, 0x2e321e51, 0x0e70ff9f,
  28.   0xefbedfdd, 0xcffcbf1b, 0x9f598f78, 0x918881a9, 0xb1caa1eb, 0xd10cc12d,
  29.   0xe16f1080, 0x00a130c2, 0x20e35004, 0x40257046, 0x83b99398, 0xa3fbb3da,
  30.   0xc33dd31c, 0xe37ff35e, 0x129022f3, 0x32d24235, 0x52146277, 0x7256b5ea,
  31.   0x95a88589, 0xf56ee54f, 0xd52cc50d, 0x34e224c3, 0x04817466, 0x64475424,
  32.   0x4405a7db, 0xb7fa8799, 0xe75ff77e, 0xc71dd73c, 0x26d336f2, 0x069116b0,
  33.   0x76764615, 0x5634d94c, 0xc96df90e, 0xe92f99c8, 0xb98aa9ab, 0x58444865,
  34.   0x78066827, 0x18c008e1, 0x28a3cb7d, 0xdb5ceb3f, 0xfb1e8bf9, 0x9bd8abbb,
  35.   0x4a755a54, 0x6a377a16, 0x0af11ad0, 0x2ab33a92, 0xed0fdd6c, 0xcd4dbdaa,
  36.   0xad8b9de8, 0x8dc97c26, 0x5c644c45, 0x3ca22c83, 0x1ce00cc1, 0xef1fff3e,
  37.   0xdf7caf9b, 0xbfba8fd9, 0x9ff86e17, 0x7e364e55, 0x2e933eb2, 0x0ed11ef0
  38. };

  39. /* Expected CRC Value */
  40. uint32_t uwExpectedCRCValue = 0x379E9F06;

  41. /* Private function prototypes -----------------------------------------------*/
  42. void SystemClock_Config(void);
  43. static void Error_Handler(void);

  44. /* Private functions ---------------------------------------------------------*/

  45. /**
  46.   * @brief  Main program
  47.   * [url=home.php?mod=space&uid=271674]@param[/url]  None
  48.   * @retval None
  49.   */
  50. int main(void)
  51. {
  52.   /* STM32F3xx HAL library initialization:
  53.        - Configure the Flash prefetch
  54.        - Configure the Systick to generate an interrupt each 1 msec
  55.        - Set NVIC Group Priority to 4
  56.        - Low Level Initialization
  57.      */
  58.   HAL_Init();

  59.   /* Configure the system clock to 64 MHz */
  60.   SystemClock_Config();

  61.   /* Configure LED1 and LED3 */
  62.   BSP_LED_Init(LED1);
  63.   BSP_LED_Init(LED3);

  64.   /*##-1- Configure the CRC peripheral #######################################*/
  65.   CrcHandle.Instance = CRC;

  66.   /* The default polynomial is used */
  67.   CrcHandle.Init.DefaultPolynomialUse    = DEFAULT_POLYNOMIAL_ENABLE;

  68.   /* The default init value is used */
  69.   CrcHandle.Init.DefaultInitValueUse     = DEFAULT_INIT_VALUE_ENABLE;

  70.   /* The input data are not inverted */
  71.   CrcHandle.Init.InputDataInversionMode  = CRC_INPUTDATA_INVERSION_NONE;

  72.   /* The output data are not inverted */
  73.   CrcHandle.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;

  74.   /* The input data are 32-bit long words */
  75.   CrcHandle.InputDataFormat              = CRC_INPUTDATA_FORMAT_WORDS;

  76.   if (HAL_CRC_Init(&CrcHandle) != HAL_OK)
  77.   {
  78.     /* Initialization Error */
  79.     Error_Handler();
  80.   }

  81.   /*##-2- Compute the CRC of "aDataBuffer" ###################################*/
  82.   //uwCRCValue = HAL_CRC_Calculate(&CrcHandle, (uint32_t *)aDataBuffer, BUFFER_SIZE);
  83.         uwCRCValue = HAL_CRC_Calculate(&CrcHandle, (uint32_t *)aDataBuffer, 1);

  84.   /*##-3- Compare the CRC value to the Expected one ##########################*/
  85.   if (uwCRCValue != uwExpectedCRCValue)
  86.   {
  87.     /* Wrong CRC value: Turn LED3 on */
  88.     Error_Handler();
  89.   }
  90.   else
  91.   {
  92.     /* Right CRC value: Turn LED1 on */
  93.     BSP_LED_On(LED1);
  94.   }

  95.   /* Infinite loop */
  96.   while (1)
  97.   {
  98.   }
  99. }
复制代码
程序里有114个数据,比如我只用一个数据
得出结果0x4bb7ed3f
我找到一个软件,算出的结果和程序里一样。
10.jpg
可是我不知道手算怎么得出同样的结果。
哪位大神知道,望告知,谢谢!

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

12

主题

3344

帖子

1

精华

论坛元老

Rank: 8Rank: 8

积分
8462
金钱
8462
注册时间
2020-5-11
在线时间
3904 小时
发表于 2023-5-25 09:18:03 | 显示全部楼层
专治疑难杂症
回复

使用道具 举报

74

主题

182

帖子

0

精华

高级会员

Rank: 4

积分
588
金钱
588
注册时间
2014-10-15
在线时间
137 小时
 楼主| 发表于 2023-5-25 15:59:20 | 显示全部楼层
谢谢!看了你给我推荐的文章,我搞好了两个硬件CRC,一个是32位的,一个是16位的。还有一个七位的,和一个自定义多项式(其实是8位的)这两个还没搞好。
其中那个七位的我看不太懂。
/******************************************************************************
* Name:    CRC-7/MMC           x7+x3+1
* Poly:    0x09
* Init:    0x00
* Refin:   False
* Refout:  False
* Xorout:  0x00
* Use:     MultiMediaCard,SD,ect.
*****************************************************************************/
uint8_t crc7_mmc(uint8_t *data, uint16_t length)
{
    uint8_t i;
    uint8_t crc = 0;     
    while(length--)
    {
        crc ^= *data++;        
        for ( i = 0; i < 8; i++ )
        {
            if ( crc & 0x80 )
                crc = (crc << 1) ^ 0x12;      
            else
                crc <<= 1;
        }
    }
    return crc >> 1;
}
明明多项式是0x09,可是程序里为什么异或0x12呢?请指教,谢谢!

回复

使用道具 举报

74

主题

182

帖子

0

精华

高级会员

Rank: 4

积分
588
金钱
588
注册时间
2014-10-15
在线时间
137 小时
 楼主| 发表于 2023-5-25 16:29:14 | 显示全部楼层
我想可能是左移了一位,于是我也把多项式左移了一位,可是还是不对。代码如下:
  1. #include "main.h"

  2. /** @addtogroup STM32L4xx_HAL_Examples
  3.   * @{
  4.   */

  5. /** @addtogroup CRC_Bytes_Stream_7bit_CRC
  6.   * @{
  7.   */

  8. /* Private typedef -----------------------------------------------------------*/
  9. /* Private define ------------------------------------------------------------*/
  10. #define BUFFER_SIZE_5  5  /* CRC7_DATA8_TEST5[] is 5-byte long   */
  11. #define BUFFER_SIZE_17 17 /* CRC7_DATA8_TEST17[] is 17-byte long */
  12. #define BUFFER_SIZE_1  1  /* CRC7_DATA8_TEST1[] is 1-byte long   */
  13. #define BUFFER_SIZE_2  2  /* CRC7_DATA8_TEST2[] is 2-byte long   */

  14. /* User-defined polynomial */
  15. //#define CRC_POLYNOMIAL_7B  0x65  /* X^7 + X^6 + X^5 + X^2 + 1,
  16. //                                  used in Train Communication Network, IEC 60870-5[17] */
  17. #define CRC_POLYNOMIAL_7B  0x65  /* X^7 + X^6 + X^5 + X^2 + 1,*/
  18. /* Private macro -------------------------------------------------------------*/
  19. /* Private variables ---------------------------------------------------------*/
  20. /* CRC handler declaration */
  21. CRC_HandleTypeDef   CrcHandle;

  22. /* Used for storing CRC Value */
  23. __IO uint32_t uwCRCValue = 0;

  24. /* Bytes buffers that will consecutively yield CRCs */
  25. static const uint8_t CRC7_DATA8_TEST5[5]   = {0x12,0x34,0xBA,0x71,0xAD};
  26. static const uint8_t CRC7_DATA8_TEST17[17] = {0x12,0x34,0xBA,0x71,0xAD,
  27.                                               0x11,0x56,0xDC,0x88,0x1B,
  28.                                               0xEE,0x4D,0x82, 0x93,0xA6,
  29.                                               0x7F,0xC3};
  30. static const uint8_t CRC7_DATA8_TEST1[1]   = {0x19};                                                
  31. static const uint8_t CRC7_DATA8_TEST2[2]   = {0xAB,0xCD};

  32.       

  33. /* Expected CRC Values */
  34. /* The 7 LSB bits are the 7-bit long CRC */
  35. uint32_t uwExpectedCRCValue_1 = 0x00000057;    /* First byte stream CRC  */
  36. uint32_t uwExpectedCRCValue_2 = 0x0000006E;    /* Second byte stream CRC */
  37. uint32_t uwExpectedCRCValue_3 = 0x0000004B;    /* Third byte stream CRC  */
  38. uint32_t uwExpectedCRCValue_4 = 0x00000026;    /* Fourth byte stream CRC */

  39. /* Private function prototypes -----------------------------------------------*/
  40. void SystemClock_Config(void);
  41. static void Error_Handler(void);

  42. /* Private functions ---------------------------------------------------------*/

  43. /**
  44.   * @brief  Main program
  45.   * @param  None
  46.   * @retval None
  47.   */
  48. int main(void)
  49. {

  50.   /* STM32L4xx HAL library initialization:
  51.        - Configure the Flash prefetch
  52.        - Systick timer is configured by default as source of time base, but user
  53.          can eventually implement his proper time base source (a general purpose
  54.          timer for example or other time source), keeping in mind that Time base
  55.          duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  56.          handled in milliseconds basis.
  57.        - Set NVIC Group Priority to 4
  58.        - Low Level Initialization
  59.      */
  60.   HAL_Init();
  61.   
  62.   /* Configure the system clock to 120 MHz */
  63.   SystemClock_Config();

  64.   /* Configure LED1 and LED3 */
  65.   BSP_LED_Init(LED1);
  66.   BSP_LED_Init(LED3);


  67.   /****************************************************************************/
  68.   /*                                                                          */
  69.   /*                     CRC peripheral initialization                        */
  70.   /*                                                                          */   
  71.   /****************************************************************************/
  72.    
  73.   CrcHandle.Instance = CRC;

  74.   /* The default polynomial is not used. The one to be used must be defined
  75.      in CrcHandle.Init.GeneratingPolynomial */  
  76.   CrcHandle.Init.DefaultPolynomialUse    = DEFAULT_POLYNOMIAL_DISABLE;
  77.   
  78.   /* Set the value of the generating polynomial.
  79.     The one used in that example is the 7-bit long CRC generating
  80.     polynomial X^7 + X^6 + X^5 + X^2 + 1 */
  81.   CrcHandle.Init.GeneratingPolynomial    = CRC_POLYNOMIAL_7B;
  82.   
  83.   /* The user-defined generating polynomial yields a 7-bit long CRC */
  84.   CrcHandle.Init.CRCLength               = CRC_POLYLENGTH_7B;

  85.   /* The default init value is used */
  86.   CrcHandle.Init.DefaultInitValueUse     = DEFAULT_INIT_VALUE_ENABLE;

  87.   /* The input data are not inverted */
  88.   CrcHandle.Init.InputDataInversionMode  = CRC_INPUTDATA_INVERSION_NONE;

  89.   /* The output data are not inverted */
  90.   CrcHandle.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;

  91.   /* The input data are bytes (8-bit long data) */
  92.   CrcHandle.InputDataFormat              = CRC_INPUTDATA_FORMAT_BYTES;

  93.   /* De-initialize the CRC peripheral */
  94.   if (HAL_CRC_DeInit(&CrcHandle) != HAL_OK)
  95.   {
  96.     /* Initialization Error */
  97.     Error_Handler();
  98.   }  

  99.   /* Then, initialize the CRC handle */
  100.   if (HAL_CRC_Init(&CrcHandle) != HAL_OK)
  101.   {
  102.     /* Initialization Error */
  103.     Error_Handler();
  104.   }


  105.   /****************************************************************************/
  106.   /*                                                                          */
  107.   /*         CRC computation of a first bytes stream                          */
  108.   /*                                                                          */   
  109.   /****************************************************************************/

  110.   /* The 7-bit long CRC of a 5-byte buffer is computed. After peripheral initialization,
  111.      the CRC calculator is initialized with the default value that is 0x7F for
  112.      a 7-bit CRC.
  113.    
  114.     The computed CRC is stored in uint32_t uwCRCValue. The 7-bit long CRC is made of
  115.     uwCRCValue 7 LSB bits. */

  116.   uwCRCValue = HAL_CRC_Accumulate(&CrcHandle, (uint32_t *)&CRC7_DATA8_TEST5, BUFFER_SIZE_5);

  117.   /* Compare the CRC value to the expected one */
  118.   if (uwCRCValue != uwExpectedCRCValue_1)
  119.   {
  120.     /* Wrong CRC value: Turn LED3 on */
  121.     Error_Handler();
  122.   }

  123.   
  124.   /****************************************************************************/
  125.   /*                                                                          */
  126.   /*         CRC computation of a second bytes stream                         */
  127.   /*                                                                          */   
  128.   /****************************************************************************/

  129.   /* The 7-bit long CRC of a 17-byte buffer is computed. The CRC calculator
  130.     is not re-initialized, instead the previously computed CRC is used
  131.     as initial value. */

  132.   uwCRCValue = HAL_CRC_Accumulate(&CrcHandle, (uint32_t *)&CRC7_DATA8_TEST17, BUFFER_SIZE_17);

  133.   /* Compare the CRC value to the expected one */
  134.   if (uwCRCValue != uwExpectedCRCValue_2)
  135.   {
  136.     /* Wrong CRC value: Turn LED3 on */
  137.     Error_Handler();
  138.   }


  139.   /****************************************************************************/
  140.   /*                                                                          */
  141.   /*         CRC computation of a single byte                                 */
  142.   /*                                                                          */   
  143.   /****************************************************************************/

  144.   /* The 7-bit long CRC of a 1-byte buffer is computed. The CRC calculator
  145.     is not re-initialized, instead the previously computed CRC is used
  146.     as initial value. */

  147.   uwCRCValue = HAL_CRC_Accumulate(&CrcHandle, (uint32_t *)&CRC7_DATA8_TEST1, BUFFER_SIZE_1);

  148.   /* Compare the CRC value to the expected one */
  149.   if (uwCRCValue != uwExpectedCRCValue_3)
  150.   {
  151.     /* Wrong CRC value: Turn LED3 on */
  152.     Error_Handler();
  153.   }


  154.   /****************************************************************************/
  155.   /*                                                                          */
  156.   /*         CRC computation of the last bytes stream                         */
  157.   /*                                                                          */   
  158.   /****************************************************************************/

  159.   /* The 7-bit long CRC of a 2-byte buffer is computed. The CRC calculator
  160.     is re-initialized with the default value that is 0x7F for a 7-bit CRC.
  161.     This is done with a call to HAL_CRC_Calculate() instead of
  162.     HAL_CRC_Accumulate(). */

  163.   uwCRCValue = HAL_CRC_Calculate(&CrcHandle, (uint32_t *)&CRC7_DATA8_TEST2, BUFFER_SIZE_2);

  164.   /* Compare the CRC value to the expected one */
  165.   if (uwCRCValue != uwExpectedCRCValue_4)
  166.   {
  167.     /* Wrong CRC value: Turn LED3 on */
  168.     Error_Handler();
  169.   }
  170.   else
  171.   {
  172.     /* Right CRC value: Turn LED1 on */
  173.     BSP_LED_On(LED1);
  174.   }  


  175.   /* Infinite loop */
  176.   while (1)
  177.   {
  178.   }
  179. }
复制代码
第一组校验值等于0x57.
我写成0x65或者左移一位变成0xca都不管用。
回复

使用道具 举报

12

主题

3344

帖子

1

精华

论坛元老

Rank: 8Rank: 8

积分
8462
金钱
8462
注册时间
2020-5-11
在线时间
3904 小时
发表于 2023-5-26 12:22:25 | 显示全部楼层
chenbingjy 发表于 2023-5-25 15:59
谢谢!看了你给我推荐的文章,我搞好了两个硬件CRC,一个是32位的,一个是16位的。还有一个七位的,和一个 ...

因它他计算过程中整体左移了一位,0x09左移一位就是0x12,所以最后会有右移一位, return crc >> 1;
专治疑难杂症
回复

使用道具 举报

12

主题

3344

帖子

1

精华

论坛元老

Rank: 8Rank: 8

积分
8462
金钱
8462
注册时间
2020-5-11
在线时间
3904 小时
发表于 2023-5-26 12:32:00 | 显示全部楼层
本帖最后由 LcwSwust 于 2023-5-26 12:34 编辑
chenbingjy 发表于 2023-5-25 16:29
我想可能是左移了一位,于是我也把多项式左移了一位,可是还是不对。代码如下:
第一组校验值等于0x57.
...

HAL库我不了解,要不你百度一下,有人说DR需要清零:https://blog.51cto.com/bruceou/4998865
或参考一下我那个链接,自己写代码验证一下?

专治疑难杂症
回复

使用道具 举报

74

主题

182

帖子

0

精华

高级会员

Rank: 4

积分
588
金钱
588
注册时间
2014-10-15
在线时间
137 小时
 楼主| 发表于 2023-5-26 20:48:43 | 显示全部楼层
LcwSwust 发表于 2023-5-26 12:32
HAL库我不了解,要不你百度一下,有人说DR需要清零:https://blog.51cto.com/bruceou/4998865
或参考一下 ...

谢谢!例子是09,左移一位是0x12。现在多项式是0x65,左移一位是0xcb,那就不是7位多项式了,成8位了。
这样不行吧?



回复

使用道具 举报

74

主题

182

帖子

0

精华

高级会员

Rank: 4

积分
588
金钱
588
注册时间
2014-10-15
在线时间
137 小时
 楼主| 发表于 2023-5-26 21:12:17 | 显示全部楼层
/* The input data are bytes (8-bit long data) */
  CrcHandle.InputDataFormat              = CRC_INPUTDATA_FORMAT_BYTES;

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
uwCRCValue = HAL_CRC_Accumulate(&CrcHandle, (uint32_t *)&CRC7_DATA8_TEST5, BUFFER_SIZE_5);
校验码是32位的,要校验的数据也被改为32位。
然后,我进到HAL_CRC_Accumulate内部:
  1. uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
  2. {
  3.   uint32_t index;      /* CRC input data buffer index */
  4.   uint32_t temp = 0U;  /* CRC output (read from hcrc->Instance->DR register) */

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

  7.   switch (hcrc->InputDataFormat)
  8.   {
  9.     case CRC_INPUTDATA_FORMAT_WORDS:
  10.       /* Enter Data to the CRC calculator */
  11.       for (index = 0U; index < BufferLength; index++)
  12.       {
  13.         hcrc->Instance->DR = pBuffer[index];
  14.       }
  15.       temp = hcrc->Instance->DR;
  16.       break;

  17.     case CRC_INPUTDATA_FORMAT_BYTES:
  18.       temp = CRC_Handle_8(hcrc, (uint8_t *)pBuffer, BufferLength);
  19.       break;

  20.     case CRC_INPUTDATA_FORMAT_HALFWORDS:
  21.       temp = CRC_Handle_16(hcrc, (uint16_t *)(void *)pBuffer, BufferLength);    /* Derogation MisraC2012 R.11.5 */
  22.       break;
  23.     default:
  24.       break;
  25.   }

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

  28.   /* Return the CRC computed value */
  29.   return temp;
  30. }
复制代码
因为又CrcHandle.InputDataFormat              = CRC_INPUTDATA_FORMAT_BYTES;
所以会进入函数CRC_Handle_8
我再进入这个函数
  1. static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)
  2. {
  3.   uint32_t i; /* input data buffer index */
  4.   uint16_t data;
  5.   __IO uint16_t *pReg;

  6.   /* Processing time optimization: 4 bytes are entered in a row with a single word write,
  7.    * last bytes must be carefully fed to the CRC calculator to ensure a correct type
  8.    * handling by the peripheral */
  9.   for (i = 0U; i < (BufferLength / 4U); i++)
  10.   {
  11.     hcrc->Instance->DR = ((uint32_t)pBuffer[4U * i] << 24U) | \
  12.                          ((uint32_t)pBuffer[(4U * i) + 1U] << 16U) | \
  13.                          ((uint32_t)pBuffer[(4U * i) + 2U] << 8U)  | \
  14.                          (uint32_t)pBuffer[(4U * i) + 3U];
  15.   }
  16.   /* last bytes specific handling */
  17.   if ((BufferLength % 4U) != 0U)
  18.   {
  19.     if ((BufferLength % 4U) == 1U)
  20.     {
  21.       *(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[4U * i];         /* Derogation MisraC2012 R.11.5 */
  22.     }
  23.     if ((BufferLength % 4U) == 2U)
  24.     {
  25.       data = ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U];
  26.       pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR);                    /* Derogation MisraC2012 R.11.5 */
  27.       *pReg = data;
  28.     }
  29.     if ((BufferLength % 4U) == 3U)
  30.     {
  31.       data = ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U];
  32.       pReg = (__IO uint16_t *)(__IO void *)(&hcrc->Instance->DR);                    /* Derogation MisraC2012 R.11.5 */
  33.       *pReg = data;

  34.       *(__IO uint8_t *)(__IO void *)(&hcrc->Instance->DR) = pBuffer[(4U * i) + 2U];  /* Derogation MisraC2012 R.11.5 */
  35.     }
  36.   }

  37.   /* Return the CRC computed value */
  38.   return hcrc->Instance->DR;
  39. }
复制代码
我感觉好像STM32还是把四个字节的数拼成一个32位的数。
看完这些,我都不知道程序该怎么写了。

回复

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-24 11:41

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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