Skip to content

Fix pico-sdk PWM initialisation #30

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 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ static inline void pwm_config_set_wrap(pwm_config *c, uint16_t wrap) {
c->top = wrap;
}

static inline void pwm_set_chan_level(uint slice_num, uint chan, uint16_t level);

/** \brief Initialise a PWM with settings from a configuration object
* \ingroup hardware_pwm
*
Expand All @@ -188,12 +190,12 @@ static inline void pwm_config_set_wrap(pwm_config *c, uint16_t wrap) {
* \param start If true the PWM will be started running once configured. If false you will need to start
* manually using \ref pwm_set_enabled() or \ref pwm_set_mask_enabled()
*/
static inline void pwm_init(uint slice_num, pwm_config *c, bool start) {
static inline void pwm_init(uint slice_num, uint chan, pwm_config *c, bool start) {
check_slice_num_param(slice_num);
pwm_hw->slice[slice_num].csr = 0;

pwm_hw->slice[slice_num].ctr = PWM_CH0_CTR_RESET;
pwm_hw->slice[slice_num].cc = PWM_CH0_CC_RESET;
pwm_set_chan_level(slice_num, chan, PWM_CH0_CC_A_RESET);
pwm_hw->slice[slice_num].top = c->top;
pwm_hw->slice[slice_num].div = c->div;
pwm_hw->slice[slice_num].csr = c->csr | (bool_to_bit(start) << PWM_CH0_CSR_EN_LSB);
Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_RASPBERRYPI/TARGET_RP2040/pwmout_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void pwmout_init(pwmout_t *obj, PinName pin)
obj->cfg = pwm_get_default_config();
pwm_config_set_wrap(&(obj->cfg), count_top);

pwm_init(obj->slice, &(obj->cfg), false);
pwm_init(obj->slice, obj->channel, &(obj->cfg), false);
gpio_set_function(pin, GPIO_FUNC_PWM);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ void pwmout_period_us(pwmout_t *obj, int period)
uint32_t min_period = 1000000 * count_top / clock_get_hz(clk_sys);

pwm_config_set_clkdiv(&(obj->cfg), (float)period / (float)min_period);
pwm_init(obj->slice, &(obj->cfg), false);
pwm_init(obj->slice, obj->channel, &(obj->cfg), false);
}

int pwmout_read_period_us(pwmout_t *obj)
Expand Down