Browse Source

stm32wl: Fix incomplete RNG initialisation

pull/3411/head
Olivier Fauchon 2 years ago
committed by Ron Evans
parent
commit
eec915170d
  1. 2
      src/machine/machine.go
  2. 7
      src/machine/machine_stm32_rng.go
  3. 7
      src/machine/machine_stm32wlx.go

2
src/machine/machine.go

@ -4,6 +4,8 @@ import "errors"
var (
ErrTimeoutRNG = errors.New("machine: RNG Timeout")
ErrClockRNG = errors.New("machine: RNG Clock Error")
ErrSeedRNG = errors.New("machine: RNG Seed Error")
ErrInvalidInputPin = errors.New("machine: invalid input pin")
ErrInvalidOutputPin = errors.New("machine: invalid output pin")
ErrInvalidClockPin = errors.New("machine: invalid clock pin")

7
src/machine/machine_stm32_rng.go

@ -15,6 +15,13 @@ func GetRNG() (uint32, error) {
rngInitDone = true
}
if stm32.RNG.SR.HasBits(stm32.RNG_SR_CECS) {
return 0, ErrClockRNG
}
if stm32.RNG.SR.HasBits(stm32.RNG_SR_SECS) {
return 0, ErrSeedRNG
}
cnt := RNG_MAX_READ_RETRIES
for !stm32.RNG.SR.HasBits(stm32.RNG_SR_DRDY) {
cnt--

7
src/machine/machine_stm32wlx.go

@ -407,7 +407,12 @@ func (t *TIM) enableMainOutput() {
func initRNG() {
stm32.RCC.AHB3ENR.SetBits(stm32.RCC_AHB3ENR_RNGEN)
stm32.RNG.CR.SetBits(stm32.RNG_CR_RNGEN)
// Enable RNG with config.A (See RM0453 22.6.2)
stm32.RNG.CR.Set(0x40F00D40) // RNG Config. A
stm32.RNG.HTCR.Set(0x17590ABC) // MAGIC NUMBER
stm32.RNG.HTCR.Set(0x0000AA74) // HTCR VALUE
stm32.RNG.CR.Set(0x00F00D4C) // CONFIG A + RNG_EN=1 + IE=1
}
//----------

Loading…
Cancel
Save