STM32HAL need HAL_gettick() but CMSIS_OS2 without os_time how do i ... ( ¯¨̯ ¯̥̥ )
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
Hi Milorad,
I use your nops delay exactly and I get a delay of 1 sec !!!! I use STM32F4 and Keil compiler and my SystemCoreClock is 72MHz. What is your SystemCoreClock?
Hi Julio,
I guess you are right, the SystemCoreClock should be also divided by 1000, so to not use integer math we should divide it by 1024 (it is close enough for this usage case) which is same as shifting to right for 10 bits, so the "for" loop should be corrected as follows:
for (i = (SystemCoreClock >> 14U); i > 0U; i--) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); }
View all questions in Keil forum