Skip to main content
Gz_it
Associate III
Solved

Problem with compiler of STM32CubeIDE

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.

This topic has been closed for replies.
Pavel A.
Pavel A.Best answer

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

-- pa

8 replies

hansd56
Senior

Is the system clock set the same?

Gz_it
Gz_itAuthor
Associate III

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 II

Did you try different compiler optimization levels?

Gz_it
Gz_itAuthor
Associate III

Hi @Knut_Knusper​ 

I choose None (-O0) for optimization.

Thank you,

Best regards.

MikeDB
Senior II

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.

Gz_it
Gz_itAuthor
Associate III

Hi @MikeDB​ 

Thank you for your advice.

Thank you,

Best regards.

Pavel A.
Pavel A.Best answer

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

-- pa

Gz_it
Gz_itAuthor
Associate III

Hi @Pavel A.​ 

Thank you for your advice.

Thank you,

Best regards.