2025-06-27 9:11 AM - last edited on 2025-06-27 10:46 AM by mƎALLEm
void STM32F4_SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
// 1. Habilitar el reloj del controlador de potencia y configurar la escala de voltaje
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
// 2. Configurar oscilador externo HSE (8 MHz), activar PLL
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;
// PLL Config:
// - PLLM = 8 (divide HSE 8MHz a 1 MHz)
// - PLLN = 336 (multiplica a 336 MHz)
// - PLLP = 4 (divide VCO para SYSCLK: 336/4 = 84 MHz)
// - PLLQ = 7 (para USB, SDIO: 336/7 = 48 MHz)
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
STM32F4_Error_Handler(1);
}
// 3. Configurar clocks del sistema y buses
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // SYSCLK = PLL = 84 MHz
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // HCLK = 84 MHz
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; // APB1 = 42 MHz (CAN)
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // APB2 = 84 MHz
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
STM32F4_Error_Handler(2);
}
}
In Keil uVision, i need a clock for a SD Card by SDIO with FatFs so i need 48MHz fot this. And then i want configurate CAN 1 at 500kbps. Keil has a timer to see how much time has passed since the start of the debug, but it advances 4 seconds when 1 second has passed.
2025-06-27 9:24 AM
> Keil has a timer to see how much time has passed since the start of the debug, but it advances 4 seconds when 1 second has passed.
Show evidence of this.
2025-06-27 9:27 AM
What board / part specifically?
Can you get an oscilloscope on a clock signal, TIM output or PA8/MCO pin?
What is HSE_VALUE defined at? See stm32f4xx_hal_conf.h
Code doesn't look problematic.
Show timing code, or toggle LED
Hard to debug/diagnose given the level of presentation currently.
2025-06-27 9:34 AM
It is with STM32F405RGT6 We Act Board
TelemetryF.c is the file of my control unit and the config file is STM32F4.c :
2025-06-27 9:35 AM
I attached some files in other response
Thanks
2025-06-27 9:45 AM
In stm32f4xx_hal_conf.h file, HSE Value is defined at 8MHz as my External Clock
2025-06-27 9:48 AM
Focus on initial bring-up of the board.
Make something simple you can debug yourself, and step through. Get some signals on pins, and measure them.
Use your ST-LINK, J-LINK or U-LINK to single step and debug code in main() and starting HSE and PLL