[PATCH] updated HAL_GetTick function

Gedare Bloom gedare at rtems.org
Mon Apr 19 16:42:26 UTC 2021


On Mon, Apr 19, 2021 at 10:41 AM Gedare Bloom <gedare at rtems.org> wrote:
>
> On Mon, Apr 19, 2021 at 2:51 AM Robin Müller <robin.mueller.m at gmail.com> wrote:
> >
> > From 88ac5780f5597a8bb3bf68c6b37fe6694956faaf Mon Sep 17 00:00:00 2001
> > From: Robin Mueller <robin.mueller.m at gmail.com>
> > Date: Mon, 19 Apr 2021 10:39:55 +0200
> > Subject: [PATCH] updated HAL_GetTick function
> >
> > Patch text went missing, here is the full version of the patch.
> > Provides implementation for HAL_GetTick but uses RTEMS.
> > Accounts for the tick base not being 1ms now
> > ---
> >  bsps/arm/stm32h7/start/bspstart.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/bsps/arm/stm32h7/start/bspstart.c b/bsps/arm/stm32h7/start/bspstart.c
> > index 2fc8133cca..e6e995a50c 100644
> > --- a/bsps/arm/stm32h7/start/bspstart.c
> > +++ b/bsps/arm/stm32h7/start/bspstart.c
> > @@ -32,9 +32,10 @@
> >
> >  #include <stm32h7xx_hal.h>
> >
> > +/* Get number of milliseconds elapsed since startup */
> >  uint32_t HAL_GetTick(void)
> >  {
> > -  return 0;
> > +  return (rtems_clock_get_ticks_since_boot() * 1000) / rtems_clock_get_ticks_per_second();
>
> This is reasonable, but note that:
> 1. usually it is better to divide before multiplying, to reduce the
> chance of arithmetic overflows.
> 2. the ticks_since_boot is 32-bits, with 1000 Hz ticking it overflows
> in ~2 months
>
> I suggest you consider
>   return rtems_clock_get_uptime_seconds()*1000;
>
> Or you can use rtems_clock_get_uptime_nanoseconds() / (10000000) if ms
> precision is needed.
>

I just saw that the HAL function also returns a u32, so it will
overflow anyway and it doesn't really matter what you do.

> >  }
> >
> >  uint32_t stm32h7_systick_frequency(void)
> > --
> > 2.29.2.windows.2
> >
> > On Mon, 19 Apr 2021 at 10:48, Robin Mueller <robin.mueller.m at gmail.com> wrote:
> >>
> >> diff --git a/bsps/arm/stm32h7/start/bspstart.c b/bsps/arm/stm32h7/start/bspstart.c
> >> index 2fc8133cca..e6e995a50c 100644
> >> --- a/bsps/arm/stm32h7/start/bspstart.c
> >> +++ b/bsps/arm/stm32h7/start/bspstart.c
> >> @@ -32,9 +32,10 @@
> >>
> >>  #include <stm32h7xx_hal.h>
> >>
> >> +/* Get number of milliseconds elapsed since startup */
> >>  uint32_t HAL_GetTick(void)
> >>  {
> >> -  return 0;
> >> +  return (rtems_clock_get_ticks_since_boot() * 1000) / rtems_clock_get_ticks_per_second();
> >>  }
> >>
> >>  uint32_t stm32h7_systick_frequency(void)
> >> --
> >> 2.29.2.windows.2
> >>
> > _______________________________________________
> > devel mailing list
> > devel at rtems.org
> > http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list