diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/i2c_api.c b/targets/TARGET_NUVOTON/TARGET_M2354/i2c_api.c index 65a9553adbf..0009905b025 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2354/i2c_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M2354/i2c_api.c @@ -441,13 +441,13 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) case 0x08: // Start case 0x10: // Master Repeat Start if (i2c_ctl & I2C_CTL0_STA_Msk) { - return 0; + goto cleanup; } else { break; } case 0xF8: // Bus Released if ((i2c_ctl & (I2C_CTL0_STA_Msk | I2C_CTL0_STO_Msk)) == I2C_CTL0_STO_Msk) { - return 0; + goto cleanup; } else { break; } @@ -458,6 +458,8 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) } } +cleanup: + i2c_enable_int(obj); return err; diff --git a/targets/TARGET_NUVOTON/TARGET_M251/i2c_api.c b/targets/TARGET_NUVOTON/TARGET_M251/i2c_api.c index b07e088742a..e0ea4152717 100644 --- a/targets/TARGET_NUVOTON/TARGET_M251/i2c_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M251/i2c_api.c @@ -425,13 +425,13 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) case 0x08: // Start case 0x10: // Master Repeat Start if (i2c_ctl & I2C_CTL0_STA_Msk) { - return 0; + goto cleanup; } else { break; } case 0xF8: // Bus Released if ((i2c_ctl & (I2C_CTL0_STA_Msk | I2C_CTL0_STO_Msk)) == I2C_CTL0_STO_Msk) { - return 0; + goto cleanup; } else { break; } @@ -442,6 +442,8 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) } } +cleanup: + i2c_enable_int(obj); return err; diff --git a/targets/TARGET_NUVOTON/TARGET_M261/i2c_api.c b/targets/TARGET_NUVOTON/TARGET_M261/i2c_api.c index 16b5a445ecf..4e1752fd29c 100644 --- a/targets/TARGET_NUVOTON/TARGET_M261/i2c_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M261/i2c_api.c @@ -430,13 +430,13 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) case 0x08: // Start case 0x10: // Master Repeat Start if (i2c_ctl & I2C_CTL0_STA_Msk) { - return 0; + goto cleanup; } else { break; } case 0xF8: // Bus Released if ((i2c_ctl & (I2C_CTL0_STA_Msk | I2C_CTL0_STO_Msk)) == I2C_CTL0_STO_Msk) { - return 0; + goto cleanup; } else { break; } @@ -447,6 +447,8 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) } } +cleanup: + i2c_enable_int(obj); return err; diff --git a/targets/TARGET_NUVOTON/TARGET_M451/i2c_api.c b/targets/TARGET_NUVOTON/TARGET_M451/i2c_api.c index d9de137fd10..452131c791c 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/i2c_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/i2c_api.c @@ -448,14 +448,14 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) case 0x08: // Start case 0x10: // Master Repeat Start if (i2c_ctl & I2C_CTL_STA_Msk) { - return 0; + goto cleanup; } else { break; } case 0xF8: // Bus Released if (i2c_ctl & (I2C_CTL_STA_Msk | I2C_CTL_STO_Msk) == I2C_CTL_STO_Msk) { - return 0; + goto cleanup; } else { break; @@ -472,8 +472,10 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) } } +cleanup: + i2c_enable_int(obj); - + return err; } diff --git a/targets/TARGET_NUVOTON/TARGET_M480/i2c_api.c b/targets/TARGET_NUVOTON/TARGET_M480/i2c_api.c index 66dae37473f..8fa211e190b 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/i2c_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/i2c_api.c @@ -432,13 +432,13 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) case 0x08: // Start case 0x10: // Master Repeat Start if (i2c_ctl & I2C_CTL0_STA_Msk) { - return 0; + goto cleanup; } else { break; } case 0xF8: // Bus Released if ((i2c_ctl & (I2C_CTL0_STA_Msk | I2C_CTL0_STO_Msk)) == I2C_CTL0_STO_Msk) { - return 0; + goto cleanup; } else { break; } @@ -449,6 +449,8 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) } } +cleanup: + i2c_enable_int(obj); return err; diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/i2c_api.c b/targets/TARGET_NUVOTON/TARGET_NANO100/i2c_api.c index bf26483d1e1..72aa9cda7a1 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/i2c_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/i2c_api.c @@ -468,14 +468,14 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) case 0x08: // Start case 0x10: // Master Repeat Start if (i2c_ctl & I2C_CON_START_Msk) { - return 0; + goto cleanup; } else { break; } case 0xF8: // Bus Released if ((i2c_ctl & (I2C_CON_START_Msk | I2C_CON_STOP_Msk)) == I2C_CON_STOP_Msk) { - return 0; + goto cleanup; } else { break; @@ -492,8 +492,10 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) } } +cleanup: + i2c_enable_int(obj); - + return err; } diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/i2c_api.c b/targets/TARGET_NUVOTON/TARGET_NUC472/i2c_api.c index f9e2b96c567..e88835cc65e 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/i2c_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/i2c_api.c @@ -465,14 +465,14 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) case 0x08: // Start case 0x10: // Master Repeat Start if (i2c_ctl & I2C_CTL_STA_Msk) { - return 0; + goto cleanup; } else { break; } case 0xF8: // Bus Released if (i2c_ctl & (I2C_CTL_STA_Msk | I2C_CTL_STO_Msk) == I2C_CTL_STO_Msk) { - return 0; + goto cleanup; } else { break; @@ -489,8 +489,10 @@ static int i2c_do_trsn(i2c_t *obj, uint32_t i2c_ctl, int sync) } } +cleanup: + i2c_enable_int(obj); - + return err; }