cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with compiler of STM32CubeIDE

Gz
Senior

Hi All;

I found the problem with 1us. I use this function below

static void DelayMicroSeconds(uint32_t uSec)
{
	uint32_t uSecVar = uSec;
	uSecVar = uSecVar* ((SystemCoreClock/1000000)/3);
	while(uSecVar--);
}

I will show result below

0690X000008BPlWQAW.jpg

My evolution board for test.

In keil use this function at 30uS

0690X000008BPlgQAG.jpg

In STM32CubeIDE use same function at 30uS

0690X000008BPllQAG.jpg

Anyone Who can help me about delay in microsecond?

Thank you,

Best regards.

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Such tight loops for delays should always be 'calibrated' first before use. Then happily ignore any difference in compilers.

-- pa

View solution in original post

8 REPLIES 8
hansd56
Senior II

Is the system clock set the same?

Gz
Senior

Hi @hansd56​ ;

Yes. I set system clock at 84MHz. Now I can do it I must to set prescale is 7 for 84MHz/1M/7 = 12. I measure via oscilloscope.

Thank you,

Best regards.

Knut_Knusper
Associate III

Did you try different compiler optimization levels?

Gz
Senior

Hi @Knut_Knusper​ 

I choose None (-O0) for optimization.

Thank you,

Best regards.

I've found the STM32CubeIDE compiler ignores many settings even on -o0.

My guess is Keil assigned a register and decremented that whilst STM32CubeIDE (can we have an agreed shorter name for this tool - "S32IDE" maybe ?) possibly does a load/store to memory every decrement which would probably accurately account for the wider time. Have a look at your .list file in the Debug folder to confirm if this is the case.

If so try using :

register volatile uint32_t   uSecVar asm ("r4");

Don't use registers less than r4 or greater than r8 because the S32IDE compiler seems to over-protect them.

Pavel A.
Evangelist III

Such tight loops for delays should always be 'calibrated' first before use. Then happily ignore any difference in compilers.

-- pa

Hi @MikeDB​ 

Thank you for your advice.

Thank you,

Best regards.

Hi @Pavel A.​ 

Thank you for your advice.

Thank you,

Best regards.