cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G-Disco Bd, doesn't display correctly in portrait mode

JJoha.2
Associate III

I started a project from scratch in CubeMX. 

and the set TouchGFX for portrait as :

Middleware->Graphics->TouchGFX, changed width : 272 and Height : 480. 

In TouchGFX designer it displays correctly as Portrait(see PortraitFromTouchGFX).PNG) but when I compiled using IAR and deployed it on the target bd, it doesn’t display correctly (see From STM32F746-Disco Display.jpg )

In Hal.hpp : It automatically sets the display orientation based on width/height, so I don't think I need to do anything else. (Changing LTDC etc)

 HAL(DMA_Interface& dmaInterface, LCD& display, TouchController& touchCtrl, uint16_t width, uint16_t height) :

    dma(dmaInterface),

    lcdRef(display),

    touchController(touchCtrl),

    mcuInstrumentation(0),

    buttonController(0),

    taskDelayFunc(0),

    frameBuffer0(0),

    frameBuffer1(0),

    frameBuffer2(0),

    refreshStrategy(REFRESH_STRATEGY_DEFAULT),

    fingerSize(1),

    lockDMAToPorch(true),

    touchSampleRate(1),

    mcuLoadPct(0),

    vSyncCnt(0),

    vSyncForFrame(1),

    vSyncCompensationEnabled(false),

    clientDirty(false),

    swapRequested(false),

    lastTouched(false),

    updateMCULoad(0),

    cc_begin(0),

    displayOrientationChangeRequested(false)

  {

    instance = this;

    DISPLAY_WIDTH = width;

    DISPLAY_HEIGHT = height;

    DISPLAY_ROTATION = rotate0;

    FRAME_BUFFER_WIDTH = DISPLAY_WIDTH;

    FRAME_BUFFER_HEIGHT = DISPLAY_HEIGHT;

    nativeDisplayOrientation = ((width >= height) ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);

  }

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III
13 REPLIES 13
Martin KJELDSEN
Chief III

Hi @JJoha.2​, can you tell me in your generated code what the ImageWidth and ImageHeight for your LTDC layer configuration is set to ?

Did you also ensure that your images are being rotated in the TouchGFX application configuration? (config/gcc/app.mk).

TouchGFX can be configured to render in portrait mode even if your hardware configuration is configured for landscape. That's why the image converter can be configured to rotate the images.

You can read more about rotating TouchGFX applications here:

https://touchgfx.zendesk.com/hc/en-us/articles/203563972-Display-Orientation

Let me know if this helps. If you're still having problems, i'll try to create an example on a disco board.

Thanks!

Martin KJELDSEN
Chief III

I did a few examples on an STM32F769-DISCO i have at home to exemplify how rotation generally works in TouchGFX.

The Canvas in your touchgfx application should match the native orientation of your display (in terms of where the first pixel is drawn and the direction subsequent pixels are drawn). If it doesn't because you either cannot change it or because you need to support a runtime change in display orientation you can do so in software with TouchGFX.

The LTDC layer configuration i'm running is 800x480 (landscape).

The following image shows the Button Example running correctly in portrait mode (Chose it because it's width is the same as the height of the display on stm32f769-disco). I'm doing this by configuring two things:

1) I'm telling the image converter to rotate all my images by changing the value of the scren_orientation property in the file config/gcc/app.mk.

screen_orientation := -rotate90

2) By forcing TouchGFX HAL into portrait mode. This mode will automatically translate touch coordinates as well. You were correct in assuming that, initially, HAL will determine the orientation as determined by the width and height of the display (Different from the width and height of the application canvas)

HAL::getInstance()->setDisplayOrientation(ORIENTATION_PORTRAIT);

0690X000006CyHoQAK.png

The following image shows the application running incorrectly because i rotated my images but "forgot" to tell TouchGFX HAL that i wanted to render frames rotated 90 degrees by calling setDisplayOrientation()

0690X000006CyHyQAK.png

The following image shows the application running incorrectly because i "forgot" to rotate the images, but correctly told HAL to render frames rotated 90 degrees.

0690X000006CyI3QAK.png

JJoha.2
Associate III

Martin,

Thanks for your valuable response. Could you please share the source code with landscape and portrait that you have mentioned above?. In the meantime I'll try what you have suggested above

JJoha.2
Associate III

Here are my settings for LTDC

void MX_LCD_Init(void) 

 LTDC_LayerCfgTypeDef pLayerCfg;

/* De-Initialize LTDC */

 HAL_LTDC_DeInit(&hltdc);

/* Configure LTDC */

 hltdc.Instance = LTDC;

 hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;

 hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;

 hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;

 hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;

 hltdc.Init.HorizontalSync = 40;

 hltdc.Init.VerticalSync = 9;

 hltdc.Init.AccumulatedHBP = 53;

 hltdc.Init.AccumulatedVBP = 11;

 hltdc.Init.AccumulatedActiveW = 533;

 hltdc.Init.AccumulatedActiveH = 283;

 hltdc.Init.TotalWidth = 565;

 hltdc.Init.TotalHeigh = 285;

 hltdc.Init.Backcolor.Blue = 0;

 hltdc.Init.Backcolor.Green = 0;

 hltdc.Init.Backcolor.Red = 0;

 if (HAL_LTDC_Init(&hltdc) != HAL_OK)

 {

  Error_Handler( );

 }

 pLayerCfg.WindowX0 = 0;

 pLayerCfg.WindowX1 = 480;

 pLayerCfg.WindowY0 = 0;

 pLayerCfg.WindowY1 = 272;

 pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;

 pLayerCfg.Alpha = 255;

 pLayerCfg.Alpha0 = 0;

 pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;

 pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;

 pLayerCfg.FBStartAdress = 0xC0000000;

 pLayerCfg.ImageWidth = 480;

 pLayerCfg.ImageHeight = 272;

 pLayerCfg.Backcolor.Blue = 0;

 pLayerCfg.Backcolor.Green = 0;

 pLayerCfg.Backcolor.Red = 0;

 if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)

 {

  Error_Handler( );

 }

 HAL_LTDC_SetPitch(&hltdc, 272, 0);

}

JJoha.2
Associate III

0690X000006Cz3sQAC.jpg

JJoha.2
Associate III

In LTDC may settings are still Landscape (that is native). I did two things as suggested in the article above:

(1) BoardConfiguration.hpp : Added hal.setDisplayOrientation(ORIENTATION_PORTRAIT), as shown below

void touchgfx_init()

{

 uint16_t dispWidth = 272;

 uint16_t dispHeight = 480;  

  

  HAL& hal = touchgfx_generic_init<STM32F7HAL>(dma, display, tc, dispWidth, dispHeight,(uint16_t*) 0, 

                        0, 0);

hal.setDisplayOrientation(ORIENTATION_PORTRAIT);

(2) file config/gcc/app.mk.

# Settings for image converter screen orientation (empty string =

# default value, -rotate90 rotates the image 90 degrees)

screen_orientation := -rotate90

With above changes I see distorted image button (as compared to my earlier changes) but still is it is not in portrait yet.

0690X000006Cz4CQAS.png0690X000006Cz47QAC.jpg

JJoha.2
Associate III

Portrait image above is from the designer and other one from the target hardware. The canvas size is correct 272x480 in my TouchGFX application

Martin KJELDSEN
Chief III

Hi @Johan Andrade​,

I created another example just to check.

0690X000006D22zQAC.jpg

My layer configuration differs from yours. 

layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA; 

.touchgfx

Modify the canvas dimensions.

config/gcc/app.mk:

screen_orientation := -rotate90

BoardConfiguration.cpp:

  1. Keep your dimensions 480 x 272 when calling touchgfx_generic_init().
  2. Keep LTDC layer dimensions 480 x 272.
  3. But call hal.setDisplayOrientation() to rotate the display in software e.g.
..
hal.lockDMAToFrontPorch(false);
hal.setDisplayOrientation(ORIENTATION_PORTRAIT);
..

Having some issues with my sharing service or i'd share the project. I thought i'd get this information to you asap. Let me know if this is not sufficient and i'll get you the actual project.

Best regards,

Martin

JJoha.2
Associate III

Hi Martin,

Thanks for your response. I think I am getting lost. could you please share your whole project, that way will be faster or send me sourced zip of your project at jjohal@fetco.com

Thanks