pwmWrite turns orange as if it is recognized by the IDE, but it fails to compile with this error
‘pwmWrite’ was not declared in this scope
Any help?
int led = PA8; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
void loop() {
pwmWrite(led, brightness);
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
I was hoping for a simple elegant way to manipulate the PWM frequency.
So I assume the solution would be off to the data sheet for prescaler and register info?
Thanks for the help.
https://github.com/rogerclarkmelbourne/Arduino_STM32
supports a few F10x and F40x chips, used with BluePills (and their clones, variants), afaik.
There are other “cores” you may consider as well, mostly “STM32 HAL” based, for example the “STM32GENERIC” core:
https://github.com/danieleff/STM32GENER … 2/variants
or “Arduino_Core_STM32” core:
[brian m – Fri Jun 15, 2018 6:42 am] –
I was hoping for a simple elegant way to manipulate the PWM frequency.
You can think of it and provide your suggestions: these cores grow based on community engagement and this is particularly true for the Libmaple core.
Btw: afaik changing the PWM frequency is not supported also in the standard Arduino cores..
Cheers, E.
STM core aims to be (as far as possible) Arduino compatible.
pwmWrite is not an standard Arduino, anyway now, we extend API to support further API.
It is planned to write New timer library which will include this kinf of feature.
[Pito – Fri Jun 15, 2018 7:32 am] –
or “Arduino_Core_STM32” core:
I thought this was what I was using. It does look like it’s been updated to 1.3.0, but after installing boards manager still shows v 1.2.0. (The 1.2.0 folder is empty though.) Looks like a reinstall may be necessary?
[edogaldo – Fri Jun 15, 2018 8:32 am] –
You can think of it and provide your suggestions: these cores grow based on community engagement and this is particularly true for the Libmaple core.
Btw: afaik changing the PWM frequency is not supported also in the standard Arduino cores..
Cheers, E.
With the UNO and NANO I was able to do it by changing timer and prescaler registers. This of course made things like millis and micros run faster than normal. I don’t think it’s documented well in standard arduino, but registers can be manipulated directly on the ATMEGA328P. Not sure about other MCUs.
The nucleo and MCU datasheet seem far less clear about register names and locations than ATMEL.
I’m moderately skilled with programming. The hardware and underlying configuration is a lot more mind boggling. I realized I’m not even sure what the default clock speed is. The board has a crystal for low power configuration, but solder bridges are not connected.
I was digging around and found some stuff in the AppData. stm32f3xx_hal_conf makes me think there’s a lot more going on than I understand.
I kinda feel like I’m barking up the wrong three here… or at least there’s a far steeper learning curve than I expected for something using Arduino IDE.
The steepest learning curve you can achieve here is with an stm32F103xx board (ie. MapleMini, BluePill, or their clones/variants). The “libmaple” based core (also known as Roger’s core) is the most used and elaborated one here (see above the list).
The HAL based cores (the one you are using) are less used here and less supported, even the situation gets better each day ![]()
Anyway the principles are the same: you interact with the devices (ie the timers) through registers and, specifically for pwm, you can change the frequency by playing with the underlying timers prescalers and counters.
An advantage respect to the 328 is that you have a dedicated timer for millis and micros so, changes to the pwm freq won’t impact the time calculations.
Cheers, E.
I was looking through the stm3f303 datasheet and I didn’t see a map of registers. I think it listed a range of 1KB for timer1 (which seems huge) but no specific registers.
I need to figure out a memory address, right? It won’t have a user friendly name like TCCRxx.
I’m sure I’m just looking in all the wrong places for this info.
Anyway, just ordered a blue pill so I can learn with that too.
Thanks
Look in the home page of your device for those and you will find all the info you need


