NRF51 unable to poweron RNG (is it a bug or is it me?)

good morning devs,

i wanted to dev some crypto stuff last nigth and therefore my first focus on rng stuff. to make it short, i dont get any random numbers out ... the rng test from tests dir simply returns zeros. I want make sure its not a problem between mouse and keyboard :slight_smile: sooo can anyone tell me if this is a bug:

ps. sorry for spaming this code here - I am still a little bit unexp with riot - and did not want to open git issue req yet.

pps. for me it seems that the ->POWER call does not work. and POWER is the only RNG offset I can not "calculate" or verify (do not find it all) in the "nrf51 seriees ref manual". hhHelp

ppps. _poweron/_poweroff calls of course deliver same result.

thanks and have a great day

Jan

--- test.c #include <stdio.h> #include <stddef.h> #include <unistd.h> #include <string.h>

#include "nrf51.h" #include "vtimer.h" #include "periph/random.h"

int main(void) {     // wait a bit     vtimer_usleep(1000 * 1000);

    printf("[DEBUG: NRF_RNG.POWER:\t\t0x%08lx]\n", NRF_RNG->POWER);     printf("[DEBUG: NRF_RNG.TASKS_START:\t0x%08lx]\n", NRF_RNG->TASKS_START);     puts("Initializing Random Number Generator driver.\n");     printf("random_init()\n");     random_init();     vtimer_usleep(1000 * 1000);     printf("[DEBUG: NRF_RNG.POWER:\t\t0x%08lx]\n", NRF_RNG->POWER);     printf("[DEBUG: NRF_RNG.TASKS_START:\t0x%08lx]\n", NRF_RNG->TASKS_START);

    printf("\nMemory map:\n");

    printf("NRF_RNG_BASE:\t\t\t0x%lx\n", NRF_RNG_BASE);     printf(" ->TASKS_START\t\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, TASKS_START));     printf(" ->TASKS_STOP\t\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, TASKS_STOP));     printf(" ->EVENTS_VALRDY\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, EVENTS_VALRDY));     printf(" ->SHORTS\t\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, SHORTS));     printf(" ->INTENSET\t\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, INTENSET));     printf(" ->INTENCLR\t\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, INTENCLR));     printf(" ->CONFIG\t\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, CONFIG));     printf(" ->VALUE\t\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, VALUE));     printf(" ->POWER\t\t\t0x%08lx\n", (long) offsetof(NRF_RNG_Type, POWER));

    printf("\n[DEBUG: NRF_RNG.POWER:\t\t0x%08lx]\n", NRF_RNG->POWER);     printf("NRF_RNG->POWER=1\n");     NRF_RNG->POWER = 1;     vtimer_usleep(1000 * 1000);     printf("[DEBUG: NRF_RNG.POWER:\t\t0x%08lx]\n", NRF_RNG->POWER);

    printf("\n[DEBUG: NRF_RNG.TASKS_START:\t0x%08lx]\n", NRF_RNG->TASKS_START);     printf("NRF_RNG->TASKS_START=1\n");     NRF_RNG->TASKS_START = 1;     vtimer_usleep(1000 * 1000);     printf("[DEBUG: NRF_RNG.TASKS_START:\t0x%08lx]\n", NRF_RNG->TASKS_START);

    return 0; }

Hello Jan,

When i start tests/periph_random example i get random numbers. Your code produces this output on PCA10000 board:

2015-01-17 10:42:12,988 - INFO # [DEBUG: NRF_RNG.POWER: 0x00000001] 2015-01-17 10:42:12,991 - INFO # [DEBUG: NRF_RNG.TASKS_START: 0x00000000] 2015-01-17 10:42:12,995 - INFO # Initializing Random Number Generator driver. 2015-01-17 10:42:12,995 - INFO # 2015-01-17 10:42:12,997 - INFO # random_init() 2015-01-17 10:42:14,000 - INFO # [DEBUG: NRF_RNG.POWER: 0x00000001] 2015-01-17 10:42:14,004 - INFO # [DEBUG: NRF_RNG.TASKS_START: 0x00000000] 2015-01-17 10:42:14,004 - INFO # 2015-01-17 10:42:14,005 - INFO # Memory map: 2015-01-17 10:42:14,008 - INFO # NRF_RNG_BASE: 0x4000d000 2015-01-17 10:42:14,010 - INFO # ->TASKS_START 0x00000000 2015-01-17 10:42:14,013 - INFO # ->TASKS_STOP 0x00000004 2015-01-17 10:42:14,016 - INFO # ->EVENTS_VALRDY 0x00000100 2015-01-17 10:42:14,018 - INFO # ->SHORTS 0x00000200 2015-01-17 10:42:14,020 - INFO # ->INTENSET 0x00000304 2015-01-17 10:42:14,023 - INFO # ->INTENCLR 0x00000308 2015-01-17 10:42:14,025 - INFO # ->CONFIG 0x00000504 2015-01-17 10:42:14,027 - INFO # ->VALUE 0x00000508 2015-01-17 10:42:14,030 - INFO # ->POWER 0x00000ffc 2015-01-17 10:42:14,030 - INFO # 2015-01-17 10:42:14,032 - INFO # [DEBUG: NRF_RNG.POWER: 0x00000001] 2015-01-17 10:42:14,034 - INFO # NRF_RNG->POWER=1 2015-01-17 10:42:15,037 - INFO # [DEBUG: NRF_RNG.POWER: 0x00000001] 2015-01-17 10:42:15,038 - INFO # 2015-01-17 10:42:15,041 - INFO # [DEBUG: NRF_RNG.TASKS_START: 0x00000000] 2015-01-17 10:42:15,043 - INFO # NRF_RNG->TASKS_START=1 2015-01-17 10:42:16,047 - INFO # [DEBUG: NRF_RNG.TASKS_START: 0x00000000]

hello frank

sh… - oh great…

if you find time maybe you can tell me more about the POWER reg/address. I read the man and power section etc. but still dont know how to calculate POWER 0x00000ffc.

ps. my dk should arrive in some hours… so i have an alternative board(s) - test performed on rfduino…

thanks for your input hm output :slight_smile:

Hi guys,

I would propose you take a good look at the NRFs errata sheet: it’s (i) quite long and (ii) tells you lot’s of things that work on one stepping but do not work on another… I took my for example quite some time to find out, that my NRF bords have their timers fixed to 24-bit width (as opposed to the description in the datasheet…) I could imagine the RNG module is also effected…

Cheers, Hauke