Skip to main content

MIPI-DSI Video Mode

This section describes how to configure a MIPI DSI interface for Video Mode and how to use this configuration with TouchGFX Generator. The example used in this article will be for 24-bit, RGB888, frame buffer format and generally goes through the following configurations in STM32CubeMX and examplifies with generated code.

  • LTDC IP
  • DSI-HOST IP
  • TouchGFX Generator

STM32CubeMX - Hardware configuration

LTDC

  • Mode
    • Set Display Type to RGB888 (24 bits) - DSI Mode
  • Layer Settings
    • Set Number of layers to 1 layer
    • Set Layer 0 - Pixel Format to RGB888
    • Set Layer 0 - Alpha constant for blending to 255

      LTDC Configuration

  • NVIC Settings
    • Enable LCD-TFT global interrupt

      LTDC NVIC Settings

DSIHOST Configuration

  • Mode
    • Set DSIHost to Video Mode
  • Display Interface
    • Set Color Coding to RGB888 (24 bits) - DSI mode
    • Remaining configurations depends on the selected LCD HW

      DSIHOST Configuration

  • NVIC Settings
    • DSIHOST global interrupt is not needed and should be disabled.

      DSIHOST NVIC Settings

STM32CubeMX - TouchGFX Generator

  • Mode
    • Enable Graphics Application
  • TouchGFX Generator
    • Set Display / Interface to Parallel RGB (LTDC) since this is still the controller the application needs to communicate with.
    • Set Application Tick Source to LTDC

      TouchGFX Generator Configuration

DSIHOST / LTDC Initialization sequence

  • The call to MX_DSIHOST_DSI_Init() must be done before MX_LTDC_Init(). This should be handled by CubeMX.

  • Call HAL_DSI_Start() at the end of MX_DSIHOST_DSI_Init(), in a User Code section.

  • After calling HAL_DSI_Start(), switch DSIHOST clock to the DSIPHY source.

    /**
    * @brief DSIHOST Initialization Function
    * @param None
    * @retval None
    */
    static void MX_DSIHOST_DSI_Init(void)
    {
    ...

    /* USER CODE BEGIN DSIHOST_Init 2 */
    // Start DSI
    if (HAL_DSI_Start(&hdsi) != HAL_OK)
    {
    Error_Handler();
    }

    /* Switch to DSI PHY PLL clock */
    RCC_PeriphCLKInitTypeDef PeriphClkInit;
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_DSI;
    PeriphClkInit.DsiClockSelection = RCC_DSICLKSOURCE_DSIPHY;
    HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
    /* USER CODE END DSIHOST_Init 2 */

    ...
    }
  • User has to add the required initialization code specific to the used LCD controller at the end of the MX_LTDC_Init() function.

    • That code will be based on the DSI HAL APIs HAL_DSI_ShortWrite() and HAL_DSI_LongWrite()
    /**
    * @brief LTDC Initialization Function
    * @param None
    * @retval None
    */
    static void MX_LTDC_Init(void)
    {
    ...

    /* USER CODE BEGIN LTDC_Init 2 */
    // Specific LCD controller's initialization code
    ...

    // Exit Sleep Mode
    if (HAL_DSI_ShortWrite(&hdsi, 0, DSI_DCS_SHORT_PKT_WRITE_P0, DSI_EXIT_SLEEP_MODE, 0x00) != HAL_OK)
    {
    Error_Handler();
    }

    HAL_Delay(120);
    /* USER CODE END LTDC_Init 2 */

    ...
    }

Updated TouchGFXHAL class for DSI Video Mode

The code for the LTDC interrupt is identical to the code generated when using Parallel RGB display interface.

One way to prevent the MIPI DSI display from turning on until we've rendered the first frame in the application is to guard the function TouchGFXHAL::endFrame to keep the display off until first frame is rendered by TouchGFX. The TouchGFXHAL::endFrame() could be updated as below, to enable the LCD and its Backlight through a HW Timer configured for PWM output.

void TouchGFXHAL::endFrame()
{
if (!display_on)
{
display_on = true;
/* Enable the LCD, Send Display on DCS command to display */
HAL_DSI_ShortWrite(&hdsi, 0, DSI_DCS_SHORT_PKT_WRITE_P1, DSI_SET_DISPLAY_ON, 0x00);
/* Start PWM Timer channel */
(void)HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_2);
/* Enable Backlight by setting Brightness to 100% */
__HAL_TIM_SET_COMPARE(&htim8, TIM_CHANNEL_2, 2U * 100);
}

TouchGFXGeneratedHAL::endFrame();
}