Browse Source

rng: fix clock error handling, based on RM.

According to L4/L0/G0 RM, in case of clock error, interrupt flag must
be cleared, and CECS flag should be cleared as soon as clock meets
requirement.

Reviewed-on: https://github.com/libopencm3/libopencm3/pull/1062
pull/1167/head
Guillaume Revaillot 6 years ago
committed by Karl Palsson
parent
commit
a8a92b4c11
  1. 7
      lib/stm32/common/rng_common_v1.c

7
lib/stm32/common/rng_common_v1.c

@ -87,6 +87,9 @@ bool rng_get_random(uint32_t *rand_nr)
* Get a random number and block until it works. * Get a random number and block until it works.
* Unless you have a clock problem, this should always return "promptly" * Unless you have a clock problem, this should always return "promptly"
* If you have a clock problem, you will wait here forever! * If you have a clock problem, you will wait here forever!
* Check device RM for clock requirements (usually fRNGCLK > fHCLK/16 or
* fRNGCLK > fHCLK/32
* @returns a random 32bit number * @returns a random 32bit number
*/ */
uint32_t rng_get_random_blocking(void) uint32_t rng_get_random_blocking(void)
@ -104,6 +107,10 @@ uint32_t rng_get_random_blocking(void)
RNG_CR |= RNG_CR_RNGEN; RNG_CR |= RNG_CR_RNGEN;
} }
if (RNG_SR & RNG_SR_CEIS) {
RNG_SR = RNG_SR & ~RNG_SR_CEIS;
}
done = rng_get_random(&rv); done = rng_get_random(&rv);
} while (!done); } while (!done);

Loading…
Cancel
Save