Skip to main content
Associate II
August 12, 2024
Solved

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

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.
TDK
TDKBest answer
August 12, 2024

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

"If you feel a post has answered your question, please click ""Accept as Solution""."

2 replies

TDK
TDKBest answer
August 12, 2024

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

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
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.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..