stm32: crc-v2: STM32F0/3 extended crc unit
Implementation of extended crc unit in f0 and f3
This commit is contained in:
parent
533e71777b
commit
34f57ae06e
110
include/libopencm3/stm32/common/crc_v2.h
Normal file
110
include/libopencm3/stm32/common/crc_v2.h
Normal file
@ -0,0 +1,110 @@
|
||||
/** @addtogroup crc_defines
|
||||
|
||||
@author @htmlonly © @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/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA CRC.H
|
||||
The order of header inclusion is important. crc.h includes the device
|
||||
specific memorymap.h header before including this header file.*/
|
||||
|
||||
/** @cond */
|
||||
#ifdef LIBOPENCM3_CRC_H
|
||||
/** @endcond */
|
||||
#ifndef LIBOPENCM3_CRC_V2_H
|
||||
#define LIBOPENCM3_CRC_V2_H
|
||||
|
||||
/**@{*/
|
||||
|
||||
#include <libopencm3/stm32/common/crc_common_all.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Register definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Data register (CRC_DR) */
|
||||
#define CRC_DR8 MMIO8(CRC_BASE + 0x00)
|
||||
#define CRC_DR16 MMIO16(CRC_BASE + 0x00)
|
||||
|
||||
/* Initial CRC Value */
|
||||
#define CRC_INIT MMIO32(CRC_BASE + 0x10)
|
||||
|
||||
/* CRC Polynomial */
|
||||
#define CRC_POL MMIO32(CRC_BASE + 0x14)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Register values */
|
||||
/*****************************************************************************/
|
||||
|
||||
#define CRC_CR_REV_OUT (1 << 7)
|
||||
|
||||
#define CRC_CR_REV_IN_SHIFT 5
|
||||
#define CRC_CR_REV_IN (3 << CRC_CR_REV_IN_SHIFT)
|
||||
#define CRC_CR_REV_IN_NONE (0 << CRC_CR_REV_IN_SHIFT)
|
||||
#define CRC_CR_REV_IN_BYTE (1 << CRC_CR_REV_IN_SHIFT)
|
||||
#define CRC_CR_REV_IN_HALF (2 << CRC_CR_REV_IN_SHIFT)
|
||||
#define CRC_CR_REV_IN_WORD (3 << CRC_CR_REV_IN_SHIFT)
|
||||
|
||||
#define CRC_CR_POLYSIZE_SHIFT 3
|
||||
#define CRC_CR_POLYSIZE (3 << CRC_CR_POLYSIZE_SHIFT)
|
||||
#define CRC_CR_POLYSIZE_32 (0 << CRC_CR_POLYSIZE_SHIFT)
|
||||
#define CRC_CR_POLYSIZE_16 (1 << CRC_CR_POLYSIZE_SHIFT)
|
||||
#define CRC_CR_POLYSIZE_8 (2 << CRC_CR_POLYSIZE_SHIFT)
|
||||
#define CRC_CR_POLYSIZE_7 (3 << CRC_CR_POLYSIZE_SHIFT)
|
||||
|
||||
/* Default polynomial */
|
||||
#define CRC_POL_DEFAULT 0x04C11DB7
|
||||
|
||||
/*****************************************************************************/
|
||||
/* API definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* API Functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
BEGIN_DECLS
|
||||
|
||||
void crc_reverse_output_enable(void);
|
||||
void crc_reverse_output_disable(void);
|
||||
|
||||
void crc_set_reverse_input(uint32_t reverse_in);
|
||||
void crc_set_polysize(uint32_t polysize);
|
||||
|
||||
void crc_set_polynomial(uint32_t polynomial);
|
||||
void crc_set_initial(uint32_t initial);
|
||||
|
||||
END_DECLS
|
||||
|
||||
/**@}*/
|
||||
|
||||
#endif
|
||||
/** @cond */
|
||||
#else
|
||||
#warning "crc_v2.h should not be included explicitly, only via crc.h"
|
||||
#endif
|
||||
/** @endcond */
|
||||
|
@ -32,58 +32,7 @@
|
||||
|
||||
#ifndef LIBOPENCM3_CRC_H
|
||||
#define LIBOPENCM3_CRC_H
|
||||
/**@{*/
|
||||
|
||||
#include <libopencm3/stm32/common/crc_common_all.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Module definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Register definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Initial CRC Value */
|
||||
#define CRC_INIT MMIO32(CRC_BASE + 0x10)
|
||||
|
||||
/* CRC Polynomial */
|
||||
#define CRC_POL MMIO32(CRC_BASE + 0x14)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Register values */
|
||||
/*****************************************************************************/
|
||||
|
||||
#define CRC_CR_REV_OUT (1 << 7)
|
||||
|
||||
#define CRC_CR_REV_IN_SHIFT 5
|
||||
#define CRC_CR_REV_IN (3 << CRC_CR_REV_IN_SHIFT)
|
||||
#define CRC_CR_REV_IN_NONE (0 << CRC_CR_REV_IN_SHIFT)
|
||||
#define CRC_CR_REV_IN_BYTE (1 << CRC_CR_REV_IN_SHIFT)
|
||||
#define CRC_CR_REV_IN_HALF (2 << CRC_CR_REV_IN_SHIFT)
|
||||
#define CRC_CR_REV_IN_WORD (3 << CRC_CR_REV_IN_SHIFT)
|
||||
|
||||
#define CRC_CR_POLYSIZE_SHIFT 3
|
||||
#define CRC_CR_POLYSIZE (3 << CRC_CR_POLYSIZE_SHIFT)
|
||||
#define CRC_CR_POLYSIZE_32BIT (0 << CRC_CR_POLYSIZE_SHIFT)
|
||||
#define CRC_CR_POLYSIZE_16BIT (1 << CRC_CR_POLYSIZE_SHIFT)
|
||||
#define CRC_CR_POLYSIZE_8BIT (2 << CRC_CR_POLYSIZE_SHIFT)
|
||||
#define CRC_CR_POLYSIZE_7BIT (3 << CRC_CR_POLYSIZE_SHIFT)
|
||||
|
||||
/* Default polynomial */
|
||||
#define CRC_POL_DEFAULT 0x04C11DB7
|
||||
|
||||
/*****************************************************************************/
|
||||
/* API definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* API Functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
BEGIN_DECLS
|
||||
|
||||
END_DECLS
|
||||
/**@}*/
|
||||
#include <libopencm3/stm32/common/crc_v2.h>
|
||||
|
||||
#endif
|
||||
|
@ -32,39 +32,6 @@
|
||||
#ifndef LIBOPENCM3_CRC_H
|
||||
#define LIBOPENCM3_CRC_H
|
||||
|
||||
#include <libopencm3/stm32/common/crc_common_all.h>
|
||||
|
||||
/* --- CRC registers ------------------------------------------------------- */
|
||||
|
||||
/* Initial CRC value (CRC_INIT) */
|
||||
#define CRC_INIT MMIO32(CRC_BASE + 0x10)
|
||||
|
||||
/* CRC polynomial (CRC_POL) */
|
||||
#define CRC_POL MMIO32(CRC_BASE + 0x14)
|
||||
|
||||
/* --- CRC_CR values ------------------------------------------------------- */
|
||||
|
||||
/* REV_OUT: Reverse output data */
|
||||
#define CRC_CR_REV_OUT (1 << 7)
|
||||
|
||||
/* REV_IN[1:0]: Reverse input data */
|
||||
#define CRC_CR_REV_IN_NOT_AFFECTED (0x0 << 5)
|
||||
#define CRC_CR_REV_IN_BYTE (0x1 << 5)
|
||||
#define CRC_CR_REV_IN_HALF_WORD (0x2 << 5)
|
||||
#define CRC_CR_REV_IN_WORD (0x3 << 5)
|
||||
|
||||
/* POLYSIZE[1:0]: Polynomial size */
|
||||
#define CRC_CR_POLYSIZE_32 (0x0 << 3)
|
||||
#define CRC_CR_POLYSIZE_16 (0x1 << 3)
|
||||
#define CRC_CR_POLYSIZE_8 (0x2 << 3)
|
||||
#define CRC_CR_POLYSIZE_7 (0x3 << 3)
|
||||
|
||||
/* --- CRC_INIT values ----------------------------------------------------- */
|
||||
|
||||
/* Bits 31:0 CRC_INIT: Programmable initial CRC value */
|
||||
|
||||
/* --- CRC_POL values ------------------------------------------------------ */
|
||||
|
||||
/* Bits 31:0 POL[31:0]: Programmable polynomial */
|
||||
#include <libopencm3/stm32/common/crc_v2.h>
|
||||
|
||||
#endif
|
||||
|
115
lib/stm32/common/crc_v2.c
Normal file
115
lib/stm32/common/crc_v2.c
Normal file
@ -0,0 +1,115 @@
|
||||
/** @addtogroup crc_defines
|
||||
|
||||
@author @htmlonly © @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;
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
@ -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 \
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user