Skip to content

Commit

Permalink
[nrf fromlist] drivers: pwm: nrfx: adjust PWM driver to fast PWM120
Browse files Browse the repository at this point in the history
Fast PWM120 instance works with 320MHz clock, thus
pwm_nrfx_get_cycles_per_sec needs to be adjusted.
Also, it uses cachable RAM, thus sys_cache function
needs to be added to flush the cached sequence.

Upstream PR #: zephyrproject-rtos/zephyr#80672

Signed-off-by: Michał Stasiak <[email protected]>
  • Loading branch information
mstasiaknordic committed Oct 31, 2024
1 parent d59b845 commit d21262b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions drivers/pwm/pwm_nrfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ static int pwm_nrfx_set_cycles(const struct device *dev, uint32_t channel,
uint32_t period_cycles, uint32_t pulse_cycles,
pwm_flags_t flags)
{
/* We assume here that period_cycles will always be 16MHz
* peripheral clock. Since pwm_nrfx_get_cycles_per_sec() function might
* be removed, see ISSUE #6958.
* TODO: Remove this comment when issue has been resolved.
*/
const struct pwm_nrfx_config *config = dev->config;
struct pwm_nrfx_data *data = dev->data;
uint16_t compare_value;
Expand Down Expand Up @@ -176,6 +171,10 @@ static int pwm_nrfx_set_cycles(const struct device *dev, uint32_t channel,

seq_values_ptr_get(dev)[channel] = PWM_NRFX_CH_VALUE(compare_value, inverted);

#ifdef CONFIG_NRFX_PWM120
sys_cache_data_flush_range((void *)config->seq.values.p_raw, config->seq.length);
#endif

LOG_DBG("channel %u, pulse %u, period %u, prescaler: %u.",
channel, pulse_cycles, period_cycles, data->prescaler);

Expand Down Expand Up @@ -243,12 +242,11 @@ static int pwm_nrfx_set_cycles(const struct device *dev, uint32_t channel,
static int pwm_nrfx_get_cycles_per_sec(const struct device *dev, uint32_t channel,
uint64_t *cycles)
{
/* TODO: Since this function might be removed, we will always return
* 16MHz from this function and handle the conversion with prescaler,
* etc, in the pin set function. See issue #6958.
*/
#ifdef CONFIG_NRFX_PWM120
*cycles = 320ul * 1000ul * 1000ul;
#else
*cycles = 16ul * 1000ul * 1000ul;

#endif
return 0;
}

Expand Down

0 comments on commit d21262b

Please sign in to comment.