2024-10-29 08:58 AM - edited 2024-10-29 09:04 AM
Hey Guys,
I have problems about configure my STM32H743VIT SysClock.
On my own PCB, i have a Crystal with 8 MHZ, and a LSE of 32.768 khz.
Settings are in my Screenshots, now if i debug my application, it ends in a Error Handler.. but why?
BTW: UART4,5,7 and USART1,2 enabled, and USB_DEVICE + USB_HOST is enabled.
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler(); /** JUMPS TO ERROR_HANDLER **/
}
my complete SystemClockConfig:
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 24;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 4;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler(); /** JUMPS TO ERROR_HANDLER **/
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
Thank you :)
2024-10-29 01:26 PM
Hello,
Sorry for my confusion, the day is long...
i have only a crystal on my pcb with 2 pins (not a crystal oscillator, with 3.3V supply), the crystal swings with 7.99997 MHZ on my oscilloscope.
i check my schematic, and i found a big problem, i have a crystal with 8mhz on 2 pins, but i forgot the decoupling condensators on the side to ground... :(
i think, that was the problem..?
2024-10-29 01:44 PM
@Sany wrote:
the crystal swings with 7.99997 MHZ on my oscilloscope.
Sorry I didn't undrstand, but you got the oscillation and 7.99997MHz is a good value. What's the problem then?
I don't think CL could induce the described issue at the beginning.
The CL are responsible to fine tune the frequency of the crystal:
From AN2867 "Guidelines for oscillator design on STM8AF/AL/S and STM32 MCUs/MPUs":
And you still didn't answer my question regarding what the exact config you are really using?
Please answer the question from my previous comment:
Bypass or not? you should not use Bypass in your case as you are using a Crystal.
2024-10-30 12:22 AM
Hello,
my configuration with crystal (no XO) 8 MHZ is this:
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 75;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 8;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_1;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
Error_Handler is called by this function with HAL_TIMEOUT:
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
/* Check the HSE State */
if (RCC_OscInitStruct->HSEState != RCC_HSE_OFF)
{
/* Get Start Tick*/
tickstart = HAL_GetTick();
/* Wait till HSE is ready */
while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == 0U)
{
if ((uint32_t)(HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
}
i dont understand the problem, why the error is HAL_TIMEOUT.
2024-10-30 01:16 AM
1- Did you solder CL load capacitors?
2- Please attach your ioc file.
2024-10-30 01:22 AM
@Sany wrote:i dont understand the problem, why the error is HAL_TIMEOUT.
It's waiting for the HSE to become ready - that is taking too long, so you get a timeout.
So look at what might prevent the HSE from starting; eg, shorting both OSC_IN and OSC_out to ground would be a pretty effective way:
2024-10-30 02:51 AM
2024-10-30 02:56 AM
@Sany wrote:i check my schematic, and i found a big problem, i have a crystal with 8mhz on 2 pins, but i forgot the decoupling condensators on the side to ground... :(
It's worse than that!
Both sides of the crystal are shorted to ground!
@Sany wrote:i think, that was the problem..?
Yep - which shows why it's important to post the schematic!
2024-10-30 03:02 AM - edited 2024-10-30 03:05 AM
Hello,
Just a question: your system clock is set to 75MHz, and the VOS is set to VOS2 while it needs to be set to VOS3:
Did you set it manually or it was set automatically by CubeMx?
2024-10-30 04:48 AM
Hey,
I enabled only the HSE and LSE and changed my system clock to 160 MHZ in CubeMX.
After i disabled my wrong soldered HSE, the system clock is changed to 75mhz after i clicked "resolve clock issues"
CubeMX sets automatically the VOS2, i changed the VOS2 now to VOS3 manually.
i created a new project, and CubeMX sets VOS to VOS0 and Product Revision to "Y". When i change the Product Revision to "V" then sets CubeMX VOS2.
That's a good hint, i wouldn't have noticed it, because my code runs, after disabling the HSE.
here is my corrected config, with VOS3, 160mhz, and disabled HSE.
2024-10-30 08:48 AM
Hello @Sany ,
your attached ioc file is setting the system clock to 64Mhz with HSI.
I'm very confused. We need to converge.
So to conclude: if you have
Rev Y: Max system clock is 400MHz at VOS1.
Rev V: Max system clock is 480MHz at VOS0.
I'm attaching your ioc file with some modifications I did to set the crystal at 8MHz and system clock at 400MHz at VOS1 (this is working on rev Y and Rev V).
If this config doesn't work:
- You need first to add CL capacitors (even I'm not sure this is the issue).
- Replace your crystal. It could be something related to the crystal.
Hope it helps.