Fix “registers may not be the same” ARM GCC error

I was developing a project using STM32F2 microcontroller when I decided to update the ARM toolchain. After have updated Code Sourcery CodeBench Lite Edition to version 2013.11-24 I encountered the following error:


core_cm3.s:826: Error: registers may not be the same — `strexb r3,r2,[r3]’


After some investigation I found this thread and according to it we need to edit some functions.

OpenĀ core_cm3.c (typically in Libraries/CMSIS/CM3/CoreSupport/core_cm3.c if using the STM32F2xx Standard Peripherals Library) and look for the functions __STREXB and __STREXH.

You have to change “=r” to “=&r” in order to have:


__ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );


__ASM volatile ("strexb %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );

I solved in this way and I hope ST will upgrade their libraries soon.


  • By Taylor Alexander, January 9, 2014 @ 6:29 am

    +1, this worked for my Atmel Sam3s code as well, in the latest Atmel SAM3S Software Package for GCC.

  • By wktey, July 15, 2014 @ 8:30 am

    This helps to solve my problem.
    Great job and thanks!

  • By Nosaki, November 11, 2014 @ 11:52 am

    This solution worked for me too.

  • By Anonymous, February 11, 2015 @ 8:59 pm


  • By Stephen, August 17, 2015 @ 10:09 am

    Thanks so much for this, it worked for me as well!

  • By Alex, August 18, 2015 @ 12:40 pm

    Thanks a lot

Other Links to this Post

RSS feed for comments on this post.

Leave a comment

WordPress Themes