I accidentally pressed "verified" on https://devzone.nordicsemi.com/f/nordic-q-a/91104/making-rand-work-on-nrf52-nrf53-with-nrf-connect-sdk when it wasn't and I don't seem to be able to un-press "verified", so here is a follow-up question:
We have an NRFConnect SDK/Zephyr project that must (a) compile both for NRF52840 and NRF5340, and, (b) needs a working rand(); nothing fancy, pseudo-random would be perfectly fine, preferable in fact since this is only used in test code and it would be good to have the sequences repeatable. As instructed by the replies to the support ticket above, we have the following lines in KConfig:
CONFIG_ENTROPY_GENERATOR=y
CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR=y
CONFIG_ENTROPY_CC3XX=y
However, though we get no KConfig errors, both NRF52 and NRF53 crash inside rand() with this setting, see below. What KConfig setting(s) are we missing? How do we end up with a single prj.conf file that will give us a plain-old pseudo-random rand() on both platforms?
NRF53 does this:
2022-08-20 12:31:32.242 U_GNSS_PRIVATE_TEST: test decoding NMEA message $GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76
2022-08-20 12:31:49.932 E: ***** MPU FAULT *****
2022-08-20 12:31:49.950 E: Data Access Violation
2022-08-20 12:31:49.966 E: MMFAR Address: 0xc
2022-08-20 12:31:49.981 E: r0/a1: 0x200057b0 r1/a2: 0x00000000 r2/a3: 0x200015e8
2022-08-20 12:31:49.998 E: r3/a4: 0x200015e8 r12/ip: 0x00000000 r14/lr: 0x000459ed
2022-08-20 12:31:50.013 E: xpsr: 0x29000000
2022-08-20 12:31:50.029 E: r4/v1: 0x00000000 r5/v2: 0xffffffff r6/v3: 0xffffffff
2022-08-20 12:31:50.044 E: r7/v4: 0x00000000 r8/v5: 0x00000000 r9/v6: 0x2002a6c1
2022-08-20 12:31:50.060 E: r10/v7: 0x200051ec r11/v8: 0xffffffff psp: 0x2002a580
2022-08-20 12:31:50.075 E: EXC_RETURN: 0xfffffffd
2022-08-20 12:31:50.090 E: Faulting instruction address (r15/pc): 0x000459ec
2022-08-20 12:31:50.107 E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
2022-08-20 12:31:50.121 E: Current thread: 0x200015e8 (main)
2022-08-20 12:31:50.137 ### Dumping current thread (main) ###
2022-08-20 12:31:50.153 0x000459ec: z_impl_k_mutex_lock /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/kernel/mutex.c:107
2022-08-20 12:31:50.169 0x000459e8: k_spin_lock /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/include/spinlock.h:141
2022-08-20 12:31:50.184 (inlined by) z_impl_k_mutex_lock /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/kernel/mutex.c:105
2022-08-20 12:31:50.200 0x00032586: k_mutex_lock /home/jenkinsslave-mlm/jenkins_workspace/workspace/iv_feature_gnss_transparent_rmea_4/_jenkins_work/17/build/zephyr/include/generated/syscalls/kernel.h:674
2022-08-20 12:31:50.215 (inlined by) mutex_lock_platform /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/nrfxlib/crypto/nrf_cc312_platform/src/nrf_cc3xx_platform_mutex_zephyr.c:291
2022-08-20 12:31:50.229 0x0004dae2: cc_mbedtls_ctr_drbg_random_with_add ??:?
2022-08-20 12:31:50.246 0x0004c4e6: nrf_cc3xx_platform_ctr_drbg_get ??:?
2022-08-20 12:31:50.262 0x0003e984: entropy_cc3xx_rng_get_entropy /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/nrf/drivers/entropy/entropy_cc310.c:77
2022-08-20 12:31:50.278 0x0003b8a8: z_impl_entropy_get_entropy /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/include/drivers/entropy.h:77
2022-08-20 12:31:50.294 (inlined by) entropy_get_entropy /home/jenkinsslave-mlm/jenkins_workspace/workspace/iv_feature_gnss_transparent_rmea_4/_jenkins_work/17/build/zephyr/include/generated/syscalls/entropy.h:33
2022-08-20 12:31:50.310 (inlined by) z_impl_sys_rand32_get /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/subsys/random/rand32_entropy_device.c:33
2022-08-20 12:31:50.326 0x00056c24: sys_rand32_get /home/jenkinsslave-mlm/jenkins_workspace/workspace/iv_feature_gnss_transparent_rmea_4/_jenkins_work/17/build/zephyr/include/generated/syscalls/rand32.h:33
2022-08-20 12:31:50.341 (inlined by) rand port/platform/zephyr/src/u_port_clib.c:81
2022-08-20 12:35:39 u_monitor_15.1 - U_GNSS_PRIVATE_TEST: test decoding NMEA message $GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76
2022-08-20 12:35:57 u_monitor_15.1 - 0x0005604c: z_impl_k_mutex_lock /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/kernel/mutex.c:107
2022-08-20 12:35:57 u_monitor_15.1 - 0x00056048: k_spin_lock /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/include/spinlock.h:141
2022-08-20 12:35:57 u_monitor_15.1 - (inlined by) z_impl_k_mutex_lock /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/kernel/mutex.c:105
2022-08-20 12:35:57 u_monitor_15.1 - 0x00046b34: k_mutex_lock /var/jenkins/workspace/iv_feature_gnss_transparent_rmea_2/_jenkins_work/15.1/build/zephyr/include/generated/syscalls/kernel.h:674
2022-08-20 12:35:57 u_monitor_15.1 - (inlined by) mutex_lock_platform /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/nrfxlib/crypto/nrf_cc310_platform/src/nrf_cc3xx_platform_mutex_zephyr.c:291
2022-08-20 12:35:57 u_monitor_15.1 - 0x0004f800: entropy_cc3xx_rng_get_entropy /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/nrf/drivers/entropy/entropy_cc310.c:77
2022-08-20 12:35:57 u_monitor_15.1 - 0x0004c984: z_impl_entropy_get_entropy /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/include/drivers/entropy.h:77
2022-08-20 12:35:57 u_monitor_15.1 - (inlined by) entropy_get_entropy /var/jenkins/workspace/iv_feature_gnss_transparent_rmea_2/_jenkins_work/15.1/build/zephyr/include/generated/syscalls/entropy.h:33
2022-08-20 12:35:57 u_monitor_15.1 - (inlined by) z_impl_sys_rand32_get /home/ubxlib/.ubxlibpkg/nrfconnectsdk-v1.6.1/zephyr/subsys/random/rand32_entropy_device.c:33
2022-08-20 12:35:57 u_monitor_15.1 - 0x000668f2: sys_rand32_get /var/jenkins/workspace/iv_feature_gnss_transparent_rmea_2/_jenkins_work/15.1/build/zephyr/include/generated/syscalls/rand32.h:33