cancel
Showing results for 
Search instead for 
Did you mean: 

How to use STLINK-V3 MCO output on Nucleo boards as a precise clock source for STM32

SofLit
ST Employee

Introduction

For cost reasons, many ST boards do not feature an external Crystal to feed the STM32’s system clock over the high-speed external clock (HSE).  On the other hand, some peripherals need a precise clock source to work and behave correctly such as CAN, FDCAN, etc. 
For these peripherals, HSI is not recommended, as the precision could be influenced over time by different factors: temperature, voltage, reflow effects, mechanical effects etc.

STLINK-V3 MCO output could be a good precise clock source for the target MCU.

This article shows how to use this source to fit the application needs. It applies only to STLINK-V3 embedded on the ST boards mainly on Nucleo boards.

This article does not apply to standalone STLINK-V3 devices.

1. Principle

The STLINK V3 module is managed by a STM32F723 MCU. This MCU can generate a clock signal on its MCO pin PA8. This clock could be used as a clock source of the target MCU of the board (see figure 1). This clock is originally generated from two principal clock sources over internal dividers:

  • The internal HSI of STM32F723 MCU.
  • The external crystal clock over HSE.

In case of the crystal, it is clocked over its OSC_IN and OSC_OUT pins over HSE. The value of the crystal could vary from an STLINK to another depending on the board. For example, on NUCLEO-H753ZI board (MB1364), the STLINK has a crystal oscillator having a value of 25 MHz while NUCLEO-H563ZI board (MB1404) has a crystal with a value of 24 MHz

Figure 1. Block diagramFigure 1. Block diagram

The following figures are the parts of schematics of NUCLEO-H753ZI (MB1364), and NUCLEO-H563ZI (MB1404).

The two schematics (figure 2 and figure 3) show how the STLINK-V3 module is clocked and how the MCO output is feeding the HSE of the target MCU. The MCO output is connected over a resistor and a solder bridge. Refer to the schematics of the respective board for more details.

Figure 2. NUCLEO-H753ZI: STLINK crystal oscillator of 25 MHzFigure 2. NUCLEO-H753ZI: STLINK crystal oscillator of 25 MHz

Figure 3. NUCLEO-H563ZI: STLINK crystal of 24 MHzFigure 3. NUCLEO-H563ZI: STLINK crystal of 24 MHz

2. How to get MCU target HSE fed by STLINK-V3 MCO with an accurate clock source

2.1. STLINK configuration

Starting from V3J7M2 version of STLINK-V3 firmware, the MCO frequency is configurable by the user using either the STLINK firmware upgrade tool or STM32CubeProgrammer using the [Firmware upgrade] button.
Firstly, refer to the respective board schematics. On the board, check the status of the solder bridges and resistors on the path of STLINK-V3 MCO pin output and OSC_IN pin input of the target MCU. This is to ensure that the clock signal arrives on OSC_IN pin.
Second, as the MCO clock needs to be accurate for the application, the selected clock output needs to be generated from HSE, which is generated from the crystal and not from HSI (16 MHz) generated internally by the STLINK-V3 MCU.
For example, in the case of NUCLEO-H753ZI, you may find the following options:

  • HSE/3 (8.33 MHz): generated by HSE 25 MHz/3 = 8.333333 MHz
  • HSE/4 (6.25 MHz): generated by HSE 25 MHz/4 = 6.25 MHz
  • HSE/5 (5 MHz): generated by HSE 25 MHz/5 = 5 MHz
  • HSI/2 (8 MHz): generated by HSI 16 MHz/2 = 8 MHz (generated from the internal MCU HSI)
  • Off: MCO output disabled

The option HSI/2 is discarded as it is generated from HSI.

The first option 8.333 MHz is generated from HSE but it presents a limitation because of an “infinite” decimal that prevents finding exact frequencies while selecting a frequency for system clock or for a PLL output. This is especially when a fractional feature in the PLL of the target MCU is not present.
The second 6.25 MHz could be an option. It has decimals, but are “finite”.
The more practical value is the third option, which is 5 MHz.

To modify the MCO frequency, you need to connect a USB data cable to the STLINK-V3 of the board and open one of the tools mentioned previously.

For the STLINK firmware upgrade tool, you need to follow these steps (see figure 4):

  • Step 1: Open the STLINK firmware upgrade tool and click the [Device Connect] button.
  • Step 2: Select the frequency that you need to output on the STLINK MCO and click the [Yes >>>] button to proceed for the update.
  • Step 3: Wait for the update to be completed. In the meantime, the STLINK LED is blinking.
  • Step 4: You receive a prompt that the upgrade was successful. Click the [OK] button.

Figure 4. Using ST-LINK firmware upgrade tool to modify the MCO frequencyFigure 4. Using ST-LINK firmware upgrade tool to modify the MCO frequency

For the STM32CubeProgrammer tool, you need to follow these steps (see figure 5):

  • Step 1: Open the STM32CubeProgrammer tool and click the [Firmware upgrade] button.
  • Step 2: A new window is opened. Click on [Refresh device list]. STLINK ID needs to be displayed under the button [Open in update mode]. Then click on this button to let STLINK enter the upgrade mode.
  • Step 3: In the [MCO Output] menu, select the needed frequency and click [Upgrade] button.
  • Step 4: The upgrade will start and the STLINK LED is blinking. Wait until the progress bar reaches 100%. The STLINK firmware is updated.

Figure 5. Using STM32CubeProgrammer tool to modify the MCO frequencyFigure 5. Using STM32CubeProgrammer tool to modify the MCO frequency

2.2. The MCU target clock configuration

The RCC of the MCU target needs to be configured to set STLINK-V3 MCO output as an external clock source. To do so, the RCC needs to be configured in Bypass mode. For more details about this configuration, refer to the respective reference manual and the datasheet of the MCU product.
Example: we need to set the system clock of the STM32H753 MCU (on NUCLEO-H753ZI) at 400 MHz and the RCC in Bypass mode with a clock source HSE of 5 MHz using STM32CubeMX tool:

  • Step 1: Go to the [Pinout & Configuration] tab and click [RCC].
  • Step 2: In the [Mode] menu, select [Bypass Clock Source] for [High Speed Clock (HSE)].
  • Step 3: Go to the [Clock Configuration] tab and set the [Input frequency] in the blue box to the same value already set for STLINK-V3 MCO (see section 2.1.) In this example, 5 MHz is set.
    Warning: Set the same input frequency value as the one configured on STLINK-V3. If the input frequency is not the same, the clock configuration is incorrect, and issues will appear in the application.
  • Step 4: Select [HSE] as an external clock source of the MCU, then select [PLLCLK] as a source clock of the system. Finally, type the desired system frequency in the writable box and hit the [Enter] key and wait until STM32CubeMX compute all the possibilities to set the final configuration. In this example, 400 MHz is selected as the system frequency.

Figure 6. Using STM32CubeMx tool to set the right RCC configurationFigure 6. Using STM32CubeMx tool to set the right RCC configuration

Related links

 

Version history
Last update:
‎2024-10-02 06:46 AM
Updated by: