Skip to content

RP2 PWMOut: constructor validation fails with varying errors #10640

Description

@dhalbert

From https://forums.adafruit.com/viewtopic.php?t=220287:

I can't initialize two PWMOut on two pins that use the same slice (for example, GP2 and GP3). But if I try, depending on which pin I initialize first, and what parameters I give to the second initializer, I get three different error messages, two of which are misleading. This makes PWM conflicts difficult to debug.

Adafruit CircuitPython 9.2.8 on 2025-05-28; Raspberry Pi Pico with rp2040
>>> import pwmio
>>> import board
>>> g2 = pwmio.PWMOut(board.GP2, frequency=20000)
>>> g3 = pwmio.PWMOut(board.GP3, variable_frequency=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid variable_frequency
>>> g2.deinit()
>>> g3 = pwmio.PWMOut(board.GP3, variable_frequency=True)
>>> g2 = pwmio.PWMOut(board.GP2, frequency=20000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: Internal resource(s) in use
>>> g3.deinit()
>>> g2 = pwmio.PWMOut(board.GP2, frequency=20000)
>>> g3 = pwmio.PWMOut(board.GP3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid frequency
>>>

I reproduced this on 10.0.0-beta.3. I suspect the deinit() code is not restoring some state properly.

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions