What's causing this power spike in STM32 low power mode












6












$begingroup$


I'm using an STM32L073RZ on a bare board with just the CPU and decoupling caps. I'm powering the board straight from an Otii Arc and measuring current consumption. I'm running MbedOS 5.11.2.



When I call the sleep() function the CPU goes into a low power mode, with an occasional 5mA spike in current consumption approximately every second, see the image below:



Current consumption



What is the cause of this? I'm attempting to place the CPU into STOP mode with an RTC running - this should draw, according to the datasheet, 1µA current.



Further to this, how can I tell which low power mode the sleep() function has chosen? I'm trying to stay away from the HAL because I've had many issues configuring interrupts and the like.



For completeness, here's the code that's running on the board:



#include "mbed.h"

int main() {
sleep();
}









share|improve this question









$endgroup$








  • 1




    $begingroup$
    I would guess your mcu is waking up once a second for some reason
    $endgroup$
    – Colin
    yesterday






  • 2




    $begingroup$
    It seems quite plausible that the RTC is generating an interrupt once per second. Put a breakpoint on the RTC interrupt handler.
    $endgroup$
    – Jeremy
    yesterday










  • $begingroup$
    @Jeremy thanks for the suggestion, doesn't appear to be an RTC interrupt as the handler doesn't trigger if I include it.
    $endgroup$
    – Adam Mitchell
    yesterday






  • 1




    $begingroup$
    @Adam - Even if the interrupt is masked, if the RTC is active it may be bringing elements out of low-power mode anyway.
    $endgroup$
    – Jeremy
    yesterday










  • $begingroup$
    @Jeremy that's a fair suggestion. I think I'll have to get to grips with the HAL so I can be absolutely sure which timers are running, which power mode the CPU is in etc.. Thanks!
    $endgroup$
    – Adam Mitchell
    yesterday
















6












$begingroup$


I'm using an STM32L073RZ on a bare board with just the CPU and decoupling caps. I'm powering the board straight from an Otii Arc and measuring current consumption. I'm running MbedOS 5.11.2.



When I call the sleep() function the CPU goes into a low power mode, with an occasional 5mA spike in current consumption approximately every second, see the image below:



Current consumption



What is the cause of this? I'm attempting to place the CPU into STOP mode with an RTC running - this should draw, according to the datasheet, 1µA current.



Further to this, how can I tell which low power mode the sleep() function has chosen? I'm trying to stay away from the HAL because I've had many issues configuring interrupts and the like.



For completeness, here's the code that's running on the board:



#include "mbed.h"

int main() {
sleep();
}









share|improve this question









$endgroup$








  • 1




    $begingroup$
    I would guess your mcu is waking up once a second for some reason
    $endgroup$
    – Colin
    yesterday






  • 2




    $begingroup$
    It seems quite plausible that the RTC is generating an interrupt once per second. Put a breakpoint on the RTC interrupt handler.
    $endgroup$
    – Jeremy
    yesterday










  • $begingroup$
    @Jeremy thanks for the suggestion, doesn't appear to be an RTC interrupt as the handler doesn't trigger if I include it.
    $endgroup$
    – Adam Mitchell
    yesterday






  • 1




    $begingroup$
    @Adam - Even if the interrupt is masked, if the RTC is active it may be bringing elements out of low-power mode anyway.
    $endgroup$
    – Jeremy
    yesterday










  • $begingroup$
    @Jeremy that's a fair suggestion. I think I'll have to get to grips with the HAL so I can be absolutely sure which timers are running, which power mode the CPU is in etc.. Thanks!
    $endgroup$
    – Adam Mitchell
    yesterday














6












6








6





$begingroup$


I'm using an STM32L073RZ on a bare board with just the CPU and decoupling caps. I'm powering the board straight from an Otii Arc and measuring current consumption. I'm running MbedOS 5.11.2.



When I call the sleep() function the CPU goes into a low power mode, with an occasional 5mA spike in current consumption approximately every second, see the image below:



Current consumption



What is the cause of this? I'm attempting to place the CPU into STOP mode with an RTC running - this should draw, according to the datasheet, 1µA current.



Further to this, how can I tell which low power mode the sleep() function has chosen? I'm trying to stay away from the HAL because I've had many issues configuring interrupts and the like.



For completeness, here's the code that's running on the board:



#include "mbed.h"

int main() {
sleep();
}









share|improve this question









$endgroup$




I'm using an STM32L073RZ on a bare board with just the CPU and decoupling caps. I'm powering the board straight from an Otii Arc and measuring current consumption. I'm running MbedOS 5.11.2.



When I call the sleep() function the CPU goes into a low power mode, with an occasional 5mA spike in current consumption approximately every second, see the image below:



Current consumption



What is the cause of this? I'm attempting to place the CPU into STOP mode with an RTC running - this should draw, according to the datasheet, 1µA current.



Further to this, how can I tell which low power mode the sleep() function has chosen? I'm trying to stay away from the HAL because I've had many issues configuring interrupts and the like.



For completeness, here's the code that's running on the board:



#include "mbed.h"

int main() {
sleep();
}






stm32 low-power mbed






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









Adam MitchellAdam Mitchell

1416




1416








  • 1




    $begingroup$
    I would guess your mcu is waking up once a second for some reason
    $endgroup$
    – Colin
    yesterday






  • 2




    $begingroup$
    It seems quite plausible that the RTC is generating an interrupt once per second. Put a breakpoint on the RTC interrupt handler.
    $endgroup$
    – Jeremy
    yesterday










  • $begingroup$
    @Jeremy thanks for the suggestion, doesn't appear to be an RTC interrupt as the handler doesn't trigger if I include it.
    $endgroup$
    – Adam Mitchell
    yesterday






  • 1




    $begingroup$
    @Adam - Even if the interrupt is masked, if the RTC is active it may be bringing elements out of low-power mode anyway.
    $endgroup$
    – Jeremy
    yesterday










  • $begingroup$
    @Jeremy that's a fair suggestion. I think I'll have to get to grips with the HAL so I can be absolutely sure which timers are running, which power mode the CPU is in etc.. Thanks!
    $endgroup$
    – Adam Mitchell
    yesterday














  • 1




    $begingroup$
    I would guess your mcu is waking up once a second for some reason
    $endgroup$
    – Colin
    yesterday






  • 2




    $begingroup$
    It seems quite plausible that the RTC is generating an interrupt once per second. Put a breakpoint on the RTC interrupt handler.
    $endgroup$
    – Jeremy
    yesterday










  • $begingroup$
    @Jeremy thanks for the suggestion, doesn't appear to be an RTC interrupt as the handler doesn't trigger if I include it.
    $endgroup$
    – Adam Mitchell
    yesterday






  • 1




    $begingroup$
    @Adam - Even if the interrupt is masked, if the RTC is active it may be bringing elements out of low-power mode anyway.
    $endgroup$
    – Jeremy
    yesterday










  • $begingroup$
    @Jeremy that's a fair suggestion. I think I'll have to get to grips with the HAL so I can be absolutely sure which timers are running, which power mode the CPU is in etc.. Thanks!
    $endgroup$
    – Adam Mitchell
    yesterday








1




1




$begingroup$
I would guess your mcu is waking up once a second for some reason
$endgroup$
– Colin
yesterday




$begingroup$
I would guess your mcu is waking up once a second for some reason
$endgroup$
– Colin
yesterday




2




2




$begingroup$
It seems quite plausible that the RTC is generating an interrupt once per second. Put a breakpoint on the RTC interrupt handler.
$endgroup$
– Jeremy
yesterday




$begingroup$
It seems quite plausible that the RTC is generating an interrupt once per second. Put a breakpoint on the RTC interrupt handler.
$endgroup$
– Jeremy
yesterday












$begingroup$
@Jeremy thanks for the suggestion, doesn't appear to be an RTC interrupt as the handler doesn't trigger if I include it.
$endgroup$
– Adam Mitchell
yesterday




$begingroup$
@Jeremy thanks for the suggestion, doesn't appear to be an RTC interrupt as the handler doesn't trigger if I include it.
$endgroup$
– Adam Mitchell
yesterday




1




1




$begingroup$
@Adam - Even if the interrupt is masked, if the RTC is active it may be bringing elements out of low-power mode anyway.
$endgroup$
– Jeremy
yesterday




$begingroup$
@Adam - Even if the interrupt is masked, if the RTC is active it may be bringing elements out of low-power mode anyway.
$endgroup$
– Jeremy
yesterday












$begingroup$
@Jeremy that's a fair suggestion. I think I'll have to get to grips with the HAL so I can be absolutely sure which timers are running, which power mode the CPU is in etc.. Thanks!
$endgroup$
– Adam Mitchell
yesterday




$begingroup$
@Jeremy that's a fair suggestion. I think I'll have to get to grips with the HAL so I can be absolutely sure which timers are running, which power mode the CPU is in etc.. Thanks!
$endgroup$
– Adam Mitchell
yesterday










2 Answers
2






active

oldest

votes


















9












$begingroup$

I can't speak about mbed specifically, but the general idea is that sleep() causes the execution of the current process to pause for some number of seconds, or indefinitely if no argument (equivalent to an argument of 0) is given.



In a multiprocess environment, that means that it simply yields the CPU to other processes. If there are no other processes ready to run, the OS may or may not put the CPU into a low-power state while waiting for interrupts — it depends on how the idle() task is written. This would not generally be the lowest-power state available on the CPU, however, since it wants to wake quickly when interrupts occur.



In your case, it appears to be waking up once a second to handle the system timer tick.



If you really want to get into a lower-power state, there are generally platform-specific calls for that, and that's exactly the sort of thing the HAL is for. You shouldn't avoid it, you should learn it.





After a quick search, I discovered that the documentation here: APIs - power management discusses this specifically.






share|improve this answer











$endgroup$













  • $begingroup$
    Thanks for your response, very useful. In Mbed, sleep() is supposed to place to CPU into a low-power mode, but no documentation that I can find explains this logic. I've disabled the SysTick IRQ in the NVIC to no avail, I guess I'll just keep turning off timers/counters until it disappears..
    $endgroup$
    – Adam Mitchell
    yesterday






  • 1




    $begingroup$
    @AdamMitchell - more likely what you need to do is actually read through the Mbed code (it is open source, even if by default they link a binary version of it) and figure out what they are doing, then decide if that can be brought into alignment with your goals, or if their goals are just too different.
    $endgroup$
    – Chris Stratton
    yesterday





















1












$begingroup$

As explained in the documentation, the following drivers can prevent deep sleep:





  • Ticker

  • Timeout

  • Timer

  • SPI

  • I2C

  • CAN

  • SerialBase




If you need to identify what is blocking deep sleep, you can build from the command line, and enable the verbose debugging - even though it seems you do not have any in your example.



You can also review the tickless documentation. I believe this mode is relatively new, so it is possible that your platform has some problems in the HAL.






share|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("schematics", function () {
    StackExchange.schematics.init();
    });
    }, "cicuitlab");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "135"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f427383%2fwhats-causing-this-power-spike-in-stm32-low-power-mode%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9












    $begingroup$

    I can't speak about mbed specifically, but the general idea is that sleep() causes the execution of the current process to pause for some number of seconds, or indefinitely if no argument (equivalent to an argument of 0) is given.



    In a multiprocess environment, that means that it simply yields the CPU to other processes. If there are no other processes ready to run, the OS may or may not put the CPU into a low-power state while waiting for interrupts — it depends on how the idle() task is written. This would not generally be the lowest-power state available on the CPU, however, since it wants to wake quickly when interrupts occur.



    In your case, it appears to be waking up once a second to handle the system timer tick.



    If you really want to get into a lower-power state, there are generally platform-specific calls for that, and that's exactly the sort of thing the HAL is for. You shouldn't avoid it, you should learn it.





    After a quick search, I discovered that the documentation here: APIs - power management discusses this specifically.






    share|improve this answer











    $endgroup$













    • $begingroup$
      Thanks for your response, very useful. In Mbed, sleep() is supposed to place to CPU into a low-power mode, but no documentation that I can find explains this logic. I've disabled the SysTick IRQ in the NVIC to no avail, I guess I'll just keep turning off timers/counters until it disappears..
      $endgroup$
      – Adam Mitchell
      yesterday






    • 1




      $begingroup$
      @AdamMitchell - more likely what you need to do is actually read through the Mbed code (it is open source, even if by default they link a binary version of it) and figure out what they are doing, then decide if that can be brought into alignment with your goals, or if their goals are just too different.
      $endgroup$
      – Chris Stratton
      yesterday


















    9












    $begingroup$

    I can't speak about mbed specifically, but the general idea is that sleep() causes the execution of the current process to pause for some number of seconds, or indefinitely if no argument (equivalent to an argument of 0) is given.



    In a multiprocess environment, that means that it simply yields the CPU to other processes. If there are no other processes ready to run, the OS may or may not put the CPU into a low-power state while waiting for interrupts — it depends on how the idle() task is written. This would not generally be the lowest-power state available on the CPU, however, since it wants to wake quickly when interrupts occur.



    In your case, it appears to be waking up once a second to handle the system timer tick.



    If you really want to get into a lower-power state, there are generally platform-specific calls for that, and that's exactly the sort of thing the HAL is for. You shouldn't avoid it, you should learn it.





    After a quick search, I discovered that the documentation here: APIs - power management discusses this specifically.






    share|improve this answer











    $endgroup$













    • $begingroup$
      Thanks for your response, very useful. In Mbed, sleep() is supposed to place to CPU into a low-power mode, but no documentation that I can find explains this logic. I've disabled the SysTick IRQ in the NVIC to no avail, I guess I'll just keep turning off timers/counters until it disappears..
      $endgroup$
      – Adam Mitchell
      yesterday






    • 1




      $begingroup$
      @AdamMitchell - more likely what you need to do is actually read through the Mbed code (it is open source, even if by default they link a binary version of it) and figure out what they are doing, then decide if that can be brought into alignment with your goals, or if their goals are just too different.
      $endgroup$
      – Chris Stratton
      yesterday
















    9












    9








    9





    $begingroup$

    I can't speak about mbed specifically, but the general idea is that sleep() causes the execution of the current process to pause for some number of seconds, or indefinitely if no argument (equivalent to an argument of 0) is given.



    In a multiprocess environment, that means that it simply yields the CPU to other processes. If there are no other processes ready to run, the OS may or may not put the CPU into a low-power state while waiting for interrupts — it depends on how the idle() task is written. This would not generally be the lowest-power state available on the CPU, however, since it wants to wake quickly when interrupts occur.



    In your case, it appears to be waking up once a second to handle the system timer tick.



    If you really want to get into a lower-power state, there are generally platform-specific calls for that, and that's exactly the sort of thing the HAL is for. You shouldn't avoid it, you should learn it.





    After a quick search, I discovered that the documentation here: APIs - power management discusses this specifically.






    share|improve this answer











    $endgroup$



    I can't speak about mbed specifically, but the general idea is that sleep() causes the execution of the current process to pause for some number of seconds, or indefinitely if no argument (equivalent to an argument of 0) is given.



    In a multiprocess environment, that means that it simply yields the CPU to other processes. If there are no other processes ready to run, the OS may or may not put the CPU into a low-power state while waiting for interrupts — it depends on how the idle() task is written. This would not generally be the lowest-power state available on the CPU, however, since it wants to wake quickly when interrupts occur.



    In your case, it appears to be waking up once a second to handle the system timer tick.



    If you really want to get into a lower-power state, there are generally platform-specific calls for that, and that's exactly the sort of thing the HAL is for. You shouldn't avoid it, you should learn it.





    After a quick search, I discovered that the documentation here: APIs - power management discusses this specifically.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited yesterday

























    answered yesterday









    Dave TweedDave Tweed

    121k9151259




    121k9151259












    • $begingroup$
      Thanks for your response, very useful. In Mbed, sleep() is supposed to place to CPU into a low-power mode, but no documentation that I can find explains this logic. I've disabled the SysTick IRQ in the NVIC to no avail, I guess I'll just keep turning off timers/counters until it disappears..
      $endgroup$
      – Adam Mitchell
      yesterday






    • 1




      $begingroup$
      @AdamMitchell - more likely what you need to do is actually read through the Mbed code (it is open source, even if by default they link a binary version of it) and figure out what they are doing, then decide if that can be brought into alignment with your goals, or if their goals are just too different.
      $endgroup$
      – Chris Stratton
      yesterday




















    • $begingroup$
      Thanks for your response, very useful. In Mbed, sleep() is supposed to place to CPU into a low-power mode, but no documentation that I can find explains this logic. I've disabled the SysTick IRQ in the NVIC to no avail, I guess I'll just keep turning off timers/counters until it disappears..
      $endgroup$
      – Adam Mitchell
      yesterday






    • 1




      $begingroup$
      @AdamMitchell - more likely what you need to do is actually read through the Mbed code (it is open source, even if by default they link a binary version of it) and figure out what they are doing, then decide if that can be brought into alignment with your goals, or if their goals are just too different.
      $endgroup$
      – Chris Stratton
      yesterday


















    $begingroup$
    Thanks for your response, very useful. In Mbed, sleep() is supposed to place to CPU into a low-power mode, but no documentation that I can find explains this logic. I've disabled the SysTick IRQ in the NVIC to no avail, I guess I'll just keep turning off timers/counters until it disappears..
    $endgroup$
    – Adam Mitchell
    yesterday




    $begingroup$
    Thanks for your response, very useful. In Mbed, sleep() is supposed to place to CPU into a low-power mode, but no documentation that I can find explains this logic. I've disabled the SysTick IRQ in the NVIC to no avail, I guess I'll just keep turning off timers/counters until it disappears..
    $endgroup$
    – Adam Mitchell
    yesterday




    1




    1




    $begingroup$
    @AdamMitchell - more likely what you need to do is actually read through the Mbed code (it is open source, even if by default they link a binary version of it) and figure out what they are doing, then decide if that can be brought into alignment with your goals, or if their goals are just too different.
    $endgroup$
    – Chris Stratton
    yesterday






    $begingroup$
    @AdamMitchell - more likely what you need to do is actually read through the Mbed code (it is open source, even if by default they link a binary version of it) and figure out what they are doing, then decide if that can be brought into alignment with your goals, or if their goals are just too different.
    $endgroup$
    – Chris Stratton
    yesterday















    1












    $begingroup$

    As explained in the documentation, the following drivers can prevent deep sleep:





    • Ticker

    • Timeout

    • Timer

    • SPI

    • I2C

    • CAN

    • SerialBase




    If you need to identify what is blocking deep sleep, you can build from the command line, and enable the verbose debugging - even though it seems you do not have any in your example.



    You can also review the tickless documentation. I believe this mode is relatively new, so it is possible that your platform has some problems in the HAL.






    share|improve this answer









    $endgroup$


















      1












      $begingroup$

      As explained in the documentation, the following drivers can prevent deep sleep:





      • Ticker

      • Timeout

      • Timer

      • SPI

      • I2C

      • CAN

      • SerialBase




      If you need to identify what is blocking deep sleep, you can build from the command line, and enable the verbose debugging - even though it seems you do not have any in your example.



      You can also review the tickless documentation. I believe this mode is relatively new, so it is possible that your platform has some problems in the HAL.






      share|improve this answer









      $endgroup$
















        1












        1








        1





        $begingroup$

        As explained in the documentation, the following drivers can prevent deep sleep:





        • Ticker

        • Timeout

        • Timer

        • SPI

        • I2C

        • CAN

        • SerialBase




        If you need to identify what is blocking deep sleep, you can build from the command line, and enable the verbose debugging - even though it seems you do not have any in your example.



        You can also review the tickless documentation. I believe this mode is relatively new, so it is possible that your platform has some problems in the HAL.






        share|improve this answer









        $endgroup$



        As explained in the documentation, the following drivers can prevent deep sleep:





        • Ticker

        • Timeout

        • Timer

        • SPI

        • I2C

        • CAN

        • SerialBase




        If you need to identify what is blocking deep sleep, you can build from the command line, and enable the verbose debugging - even though it seems you do not have any in your example.



        You can also review the tickless documentation. I believe this mode is relatively new, so it is possible that your platform has some problems in the HAL.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        Sean HoulihaneSean Houlihane

        3,37711022




        3,37711022






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Electrical Engineering Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f427383%2fwhats-causing-this-power-spike-in-stm32-low-power-mode%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Plaza Victoria

            In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

            How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...