FreeRTOS LPM

Hello,

I'm implementing FreeRTOS in RA6T2 for the project, and now I have a question about the low power mode,

according the rm_freertos_port_sleep_preserving_lpm (uint32_t xExpectedIdleTime) in rm_freertos_pot/port.c

/** Check if the LPM peripheral is set to go to Software Standby mode with WFI instruction.
* If so, change the LPM peripheral to go to Sleep mode. */

if (R_SYSTEM_SBYCR_SSBY_Msk & saved_sbycr)
{
/* Save register protect value */
uint32_t saved_prcr = R_SYSTEM->PRCR;

/* Unlock LPM peripheral registers */
R_SYSTEM->PRCR = RM_FREERTOS_PORT_UNLOCK_LPM_REGISTER_ACCESS;

/* Clear to set to sleep low power mode (not standby or deep standby) */
R_SYSTEM->SBYCR = 0U;

/* Restore register lock */
R_SYSTEM->PRCR = (uint16_t) (RM_FREERTOS_PORT_LOCK_LPM_REGISTER_ACCESS | saved_prcr);
}

I'm wondering if the sleep mode is the one and only LPM can be used in FreeRTOS?

Can I enter Software Standby mode in the project using FreeRTOS?

Thanks.

Top Replies

Parents Reply
  • Hi,

    Currently the tickless idle support in the FSP FreeRTOS port uses the sleep low power mode. This mode is more suited to this purpose as the systick timer keeps running so FreeRTOS can wake up the CPU when a timeout occurs or simple keep time.

    If it is acceptable for the RTOS to lose track of time or ignore timeouts then software standby could be used. In this mode the systick timer stops. You will of course need to enable a wake up source to exit software standby mode.

    Ian.

Children
  • Hi Ian,

    Thanks for your reply.

    After study some documents about FreeRTOS, I think it is possible to enter Software Standby mode in FreeRTOS.

    There are two weak function can be defined by user.

    configPRE_SLEEP_PROCESSING( xExpectedIdleTime );

    configPOST_SLEEP_PROCESSING( xExpectedIdleTime );

    According to my understanding, user can adjust the clock ,closed unused modules, set the register related to the specific low power mode,  set xExpectedIdleTime = 0 and enter the LPM in

    configPRE_SLEEP_PROCESSING(xExpectedIdleTime )

    After wake up from LPM, the program will skip the __WFI() because xExpectedIdleTime  = 0,

    and then execute the configPOST_SLEEP_PROCESSING( xExpectedIdleTime ).

    Is my understanding correct ?

    Thanks.

    Cooper.

  • Hi Cooper,

    This approach may work if you enable tickless idle support. You will need to take care of the code which switches the low power mode from software standby to sleep when entering LPM under RTOS control.

    What I did (without extensive testing) was not to use tickless idle mode but instead to disbale interrupts, stop the scheduler and then enter software standby mode. This worked but as I say I have not perfomred extensive testing.

         
           
            /* Re-start the one-shot timer used to wake from software standby mode */
            err = R_AGT_Start(&g_timer_agt1_ctrl);
            if (FSP_SUCCESS != err)
            {
                __BKPT(2);
            }

            __disable_irq();

            /* Stop the FreeRTOS scheduler */
            vTaskSuspendAll();
            /* Enter software standby mode */
            err = R_LPM_LowPowerModeEnter(&g_lpm0_ctrl);
            if (FSP_SUCCESS != err)
            {
                __BKPT(4);
            }
            /* Re-enable interrupts */
            __enable_irq();

            /* Restart the FreeRTOS scheduler */
            (void) xTaskResumeAll();

    Ian.

  • Thanks, Ian.

    I will try to test this in my project.

    Cooper.