Skip to content

Commit 50d7ede

Browse files
committed
drivers: i2c_stm32_v2: Data cache fixup
Replace internal function testing for data inside non cached region by stm32_buf_in_nocache() Remove debug logs about flush/invalidate cache Signed-off-by: Erik Andersson <erian747@gmail.com>
1 parent 8b40bb1 commit 50d7ede

File tree

1 file changed

+2
-38
lines changed

1 file changed

+2
-38
lines changed

drivers/i2c/i2c_ll_stm32_v2.c

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,8 @@ static inline void dma_finish(const struct device *dev, struct i2c_msg *msg)
209209
dma_stop(cfg->rx_dma.dev_dma, cfg->rx_dma.dma_channel);
210210
LL_I2C_DisableDMAReq_RX(i2c);
211211
#if defined(CONFIG_DCACHE) && defined(CONFIG_I2C_STM32_V2_DMA)
212-
if (!buf_in_nocache((uintptr_t)msg->buf, msg->len) &&
212+
if (!stm32_buf_in_nocache((uintptr_t)msg->buf, msg->len) &&
213213
((msg->flags & I2C_MSG_RW_MASK) == I2C_MSG_READ)) {
214-
LOG_DBG("Rx buffer at %p (len %zu) is in cached memory; invalidating cache",
215-
msg->buf, msg->len);
216214
sys_cache_data_invd_range((void *)msg->buf, msg->len);
217215
}
218216
#endif /* CONFIG_DCACHE && CONFIG_I2C_STM32_V2_DMA */
@@ -643,38 +641,6 @@ int i2c_stm32_error(const struct device *dev)
643641
return -EIO;
644642
}
645643

646-
#if defined(CONFIG_DCACHE) && defined(CONFIG_I2C_STM32_V2_DMA)
647-
static bool buf_in_nocache(uintptr_t buf, size_t len_bytes)
648-
{
649-
bool buf_within_nocache = false;
650-
651-
#ifdef CONFIG_NOCACHE_MEMORY
652-
/* Check if buffer is in nocache region defined by the linker */
653-
buf_within_nocache = (buf >= ((uintptr_t)_nocache_ram_start)) &&
654-
((buf + len_bytes - 1) <= ((uintptr_t)_nocache_ram_end));
655-
if (buf_within_nocache) {
656-
return true;
657-
}
658-
#endif /* CONFIG_NOCACHE_MEMORY */
659-
660-
#ifdef CONFIG_MEM_ATTR
661-
/* Check if buffer is in nocache memory region defined in DT */
662-
buf_within_nocache = mem_attr_check_buf(
663-
(void *)buf, len_bytes, DT_MEM_ARM(ATTR_MPU_RAM_NOCACHE)) == 0;
664-
if (buf_within_nocache) {
665-
return true;
666-
}
667-
#endif /* CONFIG_MEM_ATTR */
668-
669-
/* Check if buffer is in RO region (Flash..) */
670-
buf_within_nocache = (buf >= ((uintptr_t)__rodata_region_start)) &&
671-
((buf + len_bytes - 1) <= ((uintptr_t)__rodata_region_end));
672-
673-
return buf_within_nocache;
674-
}
675-
#endif /* CONFIG_DCACHE && CONFIG_I2C_STM32_V2_DMA */
676-
677-
678644
static int stm32_i2c_irq_xfer(const struct device *dev, struct i2c_msg *msg,
679645
uint8_t *next_msg_flags, uint16_t slave)
680646
{
@@ -695,10 +661,8 @@ static int stm32_i2c_irq_xfer(const struct device *dev, struct i2c_msg *msg,
695661
#endif
696662

697663
#if defined(CONFIG_DCACHE) && defined(CONFIG_I2C_STM32_V2_DMA)
698-
if (!buf_in_nocache((uintptr_t)msg->buf, msg->len) &&
664+
if (!stm32_buf_in_nocache((uintptr_t)msg->buf, msg->len) &&
699665
((msg->flags & I2C_MSG_RW_MASK) == I2C_MSG_WRITE)) {
700-
LOG_DBG("Tx buffer at %p (len %zu) is in cached memory; cleaning cache", msg->buf,
701-
msg->len);
702666
sys_cache_data_flush_range((void *)msg->buf, msg->len);
703667
}
704668
#endif /* CONFIG_DCACHE && CONFIG_I2C_STM32_V2_DMA*/

0 commit comments

Comments
 (0)