Hello NXP Team,
I am working with the S32K144 MCU using FreeRTOS and implementing Very Low Power Stop (VLPS) mode. I have a GPIO switch on PORTB intended to wake the MCU and notify a FreeRTOS task.
Setup:
GPIO switch connected to PORTB.
ISR triggers on switch press.
Using xTaskNotifyFromISR to notify a FreeRTOS task.
FreeRTOS configuration:
configPRIO_BITS = 4
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY = 0x01
configMAX_SYSCALL_INTERRUPT_PRIORITY = (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
configKERNEL_INTERRUPT_PRIORITY = 255
ISR and NVIC configuration:
PORTB->ISFR = (1U << SWITCH_PIN_NUMBER) // Clear interrupt flag for switch pin
INT_SYS_SetPriority(PORTB_IRQn, SWITCH_IRQ_PRIORITY)
INT_SYS_EnableIRQ(PORTB_IRQn)
void PORTB_IRQHandler(void) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (PORTB->ISFR & (1U << SWITCH_PIN_NUMBER)) {
PORTB->ISFR = (1U << SWITCH_PIN_NUMBER) // Clear interrupt flag
uint32_t switch_state = (((PINS_DRV_ReadPins(PTB) >> SWITCH_PIN_NUMBER) & 0x01) == 0) ? SWITCH_ON : SWITCH_OFF
xTaskNotifyFromISR(hmainTask, switch_state, eSetBits, &xHigherPriorityTaskWoken)
portYIELD_FROM_ISR(xHigherPriorityTaskWoken)
}
}
vPortEnterCritical()
status_t ret = POWER_SYS_SetMode(0, POWER_MANAGER_POLICY_AGREEMENT)
if (ret == STATUS_SUCCESS) wakeupOccurred = true
vPortExitCritical()
Observed behavior:
ISR priority = 0 (highest): MCU wakes from VLPS, but xTaskNotifyFromISR does not work.
ISR priority = 1: xTaskNotifyFromISR works, but MCU does not wake from VLPS.
My understanding:
Priority 0 interrupts cannot be masked by BASEPRI, so FreeRTOS APIs cannot be safely called.
FreeRTOS APIs must be called from ISRs with priority >= configMAX_SYSCALL_INTERRUPT_PRIORITY.
VLPS wakeup may require the highest-priority interrupt.
Questions:
What is the recommended pattern on the S32K144 to reliably wake the MCU from VLPS and safely notify a FreeRTOS task?
Is there a better approach provided by NXP?
Any guidance, reference examples, or best practices would be greatly appreciated.
Thank you!
Best regards,
Pandiyan T