I had the same problem using deep sleep mode (LPC_PMC->PD0_SLEEP0_MODE = PMC_PWR_DEEP_SLEEP_MODE):
Setting LPC_PMC->PD0_SLEEP0_HW_ENA = 0x2 seems to put the whole chip in a weird state. The GPIO state seems to be completely lost. Current consumption is unknown, as the peripherals on my board use a lot of power with the GPIOs in undefined state. As far as I have seen this happens in two cases:
- writing LPC_PMC->PD0_SLEEP0_HW_ENA=0x2 while the M0 core is not yet booted: the GPIO state is immediately lost, M4 core hangs, even if not entering a sleep at all!
- writing LPC_PMC->PD0_SLEEP0_HW_ENA=0x2 before entering sleep mode on the M0 core: the GPIO state is lost as soon as sleep mode is entered on the M0 with Chip_PMC_Set_PwrState()
Solution/workaround:
The order in which the LPC_PMC registers are set seem to be important. It looks like the PD0_SLEEP0_HW_ENA register must be set after PD0_SLEEP0_MODE, contrary to the order as described in the user manual 12.2.3. See below for a fixed version of PCM_Set_PwrState(). Note the addition at line 15:
typedef enum {
ENA_EVENT0 = (1 << 0),
ENA_EVENT1 = (1 << 1)
} ENA_EVENT;
void PMC_Set_PwrState(CHIP_PMC_PWR_STATE_T pwr_state, ENA_EVENT ena_event)
{
uint32_t prev_scr = SCB->SCR;
SCB->SCR|= 0x4;
LPC_PMC->PD0_SLEEP0_MODE = (uint32_t) pwr_state;
LPC_PMC->PD0_SLEEP0_HW_ENA = (uint32_t) ena_event;
__WFI();
SCB->SCR = prev_scr & 0x1F;
}
So far this code works for me. To put the LPC43xx in deep sleep mode from the M0 core, call the new PMC_Set_PwrState function:
PMC_Set_PwrState(PMC_PWR_DEEP_SLEEP_MODE, ENA_EVENT1);