diff --git a/include/libopencm3/stm32/crc.h b/include/libopencm3/stm32/crc.h index 6ae40854..7d80259c 100644 --- a/include/libopencm3/stm32/crc.h +++ b/include/libopencm3/stm32/crc.h @@ -55,4 +55,24 @@ /* TODO */ +/** + * Reset the CRC calculator to initial values. + */ +void crc_reset(void); + +/** + * Add a word to the crc calculator and return the result. + * @param data new word to add to the crc calculator + * @return final crc calculator value + */ +u32 crc_calculate(u32 data); + +/** + * Add a block of data to the CRC calculator and return the final result + * @param datap pointer to the start of a block of 32bit data words + * @param size length of data, in 32bit increments + * @return final CRC calculator value + */ +u32 crc_calculate_block(u32 *datap, int size); + #endif diff --git a/lib/stm32/crc.c b/lib/stm32/crc.c new file mode 100644 index 00000000..bbbe1fd2 --- /dev/null +++ b/lib/stm32/crc.c @@ -0,0 +1,44 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2012 Karl Palsson + * + * 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 . + */ + +#include + +void crc_reset(void) +{ + CRC_CR |= CRC_CR_RESET; +} + +u32 crc_calculate(u32 data) +{ + CRC_DR = data; + // Data sheet says this blocks until it's ready.... + return CRC_DR; +} + +u32 crc_calculate_block(u32 *datap, int size) +{ + int i; + for (i = 0; i < size; i++) { + CRC_DR = datap[i]; + } + return CRC_DR; +} + + + diff --git a/lib/stm32/f1/Makefile b/lib/stm32/f1/Makefile index 40c109a3..0059ba1f 100644 --- a/lib/stm32/f1/Makefile +++ b/lib/stm32/f1/Makefile @@ -31,7 +31,7 @@ ARFLAGS = rcs OBJS = vector.o rcc.o gpio.o usart.o adc.o spi.o flash.o nvic.o \ rtc.o i2c.o dma.o systick.o exti.o scb.o ethernet.o \ usb_f103.o usb.o usb_control.o usb_standard.o can.o \ - timer.o usb_f107.o desig.o + timer.o usb_f107.o desig.o crc.o VPATH += ../../usb:../