AnsweredAssumed Answered

STM32F405 RCC HSI CubeMx Config Error

Question asked by o gaste on Jun 9, 2017
Latest reply on Jun 9, 2017 by Imen D

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

 

 

Attachments

Outcomes