HeapCrash / Challenges / LTDC double buffering

LTDC double buffering

STM32H7 with D-cache on, two RGB565 framebuffers in external SDRAM, LTDC scanning out at 60 Hz. The display tears, and stale fragments occasionally flash on screen.

The code

Embedded C for Cortex-M. It compiles. There are 3 real bugs in it: the kind that pass a bench test and fail in the field.

static uint16_t fb[2][320 * 240];
static int draw_idx = 0;

/* Called by the app after drawing into fb[draw_idx] */
void frame_done(void)
{
    LTDC_Layer1->CFBAR = (uint32_t)fb[draw_idx];
    LTDC->SRCR = LTDC_SRCR_IMR;
    draw_idx ^= 1;
    memset(fb[draw_idx], 0, sizeof fb[0]);
}

What an interviewer expects

The bugs, reference fixes and the follow-up question are in the practice app, after you've tried it.

Companies that test this

Matched on the skills each company's embedded roles emphasise.

Related challenges

Flag the lines, say what breaks, then fix it and build it with clang in your browser.

Find the bugs