on
2024-09-26
05:00 AM
- edited on
2024-10-02
06:46 AM
by
Laurids_PETERSE
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.
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:
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.
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.
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:
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):
For the STM32CubeProgrammer tool, you need to follow these steps (see figure 5):
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: