2014-06-18 01:38 PM
I have a C Function which tries to copy a framebuffer to FSMC RAM, which is connected to LCD. The functions eats the frame rate of the game loop to 10FPS. It seems copying from the SDRAM to FSMC is terribly slow, but why ?
void
LCD_Flip()
{
u16 i,limit = fbHeight+fbWidth;
// We will use a precalculated limit and one single loop
LCD_SetCursor(0x00, 0x0000);
LCD_WriteRegister(0x0050,0x00);
//GRAM horizontal start position
LCD_WriteRegister(0x0051,239);
//GRAM horizontal end position
LCD_WriteRegister(0x0052,0);
//Vertical GRAM Start position
LCD_WriteRegister(0x0053,319);
//Vertical GRAM end position
LCD_WriteIndex(0x0022);
// Single loop from 0:limit-1 takes care of having to do an
// x,y conversion each iteration.
for
(i=0;i<limit;j++)
{
u16 color = frameBuffer[i];
LCD_WriteData(color);
}
}
2014-06-18 02:38 PM
The loop isn't good, the optimizer might help, subroutine call makes it less efficient.
If the write function isn't inlined, that's throwing away thousands of cycles. What's going on in the subroutine? The FSMC might be set up for slower external writes. Can the write be done more efficiently as a burst? Can you unroll the loop?. Or use LDM/STM in assembler? Can you use DMA2? Can you use an STM32F429 and drive a dumb panel instead of a controller based one?2014-06-24 06:04 AM
Thanks for your fast reply!.
The subroutine, only writes to the FSMC memoryI even replaced the subroutine to the the following line, and it's still very slow writing and very slow FPS~
*(__IO uint16_t *) (Bank1_LCD_D) = frameBuffer[i];
The problem with a newer controller, is I need to buy a new kit, I'm just doing that for hobby and I can't afford the F4 :(.
How would I optimize the writing to the FSMC ?
First I will try to unroll the loop then I will use DMA. is there any other solution without resorting to DMA,..etc? I'm really wondering, what's wrong with copying an array to the FSMC like I'm doing.
2014-06-24 07:32 AM
You'd want to look at your compiler settings, and the code it generates.
You'd want to look at the FSMC configuration. Copying large arrays to external buses is significantly slower than accessing internal memories. Consider using pointers?2014-06-24 07:57 AM
Your using i but increase j
// Single loop from 0:limit-1 takes care of having to do an
// x,y conversion each iteration.
for
(i=0;i<limit;j++)