The code
Embedded C for Cortex-M. It compiles. There are 4 real bugs in it: the kind that pass a bench test and fail in the field.
#define CFG_PAGE 255u
#define CFG_ADDR 0x0807F800u /* settings: first 1 KB of the page */
#define CAL_ADDR 0x0807FC00u /* factory calibration: second 1 KB */
typedef struct {
uint32_t magic;
uint16_t setpoint[600];
uint16_t hysteresis;
uint16_t flags;
uint32_t crc;
} cfg_t;
bool cfg_save(const cfg_t *c)
{
HAL_FLASH_Unlock();
FLASH_EraseInitTypeDef e = { .TypeErase = FLASH_TYPEERASE_PAGES,
.Banks = FLASH_BANK_1, .Page = CFG_PAGE, .NbPages = 1 };
uint32_t err;
HAL_FLASHEx_Erase(&e, &err);
const uint8_t *src = (const uint8_t *)c;
for (uint32_t i = 0; i < sizeof(cfg_t); i += 8) {
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, CFG_ADDR + i,
*(const uint64_t *)(src + i));
}
HAL_FLASH_Lock();
return true;
}What an interviewer expects
- Point to each line you'd stop in a code review.
- Say what actually breaks: the failure mode, not just the rule it violates.
- Fix it, then defend the fix when asked the follow-up.
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.
ABBIndustrial · India hiring: MediumEatonIndustrial · India hiring: HighInfineonChipmaker · India hiring: MediumNXP SemiconductorsChipmaker · India hiring: HighQuest GlobalEngineering services · India hiring: HighRenesasChipmaker · India hiring: MediumTata ElxsiEngineering services · India hiring: HighWipro EngineeringEngineering services · India hiring: High
Related challenges
Independent watchdog usageDrivers & ISRs · Medium · 3 bugs · ~5 minBootloader jump to applicationBoot & OTA · Hard · 3 bugs · ~6 minSwitching OTA slotsBoot & OTA · Medium · 3 bugs · ~5 minSaving settings to internal flashBoot & OTA · Medium · 3 bugs · ~5 minData retained across resetsBoot & OTA · Hard · 3 bugs · ~6 minBootloader image verificationBoot & OTA · Hard · 3 bugs · ~8 min
Flag the lines, say what breaks, then fix it and build it with clang in your browser.
Find the bugs