I am using STM32F7 micro with HAL libraries. I had ported freertos successfully in my code. code is running fine.
But i want to know that HAL libraries use __HAL_LOCK(HANDLE) and __HAL_UNLOCK(HANDLE) macros in all their library .c files. Though i m using rtos do i have to remove these both macros manually or is there any work around available.
Thanks and regards, Pavel
I don’t know what __HAL_LOCK() and __HAL_UNLOCK() do, but ST’s own tools generate FreeRTOS projects - what do they do for this? Can you just use a project as provided by ST?
I think the HAL comes with a version of these macros designed for FreeRTOS (using likely either a semaphore or a mutex). If not, it wouldn’t be that hard to create such a macro. Just removing them would break a lot of the code, and it has enough problems on its own, you don’t need to add to them.
this is the code snippet
#if (USE_RTOS == 1U)
/* Reserved for future use */
#error “USE_RTOS should be 0 in the current HAL release”
if((HANDLE)->Lock == HAL_LOCKED)
(HANDLE)->Lock = HAL_LOCKED;
(HANDLE)->Lock = HAL_UNLOCKED;
#endif /* USE_RTOS */
if I define USE_RTOS = 1 then code does not build. So do i have to replace __HAL_LOCK() and __HAL_UNLOCK() with semaphore or mutex in all hal libraries to use freertos properly.
Looks like in typical ST fashion, they haven’t implemented that functionality for FreeRTOS. You will need to modify THAT file to implement the __HAL_LOCK and __HAL_UNLOCK functionality. There should likely be some other function to setup the lock handle too.
No, I don’t think so. That would be pretty difficult since the “handle” they provide is the address of a device control block in the HAL for a specific device. I reviewed a couple of uses of these “locks”, and they appear merely to be for rejecting recursive calls into the HAL for that device from user-provided callback functions called by the HAL. It’s hard to see that they do anything else of any use. They are not even interrupt safe (even when not using an OS).
The HAL is not OS friendly, but I think you can use these macros as-is. Just be sure to use the HAL assuming nothing about it is threadsafe. (Redefining these macros yourself wouldn’t make the HAL threadsafe.) I haven’t looked but maybe there is an app note or user guide from ST about using the HAL with FreeRTOS. That would shed more light here.