Locks and priorities
One core runs three FreeRTOS tasks. motor has priority 3, radio 2, log 1; a bigger number is more urgent. The scheduler always runs the most urgent task that is ready. Each tick is 1 ms.
The inversion
At 0 ms only log is ready, so it runs. It calls xSemaphoreTake and gets the lock, then starts a 3 ms read on the I2C bus. Our lock is a binary semaphore: a lock with no extra rules.
At 1 ms motor wakes. 3 beats 1, so the scheduler stops log at once and runs motor. That is preemption. log keeps the lock while it waits: it is 1 ms into its 3 ms read.
At 2 ms motor needs the bus and calls xSemaphoreTake, but log holds the lock. motor is blocked, so log runs again. A short wait like this is normal: at most log's 3 ms read.
At 3 ms radio wakes. 2 beats log's 1, so radio runs. Now motor waits for log, and log waits for radio. A task that needs no lock is delaying the most urgent one. This is priority inversion.
radio runs for 6 ms, and motor's deadline at 7 ms goes by. Nothing limits this wait: a longer radio job, or more medium tasks, would stretch it further. That is called unbounded priority inversion.
radio finishes, log ends its read and gives the lock at 10 ms. motor finally takes it and finishes at 12 ms: 5 ms late. On Mars Pathfinder in 1997, a watchdog saw such a late task and reset the whole computer.
Inheritance
Same tasks, but the lock is now a FreeRTOS mutex. At 2 ms motor blocks on it as before. This time FreeRTOS lifts log to motor's priority, 3, while log holds the lock. That is priority inheritance.
At 3 ms radio wakes again, but 2 no longer beats log, which now runs at 3. log keeps the CPU and finishes its read at 4 ms. motor's wait is now bounded: only log's short read.
log gives the mutex at 4 ms and drops back to priority 1. motor takes it and finishes at 6 ms, 1 ms before its deadline. Then radio runs. Same 12 ms of work, in a better order.
Use a mutex, not a binary semaphore, to guard a shared part. Keep the code between take and give short. Give a timeout to xSemaphoreTake. Never take a mutex inside an interrupt. Inheritance limits the wait; it does not remove it.
What happens
;; step 1/11 · tasks priority bigger number = more urgent (0 is the idle task) motor 3 drives the motor; must finish 6 ms after it wakes radio 2 sends a radio packet; never touches the bus log 1 reads a sensor on the I2C bus for the log rule run the highest-priority task that is ready tick 1 ms (configTICK_RATE_HZ 1000)
The task lengths are our example, chosen to make the effect easy to see, on an STM32F407 (single-core Arm Cortex-M4) with a 1 ms tick. readSensor() and sendPacket() stand for real I2C and radio drivers. With one core only one task can run at a time; dual-core chips such as the ESP32 add more cases. A binary semaphore made with xSemaphoreCreateBinary() starts empty: it must be given once before anyone can take it. Used as a lock it works, but it has no priority inheritance. That is why FreeRTOS tells you to guard shared parts with a mutex.