diff --git a/armsrc/pm5_cep.c b/armsrc/pm5_cep.c index 8ac4e271a..8b3641cea 100644 --- a/armsrc/pm5_cep.c +++ b/armsrc/pm5_cep.c @@ -158,6 +158,11 @@ static void cep_spi_init(void) { void cep_init(void) { cep_usart_init(); cep_spi_init(); + // I2C_init(true) needs the ticks timer running (see cep_attach_poll()'s + // comment) - nothing in AppMain()'s boot sequence has started it yet at + // this point, so start it ourselves, matching bwm_charger_kick()'s + // identical boot-time I2C bring-up in armsrc/bwm_charger.c. + StartTicks(); I2C_init(true); } @@ -233,6 +238,20 @@ void cep_attach_poll(void) { } last_tick = GetTickCount(); + // The shared ticks timer (GetTicks()/WaitUS()/WaitMS(), which + // I2C_BufferReadRaw() spins on) is routinely stopped by LF/HF protocol + // code once it's done with precision timing (see e.g. em4x50.c, + // legicrf.c, hitag_common.c's StopTicks() calls). Landing here with the + // timer stopped turns WaitTicks()'s `while (GetTicks() < target)` into an + // infinite loop - a full, unrecoverable main-loop hang (this was the + // "hf search hangs the device" regression: it cycles through several + // such probes, giving this 50ms poll many chances to land in that + // window). Mirror bwm_lowbatt_poll()'s pattern (armsrc/bwm_charger.c) + // and (re)start the timer ourselves every time, exactly like every other + // periodic main-loop I2C poller in this codebase already does. + StartTicks(); + I2C_init(true); + uint8_t cc_ctrl_data; bool ret = I2C_BufferReadRaw(&cc_ctrl_data, 1, CEP_CC_STATUS_REG, CEP_CC_CONTROLLER_ADDR << 1); if (!ret) { diff --git a/common_arm/Makefile.hal b/common_arm/Makefile.hal index 99173f813..3dd901684 100644 --- a/common_arm/Makefile.hal +++ b/common_arm/Makefile.hal @@ -258,9 +258,7 @@ ifeq ($(SKIP_CEP),1) endif else ifeq ($(PLATFORM),PM5) -# Temporary measure as CEP seems to break things... -# PLATFORM_DEFS += -DWITH_CEP - $(warning Note: CEP is temporarely deactivated, until bugfix) + PLATFORM_DEFS += -DWITH_CEP endif endif