Skip to content

Commit 5065edb

Browse files
etienne-lmskartben
authored andcommitted
drivers: i2c: stm32: support more than 256 bytes transfer for RTIO
Add support for transfer of more than 256 byte in STM32 v1 and v2 RTIO drivers. Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
1 parent 616ec75 commit 5065edb

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

drivers/i2c/i2c_ll_stm32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ struct i2c_stm32_data {
7373
struct i2c_rtio *ctx;
7474
uint32_t dev_config;
7575
uint8_t *xfer_buf;
76-
uint8_t xfer_len;
76+
size_t xfer_len;
7777
uint8_t xfer_flags;
7878
#ifdef CONFIG_I2C_STM32_V1
79-
uint8_t msg_len;
79+
size_t msg_len;
8080
uint8_t is_restart;
8181
uint16_t slave_address;
8282
#endif /* CONFIG_I2C_STM32_V1 */

drivers/i2c/i2c_ll_stm32_v1_rtio.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,6 @@ int i2c_stm32_msg_start(const struct device *dev, uint8_t flags,
333333
data->is_restart = 0;
334334
data->slave_address = i2c_addr;
335335

336-
/* TODO deal with larger than 255 byte transfers correctly */
337-
if (buf_len > UINT8_MAX) {
338-
/* TODO LL_I2C_EnableReloadMode(i2c); */
339-
return -EINVAL;
340-
}
341-
342336
LL_I2C_Enable(i2c);
343337

344338
LL_I2C_DisableBitPOS(i2c);

drivers/i2c/i2c_ll_stm32_v2_rtio.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,29 @@ void i2c_stm32_event(const struct device *dev)
101101
LL_I2C_ClearFlag_STOP(i2c);
102102
LL_I2C_DisableReloadMode(i2c);
103103
i2c_stm32_master_mode_end(dev);
104+
105+
if (i2c_rtio_complete(ctx, ret)) {
106+
i2c_stm32_start(dev);
107+
return;
108+
}
104109
}
105110

106-
/* TODO handle the reload separately from complete */
107-
/* Transfer Complete or Transfer Complete Reload */
108111
if (LL_I2C_IsActiveFlag_TC(i2c) ||
109112
LL_I2C_IsActiveFlag_TCR(i2c)) {
113+
110114
/* Issue stop condition if necessary */
111-
/* TODO look at current sqe flags */
112115
if ((data->xfer_flags & I2C_MSG_STOP) != 0) {
113-
LL_I2C_GenerateStopCondition(i2c);
116+
if (data->xfer_len == 0) {
117+
LL_I2C_GenerateStopCondition(i2c);
118+
} else {
119+
LL_I2C_SetTransferSize(i2c, MIN(data->xfer_len, UINT8_MAX));
120+
}
114121
} else {
115122
i2c_stm32_disable_transfer_interrupts(dev);
116-
}
117123

118-
if ((data->xfer_len == 0) && i2c_rtio_complete(ctx, ret)) {
119-
i2c_stm32_start(dev);
124+
if ((data->xfer_len == 0) && i2c_rtio_complete(ctx, ret)) {
125+
i2c_stm32_start(dev);
126+
}
120127
}
121128
}
122129
}
@@ -162,12 +169,6 @@ int i2c_stm32_msg_start(const struct device *dev, uint8_t flags,
162169
transfer = LL_I2C_REQUEST_WRITE;
163170
}
164171

165-
/* TODO deal with larger than 255 byte transfers correctly */
166-
if (buf_len > UINT8_MAX) {
167-
/* TODO LL_I2C_EnableReloadMode(i2c); */
168-
return -EINVAL;
169-
}
170-
171172
if ((I2C_MSG_ADDR_10_BITS & flags) != 0) {
172173
LL_I2C_SetMasterAddressingMode(i2c,
173174
LL_I2C_ADDRESSING_MODE_10BIT);
@@ -178,9 +179,15 @@ int i2c_stm32_msg_start(const struct device *dev, uint8_t flags,
178179
LL_I2C_SetSlaveAddr(i2c, (uint32_t) i2c_addr << 1);
179180
}
180181

182+
if (buf_len > UINT8_MAX) {
183+
LL_I2C_EnableReloadMode(i2c);
184+
} else {
185+
LL_I2C_DisableReloadMode(i2c);
186+
}
187+
181188
LL_I2C_DisableAutoEndMode(i2c);
182189
LL_I2C_SetTransferRequest(i2c, transfer);
183-
LL_I2C_SetTransferSize(i2c, buf_len);
190+
LL_I2C_SetTransferSize(i2c, MIN(buf_len, UINT8_MAX));
184191

185192
LL_I2C_Enable(i2c);
186193

0 commit comments

Comments
 (0)