cancel
Showing results for 
Search instead for 
Did you mean: 

GetTick() and HAL_Delay(xxx);

XooM
Senior

When I give the delay time greater than 300 for the code below (500ms or 1000ms), GetTick or HAL_Delay(500); functions do not work.

If I make the time 100ms, 200ms or 300ms, it works.

When I want to control the delay at longer times, the program does not work.

Where should I look for the problem?
I am using STM32F030C6T6.

	  if(PA10_On==0)
	  {
		  Tick_PA10_On = HAL_GetTick();
		  PA10_On=1;
	  }

	  if ( PA10_On==1 &&(HAL_GetTick() - Tick_PA10_On) >= 300)
	  	 {
		 	 HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);
		 	 PA10_On=0;
	  	 }

For example, this code below does not work.

HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(PB14_GPIO_Port,PB14_Pin,GPIO_PIN_RESET);
HAL_Delay(500);

But this below code works.

HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
HAL_Delay(200);
HAL_GPIO_WritePin(PB14_GPIO_Port,PB14_Pin,GPIO_PIN_RESET);
HAL_Delay(200);

 Waits of 300ms and below work.

1 ACCEPTED SOLUTION

Accepted Solutions
gbm
Lead III

Show the declarations of all the variables used in your code, like Tick_PA10_On.

Show all the warnings you get while compiling the code. Correct your code to remove all the warnings.

Is the watchdog activated? If yes, then turn it off.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

View solution in original post

14 REPLIES 14

@XooM wrote:

When I give the delay time greater than 300 for the code below (500ms or 1000ms), GetTick or HAL_Delay(500); functions do not work.


What do you mean by, "do not work"?

  • Don't give any delay at all?
  • Give an excessive delay?
  • Crash?
  • Other??
HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
HAL_Delay(200);
HAL_GPIO_WritePin(PB14_GPIO_Port,PB14_Pin,GPIO_PIN_RESET);
HAL_Delay(200);

If I write the code above, the PA10 pin goes HIGH and LOW at 200ms intervals.

but the duration is a larger value like 400ms 500ms. It remains in the HIGH position.

Still not clear what is actually happening.

Are you saying that, with a delay value over ~ 400, your code just "stops" at the HAL_Delay() call?

ie, your code becomes equivalent to:

HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
while(1);                                                 // Code "sticks" here ?

 

When I give a value higher than 300ms for the wait time, the output remains in the HIGH position.
I don't know what to do to understand clearly.
I don't know that much.
but I can't control anything with a 500ms delay.
HAL_delay or Gettick both don't work.


@XooM wrote:

I don't know what to do to understand clearly.


Use the debugger:  can you step over that delay, or does it just "stick" in the delay - as if it where a while(1) ... ?

 


@XooM wrote:

Gettick ... don't work.


Again, what does "don't work" mean here?

What does it do?

Use the debugger to see ...

What is the relation between:

	  if(PA10_On==0)
	  {
		  Tick_PA10_On = HAL_GetTick();
		  PA10_On=1;
	  }

	  if ( PA10_On==1 &&(HAL_GetTick() - Tick_PA10_On) >= 300)
	  	 {
		 	 HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);
		 	 PA10_On=0;
	  	 }

and:

HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(PB14_GPIO_Port,PB14_Pin,GPIO_PIN_RESET);
HAL_Delay(500);

?

Need to be concise ..

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

The relationship between the two is written in the title. Neither of them works for 500 ms delay.

Not sufficient as information .. may be you need to share your project to reproduce it on a NUCLEO board (NUCLEO-F030R8).

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I don't use st board. I'm trying it on my own special pcb board. Can I have a chance to debug? rx tx is not connected. I'm connected with swdio swclk gnd vcc. I don't know how to debug