cancel
Showing results for 
Search instead for 
Did you mean: 

RTC clocks problem

asim khan
Associate III

Something is wrong with the clocking and i cant figure out. When i try to debug with step over,

 the error handler in void SystemClock_Config(void)

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

Takes me to

   /* Wait till LSE is ready */

   while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)

   {

    if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)

    {

     return HAL_TIMEOUT;

    }

   }

  }

in hal_rcc.c. where i am forever stuck.

Below is the code

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct= {0};;

 RCC_ClkInitTypeDef RCC_ClkInitStruct= {0};;

 /** Configure the main internal regulator output voltage

 */

 __HAL_RCC_PWR_CLK_ENABLE();

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 /** Initializes the RCC Oscillators according to the specified parameters

 * in the RCC_OscInitTypeDef structure.

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;

 RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 RCC_OscInitStruct.LSEState = RCC_LSE_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

 RCC_OscInitStruct.PLL.PLLM = 5;

 RCC_OscInitStruct.PLL.PLLN = 180;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

 RCC_OscInitStruct.PLL.PLLQ = 3;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Activate the Over-Drive mode

 */

 if (HAL_PWREx_EnableOverDrive() != 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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)

 {

  Error_Handler();

 }

}

void printTimeDate(char *format,...)

 {

  char str[80];

  va_list args;

  va_start(args, format);

  vsprintf(str, format,args);

  HAL_UART_Transmit(&huart4,(uint8_t *)str, strlen(str),HAL_MAX_DELAY);

  va_end(args);

 }

void set_time(void)

{

  RTC_TimeTypeDef sTime = {0};

  RTC_DateTypeDef sDate = {0};

  sTime.Hours = 15;

  sTime.Minutes = 40;

  sTime.Seconds = 34;

  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sTime.StoreOperation = RTC_STOREOPERATION_RESET;

  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)

  {

   Error_Handler();

  }

  sDate.WeekDay = RTC_WEEKDAY_THURSDAY;

  sDate.Month = RTC_MONTH_SEPTEMBER;

  sDate.Date = 9;

  sDate.Year = 21;

  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)

  {

   Error_Handler();

  }

  HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, 0x32F2);

}

static void MX_RTC_Init(void)

{

 hrtc.Instance = RTC;

 hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

 hrtc.Init.AsynchPrediv = 127;

 hrtc.Init.SynchPrediv = 255;

 hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

 hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

 hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

 if (HAL_RTC_Init(&hrtc) != HAL_OK)

 {

  Error_Handler();

 }

}0693W00000DmdaaQAB.png

3 REPLIES 3

Which STM32?

What is the hardware? Is this a "known good" board such as Nucleo or Disco, or your own?

JW

Discovery F429i

The LSE crystal is probably not populated by default, including its surrounding circuitry (capacitors, jumpers). Read OSC 32 kHz clock supply chapter in UM1670.

JW