Skip to main content
Gz_it
Associate III
May 8, 2019
Solved

Problem with compiler of STM32CubeIDE

  • May 8, 2019
  • 8 replies
  • 1732 views

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.
Best answer by Pavel A.

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

-- pa

8 replies

hansd56
Senior
May 8, 2019

Is the system clock set the same?

Gz_it
Gz_itAuthor
Associate III
May 8, 2019

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
May 8, 2019

Did you try different compiler optimization levels?

Gz_it
Gz_itAuthor
Associate III
May 8, 2019

Hi @Knut_Knusper​ 

I choose None (-O0) for optimization.

Thank you,

Best regards.

MikeDB
Senior II
May 8, 2019

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
May 9, 2019

Hi @MikeDB​ 

Thank you for your advice.

Thank you,

Best regards.

Pavel A.
Pavel A.Best answer
May 8, 2019

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
May 9, 2019

Hi @Pavel A.​ 

Thank you for your advice.

Thank you,

Best regards.