cancel
Showing results for 
Search instead for 
Did you mean: 

HSEM read lock vs write lock?

AMurr.2282
Associate III

Hi!

So I was reading the wiki here https://wiki.st.com/stm32mpu/wiki/How_to_configure_system_resources

and they tell you to use PERIPH_LOCK, which is a function that can be found here:

https://github.com/STMicroelectronics/STM32CubeMP1/blob/1.3.0/Projects/STM32MP157C-DK2/Templates/Src/lock_resource.c

However, HAL_HSEM_FastTake does a read lock and not a write lock.

When should I be using HAL_HSEM_FastTake() vs HAL_HSEM_Take()? Why does PERIPH_LOCK call HAL_HSEM_FastTake() to get a read lock when it is writing to GPIO/EXTI registers?

3 REPLIES 3
Olivier GALLIEN
ST Employee

Hi @AMurr.2282​ ,

Reading the RM again, I understand you probably make a confusion between the 2 lock methods "label" (read) or (write) and the operation to protect.

Once semaphore is taken it lock peripheral registers whatever access type.

But there's 2 ways to lock :

– 2-step lock: by writing COREID and PROCID to the semaphore, followed by a read check -> labeled (write)

– 1-step lock: by reading the COREID from the semaphore -> labeled (read) method

I supposed advantage of "read" method is to be atomic.

Is that sound clearer ?

Olivier

Olivier GALLIEN
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

> Is that sound clearer ?

Not really. In what situation would I need to use a write lock and why?

Olivier GALLIEN
ST Employee

Hi @AMurr.2282​ ,

Difference between 2-step (write) and 1-setp (read) is mentioned in RM :

"There is no PROCID available with the 1- step (read) lock" -> you can't identify the process which take the semaphore, only the COREID.

So, to arbitrate multi-process concurrency on same core, it can be more convenient to use the 2-step method.

Olivier

Olivier GALLIEN
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.