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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 #error "Must define AO_CRC_WIDTH"
26 /* Only the STM32F07x and ST32F09x series have
27 * programmable CRC units. Others can only do the ANSI CRC-32 computation
30 #if !AO_HAVE_PROGRAMMABLE_CRC_UNIT && AO_CRC_WIDTH != 32
31 #error "Target hardware does not have programmable CRC unit"
35 #if AO_CRC_WIDTH == 16
36 #define AO_CRC_POLY AO_CRC_16_DEFAULT
38 #if AO_CRC_WIDTH == 32
39 #define AO_CRC_POLY AO_CRC_32_DEFAULT
43 #if !AO_HAVE_PROGRAMMABLE_CRC_UNIT && (AO_CRC_WIDTH != 32 || AO_CRC_POLY != AO_CRC_32_ANSI)
44 #error "Target hardware does not have programmable CRC unit"
47 #if AO_CRC_WIDTH == 32
48 #define AO_CRC_CR_POLYSIZE STM_CRC_CR_POLYSIZE_32
51 #if AO_CRC_WIDTH == 16
52 #define AO_CRC_CR_POLYSIZE STM_CRC_CR_POLYSIZE_16
56 #define AO_CRC_CR_POLYSIZE STM_CRC_CR_POLYSIZE_8
60 #define AO_CRC_CR_POLYSIZE STM_CRC_CR_POLYSIZE_7
64 #define AO_CRC_INIT 0xffffffff
70 stm_crc.cr |= (1 << STM_CRC_CR_RESET);
71 while ((stm_crc.cr & (1 << STM_CRC_CR_RESET)) != 0)
78 /* Turn on the CRC clock */
79 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_CRCEN);
81 /* Need to initialize CR even on non-programmable hardware,
82 * the write to the POLYSIZE bits will be ignored in that
85 stm_crc.cr = (AO_CRC_CR_POLYSIZE << STM_CRC_CR_POLYSIZE);
86 stm_crc.init = AO_CRC_INIT;
87 #if AO_HAVE_PROGRAMMABLE_CRC_UNIT
88 stm_crc.pol = AO_CRC_POLY;