Skip to content

Commit a3e6302

Browse files
erian747jhedberg
authored andcommitted
drivers: i2c_stm32_v2: DMA fixup
Adapt DMA implementation to match changes introduced by new interrupt handler Signed-off-by: Erik Andersson <[email protected]>
1 parent b4aa7e7 commit a3e6302

File tree

1 file changed

+43
-64
lines changed

1 file changed

+43
-64
lines changed

drivers/i2c/i2c_ll_stm32_v2.c

Lines changed: 43 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -209,53 +209,6 @@ static void dma_finish(const struct device *dev, struct i2c_msg *msg)
209209

210210
#endif /* CONFIG_I2C_STM32_V2_DMA */
211211

212-
static inline void msg_init(const struct device *dev, struct i2c_msg *msg,
213-
uint8_t *next_msg_flags, uint16_t slave,
214-
uint32_t transfer)
215-
{
216-
const struct i2c_stm32_config *cfg = dev->config;
217-
struct i2c_stm32_data *data = dev->data;
218-
I2C_TypeDef *i2c = cfg->i2c;
219-
220-
if (LL_I2C_IsEnabledReloadMode(i2c)) {
221-
LL_I2C_SetTransferSize(i2c, msg->len);
222-
} else {
223-
if (I2C_ADDR_10_BITS & data->dev_config) {
224-
LL_I2C_SetMasterAddressingMode(i2c,
225-
LL_I2C_ADDRESSING_MODE_10BIT);
226-
LL_I2C_SetSlaveAddr(i2c, (uint32_t) slave);
227-
} else {
228-
LL_I2C_SetMasterAddressingMode(i2c,
229-
LL_I2C_ADDRESSING_MODE_7BIT);
230-
LL_I2C_SetSlaveAddr(i2c, (uint32_t) slave << 1);
231-
}
232-
233-
if (!(msg->flags & I2C_MSG_STOP) && next_msg_flags &&
234-
!(*next_msg_flags & I2C_MSG_RESTART)) {
235-
LL_I2C_EnableReloadMode(i2c);
236-
} else {
237-
LL_I2C_DisableReloadMode(i2c);
238-
}
239-
LL_I2C_DisableAutoEndMode(i2c);
240-
LL_I2C_SetTransferRequest(i2c, transfer);
241-
LL_I2C_SetTransferSize(i2c, msg->len);
242-
243-
#if defined(CONFIG_I2C_TARGET)
244-
data->master_active = true;
245-
#endif
246-
247-
#ifdef CONFIG_I2C_STM32_V2_DMA
248-
if (msg->len) {
249-
dma_xfer_start(dev, msg);
250-
}
251-
#endif /* CONFIG_I2C_STM32_V2_DMA */
252-
253-
LL_I2C_Enable(i2c);
254-
255-
LL_I2C_GenerateStartCondition(i2c);
256-
}
257-
}
258-
259212
#ifdef CONFIG_I2C_STM32_INTERRUPT
260213

261214
static void i2c_stm32_disable_transfer_interrupts(const struct device *dev)
@@ -829,15 +782,9 @@ static int stm32_i2c_irq_xfer(const struct device *dev, struct i2c_msg *msg,
829782
}
830783

831784
#ifdef CONFIG_I2C_STM32_V2_DMA
832-
if ((data->current.msg->flags & I2C_MSG_READ) != 0) {
833-
dma_stop(cfg->rx_dma.dev_dma, cfg->rx_dma.dma_channel);
834-
LL_I2C_DisableDMAReq_RX(regs);
835-
} else {
836-
dma_stop(cfg->tx_dma.dev_dma, cfg->tx_dma.dma_channel);
837-
LL_I2C_DisableDMAReq_TX(regs);
838-
}
839-
#endif /* CONFIG_I2C_STM32_V2_DMA */
840-
785+
/* Stop DMA and invalidate cache if needed */
786+
dma_finish(dev, msg);
787+
#endif
841788
/* Check for transfer errors or timeout */
842789
if (data->current.is_nack || data->current.is_arlo || is_timeout) {
843790
LL_I2C_Disable(regs);
@@ -857,14 +804,6 @@ static int stm32_i2c_irq_xfer(const struct device *dev, struct i2c_msg *msg,
857804
}
858805
#endif
859806
}
860-
#if defined(CONFIG_I2C_STM32_V2_DMA)
861-
if (!stm32_buf_in_nocache((uintptr_t)msg->buf, msg->len) &&
862-
((msg->flags & I2C_MSG_RW_MASK) == I2C_MSG_READ)) {
863-
LOG_DBG("Rx buffer at %p (len %zu) is in cached memory; invalidating cache",
864-
msg->buf, msg->len);
865-
sys_cache_data_invd_range(msg->buf, msg->len);
866-
}
867-
#endif /* CONFIG_I2C_STM32_V2_DMA */
868807

869808
return 0;
870809

@@ -929,6 +868,46 @@ static inline int check_errors(const struct device *dev, const char *funcname)
929868
return -EIO;
930869
}
931870

871+
static inline void msg_init(const struct device *dev, struct i2c_msg *msg,
872+
uint8_t *next_msg_flags, uint16_t slave,
873+
uint32_t transfer)
874+
{
875+
const struct i2c_stm32_config *cfg = dev->config;
876+
struct i2c_stm32_data *data = dev->data;
877+
I2C_TypeDef *i2c = cfg->i2c;
878+
879+
if (LL_I2C_IsEnabledReloadMode(i2c)) {
880+
LL_I2C_SetTransferSize(i2c, msg->len);
881+
} else {
882+
if (I2C_ADDR_10_BITS & data->dev_config) {
883+
LL_I2C_SetMasterAddressingMode(i2c,
884+
LL_I2C_ADDRESSING_MODE_10BIT);
885+
LL_I2C_SetSlaveAddr(i2c, (uint32_t) slave);
886+
} else {
887+
LL_I2C_SetMasterAddressingMode(i2c,
888+
LL_I2C_ADDRESSING_MODE_7BIT);
889+
LL_I2C_SetSlaveAddr(i2c, (uint32_t) slave << 1);
890+
}
891+
892+
if (!(msg->flags & I2C_MSG_STOP) && next_msg_flags &&
893+
!(*next_msg_flags & I2C_MSG_RESTART)) {
894+
LL_I2C_EnableReloadMode(i2c);
895+
} else {
896+
LL_I2C_DisableReloadMode(i2c);
897+
}
898+
LL_I2C_DisableAutoEndMode(i2c);
899+
LL_I2C_SetTransferRequest(i2c, transfer);
900+
LL_I2C_SetTransferSize(i2c, msg->len);
901+
902+
#if defined(CONFIG_I2C_TARGET)
903+
data->master_active = true;
904+
#endif
905+
LL_I2C_Enable(i2c);
906+
907+
LL_I2C_GenerateStartCondition(i2c);
908+
}
909+
}
910+
932911
static inline int msg_done(const struct device *dev,
933912
unsigned int current_msg_flags)
934913
{

0 commit comments

Comments
 (0)