Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


Sleep mode is not reducing power consumption

I can’t see what I’m doing wrong. The processor seems to be going to sleep, but the current remains the same.

Here is the sleep code:


~
~
int sleep(void)
{
    TIM_HandleTypeDef tim;
    uint32_t savedier = 0;

    // Reduce clock to 1 MHz
    SystemClock_Config_NOPLL_48M_100K(RCC_MSIRANGE_4);
    // Go to low-power run mode
    HAL_PWREx_EnableLowPowerRunMode();

    tim.Instance = TIM1;
    if (0 != (TIM1->CR1 & TIM_CR1_CEN))   // Turn timer off  This works!
    {
        ++savedier;
        HAL_TIM_Base_Stop_IT(&tim);
    }
    last_isr = 0xFF;
    wakeup_isr = 0;
    w_cnt = 0;

    // Request to enter SLEEP mode
    do
    {
        HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
        ++w_cnt;
    } while (0 == wakeup_isr);

    SetSysClock();
    HAL_PWREx_DisableLowPowerRunMode();
    if (0 != savedier)
        HAL_TIM_Base_Start_IT(&tim);

    return last_isr;
}
~
~


The system has FreeRTOS, the Hal timer is set to TIM1.
In the stm32l4xx_it.c I set last_isr to the interrupt position and wakeup_isr to 1 if this ISR is suppose to wake us up from sleep.

I do this because I can’t stop FreeRTOS’s system ticks and other service interrupts. I have created code that turned off those interrupts, but FreeRTOS would not work when I turned them back on.

But even with FreeRTOS running occationally, I should see some reduction in current consumption, but I see none. Not even a little.

I’ve been looking for manuals, but I can’t find anything that says what you should do to get it into low power, only what gets turned off and on and theory of operation.

I found out about the less than 2MHz and lower-power mode from comments in the HAL_PWR_EnterSLEEPMode routine.

I’ve done this before, on many different processors. Don’t know why I can’t get it to work here.

-Matt

Soon after posting this I started having build problems (see the ‘No Symbol Table’ post)

To fix that I started a new project and copied all the .c and .h files over.

Now it works (both compiler and power saving).

I think what is happening is that I modify the project with Cube while ac6 is running. As a result the .project files will become corrupt and have these strange results.

Since then I always close ac6 when running (or at least saving) with Cube. And so far I have not seen these weird build errors.

As a side note: If anyone knows how to ‘shutdown’ FreeRTOS while sleeping I would love to hear it.
Currently I have a flag I set in the interrupt routine for any interrupt I want to break out of sleep. In the sleep code I have a do while loop looking for the flag. If not seen I just re-enter sleep mode. As a result it wakes up every 1ms (to service FreeRTOS).

I don’t really want to do Tickless because I want to force the sleep mode.

I have tried turning off the system tick and restarting it, but FreeRTOS would not operate properly when I did that (even though that’s what we do in our current products - but they are an older version of FreeRTOS).

-Matt


 

Newest Forum Posts

  1. reservation car service Seattle by Jamesprede, 2025-05-01 10:06
  2. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  10. Build a project in "release" mode by tang, 2025-02-20 10:36

Last-Modified Blogs