Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

FreeRTOS CORTEX_STM32F103_IAR demo

Posted by Jakub on July 25, 2013
hi,
this is default implementation for tickless idle mode in demo:
/* Enter a critical section but don't use the taskENTER_CRITICAL()
method as that will mask interrupts that should exit sleep mode. */
__disable_interrupt();

/* If a context switch is pending or a task is waiting for the scheduler
to be unsuspended then abandon the low power entry. */
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
{
/* Restart SysTick. */
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;

/* Re-enable interrupts - see comments above __disable_interrupt()
call above. */
__enable_interrupt();
}
else
{
/* Set the new reload value. */
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;

/* Clear the SysTick count flag and set the count value back to
zero. */
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;

/* Restart SysTick. */
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;

/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
set its parameter to 0 to indicate that its implementation contains
its own wait for interrupt or wait for event instruction, and so wfi
should not be executed again. However, the original expected idle
time variable must remain unmodified, so a copy is taken. */
xModifiableIdleTime = xExpectedIdleTime;
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
if( xModifiableIdleTime > 0 )
{
__WFI();
__DSB();
__ISB();
}
configPOST_SLEEP_PROCESSING( xExpectedIdleTime );

/* Stop SysTick. Again, the time the SysTick is stopped for is
accounted for as best it can be, but using the tickless mode will
inevitably result in some tiny drift of the time maintained by the
kernel with respect to calendar time. */
portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT;

/* Re-enable interrupts - see comments above __disable_interrupt()
call above. */
__enable_interrupt();

I'm a little bit confused when I try to understand it. Before the first 'if' statement there is '__disable_interrupt()'. During I was debugging program, I noticed that this function set PRIMASK to 1, so it prevents the activation of all exceptions with configurable priority. Let's assume that condition eTaskConfirmSleepModeStatus() == eAbortSleep isn't met - so MCU is forced to sleep because of __WFI(). And my question is - why does MCU wake up? SysTick interrupt has configurable priority so I think it should by masked by setting PRIMASK to 1, am I wrong? I'm reading documentation from ST, from ARM and from FreeRTOS but I can't come to terms

RE: FreeRTOS CORTEX_STM32F103_IAR demo

Posted by Richard on July 25, 2013
First - the implementation you have posted has changed a little to remove the requirement to reset the reload value in the tick handler. Please take the implementation out of FreeRTOS V7.5.2.

To answer your question: If interrupts are globally disable by __diable_interrupt() when WFI is called then an interrupt will still bring the MCU out of sleep mode, but the interrupt will not actually be handled until interrupts are globally enabled again.

If on the other hand interrupts are masked in BASEPRI (as they would be if taskENTER_CRITICAL() or taskDISABLE_INTERRUPTS() was called) then only interrupts that have a priority above that set in BASEPRI are able to bring the MCU out of sleep mode.

Regards.

RE: FreeRTOS CORTEX_STM32F103_IAR demo

Posted by Jakub on July 25, 2013
Many thanks! It explained me a lot


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner