From c2ff5d8d417c625abad9506b8ad91300e50dbb7c Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 15 Jun 2022 18:06:09 +0200 Subject: [PATCH 1/3] nmasic: always use 2000 retries --- src/driver/source/nmasic.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/driver/source/nmasic.c b/src/driver/source/nmasic.c index 91c0e5ae..9f463981 100644 --- a/src/driver/source/nmasic.c +++ b/src/driver/source/nmasic.c @@ -59,11 +59,7 @@ -#ifdef ARDUINO -#define TIMEOUT (2000) -#else -#define TIMEOUT (0xfffffffful) -#endif +#define TIMEOUT (2000) #define WAKUP_TRAILS_TIMEOUT (4) sint8 chip_apply_conf(uint32 u32Conf) From 05c83161d5ca93e3437e70a4fd32bcd3a158680a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 15 Jun 2022 14:01:42 +0200 Subject: [PATCH 2/3] nmasic: limit retries in wait_for_bootrom() If no device is connected or init failed, wait_for_bootrom() will be stuck in an infinite loop trying to get a result from nm_read_reg(). Place an upper limit on the number of retries so we can recover from this instead of being stuck here. --- src/driver/source/nmasic.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/driver/source/nmasic.c b/src/driver/source/nmasic.c index 9f463981..b77dc5a1 100644 --- a/src/driver/source/nmasic.c +++ b/src/driver/source/nmasic.c @@ -400,6 +400,7 @@ sint8 chip_reset(void) sint8 wait_for_bootrom(uint8 arg) { sint8 ret = M2M_SUCCESS; + uint16 retries = TIMEOUT; uint32 reg = 0, cnt = 0; uint32 u32GpReg1 = 0; uint32 u32DriverVerInfo = M2M_MAKE_VERSION_INFO(M2M_RELEASE_VERSION_MAJOR_NO,\ @@ -409,13 +410,19 @@ sint8 wait_for_bootrom(uint8 arg) reg = 0; - while(1) { + while(--retries) { reg = nm_read_reg(0x1014); /* wait for efuse loading done */ if (reg & 0x80000000) { break; } nm_bsp_sleep(1); /* TODO: Why bus error if this delay is not here. */ } + + /* communication with device failed */ + if(retries == 0) { + return M2M_ERR_INIT; + } + reg = nm_read_reg(M2M_WAIT_FOR_HOST_REG); reg &= 0x1; From 6416928abb8f3993101ad362d741fcc5e251fbec Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 15 Jun 2022 18:05:45 +0200 Subject: [PATCH 3/3] nmasic: limit retries in chip_apply_conf() --- src/driver/source/nmasic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/driver/source/nmasic.c b/src/driver/source/nmasic.c index b77dc5a1..bcc766d9 100644 --- a/src/driver/source/nmasic.c +++ b/src/driver/source/nmasic.c @@ -65,6 +65,7 @@ sint8 chip_apply_conf(uint32 u32Conf) { sint8 ret = M2M_SUCCESS; + uint16 retries = TIMEOUT; uint32 val32 = u32Conf; #if (defined __ENABLE_PMU__) || (defined CONF_WINC_INT_PMU) @@ -98,9 +99,9 @@ sint8 chip_apply_conf(uint32 u32Conf) } else { break; } - } while(1); + } while(--retries); - return M2M_SUCCESS; + return retries ? M2M_SUCCESS : M2M_ERR_TIME_OUT; } void chip_idle(void) {