Skip to content

machine/nrf: stop the RNG after each read - #5851

Merged
deadprogram merged 1 commit into
devfrom
nrf-rng-stop
Oct 9, 2026
Merged

deadprogram merged 1 commit into
devfrom
nrf-rng-stop

Conversation

@deadprogram

Copy link
Copy Markdown
Member

getRNG started the RNG and never stopped it. The runtime calls it from initRand at start up to seed its random state. On a SoftDevice target the SoftDevice is not enabled yet at that point, so this path is always used. The RNG then ran for the life of the program.

This change starts the RNG for each read and stops it after the 4 bytes are read. It also clears EVENTS_VALRDY before the start, so an old event does not give an old value.

Reference: nRF52840 Product Specification, RNG, electrical specification. https://docs.nordicsemi.com/bundle/ps_nrf52840/page/rng.html

Tests

Measured on an ItsyBitsy nRF52840 (S140 6.1.1) that runs a Bluetooth beacon with -serial=none. The board was powered from a CR1220 through a multimeter. The other parts on this board use about 0.8 mA, so only the difference is useful.

TinyGo Current
dev 1.36 mA
dev with this change 0.89 mA
  • The microbit binary in the size test is 16 bytes smaller. I updated builder/testdata/binary-size.txt.
  • Builds pass for microbit, microbit-s110v8, pca10040, pca10056, nrf52840-mdk, itsybitsy-nrf52840, xiao-ble and nicenano.

getRNG started the RNG and never stopped it. The runtime calls it at
start up to seed its random state, so the RNG ran for the life of the
program. On an nRF52840 beacon this used about 0.45 mA more while the
chip slept.
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Size difference with the dev branch:

Binary size difference
 flash                          ram
 before   after   diff          before   after   diff
  13964   13948    -16  -0.11%    7260    7252     -8  -0.11% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/apds9960/proximity/main.go
   7572    7556    -16  -0.21%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
   5912    5896    -16  -0.27%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/customchar/main.go
   5992    5976    -16  -0.27%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/text/main.go
  16596   16580    -16  -0.10%    2428    2428      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hub75/main.go
  30408   30392    -16  -0.05%    4152    4152      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/microbitmatrix/main.go
   6708    6692    -16  -0.24%    3292    3292      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go
   5108    5092    -16  -0.31%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go
  58704   58688    -16  -0.03%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go
  58768   58752    -16  -0.03%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go
   6404    6388    -16  -0.25%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go
   6948    6932    -16  -0.23%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go
   6820    6804    -16  -0.23%    2324    2324      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
   6500    6484    -16  -0.25%    2316    2316      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
   6692    6676    -16  -0.24%    2324    2324      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd4in2/main.go
  20068   20068      0   0.00%    7084    7084      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650
  63596   63596      0   0.00%    6884    6884      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adt7410/main.go
  11436   11436      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
  15612   15612      0   0.00%    7492    7492      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
  10668   10668      0   0.00%    5396    5396      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
  12872   12872      0   0.00%    5408    5408      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go
   8856    8856      0   0.00%    2320    2320      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/at24cx/main.go
  10156   10156      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bh1750/main.go
   9452    9452      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/blinkm/main.go
  71984   71984      0   0.00%    3728    3720     -8  -0.21% tinygo build -size short -o ./build/test.hex -target=pinetime     ./examples/bma42x/main.go
  68220   68220      0   0.00%    6852    6852      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmi160/main.go
  29292   29292      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp180/main.go
  66860   66860      0   0.00%    6884    6884      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp280/main.go
  13852   13852      0   0.00%    5468    5468      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bmp388/main.go
  24692   24692      0   0.00%    6324    6324      0   0.00% tinygo build -size short -o ./build/test.hex -target=metro-rp2350 ./examples/bno08x/i2c/main.go
   9256    9256      0   0.00%    3360    3360      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/sram/main.go
  22868   22868      0   0.00%    3592    3592      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/time/main.go
  31400   31400      0   0.00%    5668    5668      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/alarms/main.go
  45288   45288      0   0.00%    5668    5668      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/basic/main.go
   4776    4776      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/main.go
   6992    6992      0   0.00%    2344    2344      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/async/main.go
  73248   73248      0   0.00%    7712    7712      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/flash/console/spi
  69088   69088      0   0.00%    9752    9752      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
  23684   23684      0   0.00%    8588    8588      0   0.00% tinygo build -size short -o ./build/test.bin -target=esp32-coreboard-v2 ./examples/gdew0154m09/main.go
  69968   69968      0   0.00%    7084    7084      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
  70472   70472      0   0.00%    7188    7188      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
  10228   10228      0   0.00%    5460    5460      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/hcsr04/main.go
  12188   12188      0   0.00%    5420    5420      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/hd44780i2c/main.go
  16828   16828      0   0.00%    7260    7252     -8  -0.11% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/hts221/main.go
  11772   11772      0   0.00%    7636    7636      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic
  14252   14252      0   0.00%    5596    5596      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/basic
  31140   31140      0   0.00%   38796   38796      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/pyportal_boing
  11748   11748      0   0.00%    7636    7636      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll
  14276   14276      0   0.00%    5596    5596      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/scroll
 266204  266204      0   0.00%   47480   47480      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/slideshow
  12492   12492      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go
  16236   16236      0   0.00%    7260    7252     -8  -0.11% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/lps22hb/main.go
  26616   26616      0   0.00%    2328    2328      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/lsm303agr/main.go
  29900   29900      0   0.00%    7484    7484      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/lsm303dlhc/main.go
  14140   14140      0   0.00%    5444    5444      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/lsm6ds3/main.go
  12716   12716      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mag3110/main.go
  11556   11556      0   0.00%    5428    5428      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017/main.go
  11988   11988      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017-multiple/main.go
  11868   11868      0   0.00%    5396    5396      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp3008/main.go
  74660   74660      0   0.00%    6964    6964      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp2515/main.go
  30344   30344      0   0.00%    6196    6196      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit-v2 ./examples/microbitmatrix/main.go
  10188   10188      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mma8653/main.go
  10140   10140      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go
  79820   79820      0   0.00%    8124    8124      0   0.00% tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go
  15816   15816      0   0.00%    6264    6264      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/pca9685/main.go
  15560   15560      0   0.00%    6248    6248      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/seesaw/soil-sensor
  15160   15160      0   0.00%    6248    6248      0   0.00% tinygo build -size short -o ./build/test.hex -target=qtpy-rp2040 ./examples/seesaw/rotary-encoder
   2899    2899      0   0.00%     560     560      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino ./examples/servo
  17376   17376      0   0.00%    6328    6328      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico     ./examples/sgp30
   9564    9564      0   0.00%    7436    7436      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/shifter/main.go
  58752   58752      0   0.00%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go
  15060   15060      0   0.00%    9132    9132      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao-ble ./examples/ssd1306/
  15240   15240      0   0.00%    6288    6288      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao-rp2040 ./examples/ssd1306/
  15176   15176      0   0.00%    6280    6280      0   0.00% tinygo build -size short -o ./build/test.hex -target=thumby ./examples/ssd1306/
   7236    7236      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go
  18844   18844      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/thermistor/main.go
  12764   12764      0   0.00%    5220    5220      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-bluefruit ./examples/tone
  12108   12108      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/tm1637/main.go
  14380   14380      0   0.00%    6260    6260      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/touch/capacitive
  10932   10932      0   0.00%    7428    7428      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/fourwire/main.go
  13952   13952      0   0.00%    7696    7696      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/pyportal_touchpaint/main.go
  17284   17284      0   0.00%    5508    5508      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go
  15956   15956      0   0.00%    5508    5508      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go
  27208   27208      0   0.00%   14408   14408      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840-sense ./examples/waveshare-epd/epd1in54/main.go
  31192   31192      0   0.00%   19328   19328      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/waveshare-epd/epd2in66b/main.go
   8780    8780      0   0.00%    5428    5428      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812
   6122    6122      0   0.00%    8464    8464      0   0.00% tinygo build -size short -o ./build/test.bin -target=m5stamp-c3          ./examples/ws2812
  65556   65556      0   0.00%    6636    6636      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
   1799    1799      0   0.00%     600     600      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino   ./examples/ws2812
   1280    1280      0   0.00%     182     182      0   0.00% tinygo build -size short -o ./build/test.hex -target=digispark ./examples/ws2812
   7776    7776      0   0.00%    8744    8744      0   0.00% tinygo build -size short -o ./build/test.bin -target=xiao-esp32c3 ./examples/ws2812
  33516   33516      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bme280/main.go
  18372   18372      0   0.00%    5380    5380      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/microphone/main.go
  13116   13116      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/buzzer/main.go
  14092   14092      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/veml6070/main.go
   8540    8540      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/simple/main.go
  10476   10476      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/speed/main.go
   8508    8508      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/simple/main.go
  10908   10908      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/speed/main.go
   8180    8180      0   0.00%    3324    3324      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-f103rb ./examples/shiftregister/main.go
   7596    7596      0   0.00%    2288    2288      0   0.00% tinygo build -size short -o ./build/test.hex -target=hifive1b ./examples/ssd1351/main.go
  15308   15308      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis2mdl/main.go
  13004   13004      0   0.00%    5412    5412      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/max72xx/main.go
  80092   80092      0   0.00%    7032    7032      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/dht/main.go
  40196   40196      0   0.00%    6836    6836      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8523/
  73244   73244      0   0.00%    7072    7072      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/alarm/
   9132    9132      0   0.00%    5428    5428      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/clkout/
  67960   67960      0   0.00%    7068    7068      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/time/
  73100   73100      0   0.00%    7072    7072      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/timer/
  15752   15752      0   0.00%    6256    6256      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/qmi8658c/main.go
  14840   14840      0   0.00%    6248    6248      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8591/
  10668   10668      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina260/main.go
  14828   14828      0   0.00%    5436    5436      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina219/main.go
  10600   10600      0   0.00%    5280    5280      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-l432kc ./examples/aht20/main.go
  76548   76548      0   0.00%   11508   11508      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/sdcard/console/
  63052   63052      0   0.00%    8892    8892      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/i2csoft/adt7410/
  11772   11772      0   0.00%    7444    7444      0   0.00% tinygo build -size short -o ./build/test.elf -target=wioterminal ./examples/axp192/m5stack-core2-blinky/
  12500   12500      0   0.00%    6188    6188      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/xpt2046/main.go
  12464   12464      0   0.00%    4696    4696      0   0.00% tinygo build -size short -o ./build/test.elf -target=m5stack-core2 ./examples/ft6336/basic/
  20044   20044      0   0.00%    4964    4964      0   0.00% tinygo build -size short -o ./build/test.elf -target=m5stack-core2 ./examples/ft6336/touchpaint/
  14416   14416      0   0.00%    5060    5060      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/
  46952   46952      0   0.00%    9608    9608      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/sx127x/lora_rxtx/
  37328   37328      0   0.00%    7976    7976      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/ssd1289/main.go
  15256   15256      0   0.00%    7240    7240      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
  15520   15520      0   0.00%    6272    6272      0   0.00% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go
  15872   15872      0   0.00%    6708    6708      0   0.00% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/waveshare-epd/epd2in9v2/main.go
  17548   17548      0   0.00%    6300    6300      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd30/main.go
  13848   13848      0   0.00%    6276    6276      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
   9684    9684      0   0.00%    5396    5396      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
  11388   11388      0   0.00%    5412    5412      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ds18b20/main.go
 125348  125348      0   0.00%    8448    8448      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/lora/lorawan/atcmd/
  20116   20116      0   0.00%    7852    7852      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/as560x/main.go
  15496   15496      0   0.00%    6248    6248      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu6886/main.go
   9548    9548      0   0.00%    5388    5388      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ttp229/main.go
  71224   71224      0   0.00%    7736    7736      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ndir/main_ndir.go
  63416   63416      0   0.00%    3792    3792      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ndir/main_ndir.go
  67932   67932      0   0.00%    6924    6924      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ndir/main_ndir.go
  13320   13320      0   0.00%    6240    6240      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu9150/main.go
  15220   15220      0   0.00%    6308    6308      0   0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/sh1106/macropad_spi
  11968   11968      0   0.00%    6688    6688      0   0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/encoders/quadrature-interrupt
  69608   69608      0   0.00%    7696    7696      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mcp9808/main.go
  47136   47136      0   0.00%    8352    8352      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/tmc2209/main.go
  15364   15364      0   0.00%    6196    6196      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/tmc5160/main.go
  14720   14720      0   0.00%    5216    5216      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=nicenano ./examples/sharpmem/main.go
  64568   64568      0   0.00%    6664    6664      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/max6675/main.go
  16168   16168      0   0.00%    6256    6256      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ens160/main.go
  20048   20048      0   0.00%    6360    6360      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/si5351/main.go
  25072   25072      0   0.00%    7608    7608      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/w5500/main.go
  92344   92344      0   0.00%    7988    7988      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/sd
  91324   91324      0   0.00%    8140    8140      0   0.00% tinygo build -size short -o ./build/test.hex -target=challenger-rp2040 ./examples/net/ntpclient/
 378848  378848      0   0.00%   14888   14888      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal -stack-size 8kb ./examples/net/http-get/
 126548  126548      0   0.00%    9080    9080      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 -stack-size 8kb ./examples/net/tcpclient/
 358516  358516      0   0.00%   13584   13584      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/websocket/dial/
 108488  108488      0   0.00%   11060   11060      0   0.00% tinygo build -size short -o ./build/test.hex -target=metro-m4-airlift -stack-size 8kb ./examples/net/socket/
 426296  426296      0   0.00%   17564   17564      0   0.00% tinygo build -size short -o ./build/test.hex -target=matrixportal-m4 -stack-size 8kb ./examples/net/webstatic/
 172480  172480      0   0.00%    9248    9248      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-mkrwifi1010 -stack-size 8kb ./examples/net/tlsclient/
 163828  163828      0   0.00%   10044   10044      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/mqttclient/natiu/
 122548  122548      0   0.00%   14372   14372      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webclient/
 374740  374740      0   0.00%   20020   20020      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webserver/
 373380  373380      0   0.00%   19080   19080      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/mqttclient/paho/
 180568  180568      0   0.00%   12520   12520      0   0.00% tinygo build -size short -o ./build/test.hex -target=elecrow-rp2040 -stack-size 8kb ./examples/net/tlsclient/
 126836  126836      0   0.00%   12356   12356      0   0.00% tinygo build -size short -o ./build/test.hex -target=elecrow-rp2350 -stack-size 8kb ./examples/net/ntpclient/
7052060 7051820   -240  -0.00% 1118406 1118374    -32  -0.00%

@deadprogram

Copy link
Copy Markdown
Member Author

Any feedback on this fellow nrf-interested people?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the documented hardware behavior and measured size change.

0 open findings

What changed in this PR

Stops the nRF RNG after each read to reduce idle power consumption.

Changes:

  • Clears stale RNG-ready events and starts the peripheral per read.
  • Stops the RNG after collecting four bytes.
  • Updates the micro:bit binary-size baseline.
File Description
src/​machine/​machine_nrf.go Manages RNG start, event clearing, and stop per read.
builder/​testdata/​binary-size.txt Records the resulting 16-byte code-size reduction.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/machine/machine_nrf.go
@deadprogram

Copy link
Copy Markdown
Member Author

Now merging since I need it and even the bots agree. Thanks @dkegel-fastly for your assist!

@deadprogram
deadprogram merged commit 235b14b into dev Oct 9, 2026
40 checks passed
@deadprogram
deadprogram deleted the nrf-rng-stop branch October 9, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working nRF Nordic Semi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants