cancel
Showing results for 
Search instead for 
Did you mean: 

STemWin: MPU configuration for SDRAM and LTDC

Alex Gab
Associate III
Posted on May 29, 2018 at 13:46

Hello to everyone!

Recently I was faced with a problem using GUI_GIF_Draw() function. That function works properly with a graphical memory assigned to internal RAM using GUI_ALLOC_AssignMemory() and fails if memory assigned to SDRAM.

My chip is STM32F777ZI.

SDRAM is

MT48LC32M16A2

.

My old thread:

https://community.st.com/0D50X00009XkWIZSA3

 

I suggest my problem is that MPU not properly configured for SDRAM regions. In LTDC manual (AN4861) there is a chapter with special recommendations for Cortex-M7 at page 81. This chapter containing an information about MPU regions configuration.

I created following regions:

Region0: defines the whole SDRAM memory (64 MByte in my case);

(graphical memory (aMemory) assigned to STemWin using

GUI_ALLOC_AssignMemory() (&sharpdefine GUI_NUMBYTES  0x2000000) and allocated at lower 32 Mbyte of SDRAM. It has a start address 0xC000000 as SDRAM connected through FMC Bank1);

Region1: defines the framebuffer memory (&sharpdefine LCD_LAYER0_FRAME_BUFFER  ((uint32_t)0xC2000000)); upper 32 Mbyte of SDRAM;

First I configured following attributes:

Region0: normal memory; cacheable; write-through; full access; enable execution.

Region1: normal memory; cacheable; write-through; full access; execute never.

Here is some code:

const unsigned char _acpictgif[4790UL + 1] = {...GIF array...};

int main(void)

 

{

 

  MPU_Config();

 

  SCB_EnableICache();

 

  SCB_EnableDCache();

 

   ...

 

  // Code sections with MCU, HAL, System clock, GPIO, Peripherals configuration, nothing interesting...

 

   ...

 

 // Start showing the GIF

  GUI_Init();

 

  GUI_Clear();

 

  status = GUI_GIF_Draw(_acpictgif, 4790UL + 1, 0, 0); 

 

 

  while (1) {

 

 

   GUI_Delay(100);

 

 

  }

 

 

}

void MPU_Config(void)

 

{

 

  LL_MPU_Disable();

  LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER0, 0x0, 0xC0000000, LL_MPU_TEX_LEVEL0|LL_MPU_REGION_SIZE_64MB|LL_MPU_REGION_FULL_ACCESS|

LL_MPU_INSTRUCTION_ACCESS_ENABLE|LL_MPU_ACCESS_NOT_SHAREABLE|

LL_MPU_ACCESS_CACHEABLE|LL_MPU_ACCESS_NOT_BUFFERABLE);

 

 

  LL_MPU_EnableRegion(LL_MPU_REGION_NUMBER0);

 

 

 LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER1, 0x0, 0xC2000000, LL_MPU_TEX_LEVEL0|LL_MPU_REGION_SIZE_32MB|LL_MPU_REGION_FULL_ACCESS|

LL_MPU_INSTRUCTION_ACCESS_DISABLE|LL_MPU_ACCESS_NOT_SHAREABLE|

LL_MPU_ACCESS_CACHEABLE|LL_MPU_ACCESS_NOT_BUFFERABLE);

 

  LL_MPU_EnableRegion(LL_MPU_REGION_NUMBER1);

 

 

  LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT);

 

 

}

 

Got an error.

status = 1:

 

0690X00000604WLQAY.jpg

Next I reconfigured regions to WBWA:

void MPU_Config(void)

 

{

 

  LL_MPU_Disable();

 

  LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER0, 0x0, 0xC0000000, LL_MPU_TEX_LEVEL1|LL_MPU_REGION_SIZE_64MB|LL_MPU_REGION_FULL_ACCESS|

LL_MPU_INSTRUCTION_ACCESS_ENABLE|LL_MPU_ACCESS_NOT_SHAREABLE|

LL_MPU_ACCESS_CACHEABLE|LL_MPU_ACCESS_BUFFERABLE);

 

 

  LL_MPU_EnableRegion(LL_MPU_REGION_NUMBER0);

 

 

  LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER1, 0x0, 0xC2000000, LL_MPU_TEX_LEVEL1|LL_MPU_REGION_SIZE_32MB|LL_MPU_REGION_FULL_ACCESS|

LL_MPU_INSTRUCTION_ACCESS_DISABLE|LL_MPU_ACCESS_NOT_SHAREABLE|

LL_MPU_ACCESS_CACHEABLE|LL_MPU_ACCESS_BUFFERABLE);

 

 

  LL_MPU_EnableRegion(LL_MPU_REGION_NUMBER1);

 

 

  LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT);

 

 

}

And got this one. status = 0. No errors but the GIF contains distortion artifacts:

0690X00000604WkQAI.jpg

And again I reassigned aMemory for STemWin to internal RAM and got a fine picture. status = 0:

0690X00000604c8QAA.jpg

Seems that MPU regions not properly configured in case of aMemory allocation in SDRAM.

Can anyone tell a proper MPU configuration?

Thanks for your time.

#mpu #stemwin #sdram #ltdc #gif
6 REPLIES 6
Imen.D
ST Employee
Posted on May 29, 2018 at 14:02

Hello

lexa_gb

,

As recommended in the

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fcontent%2Fccc%2Fresource%2Ftechnical%2Fdocument%2Fapplication_note%2Fgroup0%2F25%2Fca%2Ff9%2Fb4%2Fae%2Ffc%2F4e%2F1e%2FDM00287603%2Ffiles%2FDM002876pdf%2Fjcr%3Acontent%2Ftranslations%2Fen.DM002876pdf

, try to enable the FIFO underrun interrupt for determining the display size compatibility, this help you to detect display issue.

Have a look to this

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fcontent%2Fccc%2Fresource%2Ftechnical%2Fdocument%2Fapplication_note%2Fgroup0%2Fbc%2F2d%2Ff7%2Fbd%2Ffb%2F3f%2F48%2F47%2FDM00272912%2Ffiles%2FDM002729pdf%2Fjcr%3Acontent%2Ftranslations%2Fen.DM002729pdf

Application note Managing memory protection unit (MPU) in STM32 MCUs, withdetailed example of setting up the MPU.

With Regards,

Imen.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on May 29, 2018 at 19:35

Hello, Imen D!

Thank you for your response about my problem.

AN4838 contains detailed description of setting up the MPU as such without taking into account the use of LTDC.

First I configured the MPU in accordance with that example, after that I got an empty screen )

AN4861 contains more detailed information about MPU regions configuration when using SDRAM for framebuffer allocation. It says that the regions must be configured either as WT or as WBWA. I'm not sure but in my view I configured the regions in that manner (MPU_Config() in original post) and got the GIF picture on the screen as I wrote above. 

In addition, I checked the LTDC and SDRAM clocks and bandwith requirements for display resolution to fit the hardware configuration. Also I enabled all the LTDC interrupts (including error interrupts). My chip is STM32F777ZIT6, SDRAM chip is MT48LC32M16A2, LCD panel is G104XVN01.0 connected to the chip through RGB-LVDS transciever.

In my case HCLK = 200 MHz, SDRAM_CLK = 100 MHz, LTDC_CLK = 50 MHz, SDRAM bus width = 16 bits, DMA2D is using. It seems the clocks respect the requirements from Table 11 in AN4861. As I see in debug session there are no FIFO underrun or transfer error interrupts generated. The only interrupt generated is line event interrupt, which calls the line event callback function. The problem appears when using GUI_GIF_Draw() with aMemory assigned to SDRAM. However, functions GUI_BMP_Draw() and GUI_DrawBitmap() work properly regardless of aMemory allocation.

I can provide an additional code sections if it is needed.

Thanks for your time.

Alex Gab
Associate III
Posted on June 01, 2018 at 23:47

Hello to everyone.

I havemanagedGUI_GIF_Draw()to work properly with memory pool for STemWin assigned to SDRAM but still have a problem with drawing the same GIF using IMAGE_SetGIF() on IMAGE widget when using WM.

GUI_GIF_Draw()now works with the following configuration of the MPU:

void MPU_Config(void)

{

LL_MPU_Disable();

LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER0, 0x0, 0xC0000000, LL_MPU_TEX_LEVEL1|LL_MPU_REGION_SIZE_32MB|LL_MPU_REGION_FULL_ACCESS|LL_MPU_INSTRUCTION_ACCESS_ENABLE|LL_MPU_ACCESS_NOT_SHAREABLE|LL_MPU_ACCESS_CACHEABLE|LL_MPU_ACCESS_BUFFERABLE);

LL_MPU_EnableRegion(LL_MPU_REGION_NUMBER0);

LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER1, 0x0, 0xC2000000, LL_MPU_TEX_LEVEL1|LL_MPU_REGION_SIZE_32MB|LL_MPU_REGION_FULL_ACCESS|LL_MPU_INSTRUCTION_ACCESS_DISABLE|LL_MPU_ACCESS_NOT_SHAREABLE|LL_MPU_ACCESS_CACHEABLE|LL_MPU_ACCESS_NOT_BUFFERABLE);

LL_MPU_EnableRegion(LL_MPU_REGION_NUMBER1);

LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT);

}

That's on the LCD:

0690X00000604edQAA.jpg

Next I began to use Window Manager. Icreated a simple window usingGUIBuilder (WINDOW widget 1024x768) with a child IMAGE widget (1024x768) on it and assigned my GIF file to this IMAGE widget. GUIBuilder then generated a simple corresponding code (in the attached *.zip archive) with IMAGE_SetGIF()to assign the GIF. Without enabling Memory Devices (using WM_SetCreateFlags(WM_CF_MEMDEV)) all works fine (the same picture as on the photo above), but when usingWM_SetCreateFlags(WM_CF_MEMDEV)I've got an error again:

0690X00000604arQAA.jpg

I even implemented useless ''GetData()'' function to read data from the GIF-array just to reduce the memory usage and check the function IMAGE_SetGIFEx()(instead ofIMAGE_SetGIF()). As a result I've got the same error.

However, when I use Memory Device to draw the GIF without using WM:

...

extern const unsigned char _acpictgif[]; // from a GIF-file converted to C-file using BIN2C

GUI_MEMDEV_Handle hMem;

...

int main(void)

{

...

GUI_Init();

hMem = GUI_MEMDEV_Create(0, 0, 1024, 768);

GUI_MEMDEV_Select(hMem);

GUI_GIF_Draw(_acpictgif, 3678UL + 1, 0, 0);

GUI_MEMDEV_Select(0);

GUI_MEMDEV_CopyToLCD(hMem);

while (1)

{

GUI_Delay(100);

}

}

This code also works properly (fine picture as on the first photo above). Function GUI_MEMDEV_Create()returns non-zero memdev handle. Memory Device successfully created and it is allocated in SDRAM, not in internal RAM as it's easy to see the screen resolution is too much to allocate memory buffer in internal RAM. I also checked every byte of 64MByte SDRAM in -8, -16, -32 bit access modes. All the data writing to/reading from the SDRAM is correct.

So I don't understand why it doesn't work when using WM? What the difference in using Memory Devices automatically in WM or manually using GUI_MEMDEV_...() functions? What should bethe MPU settings in order to achieve STemWin to work properly with Memory Devices using WM when drawing a GIF?

Another interesting point is that in case of using BMPs and bitmaps on the IMAGE widget (IMAGE_SetBMP()andIMAGE_SetBitmap()) all the code also works properly. Even in case of using RLE8 bitmaps (which have a similar algorithm to GIF processing as far as I know, and in this case function IMAGE_SetBitmap() alsoshould take actions to process RLE unpacking as IMAGE_SetGIF() does to process a GIF, and Memory Device is also allocated inSDRAM).

I attached my simple project to this thread (it is for Atollic TrueSTUDIO).

Excuse me if my English is not good.

Thanks for any suggestions.

________________

Attachments :

GUI.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxY2&d=%2Fa%2F0X0000000azi%2FYkjwWz_0YovHuZjsTx2Uvr_LwKoI5ZzgahihTkG8mSM&asPdf=false
Vitaliy Kostyrev
Associate II
Posted on June 02, 2018 at 04:10

Hello! Make a remape of the memory,HAL_EnableFMCMemorySwapping(); address sdram = 0x60000000. The

MCU

will see the SDRAM as its memory!
Posted on June 02, 2018 at 04:31

I executed you code WindowDLG and at me all has turned out!0690X00000604duQAA.jpg

Posted on June 02, 2018 at 07:13

Hello, Vitaliy!

Thank you for your answer. I will try with your advice and write the result here.