BME280 works on STM32CubeIDE but fails on PlatformIO

Hello,

I have a custom board with an integrated BME280 sensor. I made this simple program in STM32CubeIDE which successfully reads the sensor values, but I have been unable to replicate this functionality in PlatformIO. For some reason, the call to bme.begin() fails, causing the code to loop. I suspect the issue might be related to clock configurations. This was working before, but after adding a 32MHz HSE to the board, it stopped working.

Here is the working program for STM32CubeIDE:

And here is the program for PlatformIO where bme.begin() does not pass:

Any help would be greatly appreciated. Thanks!