1.6k views
in System Integration by

Hello, I've built a graphical wizard application and am now trying to combine it with another code that was built on with cubeMX and hal and contains uart, spi, i2c, etc. But the clock in that application is configured to HSI 16MHz. The embedded wizard system clock config is configured to HSE 180MHz. What can I do to have the embedded wizard application running on a 16MHz clock? The other code cannot run at 180MHz and when I try to replace the embedded wizard system clock config function with the cubeMx system clock config function the screen doesnt light up at all anymore and when I try to use the clock config from embedded wizard in the other code that code doesn't work properly. It seems like it's one or the other! . My board is a stm32f469ni. The picture is a photo of the 16MHz clock in CubeMX. Any help would be appreciated at this point because I've tried many configurations and variations but nothing works. Thank you!

1 Answer

0 votes
by
Hello Nicolas and sorry for the late answer,

 

could you post me your whole c initialisation sequence please (SystemClock_Config) ?

Then it would be easier for me to find the issue.

 

At the first look, in your CubeMX initialisation the LTDC clock configuration is missing. Without this, the LTDC cannot bring any data to the display. Please check whether the LTDC clock configuration is also missing in the generated c code which you are using. Normally (simple) Embedded Wizard UIs should run with 18 MHz in the same way as with 180 Mhz.

 

Is your own code running in a separated task (FreeRTOS) ?

 

Greetings

 

Tim
by
Hello Tim, thank you for the answer!

This is the CubeMX SystemClock_Config:

void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

    /**Configure the main internal regulator output voltage
    */
  __HAL_RCC_PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

    /**Initializes the CPU, AHB and APB busses clocks
    */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Initializes the CPU, AHB and APB busses clocks
    */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  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_0) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Configure the Systick interrupt time
    */
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick
    */
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

***************************************************************************************************************************************************************************

I am running the standard Embedded Wizard SystemClock_Config in ew_bsp_system.c :

static void SystemClock_Config( void )
{
  RCC_ClkInitTypeDef        RCC_ClkInitStruct;
  RCC_OscInitTypeDef        RCC_OscInitStruct;
  RCC_PeriphCLKInitTypeDef  PeriphClkInitStruct;

  /* Enable Power Control clock */
  __HAL_RCC_PWR_CLK_ENABLE();

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

  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState       = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState   = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource  = RCC_PLLSOURCE_HSE;
#if defined(USE_STM32469I_DISCO_REVA)
  RCC_OscInitStruct.PLL.PLLM       = 25;
#else
  RCC_OscInitStruct.PLL.PLLM       = 8;
#endif /* USE_STM32469I_DISCO_REVA */
  RCC_OscInitStruct.PLL.PLLN       = 360;
  RCC_OscInitStruct.PLL.PLLP       = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ       = 7;
  RCC_OscInitStruct.PLL.PLLR       = 6;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  /* Activate the Over-Drive mode */
  HAL_PWREx_EnableOverDrive();

  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
     clocks dividers */
  RCC_ClkInitStruct.ClockType      = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  RCC_ClkInitStruct.SYSCLKSource   = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider  = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

  /* LCD clock configuration */
  memset( &PeriphClkInitStruct, 0, sizeof( PeriphClkInitStruct ));
  HAL_RCCEx_GetPeriphCLKConfig( &PeriphClkInitStruct );
  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;

#if EW_USE_DOUBLE_BUFFER == 1

  /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 MHz */
  /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 364 MHz */
  /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 364 MHz / 7 = 52.0 MHz */
  /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 52.0 / 2 = 26,0 MHz */
  /* These reduced LTDC clock frequency is neccessary to avoid display artefacts
     that occur on higher LTDC clock frequencies, if there is heavy memory access
     by application during display update */
  PeriphClkInitStruct.PLLSAI.PLLSAIN = 364;
  PeriphClkInitStruct.PLLSAI.PLLSAIR = 7;

#else

  /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 MHz */
  /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 417 MHz */
  /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 417 MHz / 5 = 83.4 MHz */
  /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 83.4 / 2 = 41.7 MHz */
  PeriphClkInitStruct.PLLSAI.PLLSAIN = 417;
  PeriphClkInitStruct.PLLSAI.PLLSAIR = 5;

#endif

  PeriphClkInitStruct.PLLSAIDivR     = RCC_PLLSAIDIVR_2;
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}

************************************************************************************************************************************************************************

I don't really understand what the LTDC clock configuration would be in the generated code. I can't find anything containing LDTC in the GeneratedCode folder but the TargetSpecific folder does contain the necessary LTDC initialisations.

I've tried running the the cubeMX SystemClock_Config() and the running the Embedded Wizard SystemClock_Config before the EmWiMainLoop() to make sure nothing was missing from that one but that didn't work.

I'm not using freeRTOS (I know I probably should). I put my cubeMX while(1) code in the embedded wizard main loop in the while ( cmd != CoreKeyCodePower ) loop after the Embedded Wizard code. I'm pretty sure it would work if not for the timer difference because when I only run the Embedded Wizard SystemClock_Config the screen does work and the cubeMX code also works just not at the right frequency which messes up the uart, spi, etc.

Thank you for your help!
by

Hello Nicolas,

 

to initialise the LTDC with CubeMX it is also necessary to enable and adjust these module. I recommend to use the EwBspConfigSystem() function to configure the clock and all other peripherals. Try to change the code parts in SystemClock_Config(void) located in ew_bsp_system.c which are necessary for your project (clock source).


  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState       = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState   = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource  = RCC_PLLSOURCE_HSE;
#if defined(USE_STM32469I_DISCO_REVA)
  RCC_OscInitStruct.PLL.PLLM       = 25;
#else
  RCC_OscInitStruct.PLL.PLLM       = 8;
#endif /* USE_STM32469I_DISCO_REVA */
  RCC_OscInitStruct.PLL.PLLN       = 360;
  RCC_OscInitStruct.PLL.PLLP       = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ       = 7;
  RCC_OscInitStruct.PLL.PLLR       = 6;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

The Embedded Wizard main loop must call permanently. If you insert an while(1) function inside the Embedded Wizard loop it is impossible to refresh the display.

King regards

Tim

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...