Skip to content

Commit 986add7

Browse files
authored
Merge pull request #14722 from jeromecoutant/PR_RNG
STM32 TRNG: update init to match all configs
2 parents 3ee443b + a4ae9f1 commit 986add7

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
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 */
120119
/**
121120
* @}
122121
*/
@@ -211,18 +210,10 @@ HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng)
211210
MODIFY_REG(hrng->Instance->CR, RNG_CR_CED | RNG_CR_CONDRST, hrng->Init.ClockErrorDetection | RNG_CR_CONDRST);
212211

213212
#if defined(RNG_VER_3_2) || defined(RNG_VER_3_1) || defined(RNG_VER_3_0)
214-
if ( HAL_GetREVID() == 0x2000) { // Deprecated - old MCU
215213
/*!< magic number must be written immediately before to RNG_HTCRG */
216214
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG_1);
217215
/* for best latency and to be compliant with NIST */
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-
}
216+
WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG);
226217
#endif /* RNG_VER_3_2 || RNG_VER_3_1 || RNG_VER_3_0 */
227218

228219
/* Writing bit CONDRST=0 */
@@ -691,10 +682,6 @@ HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t
691682
{
692683
hrng->State = HAL_RNG_STATE_READY;
693684
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-
}
698685
/* Process Unlocked */
699686
__HAL_UNLOCK(hrng);
700687
return HAL_ERROR;

targets/TARGET_STM/trng_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ void trng_init(trng_t *obj)
128128
}
129129

130130
/* first random number generated after setting the RNGEN bit should not be used */
131-
if (HAL_RNG_GenerateRandomNumber(&obj->handle, &dummy) != HAL_OK) {
132-
printf("trng_init: HAL_RNG_GenerateRandomNumber error 0x%x\n", obj->handle.ErrorCode); // should not occur
131+
/* could be executed few times in case of long init (obj->handle.ErrorCode can be checked for debug) */
132+
while (HAL_RNG_GenerateRandomNumber(&obj->handle, &dummy) != HAL_OK) {
133133
}
134134

135135
#if defined(CFG_HW_RNG_SEMID)

0 commit comments

Comments
 (0)