Skip to content

Commit c3103e2

Browse files
aentingerfacchinm
authored andcommitted
Fix PWM initialisation when using both channel A and channel B of a single PWM unit.
1 parent 6f40028 commit c3103e2

File tree

2 files changed

+6
-4
lines changed
  • targets/TARGET_RASPBERRYPI/TARGET_RP2040

2 files changed

+6
-4
lines changed

targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_pwm/include/hardware/pwm.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ static inline void pwm_config_set_wrap(pwm_config *c, uint16_t wrap) {
177177
c->top = wrap;
178178
}
179179

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

195197
pwm_hw->slice[slice_num].ctr = PWM_CH0_CTR_RESET;
196-
pwm_hw->slice[slice_num].cc = PWM_CH0_CC_RESET;
198+
pwm_set_chan_level(slice_num, chan, PWM_CH0_CC_A_RESET);
197199
pwm_hw->slice[slice_num].top = c->top;
198200
pwm_hw->slice[slice_num].div = c->div;
199201
pwm_hw->slice[slice_num].csr = c->csr | (bool_to_bit(start) << PWM_CH0_CSR_EN_LSB);

targets/TARGET_RASPBERRYPI/TARGET_RP2040/pwmout_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void pwmout_init(pwmout_t *obj, PinName pin)
6666
obj->cfg = pwm_get_default_config();
6767
pwm_config_set_wrap(&(obj->cfg), count_top);
6868

69-
pwm_init(obj->slice, &(obj->cfg), false);
69+
pwm_init(obj->slice, obj->channel, &(obj->cfg), false);
7070
gpio_set_function(pin, GPIO_FUNC_PWM);
7171
}
7272

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

144144
pwm_config_set_clkdiv(&(obj->cfg), (float)period / (float)min_period);
145-
pwm_init(obj->slice, &(obj->cfg), false);
145+
pwm_init(obj->slice, obj->channel, &(obj->cfg), false);
146146
}
147147

148148
int pwmout_read_period_us(pwmout_t *obj)

0 commit comments

Comments
 (0)