lpcware

LPC4357 Exclusive Access Issue

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Sal Ammoniac on Wed Sep 24 21:36:39 MST 2014
My RTOS has a small assembly procedure to set a memory location using the Cortex-M4's exclusive access feature. It uses this in the mutex lock function. The code is in the code block below. On extremely rare occasions, it fails to set the memory location passed to in in R0, I'm running this code with interrupts turned off as the Cortex-M4 instruction set manual says that an interrupt between the ldrex and strex instructions resets the exclusive access monitor. I'm not using DMA and I'm not using the Cortex-M0 in the 4357.

Is there any other reason why this code should fail when called with the memory location pointed to by R0 is already 0?



  .thumb_func
setmutex:
      ldrex r1,[r0]         // initiate exclusive access
      cbnz  r1,1f           // branch if it's already set
      mov   r2,#1           //
      strex r1,r2,[r0]      // try setting location to 1
1:
      mov   r0,r1           // set return value = 0 if set succeeded, 1 if set failed
      bx    lr              // return

Outcomes