SysTick wrong freq

Hello,
I got a simple program toggling gpio pin evergy 500 ms with a use of HAL_Delay. It works as expected when complited in STMCubeIDE.
I took the same .ioc file (picture), I generated files with stm32pio, then uploaded the same code. Pin is being toggled every 167 ms (nota bene = 500 / 3).
Can you help me pin point the problem? Can we rule out PlatformIO bug?

Spec: NucleoG431RB
Clock config:


main.c code:

#include "main.h"
#include "usart.h"
#include "gpio.h"

void SystemClock_Config(void);

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_LPUART1_UART_Init();

  while (1)
  {
    HAL_Delay(500);
    HAL_GPIO_TogglePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin);
  }

  while (1) {}
}

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV6;
  RCC_OscInitStruct.PLL.PLLN = 85;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  {
    Error_Handler();
  }
}

void Error_Handler(void)
{
  __disable_irq();
  while (1) {}
}

#ifdef  USE_FULL_ASSERT

void assert_failed(uint8_t *file, uint32_t line) {}
#endif /* USE_FULL_ASSERT */

But you have to tell PlatformIO about the 24MHz HSE frequency too, otherwise other parts of the STM32 HAL won’t know what clock you’re running at and will do wrong time unit conversions…

A project is only correctly converted from STMCubeIDE to PlatformIO when also all defines and compiler options are the same, not only the same code files.

Does your platformio.ini contain

build_flags =
   -DHSE_VALUE=24000000UL

?

Otherwise you might get some wrong default, mostly 8MHz.

Thank you.
Maybe thread should be left for newbies like me.
Is it intentional, that pio doesn’t set this defines automatically after choosing nucleo model at pio project creation?

edit:
HSE_VALUE is defined as 24MHz in “stm32g4xx_hal_conf.h” in STMCubeIDE, but as 8MHz when traced in pio. What is the reason behind this difference?