This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

about CMSIS_OS2 and STM32HAL how use?

STM32HAL need HAL_gettick() but CMSIS_OS2 without os_time how do i ... ( ¯¨̯ ¯̥̥ )

Parents
  • Hi,

    here is the solution for CMSIS-RTOS2.

    #include "cmsis_os2.h"
    
    /**
      * Override default HAL_GetTick function
      */
    uint32_t HAL_GetTick (void) {
      static uint32_t ticks;
             uint32_t i;
    
      if (osKernelGetState() == osKernelRunning) {
        return ((uint32_t)osKernelGetTickCount ());
      }
    
      /* If Kernel is not running wait approximately 1 ms then increment
         and return auxiliary tick counter value */
      for (i = (SystemCoreClock >> 4U); i > 0U; i--) {
        __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
        __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
      }
      return ++ticks;
    }
    

    Best regards, Milorad

Reply
  • Hi,

    here is the solution for CMSIS-RTOS2.

    #include "cmsis_os2.h"
    
    /**
      * Override default HAL_GetTick function
      */
    uint32_t HAL_GetTick (void) {
      static uint32_t ticks;
             uint32_t i;
    
      if (osKernelGetState() == osKernelRunning) {
        return ((uint32_t)osKernelGetTickCount ());
      }
    
      /* If Kernel is not running wait approximately 1 ms then increment
         and return auxiliary tick counter value */
      for (i = (SystemCoreClock >> 4U); i > 0U; i--) {
        __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
        __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
      }
      return ++ticks;
    }
    

    Best regards, Milorad

Children