Skip to main content
Visitor II
June 13, 2025
Question

Error: registers may not be the same -- strexb r3,r2,[r3]'

  • June 13, 2025
  • 3 replies
  • 797 views

Hi,

I am currently using the following microcontroller (STM32F100C8T6B) in my design. I am using the STM32CubeIDE and I trying to build the project, but I am getting the following compiler errors from the "core_cm3.c" file

Error: registers may not be the same -- strexb r3,r2,[r3]'

Error: registers may not be the same -- strexh r3,r2,[r3]'

Any help would be greatly appreciated

Thanks,

WJ

 

This is the version for core_cm2.c

/**************************************************************************//**

* @file core_cm3.c

* @brief CMSIS Cortex-M3 Core Peripheral Access Layer Source File

* @version V1.30

* @date 30. October 2009

*

* @note

* Copyright (C) 2009 ARM Limited. All rights reserved.

 

Below is where the error in the file

/**

* @brief STR Exclusive (8 bit)

*

* @param value value to store

* @param *addr address pointer

* @return successful / failed

*

* Exclusive STR command for 8 bit values

*/

uint32_t __STREXB(uint8_t value, uint8_t *addr)

{

uint32_t result=0;

// register uint32_t result asm ("r2");

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

return(result);

}

/**

* @brief STR Exclusive (16 bit)

*

* @param value value to store

* @param *addr address pointer

* @return successful / failed

*

* Exclusive STR command for 16 bit values

*/

uint32_t __STREXH(uint16_t value, uint16_t *addr)

{

uint32_t result=0;

register uint32_t result asm ("r2");

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

return(result);

}

 

 

    This topic has been closed for replies.

    3 replies

    Super User
    June 13, 2025

    > * @version V1.30

    > * @date 30. October 2009

    That's pretty old.

     

    The latest version, or at least a recent one generated by CubeMX is:

    * @version V5.0.8
     * @date 04. June 2018
     

     with code:

    /**
     \brief STR Exclusive (16 bit)
     \details Executes a exclusive STR instruction for 16 bit values.
     \param [in] value Value to store
     \param [in] ptr Pointer to location
     \return 0 Function succeeded
     \return 1 Function failed
     */
    __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
    {
     uint32_t result;
    
     __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
     return(result);
    }
    WJ1Author
    Visitor II
    June 13, 2025

    Thank you for your reply, may I have a copy of 

    @version V5.0.8

    Thanks,

    WJ

    Super User
    June 13, 2025

    Generate new startup CMSIS files with STM32CubeMX and copy them from there. There's quite a few files which are dependent on each other being synchronized. For example, this function has moved from core_cm3.c to cmsis_gcc.h.

     
    If you're only concerned about this function, copy/replace it with the code above.
    Super User
    June 13, 2025
    * @version V1.30
    * @date 30. October 2009

    Consider using updated GCC compiler and proper CMSIS files for STM32 (2019 or newer and without modifications). 

    This stuff should be in file cmsis_gcc.h.

     

    Super User
    June 16, 2025

    It looks like you're trying to reuse or fix some existing source that uses outdated libraries.

    If you want to create a new project for STM32F1, just use the CubeMX (or CubeIDE), it will bring up-to date libraries and many useful examples.

    If you have to make some existing project/code running quickly - help is available here .

     

    WJ1Author
    Visitor II
    June 17, 2025

    Hi Pavel,

     

    Yes, I was able to fix the errors. I needed to modify the startup file (startup_stm32f100c8tx.s) with new handlers

     

    Thank you all for your help and directions