Page 1 of 2

Options for a lot of cpu clock frequencies.

Posted: Sat Apr 11, 2020 3:01 pm
by razvitm
The Megacore allows for a wide variety of clocks for running the atmega2560 on external crystal oscillators, I would like the stm32duino to give more than the current 3 options for core frequency. So 72MHz, 48MHz and 128MHz could be complemented with 16MHz, 8MHz and if possible, lower clocks too.

Re: Options for a lot of cpu clock frequencies.

Posted: Sat Apr 11, 2020 4:40 pm
by fpiSTM
STM32 has no such option. I guess you talk about Roger's core (libmaple)

Re: Options for a lot of cpu clock frequencies.

Posted: Sat Apr 11, 2020 6:25 pm
by stas2z
roger's core allows these frequencies cuz its compatible with usb clocking

with this (stm32 official) core (not roger's one) you can configure your mcu any way you wish by overriding weak SystemClock_Config with cumbemx generated where you can play with clock parameters

Image

Re: Options for a lot of cpu clock frequencies.

Posted: Tue Apr 14, 2020 2:15 am
by mrburnette
razvitm wrote: Sat Apr 11, 2020 3:01 pm The Megacore allows for a wide variety of clocks for running the atmega2560 on external crystal oscillators, I would like the stm32duino to give more than the current 3 options for core frequency. So 72MHz, 48MHz and 128MHz could be complemented with 16MHz, 8MHz and if possible, lower clocks too.
Even with Megacore, you run great risks of libraries not working. I am intimately familiar with Roger's core and it's death came before the webpage crashed. The increasing complexity created by added options created a testing nightmare with simply too many permutations to humanly verify. Features created failures that then required fixing.

If you need the capabilities you request, you need to skip Arduino'ish cores and move to a full development environment, not one that creates a limiting wrapper around the very flexible tools.

Ray

Re: Options for a lot of cpu clock frequencies.

Posted: Tue Apr 14, 2020 12:26 pm
by razvitm
stas2z wrote: Sat Apr 11, 2020 6:25 pm roger's core allows these frequencies cuz its compatible with usb clocking

with this (stm32 official) core (not roger's one) you can configure your mcu any way you wish by overriding weak SystemClock_Config with cumbemx generated where you can play with clock parameters

Image
I'll try that first thing when I get home. So I select the MCU in CubeMx, select all the pheripherals I'll be using, and set the clocks, export a file, and use that file to overwrite some file in the STM32duino ST core?

Re: Options for a lot of cpu clock frequencies.

Posted: Tue Apr 14, 2020 1:07 pm
by fpiSTM
For the STM32 core, simply define your new SystemClock_Config at sketch level with extern "C"

Code: Select all

extern "C" void SystemClock_Config(void) {
...
 }

Re: Options for a lot of cpu clock frequencies.

Posted: Tue Apr 14, 2020 4:30 pm
by stas2z
it will be in the main.c, just copy paste this function to your sketch and add extern "C" like fpiSTM said

Re: Options for a lot of cpu clock frequencies.

Posted: Thu Apr 30, 2020 5:20 pm
by razvitm
Please help me with step by step instructions of using cubemx, arduino and the official ST core to run the stm32f103rc at say 1MHz, for the blinky sketch. I have cubemx, arduino and the st core installed. What do I do with the files generated by cubemx? Do I copy them in the arduino blinky sketch folder?

Re: Options for a lot of cpu clock frequencies.

Posted: Mon May 04, 2020 9:21 am
by razvitm
So I managed to run the MCU at 4MHz by looking into the cubemx generated files and copy-pasting the prescaler values in the stm32duino file:
c:\Users\Razvan\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\variants\PILL_F103XX\variant.cpp
I did this beause I couldn't figure out how to include the cubemx generated files in my sketch, it might be simple but someone has to show me how it's done... Until I learn, I will use this workaround...

Re: Options for a lot of cpu clock frequencies.

Posted: Mon May 04, 2020 9:43 am
by stas2z
razvitm wrote: Mon May 04, 2020 9:21 am So I managed to run the MCU at 4MHz by looking into the cubemx generated files and copy-pasting the prescaler values in the stm32duino file:
c:\Users\Razvan\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.6.1\variants\PILL_F103XX\variant.cpp
I did this beause I couldn't figure out how to include the cubemx generated files in my sketch, it might be simple but someone has to show me how it's done... Until I learn, I will use this workaround...
As i already said before, you only need to copy void SystemClock_Config(){...} from main.c generated by cubemx and paste it DIRECTLY into your .ino file and add extern "C" right before void SystemClock_Config(){ to say your compiler that it's a symbol with C linkage.

Example:
Image