Skip to main content
Graduate II
August 12, 2024
Solved

memcpy in ISR Context when another memcpy() was already running on main thread or another ISR

  • August 12, 2024
  • 2 replies
  • 1565 views

Is it safe to use memcpy() in an ISR when another memcpy() was already running on main thread or another ISR?

I am getting conflicting info on web about using memcpy() in an ISR to copy data between two uint32_t buffers.

MCU: STM32H723

CubeIDE V: 1.16.0

    This topic has been closed for replies.
    Best answer by TDK

    Yes, it's thread safe. The operations are independent, there is no shared configuration data or internal state to worry about.

    2 replies

    TDKAnswer
    Super User
    August 12, 2024

    Yes, it's thread safe. The operations are independent, there is no shared configuration data or internal state to worry about.

    Graduate II
    August 12, 2024

    The problem would come if the structure ends up with partially old data and partially new data.

    In RTOS systems you might want to lock the operations with a semaphore or mutex, so you can recover content in a more atomic fashion.