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 :)
Solved! Go to Solution.
2024-10-30 08:48 AM - edited 2024-11-07 05:19 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) / with:
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;
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.
2024-10-29 09:01 AM
@Sany wrote:i debug my application, it ends in a Error Handler.. but why? :)
Find out how it gets there!
What error code does HAL_RCC_OscConfig() return?
Where, exactly, does it return this?
2024-10-29 09:14 AM
You have ALL the source code, debug the issue, understand why the library returned an error. Work backward to the point the error is initially flagged.
You have a CRYSTAL or an XO (CRYSTAL OSCILATOR) ?
The BYPASS is for the HSE Input from a TCXO, VCXO, OCXO type clock.
If the clocks are not working, it's not going to be able to clock the processor, or the PLL, or for that to lock.
2024-10-29 09:30 AM
Hello,
You said:
@Sany wrote:
On my own PCB, i have a Crystal with 8 MHZ, and a LSE of 32.768 khz.
And in your code you set HSE in Bypass mode:
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
Are you sure you are using a Crystal and not a Crystal oscillator?
Because in case of Crystal/resonator you need to set the HSE source as the following:
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
Hope it helps.
2024-10-29 09:35 AM - edited 2024-10-29 09:36 AM
Note that the screenshots you shared are not inline with the code:
Here you set HSI as System clock source:
In your code:
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
So need to clarify what you are really testing!
2024-10-29 09:35 AM
Hello,
Sorry, I have a XO with 8 MHZ and 2 Pins, the Code jumps to the Error_Handler while Waiting for HSE has been ready. I checked with my osci, and i get a 8 MHZ signal from the XO.
/* 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;
}
}
}
(Error Code is HAL_TIMEOUT)
2024-10-29 09:40 AM - edited 2024-10-29 09:42 AM
@Sany wrote:
Sorry, I have a XO with 8 MHZ and 2 Pins,
Need to check again if you are using a crystal or crystal oscillator:
At the left is a Crystal and at the right it's a crystal oscillator. The latter needs to be powered.
Could you please share your schematics?
2024-10-29 09:49 AM
@Sany wrote:Sorry, I have a XO with 8 MHZ and 2 Pins,
Nope: with only 2 pins, it can't be an XO (Crystal Oscillator).
A crystal oscillator is an active circuit - it requires power - so will need at least 3 pins (supply, ground, output).
Difference between just a crystal, and a crystal oscillator:
2024-10-29 10:21 AM
+
2024-10-29 11:27 AM
If you are using TWO pins OSC_IN/OSC_OUT you are using a CRYSTAL
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
For an XO you'd need ONE pin OSC_IN (4-25 MHz) and BYPASS mode, ie the STM32 is NOT simulating the crystal
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; // Clock on OSC_IN, and OSC_OUT NOT VIABLE