cancel
Showing results for 
Search instead for 
Did you mean: 

how to configure HSI in STM32L5...

DYann.1
Senior II

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.

22 REPLIES 22

> Thank you but your answer is not very precis, did you see my projet.zip ?

I saw your zip file. Did you see my answer?

As I said, you will have to use LSI as a clock source to something if you want CubeMX to enable it. Otherwise it is not needed and will not be enabled.

If you feel a post has answered your question, please click "Accept as Solution".

@Andrew Neil wrote:

You said you'd made changes since the zip file you posted.


Yes it's the case with my _HSI_conf project (in projet I have the .ioc file) but I don't have the same code. What I would like to obtain 

 

 

    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI
	    | RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_LSE
	    | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_MSI;

 

 

And with  _HSI_conf project I have this code :

DYann1_1-1734702557371.png

 

 

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI
                              |RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;

 

 

I'm missing the RCC OSCILLATOR TYPE LSI line


@TDK wrote:

As I said, you will have to use LSI as a clock source to something if you want CubeMX to enable it. Otherwise it is not needed and will not be enabled.


Always very vague and evasive, nothing concrete. Can you modify my .ioc file in my _HSI_conf projet and show me the generated code ?

DYann1_0-1734702186625.png

And I have this code

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI
                              |RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_MSI;

And this is the code I am waiting for :

    /** 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;

I'm missing the RCC_OSCILLATORTYPE_LSE line