machine/stm32wl: unify implementation for RNG for stm32wl with other STM32 processors

Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
deadprogram 2021-12-15 12:47:40 +01:00 коммит произвёл Ron Evans
родитель c096f35224
коммит 5264469cbd
2 изменённых файлов: 8 добавлений и 25 удалений

Просмотреть файл

@ -1,5 +1,5 @@
//go:build stm32f4 || stm32f7 || stm32l4 //go:build stm32f4 || stm32f7 || stm32l4 || stm32wlx
// +build stm32f4 stm32f7 stm32l4 // +build stm32f4 stm32f7 stm32l4 stm32wlx
package machine package machine

Просмотреть файл

@ -13,8 +13,6 @@ import (
"unsafe" "unsafe"
) )
var rngInitDone = false
const ( const (
AF0_SYSTEM = 0 AF0_SYSTEM = 0
AF1_TIM1_2_LPTIM1 = 1 AF1_TIM1_2_LPTIM1 = 1
@ -35,7 +33,6 @@ const (
SYSCLK = 48e6 SYSCLK = 48e6
APB1_TIM_FREQ = SYSCLK APB1_TIM_FREQ = SYSCLK
APB2_TIM_FREQ = SYSCLK APB2_TIM_FREQ = SYSCLK
RNG_MAX_READ_RETRIES = 1000
) )
func CPUFrequency() uint32 { func CPUFrequency() uint32 {
@ -399,23 +396,9 @@ func (t *TIM) enableMainOutput() {
t.Device.BDTR.SetBits(stm32.TIM_BDTR_MOE) t.Device.BDTR.SetBits(stm32.TIM_BDTR_MOE)
} }
// GetRNG returns 32 bits of cryptographically secure random data func initRNG() {
func GetRNG() (uint32, error) {
if !rngInitDone {
stm32.RCC.AHB3ENR.SetBits(stm32.RCC_AHB3ENR_RNGEN) stm32.RCC.AHB3ENR.SetBits(stm32.RCC_AHB3ENR_RNGEN)
stm32.RNG.CR.SetBits(stm32.RNG_CR_RNGEN) stm32.RNG.CR.SetBits(stm32.RNG_CR_RNGEN)
rngInitDone = true
}
cnt := RNG_MAX_READ_RETRIES
for cnt > 0 && !stm32.RNG.SR.HasBits(stm32.RNG_SR_DRDY) {
cnt--
}
if cnt == 0 {
return 0, ErrTimeoutRNG
}
ret := stm32.RNG.DR.Get()
return ret, nil
} }
//---------- //----------