STM32 MCO OUTPUT
Posted: Thu Mar 14, 2019 12:00 pm
The STM32's have a possibility to bring out a clock signal called `MCO`. It takes one of the selected clock sources, puts it through a divider and brings it out to a GPIO pin. I use it to spare a crystal in a design. Be aware that when having a long wire attached to the pin, you create a nice transmitter, but if ever need the MCO this is a way to add it to micropython:
Add to the `mpconfigboard.h` of your board:
Create or modify the `board_init.c` and place in your target board directory like `boards/NUCLEO_F091RC`
Add to the `mpconfigboard.h` of your board:
Code: Select all
#define MICROPY_BOARD_EARLY_INIT STM32F091RC_board_early_init
void STM32F091RC_board_early_init(void);
#define MICROPY_HW_MCO (1)
Code: Select all
#include STM32_HAL_H
#include "mpconfigboard.h"
void STM32F091RC_board_early_init(void) {
#if defined(MICROPY_HW_MCO)
/* redirect to: source RCC_MCOSource: prescaler RCC_MCODiv:
* RCC_MCO1: PA8 RCC_MCO1SOURCE_HSI RCC_MCODIV_1
* RCC_MCO2: PC9 RCC_MCO1SOURCE_LSE RCC_MCODIV_2
* RCC_MCO1SOURCE_HSE RCC_MCODIV_3
* RCC_MCO1SOURCE_PLLCLK RCC_MCODIV_4
* RCC_MCO2SOURCE_SYSCLK RCC_MCODIV_5
* RCC_MCO2SOURCE_PLLI2SCLK
* RCC_MCO2SOURCE_I2SCLK
* RCC_MCO2SOURCE_HSE
* RCC_MCO2SOURCE_PLLCLK
**/
// output 8MHz to the PA8 output
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1);
#endif
}