Stm32g431 - how to setup the clock (PLL) with libopencm3

Hi GUys,

I have searched and searched the net, but I can’t find the G431 equivalent for
rcc_clock_setup_pll() Does anyone know where I can find that … the libopencm3 wiki is way too hard to navigate, and few eamples there for the G431

I am trying to port some code from a stm32f100 project to this micro.

The libopencm3 source is laid out pretty intuitively. For the STM32G4 in particular, I found the function you’re referring to here:

libopencm3/lib/stm32/g4/rcc.c at bb4c5d7324554fe7a3137bfbcf3b5200ee2648fa · libopencm3/libopencm3 · GitHub

So I added rcc_clock_setup_pll(&rcc_hse_16mhz_3v3[3]); // 170Mhz to my code but I get:

src/main.c: In function 'gpio_setup':
src/main.c:32:2: warning: implicit declaration of function 'rcc_clock_setup_pll' [-Wimplicit-function-declaration]
  rcc_clock_setup_pll(&rcc_hse_16mhz_3v3[3]); // 170Mhz

I have #include <libopencm3/stm32/rcc.h> at the top, so not sure why it does not compile …

It’s like platformio version of libopencm3 does not include the g431…
Screenshot shows no g431 varient option when the function is highlighted.

@ardnew Any idea’s … thanks.

Well, what you are showing in your screenshots is that the VSCode/PIO IDE isn’t able to resolve the path to your included header, so the editor draws squiggly lines and indicates an error.

Specifically. The VSCode intellisense engine probably doesn’t know where platformio or it’s libopencm3 are installed, so your relative include path is not found. To verify this, try using the absolute file path in your #include.

However, this only means your editor isn’t fully configured. It does not mean the compiler will fail to resolve that included header. Have you tried compiling?

Somebody more familiar with the PIO plug-in would have to chime in to tell you how to configure the intellisense include paths.

No, it fails compile, I showed the error above … more fully here:

No dependencies
Building in release mode
Compiling .pio/build/nucleo_g431kb/src/main.o
Generating linker script .pio/build/nucleo_g431kb/generated.stm32g431kb.ld
Compiling .pio/build/nucleo_g431kb/FrameworkLibOpenCM3/lib/stm32/common/gpio_common_all.o
Compiling .pio/build/nucleo_g431kb/FrameworkLibOpenCM3/lib/stm32/common/gpio_common_f0234.o
Compiling .pio/build/nucleo_g431kb/FrameworkLibOpenCM3/lib/stm32/common/rcc_common_all.o
Compiling .pio/build/nucleo_g431kb/FrameworkLibOpenCM3/lib/cm3/vector.o
Compiling .pio/build/nucleo_g431kb/FrameworkLibOpenCM3/lib/cm3/systick.o
Compiling .pio/build/nucleo_g431kb/FrameworkLibOpenCM3/lib/cm3/scb.o
Compiling .pio/build/nucleo_g431kb/FrameworkLibOpenCM3/lib/cm3/nvic.o
src/main.c: In function 'gpio_setup':
src/main.c:32:2: warning: implicit declaration of function 'rcc_clock_setup_pll' [-Wimplicit-function-declaration]
  rcc_clock_setup_pll(&rcc_hse_16mhz_3v3[3]); // 170Mhz
  ^~~~~~~~~~~~~~~~~~~
src/main.c:32:23: error: 'rcc_hse_16mhz_3v3' undeclared (first use in this function)
  rcc_clock_setup_pll(&rcc_hse_16mhz_3v3[3]); // 170Mhz
                       ^~~~~~~~~~~~~~~~~
src/main.c:32:23: note: each undeclared identifier is reported only once for each function it appears in
*** [.pio/build/nucleo_g431kb/src/main.o] Error 1

There is nothing wrong with intellisense as it finds the other functions like rcc_periph_clock_enable just fine …

The above function resides in rcc_common_all.c in the framework, put the rcc_clock_setup_pll function does not, it is not found anywhere …

Never mind, I have changed tack and have switched to arduino framework and already have board running at max, and setup 3-phase pwm with deadband …