2019-03-06 08:05 AM
2019-03-06 03:15 PM
If you read stm32f7xx_hal_i2c.c you'll observe __HAL_LOCK() isn't thread safe because it doesn't atomically test and set (__HANDLE__)->Lock. I.e. task A tests and finds it's unlocked, and task B preempts it and also finds it's unlocked and locks it, task A resumes and locks it too.
The API isn't thread-safe more than one way.
The general options are:
Option 2 is the better option IMHO because its software is more organised and more easily comprehended (i.e. less bugs).