Skip to content

Commit 1b946ec

Browse files
committed
Temp: Fix PWM initialisation when using both channel A and channel B of a single PWM unit.
1 parent 6f40028 commit 1b946ec

File tree

2 files changed

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

2 files changed

+4
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,13 @@ static inline void pwm_config_set_wrap(pwm_config *c, uint16_t wrap) {
188188
* \param start If true the PWM will be started running once configured. If false you will need to start
189189
* manually using \ref pwm_set_enabled() or \ref pwm_set_mask_enabled()
190190
*/
191-
static inline void pwm_init(uint slice_num, pwm_config *c, bool start) {
191+
static inline void pwm_init(uint slice_num, uint chan, pwm_config *c, bool start) {
192192
check_slice_num_param(slice_num);
193193
pwm_hw->slice[slice_num].csr = 0;
194194

195195
pwm_hw->slice[slice_num].ctr = PWM_CH0_CTR_RESET;
196-
pwm_hw->slice[slice_num].cc = PWM_CH0_CC_RESET;
196+
pwm_hw->slice[slice_num].cc &= (chan ? (~PWM_CH0_CC_A_BITS) : (~PWM_CH0_CC_B_BITS));
197+
//pwm_set_chan_level(slice_num, chan, PWM_CH0_CC_A_RESET);
197198
pwm_hw->slice[slice_num].top = c->top;
198199
pwm_hw->slice[slice_num].div = c->div;
199200
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: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)