2 * Copyright © 2015 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 #error "Must define AO_CRC_WIDTH"
25 /* Only the STM32F07x and ST32F09x series have
26 * programmable CRC units. Others can only do the ANSI CRC-32 computation
29 #if !AO_HAVE_PROGRAMMABLE_CRC_UNIT && AO_CRC_WIDTH != 32
30 #error "Target hardware does not have programmable CRC unit"
34 #if AO_CRC_WIDTH == 16
35 #define AO_CRC_POLY AO_CRC_16_DEFAULT
37 #if AO_CRC_WIDTH == 32
38 #define AO_CRC_POLY AO_CRC_32_DEFAULT
42 #if !AO_HAVE_PROGRAMMABLE_CRC_UNIT && (AO_CRC_WIDTH != 32 || AO_CRC_POLY != AO_CRC_32_ANSI)
43 #error "Target hardware does not have programmable CRC unit"
46 #if AO_CRC_WIDTH == 32
47 #define AO_CRC_CR_POLYSIZE STM_CRC_CR_POLYSIZE_32
50 #if AO_CRC_WIDTH == 16
51 #define AO_CRC_CR_POLYSIZE STM_CRC_CR_POLYSIZE_16
55 #define AO_CRC_CR_POLYSIZE STM_CRC_CR_POLYSIZE_8
59 #define AO_CRC_CR_POLYSIZE STM_CRC_CR_POLYSIZE_7
63 #define AO_CRC_INIT 0xffffffff
69 stm_crc.cr |= (1 << STM_CRC_CR_RESET);
70 while ((stm_crc.cr & (1 << STM_CRC_CR_RESET)) != 0)
77 /* Turn on the CRC clock */
78 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_CRCEN);
80 /* Need to initialize CR even on non-programmable hardware,
81 * the write to the POLYSIZE bits will be ignored in that
84 stm_crc.cr = (AO_CRC_CR_POLYSIZE << STM_CRC_CR_POLYSIZE);
85 stm_crc.init = AO_CRC_INIT;
86 #if AO_HAVE_PROGRAMMABLE_CRC_UNIT
87 stm_crc.pol = AO_CRC_POLY;