Arm Mbed OS support forum

Oscillator requirements for custom boards

Hello. I’m trying to bring up a custom board based on an existing NUCLEO board. What are the hardware requirements for the board?

Reference is the NUCLE-L432KC. What is on the board is specified in the documentation, but I have not found what is actually used or configurable to MbedOS.

Hello Sid,

Mbed selects and configures the system clock source for the NUCLEO-L432KC in the

mbed-os/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L432xC/system_clock.c

file as follows:

...


/**
  *   This file configures the system clock as follows:
  *=============================================================================
  * System clock source                | 1- PLL_HSE_EXTC        | 3- PLL_HSI
  *                                    | (external 8 MHz clock) | (internal 16 MHz)
  *                                    | 2- PLL_HSE_XTAL        | or PLL_MSI
  *                                    | (external 8 MHz xtal)  | (internal 4 MHz)
  *-----------------------------------------------------------------------------
  * SYSCLK(MHz)                        | 48                     | 80
  *-----------------------------------------------------------------------------
  * AHBCLK (MHz)                       | 48                     | 80
  *-----------------------------------------------------------------------------
  * APB1CLK (MHz)                      | 48                     | 80
  *-----------------------------------------------------------------------------
  * APB2CLK (MHz)                      | 48                     | 80
  *-----------------------------------------------------------------------------
  * USB capable (48 MHz precise clock) | YES                    | NO
  *-----------------------------------------------------------------------------
**/

#include "stm32l4xx.h"
#include "mbed_error.h"

// clock source is selected with CLOCK_SOURCE in json config
#define USE_PLL_HSE_EXTC 0x8 // Use external clock (ST Link MCO - not enabled by default)
#define USE_PLL_HSE_XTAL 0x4 // Use external xtal (X3 on board - not provided by default)
#define USE_PLL_HSI      0x2 // Use HSI internal clock
#define USE_PLL_MSI      0x1 // Use MSI internal clock

#define DEBUG_MCO        (0) // Output the MCO on PA8 for debugging (0=OFF, 1=SYSCLK, 2=HSE, 3=HSI, 4=MSI)

#if ( ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) )
uint8_t SetSysClock_PLL_HSE(uint8_t bypass);
#endif /* ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) */

#if ((CLOCK_SOURCE) & USE_PLL_HSI)
uint8_t SetSysClock_PLL_HSI(void);
#endif /* ((CLOCK_SOURCE) & USE_PLL_HSI) */

#if ((CLOCK_SOURCE) & USE_PLL_MSI)
uint8_t SetSysClock_PLL_MSI(void);
#endif /* ((CLOCK_SOURCE) & USE_PLL_MSI) */

...

You can configure Mbed to use the selected type of system clock source in an mbed_app.json configuration file.
For example, if you’d like to use an external 8 MHz crystal oscillator as clock source:

{
    "target_overrides":{
        "*": {
            "target.clock_source": "USE_PLL_HSE_XTAL"
        }
    }
}

Then Mbed first tries to use an external 8 MHz crystal oscillator. If no such clock signal is detected (because the custom board was not equipped with an external crystal oscillator) it tries to use the internal (on-chip) RC oscillator.

You can force the Mbed to use the internal oscillator even when the custom board is equipped with an external crystal oscillator. For example:

{
    "target_overrides":{
        "*": {
            "target.clock_source": "USE_PLL_HSI"
        }
    }
}

If you plan to use USB with your custom board then you should equip it with an external 8 MHz oscillator and configure it to provide the clock signal for the USB peripheral in the mbed_app.json file for example as:

{
    "target_overrides":{
        "*": {
            "target.clock_source": "USE_PLL_HSE_XTAL",
            "target.clock_source_usb": "1"
        }
    }
}

Best regards, Zoltan

If you are going to use a different frequency for the external clock, also add this line:
"macros_add": [ "HSE_VALUE=25000000ul" ],
in the custom_targets.json file.

Of course replace the example value with the actual frequency :slight_smile: