Skip to content

Commit 96b4974

Browse files
authored
[stm32][driver_crypto]修复CRC自定义设置不生效的bug (#5655)
* [stm32][drivers]修复CRC自定义设置不生效的bug * update format
1 parent 5810f4d commit 96b4974

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_crypto.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -85,7 +85,32 @@ static rt_uint32_t _crc_update(struct hwcrypto_crc *ctx, const rt_uint8_t *in, r
8585
goto _exit;
8686
}
8787

88-
HW_TypeDef->Init.CRCLength = ctx ->crc_cfg.width;
88+
switch(ctx ->crc_cfg.width)
89+
{
90+
#if defined(CRC_POLYLENGTH_7B) && defined(CRC_POLYLENGTH_8B) && defined(CRC_POLYLENGTH_16B) && defined(CRC_POLYLENGTH_32B)
91+
case 7:
92+
HW_TypeDef->Init.CRCLength = CRC_POLYLENGTH_7B;
93+
break;
94+
case 8:
95+
HW_TypeDef->Init.CRCLength = CRC_POLYLENGTH_8B;
96+
break;
97+
case 16:
98+
HW_TypeDef->Init.CRCLength = CRC_POLYLENGTH_16B;
99+
break;
100+
case 32:
101+
HW_TypeDef->Init.CRCLength = CRC_POLYLENGTH_32B;
102+
break;
103+
default :
104+
goto _exit;
105+
#else
106+
case 32:
107+
HW_TypeDef->Init.CRCLength = CRC_POLYLENGTH_32B;
108+
break;
109+
default :
110+
goto _exit;
111+
#endif /* defined(CRC_POLYLENGTH_7B) && defined(CRC_POLYLENGTH_8B) && defined(CRC_POLYLENGTH_16B) && defined(CRC_POLYLENGTH_32B) */
112+
}
113+
89114
if (HW_TypeDef->Init.DefaultInitValueUse == DEFAULT_INIT_VALUE_DISABLE)
90115
{
91116
HW_TypeDef->Init.InitValue = ctx ->crc_cfg.last_val;
@@ -404,7 +429,7 @@ static rt_err_t _crypto_create(struct rt_hwcrypto_ctx *ctx)
404429
hcrc->Instance = CRC;
405430
#endif
406431
#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32MP1)
407-
hcrc->Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
432+
hcrc->Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;
408433
hcrc->Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE;
409434
hcrc->Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_BYTE;
410435
hcrc->Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_ENABLE;

0 commit comments

Comments
 (0)