stm32: crc-v2: STM32F0/3 extended crc unit

Implementation of extended crc unit in f0 and f3
This commit is contained in:
Cem Basoglu
2016-03-04 12:57:06 +01:00
committed by Karl Palsson
parent 533e71777b
commit 34f57ae06e
6 changed files with 229 additions and 88 deletions

115
lib/stm32/common/crc_v2.c Normal file
View File

@@ -0,0 +1,115 @@
/** @addtogroup crc_defines
@author @htmlonly &copy; @endhtmlonly 2016 Cem Basoglu <cem.basoglu@web.de>
*/
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2016 Cem Basoglu <cem.basoglu@web.de>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/**@{*/
#include <libopencm3/stm32/crc.h>
/*---------------------------------------------------------------------------*/
/** @brief Enable reverse output data.
Enables the reversal of the bit order of the output data.
*/
void crc_reverse_output_enable()
{
CRC_CR |= CRC_CR_REV_OUT;
}
/*---------------------------------------------------------------------------*/
/** @brief Disable reverse output data.
Disables the reversal of the bit order of the output data.
*/
void crc_reverse_output_disable()
{
CRC_CR &= ~CRC_CR_REV_OUT;
}
/*---------------------------------------------------------------------------*/
/** @brief Reverse input data.
Controls the reversal of the bit order of the input data
@param[in] reverse_in Unsigned int32. Reversal bit order @ref crc_rev_in.
*/
void crc_set_reverse_input(uint32_t reverse_in)
{
uint32_t reg32 = CRC_CR;
reg32 = (reg32 & ~CRC_CR_REV_IN) | reverse_in;
CRC_CR = reg32;
}
/*---------------------------------------------------------------------------*/
/** @brief Polynomial size
Set the size of the polynomial.
@param[in] polysize Unsigned int32. Size of polynomial @ref crc_polysize.
*/
void crc_set_polysize(uint32_t polysize)
{
uint32_t reg32 = CRC_CR;
reg32 = (reg32 & ~CRC_CR_POLYSIZE) | polysize;
CRC_CR = reg32;
}
/*---------------------------------------------------------------------------*/
/** @brief Polynomial coefficient
Set the coefficients of the polynomial to be used for CRC calculation.
If the polynomial size is less than 32-bits, the least significant bits
have to be used to program the correct value.
@note To obtain a reliable CRC calculation, any changes to the polynomial
value or size can not be performed during a CRC calculation.
As a result, if a CRC calculation is ongoing, the application must either
reset the crc unit it or perform a CRC_DR read before changing the polynomial.
@note The default polynomial value is the CRC-32 (Ethernet) polynomial: 0x4C11DB7.
@param[in] polynomial Unsigned int32. Polynomial coefficient.
*/
void crc_set_polynomial(uint32_t polynomial)
{
CRC_POL = polynomial;
}
/*---------------------------------------------------------------------------*/
/** @brief CRC Initial value.
Sets the crc initial value.
@param[in] initial Unsigned int32. CRC initial value.
*/
void crc_set_initial(uint32_t initial)
{
CRC_INIT = initial;
}
/**@}*/

View File

@@ -39,7 +39,7 @@ ARFLAGS = rcs
OBJS = can.o flash.o rcc.o usart.o dma.o rtc.o comparator.o crc.o \
dac.o iwdg.o pwr.o gpio.o timer.o adc.o desig.o
OBJS += gpio_common_all.o gpio_common_f0234.o crc_common_all.o \
OBJS += gpio_common_all.o gpio_common_f0234.o crc_common_all.o crc_v2.o \
pwr_common_v1.o iwdg_common_all.o rtc_common_l1f024.o \
dma_common_l1f013.o exti_common_all.o spi_common_all.o \
spi_common_f03.o flash_common_f01.o dac_common_all.o \

View File

@@ -40,7 +40,7 @@ ARFLAGS = rcs
OBJS = rcc.o adc.o can.o pwr.o usart.o dma.o flash.o desig.o
OBJS += gpio_common_all.o gpio_common_f0234.o \
dac_common_all.o crc_common_all.o \
dac_common_all.o crc_common_all.o crc_v2.o \
iwdg_common_all.o pwr_common_v1.o spi_common_all.o dma_common_l1f013.o\
timer_common_all.o timer_common_f0234.o flash_common_f234.o \
flash.o exti_common_all.o rcc_common_all.o spi_common_f03.o