HeapCrash / Challenges / Data retained across resets

Data retained across resets

A .noinit section keeps a boot counter and the last fault address across resets, for field diagnostics. The reports are nonsense: huge boot counts and every reset is a “watchdog reset”.

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.

__attribute__((section(".noinit"))) static struct {
    uint32_t boot_count;
    uint32_t last_fault_pc;
} retained;

void boot_record(void)
{
    retained.boot_count++;
    if (RCC->CSR & RCC_CSR_IWDGRSTF) {
        log_watchdog_reset(retained.last_fault_pc);
    }
}

void HardFault_Handler(void)
{
    retained.last_fault_pc = __get_PSP();
    NVIC_SystemReset();
}

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