用户工具

站点工具


micropython:主要硬件平台:stm32:crc32的使用方法

STM32F4支持硬件CRC32功能,但是在以前micropython版本中并没有提供crc32计算功能。在新v1.14版本的STM32固件中,已经默认开启了CRC32计算功能(通过定义 #define MICROPYPYUBINASCII_CRC32 (1)),它的使用方法是:

from ubinascii import crc32
 
print(hex(crc32('123456789')))
print(hex(crc32(b'\x01\x02\x03\x04')))

使用硬件计算CRC速度非常快,相比软件方式要快上数百倍。下面计算100次1024字节的CRC32校验,用时约18ms。

from ubinascii import crc32
from time import ticks_us, ticks_diff
 
buf = bytearray(1024)
 
t0 = ticks_us()
for i in range(100):
    crc32(buf)
t1 = ticks_us()
 
print(ticks_diff(t1, t0), 'us')


purge    随机主题   
micropython/主要硬件平台/stm32/crc32的使用方法.txt · 最后更改: 2021/03/18 10:13 由 shaoziyang · 查看次数: 11371