8000 stm32/pyb_i2c: Fix pyb.I2C to work with dma=True on F4 MCUs. · lowfatcode/micropython@da50827 · GitHub
[go: up one dir, main page]

Skip to content

Commit da50827

Browse files
yn386dpgeorge
authored andcommitted
stm32/pyb_i2c: Fix pyb.I2C to work with dma=True on F4 MCUs.
Prior to this commit, excuting this code: i2c = I2C(1, I2C.CONTROLLER, dma=True) i2c.send(data, addr=i2c_addr) the call to i2c.send() does not return and the board needs a reset. This code works when dma=False. According to the specification, I2Cx_EV_IRQHandler should: - Write DR to address when Start condition generated. - Clear ADDR by reading SR2 after reading SR2 when address sent. These processes are included in HAL_I2C_EV_IRQHandler(), however the firmware size increses about 2KB if HAL_I2C_EV_IRQHandler is called. This commit adds above processes to i2c_ev_irq_handler, and increases firmware by less than 100 bytes. Fixes issue micropython#2643.
1 parent 8770cd2 commit da50827

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ports/stm32/pyb_i2c.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,17 @@ void i2c_ev_irq_handler(mp_uint_t i2c_id) {
472472

473473
#if defined(STM32F4)
474474

475-
if (hi2c->Instance->SR1 & I2C_FLAG_BTF && hi2c->State == HAL_I2C_STATE_BUSY_TX) {
475+
if (hi2c->Instance->SR1 & I2C_FLAG_SB) {
476+
if (hi2c->State == HAL_I2C_STATE_BUSY_TX) {
477+
hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(hi2c->Devaddress);
478+
} else {
479+
hi2c->Instance->DR = I2C_7BIT_ADD_READ(hi2c->Devaddress);
480+
}
481+
} else if (hi2c->Instance->SR1 & I2C_FLAG_ADDR) {
482+
__IO uint32_t tmp_sr2;
483+
tmp_sr2 = hi2c->Instance->SR2;
484+
UNUSED(tmp_sr2);
485+
} else if (hi2c->Instance->SR1 & I2C_FLAG_BTF && hi2c->State == HAL_I2C_STATE_BUSY_TX) {
476486
if (hi2c->XferCount != 0U) {
477487
hi2c->Instance->DR = *hi2c->pBuffPtr++;
478488
hi2c->XferCount--;

0 commit comments

Comments
 (0)
0