7 years, 2 months ago.

Use external clock signal (HSE) in Nucleo L073RZ

I'm trying to use an external clock signal geterated by a crystal (X3).

I applied this configuration: – SB54 and SB55 OFF – R35 and R37 soldered – C33 and C34 soldered with 20 pF capacitors – SB16 and SB50 OFF

However I'm not getting a valid clock signal. I monitored it with an oscilloscope.

I also tried this code:

#include "mbed.h"

int main()
{

    switch (__HAL_RCC_GET_SYSCLK_SOURCE())
    {
    case RCC_SYSCLKSOURCE_STATUS_MSI:
    	printf("MSI used as system clock.\r\n");
    	break;
    case RCC_SYSCLKSOURCE_STATUS_HSI:
        printf("HSI used as system clock.\r\n");
        break;
    case RCC_SYSCLKSOURCE_STATUS_HSE:
        printf("HSE used as system clock.\r\n");
        break;
    case RCC_SYSCLKSOURCE_STATUS_PLLCLK:
        printf("PLL used as system clock.\r\n");
        if ((RCC->CFGR & RCC_CFGR_PLLSRC) == RCC_CFGR_PLLSRC_HSE) {
        	printf("HSE oscillator clock selected as PLL input clock.\r\n");
        }
        else {
        	printf("HSI16 oscillator clock selected as PLL input clock.\r\n");
        }
        break;
    }

    printf("HCE Information: \r\n");

    if (READ_BIT(RCC->CR, RCC_CR_HSEON)){
    	printf("RCC_CR_HSEON = 1 \r\n");
    }
    else{
    	printf("RCC_CR_HSEON = 0 \r\n");
    }

    if (READ_BIT(RCC->CR, RCC_CR_HSEBYP)){
        printf("RCC_CR_HSEBYP = 1 \r\n");
    }
    else{
    	printf("RCC_CR_HSEBYP = 0 \r\n");
    }

    if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) {
    	printf("RCC_FLAG_HSERDY = 1 \r\n");
    }
    else {
    	printf("RCC_FLAG_HSERDY = 0 \r\n");
    }

}

And this is the output:

PLL used as system clock.
HSI16 oscillator clock selected as PLL input clock.
HSE Information:
RCC_CR_HSEON = 0
RCC_CR_HSEBYP = 0
RCC_FLAG_HSERDY = 0

The microcontroller is taking its internal clock instead of the external crystal.

Why doesn't it work?

Do I have to modify something in the code? I have read that the microcontroller have an auto detection function to choose the clock source.

2 Answers

7 years, 2 months ago.

Hello, your hardware setup is OK. The mbed lib is switching to external crystal after a long timeout. You can speed up this with some help. 1. Import the mbed-dev lib 2. remove the mbed lib 3. inside the mbed-dev lib go to : targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/system_stm32l0xx.c

in line 129 you can find the select switch :

  • Select the clock sources (other than HSI) to start with (0=OFF, 1=ON) */
  1. define USE_PLL_HSE_EXTC (1) /* Use external clock */
  2. define USE_PLL_HSE_XTAL (1) /* Use external xtal */

4. Set #define USE_PLL_HSE_EXTC (0) to disable using the external clock signal and use crystal.

The lib is looking for a 8 MHz xtal. The Nucleo schematic is using a crystal with 12pF load capacitance, Most 8 Mhz crystals have more. Try to use a different crystal or change C8 C3.

Best Regards, Peter

Hi Peter, thanks for your reply.

I changed the configuration as you said, but it didn't work. I don't think it solves the problem bacause it only avoids to look for an external clock before the crystal, but it ends up looking for the crystal anyway. You just save time with this change.

I also see the schematics and it uses a 8 MHz xtal with 16pF load capacitance, connected to two 20pF capacitors.

Any other idea?

posted by Viviana Marcela Quirama Cañaveral 21 Feb 2017
7 years, 2 months ago.

With the changes you made to get started it should have been identical performance as the stock Nucleo board. For some reason the clock crystal is not oscillating. What was the part number of the crystal that you soldered in at X3? And what value resistors did you use at R35 R37?

Yes the performance is the same, but you need the external crystal if you cut off the debug part and the internal osc, is not usable for your application. I have set up a test with a Nucleo L053 board. R35 and R37 = 0R (wire) C33 and C34 = 18pF. The board is working with all crystals out of my box from 4MHz to 12MHz. You see the different blinking speed of the led test program.

posted by Peter Drescher 19 Feb 2017

I'm using a 8 MHz xtal with 16pF load capacitance, I took it from another Nucleo board. C33 and C34 are 20pF, R35 and R37 are 0 Ohm.

posted by Viviana Marcela Quirama Cañaveral 21 Feb 2017