|
116 | 116 | /* Health test control register information to use in CCM algorithm */
|
117 | 117 | #define RNG_HTCFG_1 0x17590ABCU /*!< Magic number */
|
118 | 118 | #define RNG_HTCFG 0x0000A2B3U /*!< Recommended value for NIST compliancy */
|
| 119 | +#define RNG_HTCFG_REVB 0x000CAA74U /*!< Recommended value for old MCU cut - deprecated */ |
119 | 120 | /**
|
120 | 121 | * @}
|
121 | 122 | */
|
@@ -210,10 +211,18 @@ HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng)
|
210 | 211 | MODIFY_REG(hrng->Instance->CR, RNG_CR_CED | RNG_CR_CONDRST, hrng->Init.ClockErrorDetection | RNG_CR_CONDRST);
|
211 | 212 |
|
212 | 213 | #if defined(RNG_VER_3_2) || defined(RNG_VER_3_1) || defined(RNG_VER_3_0)
|
| 214 | +if ( HAL_GetREVID() == 0x2000) { // Deprecated - old MCU |
213 | 215 | /*!< magic number must be written immediately before to RNG_HTCRG */
|
214 | 216 | WRITE_REG(hrng->Instance->HTCR, RNG_HTCFG_1);
|
215 | 217 | /* 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 | + } |
217 | 226 | #endif /* RNG_VER_3_2 || RNG_VER_3_1 || RNG_VER_3_0 */
|
218 | 227 |
|
219 | 228 | /* Writing bit CONDRST=0 */
|
@@ -682,6 +691,10 @@ HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t
|
682 | 691 | {
|
683 | 692 | hrng->State = HAL_RNG_STATE_READY;
|
684 | 693 | 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 | + } |
685 | 698 | /* Process Unlocked */
|
686 | 699 | __HAL_UNLOCK(hrng);
|
687 | 700 | return HAL_ERROR;
|
|
0 commit comments