Tx_LowPower Application Description

This application provides an example of Azure RTOS ThreadX stack usage, it shows how to develop an application using ThreadX low power feature. It demonstrates how to configure the LowPower feature of Azure RTOS ThreadX stack. In addition, it shows how to use ThreadX MACRO related to the LowPower feature. The main entry function tx_application_define() is then called by ThreadX during kernel start, at this stage, the application creates 1 thread and 1 semaphore:

When the “tx_app_thread” is in suspended state, waiting for the ‘Semaphore’, the system is in idle state and the scheduler decides to enter in low power mode by calling the TX_LOW_POWER_USER_ENTER that makes the system enter the STOP Mode via the HAL_PWR_EnterSTOPMode() API.

As soon as the User button is pressed, the ‘Semaphore’ is released, and the ‘tx_app_thread’ passes in Active state.

The scheduler exits the STOP Mode by calling the TX_LOW_POWER_EXIT.

In System STOP Mode, all I/O pins keep the same state as in Run mode.

When exiting the STOP Mode, the MCU is in Run mode (Range 1 or Range 2 depending on VOS bit in PWR_CR1).

Expected success behavior

Error behaviors

On failure, an error message is printed to the serial port.

Assumptions if any

None

Known limitations

None

Notes

  1. tx_low_power_enter() service enters low power mode. For keeping track of time while in low power mode, there are two possibilities:

    1.1. A ThreadX timer is active: Function tx_timer_get_next returns TX_TRUE.

    Note that in this situation, a low power clock must be used in order to wake up the CPU for the next ThreadX timer expiration.

    Therefore an alternative clock must be programmed. Program the hardware timer source such that the next timer interrupt is equal to: tx_low_power_next_expiration tick_frequency. The tick_frequency is application-specific and typically set up in tx_low_level_initialize.

    1.2. There are no ThreadX timers active: Function tx_timer_get_next returns TX_FALSE.

    1.2.1. The application may choose not to keep the ThreadX internal
    tick count updated (define **TX_LOW_POWER_TICKLESS**), therefore there is no need
    to set up a low power clock.
    
    1.2.2. The application still needs to keep the ThreadX tick up-to-date. In this case a low power clock needs to be set up.
  2. Entering Low-power mode through WFI will be executed only if no interrupt is pending.

  3. The Debug Module must be stopped during STOP Mode, otherwise, It will generate interrupts that cause the Wake-up of the system immediately after entering the STOP Mode.

  4. The user push-button interrupt priority must be set to the highest possible value, otherwise, after exiting STOP Mode the processor will not execute the interrupt handler.

  5. To optimize the application footprint, the following ThreadX configuration options should be enabled in the tx_user.h file:

    #define TX_DISABLE_PREEMPTION_THRESHOLD

    #define TX_DISABLE_NOTIFY_CALLBACKS

    #define TX_DISABLE_REDUNDANT_CLEARING

    #define TX_DISABLE_STACK_FILLING

    #define TX_NOT_INTERRUPTABLE

    #define TX_TIMER_PROCESS_IN_ISR

    #define TX_DISABLE_ERROR_CHECKING

ThreadX usage hints

Keywords

RTOS, ThreadX, Threading, Semaphore, PWR, STOP Mode, Interrupt, EXTI, Wakeup, LowPower

Hardware and Software environment

How to use it ?

In order to make the program work, you must do the following: