Problems with triple buffer page flipping
My page flipping via the LTDC works seamlessly if my drawing routine is faster than the frame rate, but as soon it is slower, I see flickering on my LCD. It's not the type of flickering you'd see if a page is overwritten out of sync with the display. I've been wrecking my brain over this during the last two days and can't see what's wrong.
I am using the STM32H745 Disco board.
Here's the code snippet:
while(1) {
// my drawing routine here, storing data in
// graphicsMemory[currentPage][LAYER1] and
// graphicsMemory[currentPage][LAYER2]
.
.
.
// A reload event will signal that the LCD
// is pointing at the new page. If that
// hasn't occured yet, we are stalled.
while(pageFlag);
// Set frame buffer pointers to new addresses
LTDC_Layer1->CFBAR = (uint32_t) graphicsMemory[currentPage][LAYER1];
LTDC_Layer2->CFBAR = (uint32_t) graphicsMemory[currentPage][LAYER2];
// Set flag that indicates that page is ready to be pointed at.
pageFlag = 1;
// Turn on interrupt on reload
LTDC->IER = LTDC_IT_RR;
// Enable reload on next vertical blanking
LTDC->SRCR = LTDC_SRCR_VBR;
// Switch to next available page.
// Why three pages? Let's assume the first page has
// been drawn and submitted for being taken over at
// the next vertical blanking. It is unknown when that
// next vertical blanking will occur but waiting for it
// is a waste of time. So while the first page is still
// showing and the second one hasn't been taken
// over yet, the third page is updated instead.
switch (currentPage) {
case PAGE1: currentPage = PAGE2; break;
case PAGE2: currentPage = PAGE3; break;
case PAGE3: currentPage = PAGE1; break;
}
} // while(1)
void HAL_LTDC_ReloadEventCallback(LTDC_HandleTypeDef *hltdc) {
// Send signal that the page has been flipped
pageFlag = 0;
}What's wrong with this approach, causing the flickering if the drawing routine is too slow? I can't see how the displayed page is being overwritten while drawing a new page (if that's actually the cause of the problem).
