10000 stmhal/i2c: Clean the cache so that I2C DMA works on F7 MCUs. · danicampora/micropython-esp32-1@2460888 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2460888

Browse files
committed
stmhal/i2c: Clean the cache so that I2C DMA works on F7 MCUs.
1 parent aa7de3f commit 2460888

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

stmhal/i2c.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,14 @@ STATIC mp_obj_t pyb_i2c_send(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
760760
if (!use_dma) {
761761
status = HAL_I2C_Master_Transmit(self->i2c, i2c_addr, bufinfo.buf, bufinfo.len, args[2].u_int);
762762
} else {
763+
MP_HAL_CLEAN_DCACHE(bufinfo.buf, bufinfo.len);
763764
status = HAL_I2C_Master_Transmit_DMA(self->i2c, i2c_addr, bufinfo.buf, bufinfo.len);
764765
}
765766
} else {
766767
if (!use_dma) {
767768
status = HAL_I2C_Slave_Transmit(self->i2c, bufinfo.buf, bufinfo.len, args[2].u_int);
768769
} else {
770+
MP_HAL_CLEAN_DCACHE(bufinfo.buf, bufinfo.len);
769771
status = HAL_I2C_Slave_Transmit_DMA(self->i2c, bufinfo.buf, bufinfo.len);
770772
}
771773
}
@@ -834,12 +836,14 @@ STATIC mp_obj_t pyb_i2c_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
834836
if (!use_dma) {
835837
status = HAL_I2C_Master_Receive(self->i2c, i2c_addr, (uint8_t*)vstr.buf, vstr.len, args[2].u_int);
836838
} else {
839+
MP_HAL_CLEANINVALIDATE_DCACHE(vstr.buf, vstr.len);
837840
status = HAL_I2C_Master_Receive_DMA(self->i2c, i2c_addr, (uint8_t*)vstr.buf, vstr.len);
838841
}
839842
} else {
840843
if (!use_dma) {
841844
status = HAL_I2C_Slave_Receive(self->i2c, (uint8_t*)vstr.buf, vstr.len, args[2].u_int);
842845
} else {
846+
MP_HAL_CLEANINVALIDATE_DCACHE(vstr.buf, vstr.len);
843847
status = HAL_I2C_Slave_Receive_DMA(self->i2c, (uint8_t*)vstr.buf, vstr.len);
844848
}
845849
}
@@ -920,6 +924,7 @@ STATIC mp_obj_t pyb_i2c_mem_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp_
920924
dma_init(&rx_dma, self->rx_dma_descr, self->i2c);
921925
self->i2c->hdmatx = NULL;
922926
self->i2c->hdmarx = &rx_dma;
927+
MP_HAL_CLEANINVALIDATE_DCACHE(vstr.buf, vstr.len);
923928
status = HAL_I2C_Mem_Read_DMA(self->i2c, i2c_addr, mem_addr, mem_addr_size, (uint8_t*)vstr.buf, vstr.len);
924929
if (status == HAL_OK) {
925930
status = i2c_wait_dma_finished(self->i2c, args[3].u_int);
@@ -988,6 +993,7 @@ STATIC mp_obj_t pyb_i2c_mem_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp
988993
dma_init(&tx_dma, self->tx_dma_descr, self->i2c);
989994
self->i2c->hdmatx = &tx_dma;
990995
self->i2c->hdmarx = NULL;
996+
MP_HAL_CLEAN_DCACHE(bufinfo.buf, bufinfo.len);
991997
status = HAL_I2C_Mem_Write_DMA(self->i2c, i2c_addr, mem_addr, mem_addr_size, bufinfo.buf, bufinfo.len);
992998
if (status == HAL_OK) {
993999
status = i2c_wait_dma_finished(self->i2c, args[3].u_int);

stmhal/mphalport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#define MP_HAL_CLEAN_DCACHE(addr, size)
1111
#elif defined(MCU_SERIES_F7)
1212
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420)
13-
#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) (SCB_CleanInvalidateDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
14-
#define MP_HAL_CLEAN_DCACHE(addr, size) (SCB_CleanDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
13+
#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) (SCB_CleanInvalidateDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)((uint8_t*)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
14+
#define MP_HAL_CLEAN_DCACHE(addr, size) (SCB_CleanDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)((uint8_t*)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
1515
#elif defined(MCU_SERIES_L4)
1616
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1fff7590)
1717
#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size)

0 commit comments

Comments
 (0)
0