cancel
Showing results for 
Search instead for 
Did you mean: 

sysem us startup time

askari.nima
Associate II
Posted on January 13, 2015 at 17:25

I use      #define   micros()                   SysTick->VAL + HAL_GetTick()*1000

is it true ?
2 REPLIES 2
Posted on January 13, 2015 at 17:35

I use    #define   micros()                   SysTick->VAL + HAL_GetTick()*1000

 

is it true ?

HAL_GetTick() depends on interrupts functioning, and there's likely a potential race hazard here. Why not use a free running 32-bit counter?
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
askari.nima
Associate II
Posted on January 13, 2015 at 18:20

I want to make a general library for stm32 micro

I found the way

.h

#ifndef    _GENERAL_LIB_H

#define    _GENERAL_LIB_H

#ifdef __cplusplus

 extern ''C'' {

#endif

#include ''stm32f4xx_hal.h''

uint32_t        millis(void);

uint32_t        micros(void);

void            delay_us(uint32_t delay);

#define         delay_ms(delay)         HAL_Delay(delay)

#ifdef __cplusplus

}

#endif

#endif

.c

#include ''general_lib.h''

//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////

uint32_t    millis(void)

{

  return HAL_GetTick();

}

//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////

uint32_t    micros(void)

{

  uint32_t  clock1 = (SystemCoreClock/1000);

  uint32_t  clock2 = (SystemCoreClock/1000000);

  return ((clock1-SysTick->VAL)/clock2 +(HAL_GetTick()*1000));

}

//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////

void    delay_us(uint32_t       delay)

{

 

  uint32_t  d2;

  d2= micros();

  while(micros() - d2 < delay);

    

}