Skip to content

nRF52: clean pwm structures on deinit #14230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}


/***
* _ _ _____ _______
Expand Down
9 changes: 9 additions & 0 deletions targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pinmap_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/pwmout_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down