cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo external 32khz clock.

mbmail4
Associate II
Posted on September 06, 2016 at 03:15

Hi Everyone.

I'm having trouble starting the external 32khz RTC source as fitted to the Nucleo. Are there any issues with this clock on the Nucleo, has anyone got it to work?

Thanks

Martin

7 REPLIES 7
Posted on September 06, 2016 at 03:52

Which board models specifically, most of the Nucleo boards I have don't come with the 32 KHz crystal.

The crystals aren't inherently difficult to start and test, but the STM32 design has some specific requirements electrically.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
mbmail4
Associate II
Posted on September 06, 2016 at 04:18

Hi Clive, its the Nucleo64, its marked as X2, ABS25-32.768KHZ-6-T on the schematic.

Posted on September 06, 2016 at 07:06

Hazy crystal ball here. What do you mean by trouble and how do you try to start it? Which STM32 device? Which version of Nucleo board (UM mentions 3 different LSE configurations)? What is the state of SB45?

JW

mbmail4
Associate II
Posted on September 06, 2016 at 07:27

JW, its the F303RE. I set up for RCC_RTCCLKSOURCE_LSE and it fails. When I use the RCC_RTCCLKSOURCE_LSI setting, it works? not sure why.

thanks

Martin

void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)

{

  if(hrtc->Instance==RTC)

  {

    __HAL_RCC_PWR_CLK_ENABLE();

    HAL_PWR_EnableBkUpAccess();

    __HAL_RCC_RTC_ENABLE();

  }

}

void SystemClock_Config(void)

{

  RCC_OscInitTypeDef RCC_OscInitStruct;

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_PeriphCLKInitTypeDef PeriphClkInit;

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;

  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

  RCC_OscInitStruct.LSIState = RCC_LSI_ON;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

  {

    Error_Handler();

  }

  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;

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

  {

    Error_Handler();

  }

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB | RCC_PERIPHCLK_USART1

      | RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_RTC;

  PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;

  PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;

  PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;

  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;

  PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;

  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

  {

    Error_Handler();

  }

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */

  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

Walid FTITI_O
Senior II
Posted on September 06, 2016 at 15:06

Hi b.m.002,

To get the LSE working correctly, you would make the following change in the shared code:

* Replace ''RCC_OSCILLATORTYPE_LSI'' by ''RCC_OSCILLATORTYPE_LSE''

* Replace ''RCC_LSI_ON'' with ''RCC_LSI_OFF''

* Add this line :

  RCC_OscInitStruct.LSEState = RCC_LSE_ON;

* Replace ''RCC_RTCCLKSOURCE_LSI'' with ''RCC_RTCCLKSOURCE_LSE''

-Hannibal-

Posted on September 06, 2016 at 15:17

I don't use Cube, but you may want to try the supplied example first

[STM32Cube_FW_F3_V1.6.0]\Projects\STM32F303RE-Nucleo\Examples\RTC\RTC_Calendar

JW
mbmail4
Associate II
Posted on September 07, 2016 at 04:04

thanks JW, that worked Hannibal, cheers