-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy path0070-rp2040-Fix-I2CSlave-synchronization-issue-by-adding-.patch
46 lines (40 loc) · 1.63 KB
/
0070-rp2040-Fix-I2CSlave-synchronization-issue-by-adding-.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From cd48fa6a9e18f30d582647e960dd285a1e193ae9 Mon Sep 17 00:00:00 2001
From: giulcioffi <g.cioffi@arduino.cc>
Date: Thu, 7 Oct 2021 18:11:59 +0200
Subject: [PATCH 070/204] rp2040: Fix I2CSlave synchronization issue by adding
a timeout for the read
---
.../TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c b/targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c
index 2b776562a1..ec52728f63 100644
--- a/targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c
+++ b/targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c
@@ -24,6 +24,8 @@
#define WriteGeneral 2 // the master is writing to all slave
#define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
+#define BYTE_TIMEOUT_US ((SystemCoreClock / obj->baudrate) * 3 * 10)
+
/******************************************************************************
* CONST
******************************************************************************/
@@ -193,7 +195,18 @@ int i2c_slave_receive(i2c_t *obj)
*/
int i2c_slave_read(i2c_t *obj, char *data, int length)
{
- size_t read_len = i2c_read_raw_blocking(obj->dev, (uint8_t *)data, length);
+ int read_len = 0;
+
+ int timeout = 120 * (length + 1);
+ while (!i2c_get_read_available(obj->dev)) {
+ tight_loop_contents();
+ }
+ while (--timeout != 0) {
+ if (i2c_get_read_available(obj->dev)) {
+ data[read_len++] = i2c_get_hw(obj->dev)->data_cmd;
+ }
+ wait_us(1);
+ }
DEBUG_PRINTF("i2c_slave read %d bytes\r\n", read_len);
--
2.39.1