From 039ab0de462f0b45e45d71d1fa1d1e2e5fb0e444 Mon Sep 17 00:00:00 2001 From: gullradriel Date: Tue, 17 Dec 2024 22:00:47 +0100 Subject: [PATCH 1/2] define replacement for enable and disable irq for m0 --- firmware/common/locking.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/common/locking.h b/firmware/common/locking.h index 392b689de..2e0b64296 100644 --- a/firmware/common/locking.h +++ b/firmware/common/locking.h @@ -40,14 +40,14 @@ #else static inline uint32_t load_exclusive(volatile uint32_t* addr) { - __disable_irq(); + __asm volatile("cpsid i"); return *addr; } static inline uint32_t store_exclusive(uint32_t val, volatile uint32_t* addr) { *addr = val; - __enable_irq(); + __asm volatile("cpsie i"); return 0; } #endif From 9bdf731fc0b22ff40c28d22fb18f5c7d3e7dafa8 Mon Sep 17 00:00:00 2001 From: gullradriel Date: Wed, 18 Dec 2024 17:01:18 +0100 Subject: [PATCH 2/2] added memory clobber to prevent memory reordering --- firmware/common/locking.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/common/locking.h b/firmware/common/locking.h index 2e0b64296..5620f2f95 100644 --- a/firmware/common/locking.h +++ b/firmware/common/locking.h @@ -40,14 +40,14 @@ #else static inline uint32_t load_exclusive(volatile uint32_t* addr) { - __asm volatile("cpsid i"); + __asm volatile("cpsid i" ::: "memory"); return *addr; } static inline uint32_t store_exclusive(uint32_t val, volatile uint32_t* addr) { *addr = val; - __asm volatile("cpsie i"); + __asm volatile("cpsie i" ::: "memory"); return 0; } #endif