Skip to content

Commit f599a54

Browse files
committed
STM32L5 RNG : update for deprecated MCU version
1 parent 7d1f5c4 commit f599a54

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

targets/TARGET_STM/TARGET_STM32L5/STM32Cube_FW/STM32L5xx_HAL_Driver/stm32l5xx_hal_rng.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
/* Health test control register information to use in CCM algorithm */
117117
#define RNG_HTCFG_1 0x17590ABCU /*!< Magic number */
118118
#define RNG_HTCFG 0x0000A2B3U /*!< Recommended value for NIST compliancy */
119+
#define RNG_HTCFG_REVB 0x000CAA74U /*!< Recommended value for old MCU cut - deprecated */
119120
/**
120121
* @}
121122
*/
@@ -210,10 +211,18 @@ HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng)
210211
MODIFY_REG(hrng->Instance->CR, RNG_CR_CED | RNG_CR_CONDRST, hrng->Init.ClockErrorDetection | RNG_CR_CONDRST);
211212

212213
#if defined(RNG_VER_3_2) || defined(RNG_VER_3_1) || defined(RNG_VER_3_0)
214+
if ( HAL_GetREVID() == 0x2000) { // Deprecated - old MCU
213215
/*!< magic number must be written immediately before to RNG_HTCRG */
214216
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG_1);
215217
/* for best latency and to be compliant with NIST */
216-
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG);
218+
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG_REVB);
219+
}
220+
else {
221+
/*!< magic number must be written immediately before to RNG_HTCRG */
222+
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG_1);
223+
/* for best latency and to be compliant with NIST */
224+
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG);
225+
}
217226
#endif /* RNG_VER_3_2 || RNG_VER_3_1 || RNG_VER_3_0 */
218227

219228
/* Writing bit CONDRST=0 */
@@ -682,6 +691,10 @@ HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t
682691
{
683692
hrng->State = HAL_RNG_STATE_READY;
684693
hrng->ErrorCode = HAL_RNG_ERROR_TIMEOUT;
694+
if (__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_SECS) != RESET)
695+
{
696+
hrng->ErrorCode |= HAL_RNG_ERROR_SEED;
697+
}
685698
/* Process Unlocked */
686699
__HAL_UNLOCK(hrng);
687700
return HAL_ERROR;

0 commit comments

Comments
 (0)