2019-01-12 03:44 AM
I have called the three functions as:
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_SET);
when debugging it either jumps to hard fault or hangs.
The SystemClock_Config() is as follows:
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
/**Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
/**Initializes the CPU, AHB and APB busses clocks
*/
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 = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;
//HAL_RCC_OscConfig(&RCC_OscInitStruct);
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Initializes the CPU, AHB and APB busses clocks
*/
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_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
//HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
// /**Configure the Systick interrupt time
// */
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
// /**Configure the Systick
// */
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
// /* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
2019-01-12 04:20 AM
The chip normally boots with hsi and you can use the debugger step by step to find out if hse with pll works.
First chech hse without pll is functional. If not, check external oscillator on oscilloscope. If looks good, step by step with pll code. Maybe coefficients are wrong and mcu step back to hsi.
2019-01-12 06:23 AM
Check if it is entering the _Error_Handler(), have that actually report status to a console.
If the clock is not starting it is going to take the failure path.
Enable the HSE, and route to the MCO (PA8) pin, and validate with a scope.
2019-01-14 02:16 AM
Thanks for the reply.
I have tried your solution but facing the problem as:
While using the debugger it jumps to HardFault_Handler from the funtion "HAL_RCC_GetSysClockFreq".
Hence the HSE with PLL doesn't work.
I have checked the external oscillator which is working fine.
Can you please help me out with PLL coefficients?
2019-01-14 02:18 AM
I have checked with HSE enable and PLL disabled state. This state gives me the 8MHz output when checked on the scope.
The PLL doesn't work with internal oscillator too.
Please provide the solution.