Skip to main content
Associate II
Dec 9, 2023 1:21 PM UTC
Solved

Microsecond delay for STM32G030F6P6TR

Hello I am trying to work with Microseconds delay in my code

so follow this very help full post on web POST

and I configure TIMER 3 ( I have also check with all available timer )

But unfortunately, it doesn't work for my STM32GO3O MCU

 

/* USER CODE BEGIN 0 */
void delay(uint16_t delay)
{
__HAL_TIM_SET_COUNTER (&htim3,0);
while (__HAL_TIM_GET_COUNTER(&htim3)<delay);
}
/* USER CODE END 0 */

 

 

while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);
  delay(50);
  }
 
I don't have any external crystal oscillator attached ..

I used pin PA6 to debug the pulse output on the oscilloscope. but PA6 not changing the state.

 

please help how can I able to work with microseconds delay in STM32G030

 

This topic has been closed for replies.
STTwo-32
STTwo-32Best answer
ST Technical Moderator
Dec 9, 2023 2:03 PM UTC

Hello @sandeep3 

You need to add HAL_TIM_Base_Start(&htim3) to the main loop after the initialisation of all peripherals.

Best Regards

STTwo-32 

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.

5 replies

Tesla DeLorean
Guru
Dec 9, 2023 1:37 PM UTC

Can you see TIM3 CNT cycling thru 0x0000 .. 0xFFFF in the debugger peripheral view?

For 64 MHz and 1us ticks set Prescaler to 64-1

I'd delta the count rather than zero the count,  as that would be thread/interrupt safe.

 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
sandeep3Author
Associate II
Dec 9, 2023 1:54 PM UTC

no increment observed int the counter.

TDK
Dec 9, 2023 1:44 PM UTC

Did you start the timer?

"If you feel a post has answered your question, please click ""Accept as Solution""."
sandeep3Author
Associate II
Dec 9, 2023 1:53 PM UTC

I think I miss as I am new to stm32 please guide how to start the timer. 

STTwo-32
STTwo-32Best answer
ST Technical Moderator
Dec 9, 2023 2:03 PM UTC

Hello @sandeep3 

You need to add HAL_TIM_Base_Start(&htim3) to the main loop after the initialisation of all peripherals.

Best Regards

STTwo-32 

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.