RAK3172 PWM provide only 186kHz maximum frequency

Hey!

I need generate PWM frequency around 1.5MHz, but cannot make more than 186kHz.
Any advice please?
Thank a lot!
Code:

uint8_t ledPin = PA0;	
int freq = 186000; // working fine

//int freq = 200000; // doesn't work
//int freq = 1500000; // doesn't work too

void setup()
{
  Serial.begin(115200);
  delay(2000);
  
  tone(ledPin, freq);
}

void loop()
{
    tone(ledPin, freq);
    delay(5000);
    noTone(ledPin);
    delay(5000);
}

Ok, I find out that problem in Prescaler value for Timer + Counter Period, which are too high, but how I can decrease them?
I need Prescaler value as 1 and Counter-Period value from around 15-31.
Maybe there a way to update API and add new methods which introduce that values as params?

Hi @Diaver ,

RUI3 abstracts different commonly used functionalities (inspired with Arduino) to different MCUs like ST, Nordic and Apollo.

Tone is a generic feature that can be used in different use case. However, making counter period for ST configurable will require as to exposed it for Nordic and Apollo as well since RUI3 API should work on all MCUs.

Counter period modification is low level already and if you need a very low counter-period, you will need to directly configure the STM32Wl registers and not via RUI3 API.

Hey!
I actually made it work, and now able to generate whatever frequency I really need, with one small workaround :smiley:

But I would highly recommend add one more PWM function to your Arduino API to let users set Prescaler and Period for PWM timers + update documentation in relation to PWN, because now it is not really clear which PWM pins devs able to use.
Thanks!

Here is a link how to achieve almost any PWM frequency RAK3172 PWM tone function is working only with build-in LEDs - #4 by Diaver