The code below shows how to configure pin A8 to output the MCO signal, the Sys clock is running at 16MHz by default,we set this signal to be the output in pin MCO but preescaled by 32 in order to have a more manageable 500KHz signal.

#include "bsp.h"

int main( void )
{
    GPIO_InitTypeDef GPIO_InitStruct; /*gpios init structure*/
    
    HAL_Init();     /*Init HAL library and call the HAL_MspInit function*/
    
    __HAL_RCC_GPIOA_CLK_ENABLE();     /*eneable port A clock */
    
    /*Set pin A8 as MCO to reflect the sysclok frequency*/
    GPIO_InitStruct.Pin   = GPIO_PIN_8;
    GPIO_InitStruct.Mode  = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull  = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
    /*apply configuration configuracion*/
    HAL_GPIO_Init( GPIOA, &GPIO_InitStruct );
    
    /*set the MCO1 to output the internal Sysclock signal divided by 32
    we gonna get a frequecy of 500KHz, since by default the sysclock
    frequency is 16MHz*/
    HAL_RCC_MCOConfig( RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_32 );
    
    while (1)
    {
    }
}