@@ -321,12 +321,13 @@ def _clock_pwm_deinit(self):
321321 self ._clock_pwm .deinit ()
322322 self ._clock_pwm = None
323323
324- def clock_project_PWM (self , freqHz :int , duty_u16 :int = (0xffff / 2 ), quiet :bool = False ):
324+ def clock_project_PWM (self , freqHz :int , duty_u16 :int = (0xffff / 2 ), quiet :bool = False , max_rp2040_freq : int = 133_000_000 ):
325325 '''
326326 Start an automatic clock for the selected project (using
327327 PWM).
328328 @param freqHz: The frequency of the clocking, in Hz, or 0 to disable PWM
329- @param duty_u16: Optional duty cycle (0-0xffff), defaults to 50%
329+ @param duty_u16: Optional duty cycle (0-0xffff), defaults to 50%
330+ @param max_rp2040_freq: Maximum RP2040 frequency, overclocking above 133MHz allows higher clock frequencies
330331 '''
331332 if freqHz > 0 :
332333 self .pins .project_clk_driven_by_RP2040 (True )
@@ -353,8 +354,10 @@ def clock_project_PWM(self, freqHz:int, duty_u16:int=(0xffff/2), quiet:bool=Fals
353354 if self ._clock_pio is not None :
354355 self ._clock_pio .stop ()
355356 try :
356- rp2040_sys_clock = self ._get_best_rp2040_freq (freqHz )
357- platform .set_RP_system_clock (rp2040_sys_clock )
357+ rp2040_sys_clock = self ._get_best_rp2040_freq (freqHz , max_rp2040_freq )
358+ if rp2040_sys_clock != platform .get_RP_system_clock ():
359+ log .info (f'Setting RP2040 system clock to { rp2040_sys_clock } Hz' )
360+ platform .set_RP_system_clock (rp2040_sys_clock )
358361 self ._clock_pwm = self .pins .rp_projclk .pwm (freqHz , duty_u16 )
359362 except Exception as e :
360363 log .error (f"Could not set project clock PWM: { e } " )
0 commit comments