Skip to main content
Explorer
December 18, 2024
Question

how to configure HSI in STM32L5...

  • December 18, 2024
  • 2 replies
  • 2373 views

Hello,

I would like to know if it's possible to configure my evaluation board HSI, I have this code and I would like to adapt it on my evaluation card and see if it is compatible with the rest :

 

 

// HSI
//
void SystemClock_Config(void)
 {

 RCC_OscInitTypeDef RCC_OscInitStruct =
	{ 
	0
	};
 RCC_ClkInitTypeDef RCC_ClkInitStruct =
	{
	0
	};

 /** Configure the main internal regulator output voltage
 */
 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE0) != HAL_OK)
	{
	Error_Handler();
	}

 /** Initializes the RCC Oscillators according to the specified parameters
 * in the RCC_OscInitTypeDef structure.
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI
	 | RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_LSE
	 | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_MSI;
 RCC_OscInitStruct.LSEState = RCC_LSE_BYPASS;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
 RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV1;
 RCC_OscInitStruct.LSIState = RCC_LSI_ON;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.MSIState = RCC_MSI_ON;
 RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL.PLLM = 2;
 RCC_OscInitStruct.PLL.PLLN = 23;
 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV8;
 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
	{
	Error_Handler();
	}

 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
	 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
	{
	Error_Handler();
	}

 /** Enable MSI Auto calibration
 */
 HAL_RCCEx_EnableMSIPLLMode();

 /** MCO configuration
 */
 HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1);

 //__HAL_RCC_PWR_CLK_ENABLE();
 }

 

 

With the .ioc file, it's better for understanding.

Thank you for your helps.

    This topic has been closed for replies.

    2 replies

    Super User
    December 18, 2024

    @DYann.1 wrote:

    my evaluation board .


    What evaluation board is it?

    And what STM32L5 chip, exactly?

    See: https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

     

    But HSI = the High-Speed Internal oscillator of the STM32L5 chip itself.

    Because it's internal to the chip, configuring it is entirely independent of what board it's mounted on.

     

    You can use CubeMX (either standalone, or within CubeIDE) to configure the clock system - including the internal oscillators.

    DYann.1Author
    Explorer
    December 19, 2024

    @Andrew Neil wrote:

    @DYann.1 wrote:

    my evaluation board .


    What evaluation board is it?

    And what STM32L5 chip, exactly?


    Hi,

    My board is STM32L552E-EV with STM32L552ZE MCU, yes in the example is the same microprocessor. I have this tab so how can I generate identical code in the example ?   
    DYann1_0-1734648095423.png

    How to select the HSI and configure the clock system to have the same code ?

    Super User
    December 20, 2024

    @DYann.1 wrote:

    How to select the HSI ...


    As you can see in the diagram, you have two options:

    AndrewNeil_0-1734689644857.png

    1. You can use it direct
    2. You can use it via the PLL

     


    @DYann.1 wrote:
    ... and configure the clock system to have the same code ?

    Just make the settings the same as in that example.

    Super User
    December 18, 2024

    Look at the values set by the code and duplicate those settings within the Clock Configuration tab in CubeMX.

    TDK_0-1734545335826.png

    If you're stuck, explain what you're stuck on along with a screenshot of your clock configuration screen.

     

    HSI is configured on by default, but it seems like you want to configure the PLL as well based on your post.

    DYann.1Author
    Explorer
    December 20, 2024

    @TDK wrote:

    Look at the values set by the code and duplicate those settings within the Clock Configuration tab in CubeMX.

    TDK_0-1734545335826.png

    If you're stuck, explain what you're stuck on along with a screenshot of your clock configuration screen.


    first, I would like to have these 5 lines,

    DYann1_1-1734652627829.png

    And after trying several options it seems to me that it's impossible to have LSI and LSE at the same time 
    DYann1_2-1734652813384.png

    Did I miss something ? Here is my configuration in this attached, can you tell me where the errors are ? Thank you

     

    PJ : _HSI_conf.zip

    Super User
    December 20, 2024

    What you have circled in the RTC clock selection. You can't have the RTC run from LSE and LSI at the same time.

    If you use LSI somewhere in the system it will be automatically enabled in CubeMX.