Problems with optimization -Os

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with optimization -Os

1,922 Views
David_Estevez
Contributor I

Hello,

I'm using an S32K116 microcontroller where I run a program that executes a cycle of functions, then it goes into VLPS (Very Low Power Stop) mode, and a 100ms timer wakes it up, and so on consecutively. The problem is that the program works fine if I don't use any compiler optimization. But as soon as I apply -Os optimization, it seems like the cycle speeds up and doesn't respect the 100ms VLPS mode. How can I fix it so that it works with optimization?

Regards,

David

0 Kudos
Reply
10 Replies

1,912 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

Do you see some warning messages?

0 Kudos
Reply

1,908 Views
David_Estevez
Contributor I

No

0 Kudos
Reply

1,905 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

I would test other optimization level, maybe that could give you some clues:

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

 

0 Kudos
Reply

1,895 Views
David_Estevez
Contributor I

Hi again,

As I could see, the problem comes from the FlexCAN. Some CAN interrupt is waking up the microcontroller (uC), but we are neither receiving nor sending any messages. With any optimization, this interrupt that is waking up the uC doesn't appear, but with -Os, it is appearing. I don't know why.

0 Kudos
Reply

1,880 Views
David_Estevez
Contributor I

Hi again,

I already saw what's happening. The problem is that I send a message via CAN just before going to sleep, and without optimizing the program, it's slower and there's no issue. But when optimizing, it's the transmission complete interrupt that wakes up the VLPS mode. Is there any way to select which types of interrupts are allowed to wake up the VLPS mode? For example, can only the timer be allowed to wake it up?

0 Kudos
Reply

1,868 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

I just discussed with colleague having knowledge of low power modes on this device giving me some important notes to this topic:

- FlexCAN can perform wake-up only in Pretended mode that is not available in VLPS

-Alternatively you can use GPIO interrupt on RX pins

- Before entering VLPS, FlexCAN is supposed to be turned off completely.

So the conclusion is that possibly your application is not in VLPS mode because in such case FlexCAN would not work. To prove it, you could measure current consumption or use CLKOUT and measure BUS_CLK frequency.

0 Kudos
Reply

1,853 Views
David_Estevez
Contributor I
 

I think I am entering VLPS mode because:

     -The consumption drops from 0.74mA to 0.60mA.

     -Without enabling the SIRC clock to function in sleep mode, it does not wake up again:Captura de pantalla 2025-02-26 181230.png

However, it is the CAN interruption that wakes it up. Could it be related to the fact that I am using an external CAN transceiver? My function to enter VLPS mode is as follows:

Captura de pantalla 2025-02-26 181033.png

 

0 Kudos
Reply

1,825 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

that's not a big current drop indeed. If you see DS values, VLPS current are specified in uAmps

image.png

How I have already answered, FlexCAN needs to be turned off completely.

0 Kudos
Reply

1,818 Views
David_Estevez
Contributor I

Hi again,

I have a few questions more. 

That is, does the FlexCAN have to be turned off by code? Doesn't it automatically turn off when entering VLPS? Do any other resources need to be disabled before entering VLPS, such as a clock or another peripheral, or does the VLPS mode handle it automatically?

And regarding the function I sent you, is it correct? I wrote it exactly as stated in the RM manual, but I’m not sure if I’m missing anything else.

 

0 Kudos
Reply

1,718 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport
 

It is described in RM, section 55.1.9.

image.png

0 Kudos
Reply