来自:https://forum.micropython.org/viewtopic.php?t=8316&p=47337#p47337
STM32H7/F7支持自定义的多项式,因此可以计算多种CRC,而STM32F4只能计算固定的CRC32。
@micropython.viper
def __stm_crc_16(self, data, size : int) -> int: # private
ptr32(stm.CRC + stm.CRC_CR)[0] = (1 << 3) | 1 # Reset and put into 1 byte per write mode.
crc8 = ptr8(stm.CRC + stm.CRC_DR)
d = ptr8(data)
for i in range(size):
crc8[0] = d[i]
return ptr32(stm.CRC + stm.CRC_DR)[0]
if omv.board_type() == "H7":
stm.mem32[stm.RCC + stm.RCC_AHB4ENR] = stm.mem32[stm.RCC + stm.RCC_AHB4ENR] | (1 << 19) # Enable CRC clock
stm.mem32[stm.CRC + stm.CRC_POL] = 0x1021
elif omv.board_type() == "F7":
stm.mem32[stm.RCC + stm.RCC_AHB1ENR] = stm.mem32[stm.RCC + stm.RCC_AHB1ENR] | (1 << 12) # Enable CRC clock
stm.mem32[stm.CRC + stm.CRC_POL] = 0x1021
看不太懂啊