Hello,
Mr. Daniel,
I have followed the example and procedure to enter into the VLPS that, before entering into VLPS FIRC and SOSC should be off and only SIRC should be running and also I converted the CAN rx pin as normal gpio pin for detecting the interrupt but its not detecting.
Can you please tell me what I am missing or doing wrong configuration while entering to RUN to VLPS.
And also when I am directly entering into the VLPS still the application code is in RUN condition.
So I am first entering into VLPR and then VLPS from it.
Please give the solution.
// Currently first entering into VLPR if some conditions are met.
void RUN_to_VLPR (void)
{
INT8U mode;
init_NVIC();
mode = (SMC->PMSTAT & SMC_PMSTAT_PMSTAT_MASK) >> SMC_PMSTAT_PMSTAT_SHIFT;
if((mode != VLPR_MODE))
{
b_PWRModeChg = OFF;
CAN0->CTRL1 = CAN_CTRL1_CLKSRC(0); // CAN clock is configured as system clock
SCG->SOSCCSR = SCG_SOSCCSR_SOSCCMRE(0); // disabled SCOSC monitor
SCG->FIRCCSR = SCG_FIRCCSR_FIRCEN(0); // disable FIRC
SCG->SOSCCSR = SCG_SOSCCSR_SOSCEN(0); // disabled SOSC
SMC->PMPROT |= SMC_PMPROT_AVLP(1);
if(SMC->PMSTAT == RUN_MODE)
{
PMC->REGSC |= PMC_REGSC_BIASEN_MASK;
SMC->PMCTRL = SMC_PMCTRL_RUNM(2);
while(SMC->PMSTAT != 0x04);
}
f_OP_PWRMode = Md_vlpr;
RUN_to_VLPS();
}
}
void RUN_to_VLPS (void)
{
// DISABLE_INTERRUPTS(); // I think its not working
INT8U mode;
// the below configuration is for configuring CANrx pin as gpio interrupt wakeup capable
INT_SYS_EnableIRQ(PORT_IRQn);
PINS_DRV_SetPinDirection(PTE, 4, GPIO_INPUT_DIRECTION);
PINS_DRV_SetMuxModeSel(PORTE, 4, PORT_MUX_AS_GPIO);
PINS_DRV_SetPinIntSel(PORTE, 4, PORT_INT_RISING_EDGE);;
PINS_DRV_SetPullSel(PORTE, 4, PORT_INTERNAL_PULL_UP_ENABLED);
mode = (SMC->PMSTAT & SMC_PMSTAT_PMSTAT_MASK) >> SMC_PMSTAT_PMSTAT_SHIFT;
if(mode == VLPR_MODE)
{
init_SIRC();
Goto_SIRC();
S32_SCB ->SCR|=S32_SCB_SCR_SLEEPDEEP_MASK;
SMC->PMPROT |= SMC_PMPROT_AVLP_MASK;
SMC->PMCTRL=SMC_PMCTRL_STOPM(2);
PMC->REGSC |= PMC_REGSC_BIASEN_MASK;
}
/* Check if current mode is RUN mode */
if(SMC->PMSTAT == VLPR_MODE)
{
/* Go to deep sleep mode */
asm("WFI");
}
}
void Goto_SIRC(void)
{
// is this required, as you did like this
uint32_t srie = RCM->SRIE;
RCM->SRIE = 0x0000;
RCM->SRIE = 0xFFFF;
// taken from user manual of s32k
SCG->RCCR = SCG_RCCR_SCS(2);
SCG->RCCR = SCG_RCCR_DIVBUS(1);
SCG->RCCR = SCG_RCCR_DIVSLOW(0);
SCG->RCCR = SCG_RCCR_DIVSLOW(3);
while(!((SCG->CSR & (0x0F000000)) & 0x02000000));
while((SCG->SIRCCSR & (1 << 25)) == 0);
RCM->SRIE = srie;
}
void init_SIRC(void)
{
SCG->SIRCCSR &= ~ (1 << 24);
SCG->SIRCCSR = SCG_SIRCCSR_SIRCEN(1);
SCG->SIRCDIV |= 0x0404;
while((SCG->SIRCCSR & (1 << 24)) == 0); // wait until clock is valid
SCG->SIRCCSR |= (1 << 24);
}
// PORTE, PORTA
void init_NVIC(void)
{
// PORT_interrupt
S32_NVIC->ICPR[0] = (1 << 9);
S32_NVIC->ISER[0] = (1 << 9);
S32_NVIC->IPR[2] = S32_NVIC_IPR_PRI_1(1); // Priority level 1
}
Thanks and Regards,
Shinde Umesh