cancel
Showing results for 
Search instead for 
Did you mean: 

FCLK, stop mode 2 and processing time STM32L476 nucleo

Mich1
Associate III

Hello,

I am testing the processing time of a STM32L476 chip on a Nucleo board.

Here below is the code:

uint8_t algo_principal(s16 xin, s16 yin, s16 zin)
{
    uint8_t retour;
    uint32_t i;
    uint32_t test;
 
    test = (uint32_t )xin + (uint32_t )yin + (uint32_t )zin;
        
    TESTA11_ON;
    for (i=0; i < 25000; i++)
    {
        test *= test;
    }
    TESTA11_OFF;
	
    if (test < 85695)
        retour = 0;
    else
        retour = 1;
	
    return (retour);
}

This code is called every 20ms (external accelerometer interuption) and the microcontroler is in stop mode 2 when not busy => Function EnterStop2Mode() from the LL exemple.

To configure the clock, I use CubeMx to be sure not to badly configure the device.

I measure the time between TESTA11_OFF-TESTA11_ON.

For the 8MHz configuration:

0690X000006DHKoQAO.png

CubeMx sets : LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);

0690X000006DHL3QAO.png

The processing time is 6.28ms

I change the configuration to 16MHz by CubeMx:

0690X000006DHL8QAO.png

CubeMx sets : LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);

The processing time is always 6.28ms.

Even if I change the clock to 80MHz (latency set to 4 this time), the processing time is always 6.28ms.

This time is always the same whatever the clock frequency used. How could it be possible?

Even with to different clock frequencies (8 and 16 MHz) and the same flash latency (0), the processing time is the same.

How could I correct that?

If I do not set the STM32L476 in stop mode 2 when CPU not busy I have:

8 MHz: processing time: 12.56ms

16 MHz: processing time 6.28ms

80 MHz: processing time 1.26ms.

At 8 or 80 MHz, why the processing time of a function which lasts many ms depends of the stop mode 2 when the CPU is not busy?

At 8 MHz, why the processing time is faster when the CPU enters the Stop Mode 2 while inactive?

Best regards

Mich

1 ACCEPTED SOLUTION

Accepted Solutions

When you turn on your device the code generated by Cube configures your clocks as you have set it in CubeMX, for example it alters the RCC registers so that the main clock becomes 80MHz.

After entering and exiting the STOP mode 2, all that configuration is erased, now you need to reconfigure it. [Click Show More]

See, for example, this project under STM32Cube_FW_L4_V1.13.0/Projects/NUCLEO-L412KB/Examples/PWR/PWR_STOP2 in Cube's repository. In main.c, after exiting the stop mode, it calls SYSCLKConfig_STOP(). You'll have to create some function like that and call it too.

View solution in original post

4 REPLIES 4

Are you (re)initializing your desired clocks after exiting STOP mode 2?

Excerpt from the RM:

When exiting Stop 2 mode by issuing an interrupt or a wakeup event, the HSI16 oscillator is selected as system clock if the bit STOPWUCK is set in Clock configuration register (RCC_CFGR). The MSI oscillator is selected as system clock if the bit STOPWUCK is cleared. The wakeup time is shorter when HSI16 is selected as wakeup system clock. The MSI selection allows wakeup at higher frequency, up to 48 MHz.

When exiting the Stop 2 mode, the MCU is in Run mode (Range 1 or Range 2 depending on VOS bit in PWR_CR1). 

Mich1
Associate III

You are right, I forgot it.

I use HSI clock and the STOPWUCK is already set to 1, which clock part should I re-configure?

When you turn on your device the code generated by Cube configures your clocks as you have set it in CubeMX, for example it alters the RCC registers so that the main clock becomes 80MHz.

After entering and exiting the STOP mode 2, all that configuration is erased, now you need to reconfigure it. [Click Show More]

See, for example, this project under STM32Cube_FW_L4_V1.13.0/Projects/NUCLEO-L412KB/Examples/PWR/PWR_STOP2 in Cube's repository. In main.c, after exiting the stop mode, it calls SYSCLKConfig_STOP(). You'll have to create some function like that and call it too.

Mich1
Associate III

Thanks a lot for the answer. It is working now.