cancel
Showing results for 
Search instead for 
Did you mean: 

can't escape while loop in SystemClock_Config();

td
Associate II
Posted on June 14, 2018 at 09:35

So i noticed something interesting. When setting up a project with cube or looking at a ST example for USB host the Config for system clock is like this.

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_SCALE1);

/**Initializes the CPU, AHB and APB busses clocks */

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.LSIState = RCC_LSI_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLM = 25;

RCC_OscInitStruct.PLL.PLLN = 192;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

RCC_OscInitStruct.PLL.PLLQ = 4;

HAL_RCC_OscConfig(&RCC_OscInitStruct);

/**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_DIV4;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);

/**Configure the Systick interrupt time */

HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

/**Configure the Systick */

HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

When the HAL_RCC_OscConfig(&RCC_OscInitStruct); runs there is a while and the only way to escape from it is by reading the Systemtick which is not configured yet 

:(

/* Wait till HSE is ready */

while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {

if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)

{ return HAL_TIMEOUT; }

}

4 REPLIES 4
Posted on June 14, 2018 at 10:23

I'm not going to dig into Cube/CubeMX internals: Isn't systick interrupt already enabled in the startup code, i.e. before entering main()?

JW

td
Associate II
Posted on June 14, 2018 at 14:23

I put a breakpoint in the interrupt it's does not enter and

systick

stays zero
Posted on June 15, 2018 at 14:52

Hello!

Systick is allready initialized before clock configuration , inside HAL_Init()  (HSI is the source clock.)

HAL_Init() is the first function called inside main();

Check , if in this infinite waiting loop the MCU is in Handler or  Thread mode (if  is any interrupt active and not handled by software)   Check also if SysTick_Handler() exists and it is linked

if is posible post .ioc file

Pavel A.
Evangelist III
Posted on June 15, 2018 at 20:59

Well whether the SysTick increments or not is a different issue (in presence of freeRTOS the HAL tick source may be defined as some other timer, not SysTick). The real issue is that 

__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) will not return SET for a long time. This means a problem with your ext. oscillator config (wrong mode, wrong frequency).

-- pa