From eed135228289a8059d5908ce2ee56865c2d7bbfe Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 13 Apr 2014 14:06:10 +0100 Subject: [PATCH] Fix CC2538 random_init lockup Contiki sometimes fails to boot correctly and locks up in random_init() This problem only manifests itself for specific versions of the arm-gcc toolchain and then again only for specific levels of optimisation (-Os vs -O2, depending on the value of the SMALL make variable) The lockup is caused when we write an RFCORE XREG before the RF clock ungating has taken effect, which in turn only occurs depending on the assembly generated for those two instructions: REG(SYS_CTRL_RCGCRFC) = 1; REG(RFCORE_XREG_FRMCTRL0) = 0x00000008; This commit makes the RNG wait for the ungating to take effect before attempting to write the register --- cpu/cc2538/dev/random.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpu/cc2538/dev/random.c b/cpu/cc2538/dev/random.c index a4ef7c03a..8c955aa8a 100644 --- a/cpu/cc2538/dev/random.c +++ b/cpu/cc2538/dev/random.c @@ -92,6 +92,9 @@ random_init(unsigned short seed) /* Enable clock for the RF Core */ REG(SYS_CTRL_RCGCRFC) = 1; + /* Wait for the clock ungating to take effect */ + while(REG(SYS_CTRL_RCGCRFC) != 1); + /* Infinite RX - FRMCTRL0[3:2] = 10 * This will mess with radio operation - see note above */ REG(RFCORE_XREG_FRMCTRL0) = 0x00000008;