Skip to content

Commit 058c882

Browse files
authored
Merge pull request #18214 from benpicco/drivers/atwinc15x0-timeout
drivers/atwinc15x0: add timeout to init
2 parents 55b57e1 + 9c8fa57 commit 058c882

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From 9664046ab3fb2355fc3058bef90cc8727a67730b Mon Sep 17 00:00:00 2001
2+
From: Benjamin Valentin <benjamin.valentin@ml-pa.com>
3+
Date: Wed, 15 Jun 2022 18:06:09 +0200
4+
Subject: [PATCH 1/3] nmasic: always use 2000 retries
5+
6+
---
7+
src/driver/source/nmasic.c | 6 +-----
8+
1 file changed, 1 insertion(+), 5 deletions(-)
9+
10+
diff --git a/src/driver/source/nmasic.c b/src/driver/source/nmasic.c
11+
index 91c0e5a..9f46398 100644
12+
--- a/src/driver/source/nmasic.c
13+
+++ b/src/driver/source/nmasic.c
14+
@@ -59,11 +59,7 @@
15+
16+
17+
18+
-#ifdef ARDUINO
19+
-#define TIMEOUT (2000)
20+
-#else
21+
-#define TIMEOUT (0xfffffffful)
22+
-#endif
23+
+#define TIMEOUT (2000)
24+
#define WAKUP_TRAILS_TIMEOUT (4)
25+
26+
sint8 chip_apply_conf(uint32 u32Conf)
27+
--
28+
2.34.1
29+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
From 142506c9ed4e2d3a1c59cf39cd86473074981c6a Mon Sep 17 00:00:00 2001
2+
From: Benjamin Valentin <benjamin.valentin@ml-pa.com>
3+
Date: Wed, 15 Jun 2022 14:01:42 +0200
4+
Subject: [PATCH 2/3] nmasic: limit retries in wait_for_bootrom()
5+
6+
If no device is connected or init failed, wait_for_bootrom() will
7+
be stuck in an infinite loop trying to get a result from nm_read_reg().
8+
9+
Place an upper limit on the number of retries so we can recover from
10+
this instead of being stuck here.
11+
---
12+
src/driver/source/nmasic.c | 9 ++++++++-
13+
1 file changed, 8 insertions(+), 1 deletion(-)
14+
15+
diff --git a/src/driver/source/nmasic.c b/src/driver/source/nmasic.c
16+
index 9f46398..b77dc5a 100644
17+
--- a/src/driver/source/nmasic.c
18+
+++ b/src/driver/source/nmasic.c
19+
@@ -400,6 +400,7 @@ sint8 chip_reset(void)
20+
sint8 wait_for_bootrom(uint8 arg)
21+
{
22+
sint8 ret = M2M_SUCCESS;
23+
+ uint16 retries = TIMEOUT;
24+
uint32 reg = 0, cnt = 0;
25+
uint32 u32GpReg1 = 0;
26+
uint32 u32DriverVerInfo = M2M_MAKE_VERSION_INFO(M2M_RELEASE_VERSION_MAJOR_NO,\
27+
@@ -409,13 +410,19 @@ sint8 wait_for_bootrom(uint8 arg)
28+
29+
30+
reg = 0;
31+
- while(1) {
32+
+ while(--retries) {
33+
reg = nm_read_reg(0x1014); /* wait for efuse loading done */
34+
if (reg & 0x80000000) {
35+
break;
36+
}
37+
nm_bsp_sleep(1); /* TODO: Why bus error if this delay is not here. */
38+
}
39+
+
40+
+ /* communication with device failed */
41+
+ if(retries == 0) {
42+
+ return M2M_ERR_INIT;
43+
+ }
44+
+
45+
reg = nm_read_reg(M2M_WAIT_FOR_HOST_REG);
46+
reg &= 0x1;
47+
48+
--
49+
2.34.1
50+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
From c1efd943abeb7ddf643bdb0849d1d70ae748ac5d Mon Sep 17 00:00:00 2001
2+
From: Benjamin Valentin <benjamin.valentin@ml-pa.com>
3+
Date: Wed, 15 Jun 2022 18:05:45 +0200
4+
Subject: [PATCH 3/3] nmasic: limit retries in chip_apply_conf()
5+
6+
---
7+
src/driver/source/nmasic.c | 5 +++--
8+
1 file changed, 3 insertions(+), 2 deletions(-)
9+
10+
diff --git a/src/driver/source/nmasic.c b/src/driver/source/nmasic.c
11+
index b77dc5a..bcc766d 100644
12+
--- a/src/driver/source/nmasic.c
13+
+++ b/src/driver/source/nmasic.c
14+
@@ -65,6 +65,7 @@
15+
sint8 chip_apply_conf(uint32 u32Conf)
16+
{
17+
sint8 ret = M2M_SUCCESS;
18+
+ uint16 retries = TIMEOUT;
19+
uint32 val32 = u32Conf;
20+
21+
#if (defined __ENABLE_PMU__) || (defined CONF_WINC_INT_PMU)
22+
@@ -98,9 +99,9 @@ sint8 chip_apply_conf(uint32 u32Conf)
23+
} else {
24+
break;
25+
}
26+
- } while(1);
27+
+ } while(--retries);
28+
29+
- return M2M_SUCCESS;
30+
+ return retries ? M2M_SUCCESS : M2M_ERR_TIME_OUT;
31+
}
32+
void chip_idle(void)
33+
{
34+
--
35+
2.34.1
36+

0 commit comments

Comments
 (0)