diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/i2c_api.c b/targets/TARGET_NUVOTON/TARGET_M2354/i2c_api.c index 65a9553adb..0009905b02 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 b07e088742..e0ea415271 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 16b5a445ec..4e1752fd29 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 d9de137fd1..452131c791 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 66dae37473..8fa211e190 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 bf26483d1e..72aa9cda7a 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 f9e2b96c56..e88835cc65 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; }