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:

Hi again, thanks for the information. Per Zoltan’s comment it seems like the oscillator will be automatically configured to the internal RC oscillator.

Knowing this I created a board that is essentially a STM32L432KC and a debug connector.

When debugged, the device does start running my code. Most of the real interaction my program does is in RTOS tasks, and the device runs the initialization of those tasks and then sleeps. It never wakes up. The device pauses indefinitely at stm32l4xx_hal_pwr.c:481 which is a wait for interrupt instruction.

What might be wrong with the clock subsystem? Anything else to check?

The STM32L432KC is using the tickless feature of the Mbed RTOS. Try to disable the tickless feature via a mbed_app.json configuration file. For example:

{
    "target_overrides": {
        "*": {
            "target.macros_remove": ["MBED_TICKLESS"]
        }
    }
}

Or call sleep_manager_lock_deep_sleep(); to disable the deep sleep mode at begin of your program.

1 Like

Thanks Zoltan. I’ve added indicated lines to mbed_app.json and additionally tried calling sleep_manager_lock_deep_sleep. Unfortunately, if I set a breakpoint on main I can step my code until I call ThisThread::sleep_for and I see the MCU enter sleep but never wake.

My basic checklist is figuring out that I’ve got the newest version of mbed, etc. How do I do that? Is there anything else to check? I’ve tried doing a clean build as well.

I notice that list from gdb prints out the wrong source file somehow and am concerned about the build artifacts. I can follow up with this and get back to the forum on it if it turns up being build system related, but I am hoping there is some set of common issues that someone experienced with mbed could point me to.

Longer term I’d like to figure out what is making the sleep behavior malfunction, but I’m fine with getting tickful mode set up.