VLPS Wakeup ISR + FreeRTOS xTaskNotifyFromISR Issue on S32K144

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VLPS Wakeup ISR + FreeRTOS xTaskNotifyFromISR Issue on S32K144

Jump to solution
1,524 Views
Panidiyan_T
Contributor I

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:

  1. ISR priority = 0 (highest): MCU wakes from VLPS, but xTaskNotifyFromISR does not work.

  2. 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:

  1. What is the recommended pattern on the S32K144 to reliably wake the MCU from VLPS and safely notify a FreeRTOS task?

  2. 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

 

0 Kudos
Reply
1 Solution
1,479 Views
danielmartynek
NXP TechSupport
NXP TechSupport

I haven’t found any official example combining FreeRTOS and VLPS.
From what I see, the wake-up issue is likely caused by SysTick still running.
Try disabling SysTick right before calling POWER_SYS_SetMode() to enter VLPS.

Keep in mind:

In VLPS, the SysTick timer is disabled because the core clock is gated.
However, if you have a debugger connected, the MCU does not enter true VLPS; instead, it goes into an emulated STOP mode.

danielmartynek_0-1762786752586.png

Additionally, the FreeRTOS port.c already provides a weak implementation of vPortSuppressTicksAndSleep().

It stops SysTick during idle.
Calculates reload values for the next tick.
Executes __WFI().
Calls two hooks: configPRE_SLEEP_PROCESSING() configPOST_SLEEP_PROCESSING()

This is a weak implementation, it can be overwritten by your own implementation. 

 

Regards,

Daniel

View solution in original post

0 Kudos
Reply
4 Replies
1,492 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @Panidiyan_T,

If you could share the project I could test it on my side.

Anyway, FreeRTOS requires that ISRs calling FromISR APIs have a priority equal or lower than configMAX_SYSCALL_INTERRUPT_PRIORITY.

Don't call vPortEnterCritical() before POWER_SYS_SetMode().

 

0 Kudos
Reply
1,490 Views
Panidiyan_T
Contributor I

Hi @danielmartynek 

Thank you for the quick response.

If I remove the vPortEnterCritical() call before POWER_SYS_SetMode(), the MCU does not actually enter VLPS mode — it transitions momentarily and then immediately wakes up.

Could you please suggest the correct or recommended approach to properly enter VLPS mode while running FreeRTOS?
If possible, could you also share an example or reference implementation demonstrating how to safely enter VLPS from a FreeRTOS task context?

Thank you for your support!

Best regards,
Pandiyan T

0 Kudos
Reply
1,480 Views
danielmartynek
NXP TechSupport
NXP TechSupport

I haven’t found any official example combining FreeRTOS and VLPS.
From what I see, the wake-up issue is likely caused by SysTick still running.
Try disabling SysTick right before calling POWER_SYS_SetMode() to enter VLPS.

Keep in mind:

In VLPS, the SysTick timer is disabled because the core clock is gated.
However, if you have a debugger connected, the MCU does not enter true VLPS; instead, it goes into an emulated STOP mode.

danielmartynek_0-1762786752586.png

Additionally, the FreeRTOS port.c already provides a weak implementation of vPortSuppressTicksAndSleep().

It stops SysTick during idle.
Calculates reload values for the next tick.
Executes __WFI().
Calls two hooks: configPRE_SLEEP_PROCESSING() configPOST_SLEEP_PROCESSING()

This is a weak implementation, it can be overwritten by your own implementation. 

 

Regards,

Daniel

0 Kudos
Reply
1,456 Views
Panidiyan_T
Contributor I
Hi Daniel,

After disabling the SysTick timer before calling POWER_SYS_SetMode(), the system is now entering VLPS successfully without using vPortEnterCritical().
Also, the wake-up and notify-from-ISR mechanisms are both working together as expected.

Thanks a lot for your guidance!

Best regards,
Pandiyan
0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2201694%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EVLPS%20Wakeup%20ISR%20%2B%20FreeRTOS%20xTaskNotifyFromISR%20Issue%20on%20S32K144%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2201694%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%20NXP%20Team%2C%3C%2FP%3E%3CP%3EI%20am%20working%20with%20the%20S32K144%20MCU%20using%20FreeRTOS%20and%20implementing%20Very%20Low%20Power%20Stop%20(VLPS)%20mode.%20I%20have%20a%20GPIO%20switch%20on%20PORTB%20intended%20to%20wake%20the%20MCU%20and%20notify%20a%20FreeRTOS%20task.%3C%2FP%3E%3CP%3ESetup%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EGPIO%20switch%20connected%20to%20PORTB.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EISR%20triggers%20on%20switch%20press.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EUsing%20xTaskNotifyFromISR%20to%20notify%20a%20FreeRTOS%20task.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EFreeRTOS%20configuration%3A%3CBR%20%2F%3EconfigPRIO_BITS%20%3D%204%3CBR%20%2F%3EconfigLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY%20%3D%200x01%3CBR%20%2F%3EconfigMAX_SYSCALL_INTERRUPT_PRIORITY%20%3D%20(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY%20%26lt%3B%26lt%3B%20(8%20-%20configPRIO_BITS))%3CBR%20%2F%3EconfigKERNEL_INTERRUPT_PRIORITY%20%3D%20255%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3EISR%20and%20NVIC%20configuration%3A%3CBR%20%2F%3EPORTB-%26gt%3BISFR%20%3D%20(1U%20%26lt%3B%26lt%3B%20SWITCH_PIN_NUMBER)%20%2F%2F%20Clear%20interrupt%20flag%20for%20switch%20pin%3CBR%20%2F%3EINT_SYS_SetPriority(PORTB_IRQn%2C%20SWITCH_IRQ_PRIORITY)%3CBR%20%2F%3EINT_SYS_EnableIRQ(PORTB_IRQn)%3C%2FP%3E%3CP%3Evoid%20PORTB_IRQHandler(void)%20%7B%3CBR%20%2F%3EBaseType_t%20xHigherPriorityTaskWoken%20%3D%20pdFALSE%3B%3CBR%20%2F%3Eif%20(PORTB-%26gt%3BISFR%20%26amp%3B%20(1U%20%26lt%3B%26lt%3B%20SWITCH_PIN_NUMBER))%20%7B%3CBR%20%2F%3EPORTB-%26gt%3BISFR%20%3D%20(1U%20%26lt%3B%26lt%3B%20SWITCH_PIN_NUMBER)%20%2F%2F%20Clear%20interrupt%20flag%3CBR%20%2F%3Euint32_t%20switch_state%20%3D%20(((PINS_DRV_ReadPins(PTB)%20%26gt%3B%26gt%3B%20SWITCH_PIN_NUMBER)%20%26amp%3B%200x01)%20%3D%3D%200)%20%3F%20SWITCH_ON%20%3A%20SWITCH_OFF%3CBR%20%2F%3ExTaskNotifyFromISR(hmainTask%2C%20switch_state%2C%20eSetBits%2C%20%26amp%3BxHigherPriorityTaskWoken)%3CBR%20%2F%3EportYIELD_FROM_ISR(xHigherPriorityTaskWoken)%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3EvPortEnterCritical()%3CBR%20%2F%3Estatus_t%20ret%20%3D%20POWER_SYS_SetMode(0%2C%20POWER_MANAGER_POLICY_AGREEMENT)%3CBR%20%2F%3Eif%20(ret%20%3D%3D%20STATUS_SUCCESS)%20wakeupOccurred%20%3D%20true%3CBR%20%2F%3EvPortExitCritical()%3C%2FP%3E%3CP%3EObserved%20behavior%3A%3C%2FP%3E%3COL%3E%3CLI%3E%3CP%3EISR%20priority%20%3D%200%20(highest)%3A%20MCU%20wakes%20from%20VLPS%2C%20but%20xTaskNotifyFromISR%20does%20not%20work.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EISR%20priority%20%3D%201%3A%20xTaskNotifyFromISR%20works%2C%20but%20MCU%20does%20not%20wake%20from%20VLPS.%3C%2FP%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3EMy%20understanding%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EPriority%200%20interrupts%20cannot%20be%20masked%20by%20BASEPRI%2C%20so%20FreeRTOS%20APIs%20cannot%20be%20safely%20called.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EFreeRTOS%20APIs%20must%20be%20called%20from%20ISRs%20with%20priority%20%26gt%3B%3D%20configMAX_SYSCALL_INTERRUPT_PRIORITY.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EVLPS%20wakeup%20may%20require%20the%20highest-priority%20interrupt.%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3EQuestions%3A%3C%2FP%3E%3COL%3E%3CLI%3E%3CP%3EWhat%20is%20the%20recommended%20pattern%20on%20the%20S32K144%20to%20reliably%20wake%20the%20MCU%20from%20VLPS%20and%20safely%20notify%20a%20FreeRTOS%20task%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EIs%20there%20a%20better%20approach%20provided%20by%20NXP%3F%3C%2FP%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3EAny%20guidance%2C%20reference%20examples%2C%20or%20best%20practices%20would%20be%20greatly%20appreciated.%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3CP%3EBest%20regards%2C%3CBR%20%2F%3EPandiyan%20T%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2202548%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20VLPS%20Wakeup%20ISR%20%2B%20FreeRTOS%20xTaskNotifyFromISR%20Issue%20on%20S32K144%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2202548%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHi%20Daniel%2C%3CBR%20%2F%3E%3CBR%20%2F%3EAfter%20disabling%20the%20SysTick%20timer%20before%20calling%20POWER_SYS_SetMode()%2C%20the%20system%20is%20now%20entering%20VLPS%20successfully%20without%20using%20vPortEnterCritical().%3CBR%20%2F%3EAlso%2C%20the%20wake-up%20and%20notify-from-ISR%20mechanisms%20are%20both%20working%20together%20as%20expected.%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20a%20lot%20for%20your%20guidance!%3CBR%20%2F%3E%3CBR%20%2F%3EBest%20regards%2C%3CBR%20%2F%3EPandiyan%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2201946%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20VLPS%20Wakeup%20ISR%20%2B%20FreeRTOS%20xTaskNotifyFromISR%20Issue%20on%20S32K144%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2201946%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20haven%E2%80%99t%20found%20any%20official%20example%20combining%20FreeRTOS%20and%20VLPS.%3CBR%20%2F%3EFrom%20what%20I%20see%2C%20the%20wake-up%20issue%20is%20likely%20caused%20by%20SysTick%20still%20running.%3CBR%20%2F%3ETry%20disabling%20SysTick%20right%20before%20calling%20POWER_SYS_SetMode()%20to%20enter%20VLPS.%3C%2FP%3E%0A%3CP%3EKeep%20in%20mind%3A%3C%2FP%3E%0A%3CP%3EIn%20VLPS%2C%20the%20SysTick%20timer%20is%20disabled%20because%20the%20core%20clock%20is%20gated.%3CBR%20%2F%3EHowever%2C%20if%20you%20have%20a%20debugger%20connected%2C%20the%20MCU%20does%20not%20enter%20true%20VLPS%3B%20instead%2C%20it%20goes%20into%20an%20emulated%20STOP%20mode.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22danielmartynek_0-1762786752586.png%22%20style%3D%22width%3A%20509px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22danielmartynek_0-1762786752586.png%22%20style%3D%22width%3A%20509px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F364718iEB24FCE522089057%2Fimage-dimensions%2F509x220%3Fv%3Dv2%22%20width%3D%22509%22%20height%3D%22220%22%20role%3D%22button%22%20title%3D%22danielmartynek_0-1762786752586.png%22%20alt%3D%22danielmartynek_0-1762786752586.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EAdditionally%2C%20the%20FreeRTOS%20port.c%20already%20provides%20a%20weak%20implementation%20of%26nbsp%3BvPortSuppressTicksAndSleep().%3C%2FP%3E%0A%3CP%3EIt%20stops%20SysTick%20during%20idle.%3CBR%20%2F%3ECalculates%20reload%20values%20for%20the%20next%20tick.%3CBR%20%2F%3EExecutes%20__WFI().%3CBR%20%2F%3ECalls%20two%20hooks%3A%20configPRE_SLEEP_PROCESSING()%20configPOST_SLEEP_PROCESSING()%3C%2FP%3E%0A%3CP%3EThis%20is%26nbsp%3Ba%20weak%20implementation%2C%20it%20can%20be%20overwritten%20by%20your%20own%20implementation.%26nbsp%3B%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ERegards%2C%3C%2FP%3E%0A%3CP%3EDaniel%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2201900%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20VLPS%20Wakeup%20ISR%20%2B%20FreeRTOS%20xTaskNotifyFromISR%20Issue%20on%20S32K144%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2201900%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F160001%22%20target%3D%22_blank%22%3E%40danielmartynek%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20the%20quick%20response.%3C%2FP%3E%3CP%3EIf%20I%20remove%20the%20vPortEnterCritical()%20call%20before%20POWER_SYS_SetMode()%2C%20the%20MCU%20does%20not%20actually%20enter%20VLPS%20mode%20%E2%80%94%20it%20transitions%20momentarily%20and%20then%20immediately%20wakes%20up.%3C%2FP%3E%3CP%3ECould%20you%20please%20suggest%20the%20correct%20or%20recommended%20approach%20to%20properly%20enter%20VLPS%20mode%20while%20running%20FreeRTOS%3F%3CBR%20%2F%3EIf%20possible%2C%20could%20you%20also%20share%20an%20example%20or%20reference%20implementation%20demonstrating%20how%20to%20safely%20enter%20VLPS%20from%20a%20FreeRTOS%20task%20context%3F%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20support!%3C%2FP%3E%3CP%3EBest%20regards%2C%3CBR%20%2F%3EPandiyan%20T%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2201891%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20VLPS%20Wakeup%20ISR%20%2B%20FreeRTOS%20xTaskNotifyFromISR%20Issue%20on%20S32K144%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2201891%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F250965%22%20target%3D%22_blank%22%3E%40Panidiyan_T%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EIf%20you%20could%20share%20the%20project%20I%20could%20test%20it%20on%20my%20side.%3C%2FP%3E%0A%3CP%3EAnyway%2C%26nbsp%3BFreeRTOS%20requires%20that%20ISRs%20calling%20FromISR%20APIs%20have%20a%20priority%20equal%20or%20lower%20than%20configMAX_SYSCALL_INTERRUPT_PRIORITY.%3C%2FP%3E%0A%3CP%3EDon't%20call%20vPortEnterCritical()%20before%26nbsp%3BPOWER_SYS_SetMode().%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E