Skip to content

Commit 21d8242

Browse files
committed
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.
1 parent e30ca0e commit 21d8242

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

stmhal/i2c.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ void i2c_ev_irq_handler(mp_uint_t i2c_id) {
340340
return;
341341
}
342342

343+
#if defined(MCU_SERIES_F4)
344+
343345
if (hi2c->Instance->SR1 & I2C_FLAG_BTF && hi2c->State == HAL_I2C_STATE_BUSY_TX) {
344346
if (hi2c->XferCount != 0U) {
345347
hi2c->Instance->DR = *hi2c->pBuffPtr++;
@@ -353,6 +355,13 @@ void i2c_ev_irq_handler(mp_uint_t i2c_id) {
353355
hi2c->State = HAL_I2C_STATE_READY;
354356
}
355357
}
358+
359+
#else
360+
361+
// if not an F4 MCU, use the HAL's IRQ handler
362+
HAL_I2C_EV_IRQHandler(hi2c);
363+
364+
#endif
356365
}
357366

358367
void i2c_er_irq_handler(mp_uint_t i2c_id) {
@@ -378,6 +387,8 @@ void i2c_er_irq_handler(mp_uint_t i2c_id) {
378387
return;
379388
}
380389

390+
#if defined(MCU_SERIES_F4)
391+
381392
uint32_t sr1 = hi2c->Instance->SR1;
382393

383394
// I2C Bus error
@@ -404,6 +415,13 @@ void i2c_er_irq_handler(mp_uint_t i2c_id) {
404415
hi2c->ErrorCode |= HAL_I2C_ERROR_OVR;
405416
__HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_OVR);
406417
}
418+
419+
#else
420+
421+
// if not an F4 MCU, use the HAL's IRQ handler
422+
HAL_I2C_ER_IRQHandler(hi2c);
423+
424+
#endif
407425
}
408426

409427
STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t timeout) {

0 commit comments

Comments
 (0)