diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.c index 1387714cc6..9378ac7e07 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.c +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.c @@ -369,6 +369,27 @@ int pin_instance_pwm(PinName pwm) return instance; } +/** + * Brief Find hardware instance for the provided PWM pin and free it + * + * Parameter pwm pwm pin. + * + * Return Nothing + */ +void pin_instance_pwm_free(PinName pwm) +{ + /* Search dynamic map for entry. */ + for (size_t index = 0; index < NORDIC_PWM_COUNT; index++) { + + /* Pins match previous dynamic allocation, return instance. */ + if (nordic_internal_pwm[index] == pwm) { + + nordic_internal_pwm[index] = NC; + break; + } + } +} + /*** * _ _ _____ _______ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.h index e80b8a5ec9..2cb5e0dc30 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.h +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.h @@ -120,6 +120,15 @@ int pin_instance_spi(PinName mosi, PinName miso, PinName clk); */ int pin_instance_pwm(PinName pwm); +/** + * Brief Find hardware instance for the provided PWM pin and free it + * + * Parameter pwm pwm pin. + * + * Return Nothing + */ +void pin_instance_pwm_free(PinName pwm); + /** * @brief Find hardware instance for the provided UART pins. * diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pwmout_api.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pwmout_api.c index 25b214a801..264fea81ae 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pwmout_api.c +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pwmout_api.c @@ -173,6 +173,9 @@ void pwmout_free(pwmout_t *obj) MBED_ASSERT(obj); + /* Also deinit the undelying PinMap_PWM entry */ + pin_instance_pwm_free(obj->pin); + /* Uninitialize PWM instance. */ nrfx_pwm_uninit(&nordic_nrf5_pwm_instance[obj->instance]); }