Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builder/testdata/binary-size.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
target package opt code rodata data bss
hifive1b examples/echo z 4558 402 0 2276
microbit examples/serial z 3017 439 8 2272
microbit examples/serial z 3001 439 8 2272
wioterminal examples/pininterrupt z 8458 1798 148 7536
cortex-m-qemu ./testdata/size-corpus z 9923 1301 80 4188
cortex-m-qemu ./testdata/size-corpus 2 17482 862 72 4188
Expand Down
16 changes: 7 additions & 9 deletions src/machine/machine_nrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,12 @@ func (i2c *I2C) signalStop() error {
return nil
}

var rngStarted = false

// getRNG returns 32 bits of non-deterministic random data based on internal thermal noise.
// According to Nordic's documentation, the random output is suitable for cryptographic purposes.
func getRNG() (ret uint32, err error) {
// There's no apparent way to check the status of the RNG peripheral's task, so simply start it
// to avoid deadlocking while waiting for output.
if !rngStarted {
nrf.RNG.TASKS_START.Set(1)
nrf.RNG.SetCONFIG_DERCEN(nrf.RNG_CONFIG_DERCEN_Enabled)
rngStarted = true
}
nrf.RNG.SetCONFIG_DERCEN(nrf.RNG_CONFIG_DERCEN_Enabled)
Comment thread
deadprogram marked this conversation as resolved.
nrf.RNG.EVENTS_VALRDY.Set(0)
nrf.RNG.TASKS_START.Set(1)

// The RNG returns one byte at a time, so stack up four bytes into a single uint32 for return.
for i := 0; i < 4; i++ {
Expand All @@ -343,6 +337,10 @@ func getRNG() (ret uint32, err error) {
nrf.RNG.EVENTS_VALRDY.Set(0)
}

// A running RNG uses current all the time, so stop it after each read.
// See https://docs.nordicsemi.com/bundle/ps_nrf52840/page/rng.html, electrical specification.
nrf.RNG.TASKS_STOP.Set(1)

return ret, nil
}

Expand Down
Loading