This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

DFU thread tutorial nrf5RandomInit stuck

Hello,

I have been trying to follow tutorial from:

https://devzone.nordicsemi.com/nordic/short-range-guides/b/mesh-networks/posts/thread-tutorial-practical-guide-for-device-upgrade-ota

but I encounter multiple issue maybe because I use newer SDK version.

I am trying to build example:

make -j -C Client\pca10056\blank\armgcc

Current problem causes runtime application stuck at system initialization. Namely it fails to init nrf5RandomInit:

(gdb) bt
#0  bufferCount () at ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c:63
#1  bufferIsUint32Ready () at ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c:73
#2  nrf5RandomInit () at ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c:173
#3  0x000198a0 in otSysInit () at ../../../../openthread/examples/platforms/nrf528xx/src/system.c:95
#4  0x00013404 in thread_init (p_config=0x2000222c <startupTaskStack+8092>) at /home/pawpys/git_projects/SKGE_3CE_I01_FW/FW_NRF_LIBS_/components/thread/utils/thread_utils.c:175

Target waits infinitely for some results. There is no timeout implemented so it doesn't return any meaningful errors.

 60│ ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c:
 61│    0x0001a1fe <+66>:    bl      0x1a130 <generatorStart>
 62│
 63│ 62      in ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c
 64│    0x0001a202 <+70>:    ldr     r3, [r0, #0]
 65│
 66│ 63      in ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c
 67├──> 0x0001a204 <+72>:    ldr     r2, [r1, #0]
 68│    0x0001a206 <+74>:    subs    r3, r3, r2
 69│
 70│ 171     in ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c
 71│ 172     in ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c
 72│ 173     in ../../../../openthread/examples/platforms/nrf528xx/src/entropy.c
 73│    0x0001a208 <+76>:    cmp     r3, #3
 74│    0x0001a20a <+78>:    bls.n   0x1a202 <nrf5RandomInit+70>

I am guessing it is fallowing code from entropy.c from Openthread implementation:

static inline uint32_t bufferCount(void)
{
    uint32_t writePos = sWritePosition;
    return writePos - sReadPosition;
}

static inline bool bufferIsUint32Ready(void)
{
    return (bufferCount() >= 4);
}

// Wait for the first randomized 4 bytes, to randomize software generator seed.
while (!bufferIsUint32Ready())
    ;
  
 static inline void bufferPut(uint8_t val)
{
    if (!bufferIsFull())
    {
        sBuffer[(sWritePosition++) % RNG_BUFFER_SIZE] = val;
    }
}
   
 void RNG_IRQHandler(void)
 {
     if (nrf_rng_event_get(NRF_RNG_EVENT_VALRDY) && nrf_rng_int_get(NRF_RNG_INT_VALRDY_MASK))
     {
         nrf_rng_event_clear(NRF_RNG_EVENT_VALRDY);

         bufferPut(nrf_rng_random_value_get());

         if (bufferIsFull())
         {
             generatorStop();
         }
     }
 }

which I think is caused by missing IRQ generated by RNG.

What am I missing or what is this tutorial possibly missing due to updated SDK to version T&Z 4.1.0 ?

Regardles of this issue I suggest implementing timeout on this function and return some error code in future releases.

Related