cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Clock

verogarciaa
Associate
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.

6 REPLIES 6
TDK
Super User

> 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.

If you feel a post has answered your question, please click "Accept as Solution".

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

It is with STM32F405RGT6 We Act Board

https://github.com/WeActStudio/WeActStudio.STM32F4_64Pin_CoreBoard/blob/master/Hardware/WeAct-STM32F4_64PIN-CoreBoard_V11%20SchDoc.pdf

 

TelemetryF.c is the file of my control unit and the config file is STM32F4.c :

I attached some files in other response

Thanks

In stm32f4xx_hal_conf.h file, HSE Value is defined at 8MHz as my External Clock

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..