Skip to main content
IYetk
Associate III
October 5, 2019
Solved

a loop which iterates infinitely for x seconds - stm32mp157c-dk2

  • October 5, 2019
  • 4 replies
  • 1612 views

Hi,

In my M4 program within while loop, I have made a for loop which iterates infinitely for 0.75 seconds like this but didnt work at all. I used time.h for that.

Are we allowed to make this kind of loop within the while loop in M4 program ?

Do you have any idea why it didnt work ?

 clock_t begin;
 double time_spent;
 unsigned int i;
 
 begin = clock();
 for (i=0;1;i++)
 {
 /*do my staff */
 if (VirtUart0RxMsg) {
 Check_Delay(VirtUart0ChannelBuffRx, VirtUart0ChannelRxSize);
 VIRT_UART_Transmit(&huart0, VirtUart0ChannelBuffRx, VirtUart0ChannelRxSize);
 VirtUart0RxMsg = RESET;
 }
 
 time_spent = (double)(clock() - begin) / CLOCKS_PER_SEC;
 if (time_spent>=0.75)
 break;
 }
 }

This topic has been closed for replies.
Best answer by IYetk

I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

This issue can be closed.

4 replies

PatrickF
Technical Moderator
October 7, 2019

Hello,

Maybe a basic SW issue, but I think you need to provide more details.

Do you try to debug it ? Do the loop hang on some function ? Is the loop exit too early ? Did you check the clock() value returned ?

In order to give better visibility on the answered topics, please click on 'Best Answer' on the reply which solved your issue or answered your question.Tip of the day: Try Sidekick STM32 AI agent
IYetk
IYetkAuthor
Associate III
October 12, 2019

I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

This issue can be closed.

IYetk
IYetkAuthor
Associate III
October 7, 2019

I will debug it and write you the details...

yakabmarci
Associate III
October 9, 2019

how can something iterate infinitely for a finite amount of seconds?

IYetk
IYetkAuthor
Associate III
October 10, 2019

You are right. There is a misunderstanding here.

I just mean "a loop which iterates an amount of seconds"

IYetk
IYetkAuthorBest answer
Associate III
October 12, 2019

I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

This issue can be closed.