cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F405 RCC HSI CubeMx Config Error

o gaste
Associate III
Posted on June 09, 2017 at 12:31

hello

I'm using a STM32F405RG LQFP64 with an oscillator of 8mhz I configured all clock up to max speed using HSE as PLLSRC and PLLCLK as SYSCLK src all looks good on cubemx config and generated code looks good too

   /**Initializes the CPU, AHB and APB busses clocks

    */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;

  RCC_OscInitStruct.HSEState = RCC_HSE_ON;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

  RCC_OscInitStruct.PLL.PLLM = 4;

  RCC_OscInitStruct.PLL.PLLN = 168;

  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

  RCC_OscInitStruct.PLL.PLLQ = 7;

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

  {

    Error_Handler();

  }

but when i dig in HAL_RCC_OscConfig() it looks that 'HSI config' section is exiting on error

/*----------------------------- HSI Configuration --------------------------*/

  if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)

  {

    /* Check the parameters */

    assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));

    assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));

    /* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */

    if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSI) ||\

      ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSI)))

    {

      /* When HSI is used as system clock it will not disabled */

      if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))

      {

        return HAL_ERROR;

      }

      /* Otherwise, just the calibration is allowed */

      else

      {

        /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/

        __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);

      }

    }

else

    {

      /* Check the HSI State */

      if((RCC_OscInitStruct->HSIState)!= RCC_HSI_OFF)

      {

        /* Enable the Internal High Speed oscillator (HSI). */

        __HAL_RCC_HSI_ENABLE();

it falls into error because it checks RCC_FLAG_HSIRDY before configuring HSI and as HSI is default clock src at reset it's always ready

I want to disable HSI so logicaly RCC_OscInitStruct->HSIState is set to RCC_HSI_OFF (by defaut)

and as the set of HSI config comes after it's never disable

to make it work I can just remove RCC_OSCILLATORTYPE_HSI in RCC_OscInitStruct.OscillatorType it will keep HSI ON but it select correctly HSE, PLL SRC, and SYSCLK source

I dont want to say it's a mistake in HAL and I'm pretty sure I made something wrong but I already use Cube MX on other stm32F mcu (cortex M3 and M4 and others) and It's the first time I have this type of issue

if some one can see what I did wrong I would be nice

thank's for any idea

ps : I put my cubemx '.ioc' file in attachement if it helps

3 REPLIES 3
Imen.D
ST Employee
Posted on June 09, 2017 at 12:44

Hi

olivier.gaste

,

You are using an old CubeMx version with limitation

in the clock configuration and t

his has been corrected.

I advise you to upgrade to the last version CubeMx 4.0

Thanks

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on June 09, 2017 at 13:53

YEAAAAA !!!

tank's a lot Imen D !! once again you saved my life !!

I updated the cubeMx and It looks to work at least for RCC

I needed to rebuild totaly the IOC config because automatic import of old versioned IOC file looks to dead lock project files generation

but it's not a big issue

thank's again

Posted on June 09, 2017 at 14:55

Hi

olivier.gaste

,

You are welcome

To usean old .ioc project, you should first EDIT the .ioc file and REMOVE theRCC.OscillatorType that you don't need:

E.g: Remove this line

RCC.OscillatorTypeHSI=RCC_OSCILLATORTYPE_HSI

Then re-generate the project and this will resolve your problem.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen