Skip to main content
Graduate II
July 17, 2025
Question

USART & Clock issue/question STLINKV3 related

  • July 17, 2025
  • 2 replies
  • 611 views

Hi everyone.

 

Im using the nucleo-h743zi2 and im facing the following issue:

 

When trying to printf using redirect to usart3 with the following clock settings:

 

/**
 * @brief System Clock Configuration
 * The system Clock is configured as follow : 
 * System Clock source = PLL (HSE BYPASS)
 * SYSCLK(Hz) = 400000000 (CPU Clock)
 * HCLK(Hz) = 200000000 (AXI and AHBs Clock)
 * AHB Prescaler = 2
 * D1 APB3 Prescaler = 2 (APB3 Clock 100MHz)
 * D2 APB1 Prescaler = 2 (APB1 Clock 100MHz)
 * D2 APB2 Prescaler = 2 (APB2 Clock 100MHz)
 * D3 APB4 Prescaler = 2 (APB4 Clock 100MHz)
 * HSE Frequency(Hz) = 8000000
 * PLL_M = 4
 * PLL_N = 400
 * PLL_P = 2
 * PLL_Q = 4
 * PLL_R = 2
 * VDD(V) = 3.3
 * Flash Latency(WS) = 4
 * @PAram None
 * @retval None
 */
static void SystemClock_Config(void)
{
 RCC_ClkInitTypeDef RCC_ClkInitStruct;
 RCC_OscInitTypeDef RCC_OscInitStruct;
 HAL_StatusTypeDef ret = HAL_OK;

 /* The voltage scaling allows optimizing the power consumption when the device is
 clocked below the maximum system frequency, to update the voltage scaling value
 regarding system frequency refer to product datasheet. */
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}

 /* Enable D2 domain SRAM3 Clock (0x30040000 AXI)*/
 __HAL_RCC_D2SRAM3_CLK_ENABLE();

 /* Enable HSE Oscillator and activate PLL with HSE as source */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
 RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
 RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
 RCC_OscInitStruct.CSIState = RCC_CSI_OFF;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

 RCC_OscInitStruct.PLL.PLLM = 4;
 RCC_OscInitStruct.PLL.PLLN = 400;
 RCC_OscInitStruct.PLL.PLLFRACN = 0;
 RCC_OscInitStruct.PLL.PLLP = 2;
 RCC_OscInitStruct.PLL.PLLR = 2;
 RCC_OscInitStruct.PLL.PLLQ = 4;

 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_1;
 ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
 if(ret != HAL_OK)
 {
 while(1);
 }

 /* Select PLL as system clock source and configure bus clocks dividers */
 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 | \
 RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1);

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2; 
 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; 
 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2; 
 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2; 
 ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
 if(ret != HAL_OK)
 {
 while(1);
 }
}

Only works when im doing firmware update to 5MHZ HSE.

I tried to configure a setting trough stm32cubeMX with 8MHZ as input and 400MHZ as Sysclk  but got only garbge when printing.

I add this code + the stm32h..msp file to my src to the lwip_netconn_rtos example

Any ideas or explaination would be awosome thx! 

    This topic has been closed for replies.

    2 replies

    Super User
    July 17, 2025

    > RCC_HSE_BYPASS

    The clock rate used in the calculations will need to match the clock rate coming in. You do this by setting HSE_VALUE in the code, or on the left in the IOC clock tab.

    The clock rate coming in from the st-link is typically 8 MHz, but this can also be changed via the firmware upgrade tool.

    Ariel1Author
    Graduate II
    July 17, 2025

    Yea thats the weird  thing is that when trying to config with 5MHZ input +400MHZ sysclk in stm32cubeMX and using these settings the printf is outputting garbage.

    And when using 5MHZ and the settings i sent above it output correctly🥲

     

    Any ideas what could make this happen? 

    Maybe other settings in this example that i miss? https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Projects%2FNUCLEO-H743ZI%2FApplications%2FLwIP%2FLwIP_HTTP_Server_Netconn_RTOS%2FSrc 

    Super User
    July 17, 2025

    Is your st-link clock set to output 5 MHz? Sounds like it is.

    Open stm32cubeprogrammer, go into firmware upgrade.

    Super User
    July 17, 2025

    The problem is that the bypass HSE clock source going from the ST-LINK has two options: the default is 8.0 MHz but its source is HSI - which is imprecise. If you want the precise HSE - then the frequency will be 25/3 = 8.3(3).

    With the latest firmware you can select  also HSE/5.

     

    PavelA_0-1752783928630.png

    PavelA_1-1752784683590.png

     

    Ariel1Author
    Graduate II
    July 17, 2025

    You can also use 5MHZ HSE -
    https://community.st.com/t5/stm32-mcus/how-to-use-stlink-v3-mco-output-on-nucleo-boards-as-a-precise/ta-p/723361
    I Hope it will help you also (:

    with this can you look at my 2 questions above please?
    @Pavel A. 

    Thanks (:

    Super User
    July 17, 2025

    Is HSE_VALUE defined in the Eclipse project preprocessor defines? Defining only in hal_conf.h is not enough IIRC. I don't remember why exactly. 

    Yep I stand corrected, thanks.