From 21d82421cd7b3a3f74850cffaf84646ff49a04f2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 21 Nov 2016 16:12:09 +1100 Subject: [PATCH] stmhal/i2c: Use the HAL's I2C IRQ handler for F7 and L4 MCUs. The custom IRQ handler only works for F4 MCUs, which have the SR1 register. --- stmhal/i2c.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 17557a46e5..6146419a91 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -340,6 +340,8 @@ void i2c_ev_irq_handler(mp_uint_t i2c_id) { return; } + #if defined(MCU_SERIES_F4) + if (hi2c->Instance->SR1 & I2C_FLAG_BTF && hi2c->State == HAL_I2C_STATE_BUSY_TX) { if (hi2c->XferCount != 0U) { hi2c->Instance->DR = *hi2c->pBuffPtr++; @@ -353,6 +355,13 @@ void i2c_ev_irq_handler(mp_uint_t i2c_id) { hi2c->State = HAL_I2C_STATE_READY; } } + + #else + + // if not an F4 MCU, use the HAL's IRQ handler + HAL_I2C_EV_IRQHandler(hi2c); + + #endif } void i2c_er_irq_handler(mp_uint_t i2c_id) { @@ -378,6 +387,8 @@ void i2c_er_irq_handler(mp_uint_t i2c_id) { return; } + #if defined(MCU_SERIES_F4) + uint32_t sr1 = hi2c->Instance->SR1; // I2C Bus error @@ -404,6 +415,13 @@ void i2c_er_irq_handler(mp_uint_t i2c_id) { hi2c->ErrorCode |= HAL_I2C_ERROR_OVR; __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_OVR); } + + #else + + // if not an F4 MCU, use the HAL's IRQ handler + HAL_I2C_ER_IRQHandler(hi2c); + + #endif } STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t timeout) {