Skip to main content
Visitor II
June 24, 2020
Question

__HAL_LOCK(x) function in STM32 with FreeRTOS

  • June 24, 2020
  • 1 reply
  • 998 views

I'm using STM32F767 and referring STM32746G-Discovery code. I've question regarding __HAL_LOCK() function. if I'm using FreeRTOS, I've created 2 threads, one to to handle QSPI interface for flash and second thread to handle CAN communication and reading ADC. if I write to block of data into flash over QSPI then HAL will be locked. will it block other interrupts too, can I read ADC in while the flash writing is going on? OR

will other functions continue to work?

    This topic has been closed for replies.

    1 reply

    Super User
    June 25, 2020

    The __HAL_LOCK only locks a peripheral at a time. If only one thread does QSPI and only one thread does CAN, you'll be fine.

    Note also that __HAL_LOCK is not thread-safe, so the safe thing to do is to ensure each peripheral is only accessed by a single thread. There are other methods, but that's the most straightforward.

    AShel.1Author
    Visitor II
    June 25, 2020

    thanks TDK

    so, if I lock SPI like _HAL_LOCK(QSPI); still I'll be able to get interrupts on CAN receive pin.