Skip to content

Commit a67737f

Browse files
Merge pull request #5086 from pan-/systick_sleep_fix
Sleep: Disallow sleep for targets turning off the systick clock at sleep entry
2 parents fad6755 + 6cb1a23 commit a67737f

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

platform/mbed_sleep.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ extern "C" {
6262

6363
/** Lock the deep sleep mode
6464
*
65-
* This locks the automatic deep mode selection.
65+
* This locks the automatic deep mode selection.
6666
* sleep_manager_sleep_auto() will ignore deepsleep mode if
6767
* this function is invoked at least once (the internal counter is non-zero)
6868
*
6969
* Use this locking mechanism for interrupt driven API that are
7070
* running in the background and deepsleep could affect their functionality
71-
*
71+
*
7272
* The lock is a counter, can be locked up to USHRT_MAX
7373
* This function is IRQ and thread safe
7474
*/
7575
void sleep_manager_lock_deep_sleep(void);
7676

7777
/** Unlock the deep sleep mode
7878
*
79-
* Use unlocking in pair with sleep_manager_lock_deep_sleep().
80-
*
79+
* Use unlocking in pair with sleep_manager_lock_deep_sleep().
80+
*
8181
* The lock is a counter, should be equally unlocked as locked
8282
* This function is IRQ and thread safe
8383
*/
@@ -97,7 +97,7 @@ bool sleep_manager_can_deep_sleep(void);
9797
* @note
9898
* If MBED_DEBUG is defined, only hal_sleep is allowed. This ensures the debugger
9999
* to be active for debug modes.
100-
*
100+
*
101101
*/
102102
void sleep_manager_sleep_auto(void);
103103

@@ -106,6 +106,10 @@ void sleep_manager_sleep_auto(void);
106106
* @note This function can be a noop if not implemented by the platform.
107107
* @note This function will be a noop in debug mode (debug build profile when MBED_DEBUG is defined).
108108
* @note This function will be a noop while uVisor is in use.
109+
* @note This function will be a noop if the following conditions are met:
110+
* - The RTOS is present
111+
* - The processor turn off the Systick clock during sleep
112+
* - The target does not implement tickless mode
109113
*
110114
* The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the
111115
* system clock to the core is stopped until a reset or an interrupt occurs. This eliminates
@@ -123,7 +127,9 @@ __INLINE static void sleep(void)
123127
{
124128
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
125129
#if DEVICE_SLEEP
130+
#if (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_STCLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS)
126131
sleep_manager_sleep_auto();
132+
#endif /* (MBED_CONF_RTOS_PRESENT == 0) || (DEVICE_STCLK_OFF_DURING_SLEEP == 0) || defined(MBED_TICKLESS) */
127133
#endif /* DEVICE_SLEEP */
128134
#endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
129135
}

targets/targets.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,6 +3025,7 @@
30253025
"inherits": ["Target"],
30263026
"core": "Cortex-M4F",
30273027
"macros": ["NRF52", "TARGET_NRF52832", "BLE_STACK_SUPPORT_REQD", "SOFTDEVICE_PRESENT", "S132", "CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\"", "MBED_TICKLESS"],
3028+
"device_has": ["STCLK_OFF_DURING_SLEEP"],
30283029
"extra_labels": ["NORDIC", "MCU_NRF52", "MCU_NRF52832", "NRF5", "SDK11", "NRF52_COMMON"],
30293030
"OUTPUT_EXT": "hex",
30303031
"is_disk_virtual": true,
@@ -3062,14 +3063,14 @@
30623063
"supported_form_factors": ["ARDUINO"],
30633064
"inherits": ["MCU_NRF52"],
30643065
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
3065-
"device_has": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
3066+
"device_has_add": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
30663067
"release_versions": ["2", "5"],
30673068
"device_name": "nRF52832_xxAA"
30683069
},
30693070
"UBLOX_EVA_NINA": {
30703071
"inherits": ["MCU_NRF52"],
30713072
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
3072-
"device_has": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
3073+
"device_has_add": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
30733074
"release_versions": ["2", "5"],
30743075
"overrides": {"uart_hwfc": 0},
30753076
"device_name": "nRF52832_xxAA"
@@ -3078,15 +3079,15 @@
30783079
"supported_form_factors": ["ARDUINO"],
30793080
"inherits": ["MCU_NRF52"],
30803081
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
3081-
"device_has": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
3082+
"device_has_add": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
30823083
"release_versions": ["2", "5"],
30833084
"device_name": "nRF52832_xxAA"
30843085
},
30853086
"DELTA_DFBM_NQ620": {
30863087
"supported_form_factors": ["ARDUINO"],
30873088
"inherits": ["MCU_NRF52"],
30883089
"macros_add": ["BOARD_PCA10040", "NRF52_PAN_12", "NRF52_PAN_15", "NRF52_PAN_58", "NRF52_PAN_55", "NRF52_PAN_54", "NRF52_PAN_31", "NRF52_PAN_30", "NRF52_PAN_51", "NRF52_PAN_36", "NRF52_PAN_53", "S132", "CONFIG_GPIO_AS_PINRESET", "BLE_STACK_SUPPORT_REQD", "SWI_DISABLE0", "NRF52_PAN_20", "NRF52_PAN_64", "NRF52_PAN_62", "NRF52_PAN_63"],
3089-
"device_has": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
3090+
"device_has_add": ["ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"],
30903091
"release_versions": ["2", "5"],
30913092
"overrides": {"lf_clock_src": "NRF_LF_SRC_RC"},
30923093
"config": {
@@ -3105,6 +3106,7 @@
31053106
"inherits": ["Target"],
31063107
"core": "Cortex-M4F",
31073108
"macros": ["TARGET_NRF52840", "BLE_STACK_SUPPORT_REQD", "SOFTDEVICE_PRESENT", "S140", "NRF_SD_BLE_API_VERSION=5", "NRF52840_XXAA", "NRF_DFU_SETTINGS_VERSION=1", "NRF_SD_BLE_API_VERSION=5", "CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\""],
3109+
"device_has": ["STCLK_OFF_DURING_SLEEP"],
31083110
"extra_labels": ["NORDIC", "MCU_NRF52840", "NRF5", "SDK13", "NRF52_COMMON"],
31093111
"OUTPUT_EXT": "hex",
31103112
"is_disk_virtual": true,
@@ -3143,7 +3145,7 @@
31433145
"supported_form_factors": ["ARDUINO"],
31443146
"inherits": ["MCU_NRF52840"],
31453147
"macros_add": ["BOARD_PCA10056", "CONFIG_GPIO_AS_PINRESET", "SWI_DISABLE0", "NRF52_ERRATA_20"],
3146-
"device_has": ["FLASH", "ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "TRNG"],
3148+
"device_has_add": ["FLASH", "ANALOGIN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "TRNG"],
31473149
"release_versions": ["2", "5"],
31483150
"device_name": "nRF52840_xxAA"
31493151
},

tools/targets/lint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def check_inherits(dict):
8282
"LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT",
8383
"PWMOUT", "RTC", "TRNG","SERIAL", "SERIAL_ASYNCH",
8484
"SERIAL_FC", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE",
85-
"STORAGE"]
85+
"STORAGE", "STCLK_OFF_DURING_SLEEP"]
8686
def check_device_has(dict):
8787
for name in dict.get("device_has", []):
8888
if name not in DEVICE_HAS_ALLOWED:

0 commit comments

Comments
 (0)