2025-06-13 9:02 AM
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);
}
2025-06-13 9:16 AM
> * @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);
}
2025-06-13 9:33 AM
Thank you for your reply, may I have a copy of
@version V5.0.8
Thanks,
WJ
2025-06-13 9:34 AM - edited 2025-06-13 9:37 AM
* @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.
2025-06-13 9:59 AM
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.
2025-06-16 9:17 AM
Hi,
Thank you for the all the suggestions, I was able to resolve the registers issues.
NOW, I am having the following handlers below. Do I make sure they are in "startup_stm32f100c8tx"?
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x120): undefined reference to `MPUFaultDefault_Handler'
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x124): undefined reference to `BusFaultDefault_Handler'
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x128): undefined reference to `UsageFaultDefault_Handler'
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x12c): undefined reference to `SVCallDefault_Handler'
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x130): undefined reference to `DebugDefault_Handler'
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x134): undefined reference to `PendSVDefault_Handler'
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x13c): undefined reference to `WatchdogDefault_Handler'
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x140): undefined reference to `PVDDefault_Handler'
/Core/Src/system_stm32f10x.c:299:(.text.SystemInit+0x144): undefined reference to `TamperDefault_Handler'
2025-06-16 4:36 PM
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 .
2025-06-16 7:40 PM
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