Library 40- Output clocks from STM32F4
STM32F4 has capability to output different clocks on specific 2 pins. You are able to output clocks in original frequency (no prescaler) and also with prescaler values 2, 3, 4 and 5.
2 pins are used to output different frequencies. They are not able to output the same clocks. You can output:
- MCO1
- HSI: High Speed Internal oscillator, 16MHz RC
- HSE: High Speed External oscillator, or External User clock
- LSE: Low speed, 32768Hz oscillator or ceramic resonator
- PLLCLK: Output clock from PLL
- Differ between settings for PLL
- MCO2
- SYSCLK: System core clock output
- PLLI2SCLK: Accurate clock for high-quality audio performance in I2S and SAI interfaces
- HSE: High Speed External oscillator, or External User clock
- PLLCLK: Output clock from PLL
- Differ between settings for PLL
Each clock can be output with no prescaler, or value between 2 – 5.
Library
Features
- Output different system clocks from STM32F4
- 2 output pins supported
Depedencies
- CMSIS
- STM32F4xx
- STM32F4xx RCC
- STM32F4xx GPIO
- TM
- TM GPIO
- defines.h
- TM GPIO
STM32F4xx | MCOx | Description |
---|---|---|
PA8 | MCO1 | MCO1 output pin |
PC9 | MCO2 | MCO2 output pin |
Functions and enumerations
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
/** * Prescaler value for output clock * * Parameters: * - TM_MCOOUTPUT_Prescaler_1 * Output original value of clock on MCO pin * - TM_MCOOUTPUT_Prescaler_2 * Output clock is orignial / 2 * - TM_MCOOUTPUT_Prescaler_3 * Output clock is original / 3 * - TM_MCOOUTPUT_Prescaler_4 * Output clock is original / 4 * - TM_MCOOUTPUT_Prescaler_5 * Output clock is original / 5 */ typedef enum { TM_MCOOUTPUT_Prescaler_1, TM_MCOOUTPUT_Prescaler_2, TM_MCOOUTPUT_Prescaler_3, TM_MCOOUTPUT_Prescaler_4, TM_MCOOUTPUT_Prescaler_5 } TM_MCOOUTPUT_Prescaler_t; /** * Possible output clocks on MCO1 pin * * Parameters: * - TM_MCOOUTPUT1_Source_HSI * High Speed Internal clock, 16MHz RC oscillator * - TM_MCOOUTPUT1_Source_HSE * High Speed External clock, external crystal or user clock * - TM_MCOOUTPUT1_Source_LSE * External 32738Hz low-speed oscillator or ceramic resonator * - TM_MCOOUTPUT1_Source_PLLCLK * Output from PLL */ typedef enum { TM_MCOOUTPUT1_Source_HSI, TM_MCOOUTPUT1_Source_HSE, TM_MCOOUTPUT1_Source_LSE, TM_MCOOUTPUT1_Source_PLLCLK } TM_MCOOUTPUT1_Source_t; /** * Possible output clocks on MCO2 pin * * Parameters: * - TM_MCOOUTPUT2_Source_SYSCLK * System core clock * - TM_MCOOUTPUT2_Source_PLLI2SCLK * Accurate clock for high-quality audio performance in I2S and SAI interfaces * - TM_MCOOUTPUT2_Source_HSE * High Speed External clock, external crystal or user clock * - TM_MCOOUTPUT2_Source_PLLCLK * Output from PLL * */ typedef enum { TM_MCOOUTPUT2_Source_SYSCLK, TM_MCOOUTPUT2_Source_PLLI2SCLK, TM_MCOOUTPUT2_Source_HSE, TM_MCOOUTPUT2_Source_PLLCLK } TM_MCOOUTPUT2_Source_t; /** * Initialize and prepare MCO1 pin to output clock * * No return */ extern void TM_MCOOUTPUT_InitMCO1(void); /** * Set output for MCO1 pin * * Parameters: * - TM_MCOOUTPUT1_Source_t Source * Specific clock source for MCO1 * - TM_MCOOUTPUT_Prescaler_t Prescaler * Prescaler used for clock * * No return */ extern void TM_MCOOUTPUT_SetOutput1(TM_MCOOUTPUT1_Source_t Source, TM_MCOOUTPUT_Prescaler_t Prescaler); /** * Initialize and prepare MCO2 pin to output clock * * No return */ extern void TM_MCOOUTPUT_InitMCO2(void); /** * Set output for MCO2 pin * * Parameters: * - TM_MCOOUTPUT2_Source_t Source * Specific clock source for MCO2 * - TM_MCOOUTPUT_Prescaler_t Prescaler * Prescaler used for clock * * No return */ extern void TM_MCOOUTPUT_SetOutput2(TM_MCOOUTPUT2_Source_t Source, TM_MCOOUTPUT_Prescaler_t Prescaler); |
Example
Example below outputs:
- HSI clock on pin MCO1 (PA8) with prescaler 2 = 16MHz / 2 = 8MHz
- SYSCLK clock on pin MCO2 (PC9) with prescaler 4
- On STM32F4-Discovery = 168MHz / 4 = 42MHz
- On STM32F429-Discovery = 180MHz / 4 = 45MHz
- On Nucleo F401RE = 84MHz / 4 = 21MHz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/** * Keil project for MCO output * * Before you start, select your target, on the right of the "Load" button * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision 5 */ /* Include core modules */ #include "stm32f4xx.h" /* Include my libraries here */ #include "defines.h" #include "tm_stm32f4_mco_output.h" int main(void) { /* Initialize system */ SystemInit(); /* Initialize MCO1 output, pin PA8 */ TM_MCOOUTPUT_InitMCO1(); /* Initialize MCO2 output, pin PC9 */ TM_MCOOUTPUT_InitMCO2(); /* Set MCO1 output = HSI with prescaler 2 = 16MHz / 2 = 8MHz*/ TM_MCOOUTPUT_SetOutput1(TM_MCOOUTPUT1_Source_HSI, TM_MCOOUTPUT_Prescaler_2); /* Set MCO2 output = SYSCLK / 4 */ TM_MCOOUTPUT_SetOutput2(TM_MCOOUTPUT2_Source_SYSCLK, TM_MCOOUTPUT_Prescaler_4); while (1) { } } |
Project is available on Github, download library below.
Output different clocks from STM32F4
Recent comments