diff --git a/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/portability.cpp b/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/portability.cpp
index 257a931f895722011266f4a8f8c054bdbb1bc60c..f2d690bfa547ccf7894e437dd11460397cded339 100644
--- a/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/portability.cpp
+++ b/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/portability.cpp
@@ -37,10 +37,6 @@
 
 using namespace std;
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -53,7 +49,7 @@ namespace miosix_private {
 void ISR_yield() __attribute__((noinline));
 void ISR_yield()
 {
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     miosix::Scheduler::IRQfindNextThread();
 }
 
@@ -73,19 +69,6 @@ extern "C" void kernel_SWI_Routine()
     restoreContext();
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[13] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {    
     //Jump to reset vector
diff --git a/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/portability_impl.h b/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/portability_impl.h
index eade54a399cc537afc0118cef9ac67e5c92a5ee5..5fef5e0cef359ffb85e7d5bf20f7228516481079 100644
--- a/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/portability_impl.h
+++ b/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/portability_impl.h
@@ -62,6 +62,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=13; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM0_stm32f0/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM0_stm32f0/common/interfaces-impl/portability.cpp
index ad5c2f775c955ad42eda56f3493e2f9bc246f551..fd0448aff7b74facf4b0826ad244fd61e20c10f4 100644
--- a/miosix/arch/cortexM0_stm32f0/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM0_stm32f0/common/interfaces-impl/portability.cpp
@@ -48,10 +48,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -64,23 +60,10 @@ namespace miosix_private {
 void ISR_yield() __attribute__((noinline));
 void ISR_yield()
 {
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     miosix::Scheduler::IRQfindNextThread();
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM0_stm32f0/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM0_stm32f0/common/interfaces-impl/portability_impl.h
index c3e7e37dd44aab007beca75f1e305349ccb22264..841bed9e6444a3e72322cf8698413c36219f92ab 100644
--- a/miosix/arch/cortexM0_stm32f0/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM0_stm32f0/common/interfaces-impl/portability_impl.h
@@ -55,6 +55,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/portability.cpp
index 31b1c2e01422d53b5aec52ff687838c624a251cd..652d6c0a3c0965a80cfc39445d94741a3cf977ca 100644
--- a/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/portability.cpp
@@ -48,10 +48,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -64,23 +60,10 @@ namespace miosix_private {
 void ISR_yield() __attribute__((noinline));
 void ISR_yield()
 {
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     miosix::Scheduler::IRQfindNextThread();
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/portability_impl.h
index 6e8561c403ca9ef62806129699ad925e1ec16d43..3fc6c8d3368b6763859251bce49ed7f0cbf1126b 100644
--- a/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/portability_impl.h
@@ -56,6 +56,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM3_stm32f1/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM3_stm32f1/common/interfaces-impl/portability.cpp
index d901c53a320344455078328356f8b1091a0fafd6..a130ee17ac083a01844d7d559f6cf41f816b6ac5 100644
--- a/miosix/arch/cortexM3_stm32f1/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM3_stm32f1/common/interfaces-impl/portability.cpp
@@ -48,10 +48,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -64,23 +60,10 @@ namespace miosix_private {
 void ISR_yield() __attribute__((noinline));
 void ISR_yield()
 {
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     miosix::Scheduler::IRQfindNextThread();
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM3_stm32f1/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM3_stm32f1/common/interfaces-impl/portability_impl.h
index 2b6773e5b3f4d1d7f6b3cd413b6e4182250cae1f..1455471a2e0937c8f1770249383d09d0fb80467a 100644
--- a/miosix/arch/cortexM3_stm32f1/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM3_stm32f1/common/interfaces-impl/portability_impl.h
@@ -55,6 +55,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability.cpp
index 7907b5d1095f69df3a44c7ad2bc2aeae3e2b8e85..c8ec48217317848c078917c230af899876efe3bf 100644
--- a/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability.cpp
@@ -53,10 +53,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -97,7 +93,7 @@ void ISR_yield()
         }
     }
     #endif // WITH_PROCESSES
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     
     #ifdef WITH_PROCESSES
     //If processes are enabled, check the content of r3. If zero then it
@@ -114,19 +110,6 @@ void ISR_yield()
     #endif //WITH_PROCESSES
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability_impl.h
index 1ab67d48e0c69304dbded9d66327d2003bc89fec..31aa36daa2b9d5e895d1bef30607351d761a11e3 100644
--- a/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM3_stm32f2/common/interfaces-impl/portability_impl.h
@@ -56,6 +56,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM3_stm32l1/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM3_stm32l1/common/interfaces-impl/portability.cpp
index 65d23656d3482978c57b8f30f620a4dd4b50db97..0c60ba1ae833a96b3cbd3d69a45b636fa163e08e 100644
--- a/miosix/arch/cortexM3_stm32l1/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM3_stm32l1/common/interfaces-impl/portability.cpp
@@ -48,10 +48,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -64,23 +60,10 @@ namespace miosix_private {
 void ISR_yield() __attribute__((noinline));
 void ISR_yield()
 {
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     miosix::Scheduler::IRQfindNextThread();
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM3_stm32l1/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM3_stm32l1/common/interfaces-impl/portability_impl.h
index 2b6773e5b3f4d1d7f6b3cd413b6e4182250cae1f..1455471a2e0937c8f1770249383d09d0fb80467a 100644
--- a/miosix/arch/cortexM3_stm32l1/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM3_stm32l1/common/interfaces-impl/portability_impl.h
@@ -55,6 +55,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM4_atsam4l/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM4_atsam4l/common/interfaces-impl/portability.cpp
index 8723b8f2d2f777c8ad64171b92334d8e2640f4f0..125de5f9095ea3235e3fc33c3929bcf738ee2d0a 100644
--- a/miosix/arch/cortexM4_atsam4l/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM4_atsam4l/common/interfaces-impl/portability.cpp
@@ -50,10 +50,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -66,23 +62,10 @@ namespace miosix_private {
 void ISR_yield() __attribute__((noinline));
 void ISR_yield()
 {
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     miosix::Scheduler::IRQfindNextThread();
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM4_atsam4l/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM4_atsam4l/common/interfaces-impl/portability_impl.h
index fa63ba4042e017b327550d2ded53c05132036cbc..fe5ab1db7e1a842b7fa85b330a4067dc7065c298 100644
--- a/miosix/arch/cortexM4_atsam4l/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM4_atsam4l/common/interfaces-impl/portability_impl.h
@@ -54,6 +54,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM4_stm32f3/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM4_stm32f3/common/interfaces-impl/portability.cpp
index 97da99e99b22baebefdea71e696872af398bec7a..7b83129cf02fbcaf93172e69af0e77d208384c2a 100644
--- a/miosix/arch/cortexM4_stm32f3/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM4_stm32f3/common/interfaces-impl/portability.cpp
@@ -53,10 +53,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -97,7 +93,7 @@ void ISR_yield()
         }
     }
     #endif // WITH_PROCESSES
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     
     #ifdef WITH_PROCESSES
     //If processes are enabled, check the content of r3. If zero then it
@@ -114,19 +110,6 @@ void ISR_yield()
     #endif //WITH_PROCESSES
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM4_stm32f3/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM4_stm32f3/common/interfaces-impl/portability_impl.h
index 904881868c4e74c7939d80896453c7038a0a3f8a..fe69a39e696b6d263ef8fa21bce14bd91e657239 100644
--- a/miosix/arch/cortexM4_stm32f3/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM4_stm32f3/common/interfaces-impl/portability_impl.h
@@ -60,6 +60,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/portability.cpp
index 6ca667d946c658557c9e1334ecd1b3dc79975cbc..41ce36e273a979c6cfa327d08e9fac5e0fa4a4ac 100644
--- a/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/portability.cpp
@@ -53,10 +53,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -97,7 +93,7 @@ void ISR_yield()
         }
     }
     #endif // WITH_PROCESSES
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     
     #ifdef WITH_PROCESSES
     //If processes are enabled, check the content of r3. If zero then it
@@ -114,19 +110,6 @@ void ISR_yield()
     #endif //WITH_PROCESSES
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/portability_impl.h
index 29a75e5e94ee192f832421b0a3686371cae855a6..032962b0eb5ed2df8363790488adab3f228177f6 100644
--- a/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM4_stm32f4/common/interfaces-impl/portability_impl.h
@@ -60,6 +60,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM4_stm32l4/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM4_stm32l4/common/interfaces-impl/portability.cpp
index 6ca667d946c658557c9e1334ecd1b3dc79975cbc..41ce36e273a979c6cfa327d08e9fac5e0fa4a4ac 100644
--- a/miosix/arch/cortexM4_stm32l4/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM4_stm32l4/common/interfaces-impl/portability.cpp
@@ -53,10 +53,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -97,7 +93,7 @@ void ISR_yield()
         }
     }
     #endif // WITH_PROCESSES
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     
     #ifdef WITH_PROCESSES
     //If processes are enabled, check the content of r3. If zero then it
@@ -114,19 +110,6 @@ void ISR_yield()
     #endif //WITH_PROCESSES
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM4_stm32l4/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM4_stm32l4/common/interfaces-impl/portability_impl.h
index 29a75e5e94ee192f832421b0a3686371cae855a6..032962b0eb5ed2df8363790488adab3f228177f6 100644
--- a/miosix/arch/cortexM4_stm32l4/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM4_stm32l4/common/interfaces-impl/portability_impl.h
@@ -60,6 +60,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM7_stm32f7/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM7_stm32f7/common/interfaces-impl/portability.cpp
index ad4b3e9933c1bcedf432dbcfd7ea36e66f55dd24..63198acc549a294100dae7cda4c9dd9270cce1ca 100644
--- a/miosix/arch/cortexM7_stm32f7/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM7_stm32f7/common/interfaces-impl/portability.cpp
@@ -53,10 +53,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -97,7 +93,7 @@ void ISR_yield()
         }
     }
     #endif // WITH_PROCESSES
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     
     #ifdef WITH_PROCESSES
     //If processes are enabled, check the content of r3. If zero then it
@@ -114,19 +110,6 @@ void ISR_yield()
     #endif //WITH_PROCESSES
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM7_stm32f7/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM7_stm32f7/common/interfaces-impl/portability_impl.h
index 29a75e5e94ee192f832421b0a3686371cae855a6..032962b0eb5ed2df8363790488adab3f228177f6 100644
--- a/miosix/arch/cortexM7_stm32f7/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM7_stm32f7/common/interfaces-impl/portability_impl.h
@@ -60,6 +60,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/arch/cortexM7_stm32h7/common/interfaces-impl/portability.cpp b/miosix/arch/cortexM7_stm32h7/common/interfaces-impl/portability.cpp
index ad4b3e9933c1bcedf432dbcfd7ea36e66f55dd24..63198acc549a294100dae7cda4c9dd9270cce1ca 100644
--- a/miosix/arch/cortexM7_stm32h7/common/interfaces-impl/portability.cpp
+++ b/miosix/arch/cortexM7_stm32h7/common/interfaces-impl/portability.cpp
@@ -53,10 +53,6 @@ void SVC_Handler()
     restoreContext();
 }
 
-namespace miosix {
-extern volatile Thread *cur;///\internal Do not use outside the kernel
-}
-
 namespace miosix_private {
 
 /**
@@ -97,7 +93,7 @@ void ISR_yield()
         }
     }
     #endif // WITH_PROCESSES
-    IRQstackOverflowCheck();
+    miosix::Thread::IRQstackOverflowCheck();
     
     #ifdef WITH_PROCESSES
     //If processes are enabled, check the content of r3. If zero then it
@@ -114,19 +110,6 @@ void ISR_yield()
     #endif //WITH_PROCESSES
 }
 
-void IRQstackOverflowCheck()
-{
-    const unsigned int watermarkSize=miosix::WATERMARK_LEN/sizeof(unsigned int);
-    for(unsigned int i=0;i<watermarkSize;i++)
-    {
-        if(miosix::cur->watermark[i]!=miosix::WATERMARK_FILL)
-            miosix::errorHandler(miosix::STACK_OVERFLOW);
-    }
-    if(miosix::cur->ctxsave[0] < reinterpret_cast<unsigned int>(
-            miosix::cur->watermark+watermarkSize))
-        miosix::errorHandler(miosix::STACK_OVERFLOW);
-}
-
 void IRQsystemReboot()
 {
     NVIC_SystemReset();
diff --git a/miosix/arch/cortexM7_stm32h7/common/interfaces-impl/portability_impl.h b/miosix/arch/cortexM7_stm32h7/common/interfaces-impl/portability_impl.h
index 29a75e5e94ee192f832421b0a3686371cae855a6..032962b0eb5ed2df8363790488adab3f228177f6 100644
--- a/miosix/arch/cortexM7_stm32h7/common/interfaces-impl/portability_impl.h
+++ b/miosix/arch/cortexM7_stm32h7/common/interfaces-impl/portability_impl.h
@@ -60,6 +60,7 @@
 extern "C" {
 extern volatile unsigned int *ctxsave;
 }
+const int stackPtrOffsetInCtxsave=0; ///< Allows to locate the stack pointer
 
 /**
  * \internal
diff --git a/miosix/interfaces/portability.h b/miosix/interfaces/portability.h
index 256a78eae18e3ad945bbe27984b8b823f4013417..22aa758aa034854f3659ff624c4d78cb2e1e65ff 100644
--- a/miosix/interfaces/portability.h
+++ b/miosix/interfaces/portability.h
@@ -228,13 +228,6 @@ inline void portableSwitchToUserspace();
 
 #endif //WITH_PROCESSES
 
-/**
- * \internal
- * Used before every context switch to check if the stack of the thread has
- * overflowed must be called before IRQfindNextThread().
- */
-void IRQstackOverflowCheck();
-
 /**
  * \internal
  * Called by miosix::start_kernel to handle the architecture-specific part of
diff --git a/miosix/kernel/kernel.cpp b/miosix/kernel/kernel.cpp
index 479ca479b21de49452a1e88175498463f0a01bc8..a7329888839f3e6cf6d49764da40dd4aec6685eb 100755
--- a/miosix/kernel/kernel.cpp
+++ b/miosix/kernel/kernel.cpp
@@ -684,6 +684,18 @@ bool Thread::IRQreportFault(const miosix_private::FaultData& fault)
 
 #endif //WITH_PROCESSES
 
+void Thread::IRQstackOverflowCheck()
+{
+    const unsigned int watermarkSize=WATERMARK_LEN/sizeof(unsigned int);
+    for(unsigned int i=0;i<watermarkSize;i++)
+    {
+        if(cur->watermark[i]!=WATERMARK_FILL) errorHandler(STACK_OVERFLOW);
+    }
+    if(cur->ctxsave[stackPtrOffsetInCtxsave] <
+        reinterpret_cast<unsigned int>(cur->watermark+watermarkSize))
+        errorHandler(STACK_OVERFLOW);
+}
+
 void Thread::threadLauncher(void *(*threadfunc)(void*), void *argv)
 {
     void *result=0;
diff --git a/miosix/kernel/kernel.h b/miosix/kernel/kernel.h
index 58ece03c225700c055b7c98e4ff404fc6c2519b3..3a6d5dbb5aee26d854388e94a75a53ee4876e152 100755
--- a/miosix/kernel/kernel.h
+++ b/miosix/kernel/kernel.h
@@ -746,7 +746,14 @@ public:
     static bool IRQreportFault(const miosix_private::FaultData& fault);
     
     #endif //WITH_PROCESSES
-	
+
+    /**
+     * \internal
+     * Used before every context switch to check if the stack of the thread
+     * being preempted has overflowed
+     */
+    static void IRQstackOverflowCheck();
+
 private:
     //Unwanted methods
     Thread(const Thread& p);///< No public copy constructor
@@ -1031,8 +1038,6 @@ private:
     #endif //WITH_CPU_TIME_COUNTER
     
     //friend functions
-    //Needs access to watermark, ctxsave
-    friend void miosix_private::IRQstackOverflowCheck();
     //Need access to status
     friend void IRQaddToSleepingList(SleepData *x);
     //Needs access to status
diff --git a/miosix/kernel/scheduler/timer_interrupt.h b/miosix/kernel/scheduler/timer_interrupt.h
index 0928443e38298e5964576b6dccc593a83e3958d1..347e9bf3cfe1f6bed4dcd2c70731e683ed6cd898 100644
--- a/miosix/kernel/scheduler/timer_interrupt.h
+++ b/miosix/kernel/scheduler/timer_interrupt.h
@@ -44,7 +44,7 @@ extern bool IRQwakeThreads(long long currentTime);///\internal Do not use outsid
  */
 inline void IRQtimerInterrupt(long long currentTime)
 {
-    miosix_private::IRQstackOverflowCheck();
+    Thread::IRQstackOverflowCheck();
     bool hptw = IRQwakeThreads(currentTime);
     if(currentTime >= Scheduler::IRQgetNextPreemption() || hptw)
     {