aboutsummaryrefslogtreecommitdiff
path: root/src/crc32.c
diff options
context:
space:
mode:
authorUwe Bonnes2013-01-23 16:11:17 +0100
committerUwe Bonnes2013-01-23 16:11:17 +0100
commit32b909067b2a34f475a52585b965c195de87c172 (patch)
tree42e1ad85f4c5789462534461313d661efb329de8 /src/crc32.c
parentd868088d78caf96e5e46bdcbc57153e7370d255d (diff)
STM32: Use hardware CRC unit
Diffstat (limited to 'src/crc32.c')
-rw-r--r--src/crc32.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/crc32.c b/src/crc32.c
index 25cd53b..d5c8732 100644
--- a/src/crc32.c
+++ b/src/crc32.c
@@ -21,6 +21,7 @@
#include "platform.h"
#include "target.h"
+#if !defined(STM32F1) && !defined(STM32F4)
static const uint32_t crc32_table[] = {
0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9,
0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005,
@@ -107,4 +108,31 @@ uint32_t generic_crc32(struct target_s *target, uint32_t base, int len)
}
return crc;
}
+#else
+#include <libopencm3/stm32/crc.h>
+uint32_t generic_crc32(struct target_s *target, uint32_t base, int len)
+{
+ uint32_t data;
+ uint8_t byte;
+
+ CRC_CR |= CRC_CR_RESET;
+
+ while (len >3) {
+ if (target_mem_read_words(target, &data, base, 1) != 0)
+ return -1;
+
+ CRC_DR = data;
+ base+=4;
+ len -= 4;
+ }
+ while (len--) {
+ if (target_mem_read_bytes(target, &byte, base, 1) != 0)
+ return -1;
+
+ CRC_DR = byte;
+ base++;
+ }
+ return CRC_DR;
+}
+#endif