Stm32 CRC register operation

Source: Internet
Author: User

// CRC. c

/*************************************** **************************************** ******************/
/* Stm32 CRC
*/
// 20120427

# Include "stm32f10x_map.h"
# Include "system. H"
# Include "CRC. H"

/*************************************** **************************************** **************************************** **
* Function:
Void crc_reset (void)
* Function:
Reset CRC
* Parameters:
None
* Return value:
None
* Dependency:
Underlying macro definition
* Author:
Chen Peng
* Time:
20120427
* Last modification time: 20120427
* Description: reset CRC.
**************************************** **************************************** **************************************** */
Void crc_reset (void)
{
CRC-> Cr = 0x00000001;
// Reset crc_dr
}

/*************************************** **************************************** **************************************** **
* Function:
Void crc_init (void)
* Function:
Initialize the CRC Module
* Parameters:
None
* Return value:
None
* Dependency:
Underlying macro definition
* Author:
Chen Peng
* Time:
20120427
* Last modification time: 20120427
* Description: enables CRC clock.
**************************************** **************************************** **************************************** */
Void crc_init (void)
{
Deviceclockenable (dev_crc, enable );
// Enable CRC clock
Crc_reset ();
// Reset CRC
}

/*************************************** **************************************** **************************************** **
* Function:
U32 crc_calculatecrc (u32 data)
* Function:
Calculate 32-bit CRC of a single data
* Parameters:
Calculated value
* Return value:
32bit CRC Check Value
* Dependency:
Underlying macro definition
* Author:
Chen Peng
* Time:
20120427
* Last modification time: 20120427
* Description: calculates the CRC value. registers must be cleared before each write, that is, CRC is reset.
**************************************** **************************************** **************************************** */
U32 crc_calculatecrc (u32 data)
{
Crc_reset ();
// Reset CRC
CRC-> DR = data;
// Write the data to generate CRC
Return CRC-> Dr;
// Return CRC
}

/*************************************** **************************************** **************************************** **
* Function:
U32 crc_calculateblockcrc (u8 pbuffer [], u32 bufferlength)
* Function:
Calculate the CRC of the data in the buffer.
* Parameters:
Pbuffer []: buffer pointer, bufferlength: buffer size
* Return value:
32bit CRC Check Value
* Dependency:
Underlying macro definition
* Author:
Chen Peng
* Time:
20120502
* Last modification time: 20120502
* Note: reset CRC before writing
**************************************** **************************************** **************************************** */
U32 crc_calculateblockcrc (u8 pbuffer [], u32 bufferlength)
{
U32 I;

Crc_reset ();
// Reset CRC
For (I = 0; I <bufferlength; I ++)
CRC-> DR = (u32) pbuffer [I];
// Write data cyclically

Return CRC-> Dr;
// Return CRC
}

// CRC. h

/*************************************** **************************************** ******************/
/* Stm32 CRC
*/
// 20120427

# Ifndef _ crc_h _
# DEFINE _ crc_h _

# Include "stm32f10x_map.h"
# Include "system. H"
# Include "CRC. H"

Void crc_init (void); // initialize the CRC Module
Void crc_reset (void); // reset CRC
U32 crc_calculatecrc (u32 data); // calculate 32bit CRC
U32 crc_calculateblockcrc (u8 pbuffer [], u32 bufferlength );
// Calculate the CRC of the data in the buffer.

# Endif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.