CMSIS-Core (Cortex-M)  Version 5.1.1
CMSIS-Core support for Cortex-M processor-based devices
 All Data Structures Files Functions Variables Enumerations Enumerator Groups Pages
Compiler Control

Compiler agnostic #define symbols for generic C/C++ source code. More...

Macros

#define __ARM_ARCH_6M__
 Set to 1 when generating code for Armv6-M (Cortex-M0, Cortex-M1) More...
 
#define __ARM_ARCH_7M__
 Set to 1 when generating code for Armv7-M (Cortex-M3) More...
 
#define __ARM_ARCH_7EM__
 Set to 1 when generating code for Armv7-M (Cortex-M4) with FPU. More...
 
#define __ARM_ARCH_8M_BASE__
 Set to 1 when generating code for Armv8-M Baseline. More...
 
#define __ARM_ARCH_8M_MAIN__
 Set to 1 when generating code for Armv8-M Mainline. More...
 
#define __ASM
 Pass information from the compiler to the assembler. More...
 
#define __INLINE
 Recommend that function should be inlined by the compiler. More...
 
#define __STATIC_INLINE
 Define a static function should be inlined by the compiler. More...
 
#define __NO_RETURN
 Inform the compiler that a function does not return. More...
 
#define __USED
 Inform that a variable shall be retained in executable image. More...
 
#define __WEAK
 Export a function or variable weakly to allow overwrites. More...
 
#define __PACKED
 Request smallest possible alignment. More...
 
#define __PACKED_STRUCT
 Request smallest possible alignment for a structure. More...
 
#define __UNALIGNED_UINT32
 Pointer for unaligned access of a uint32_t variable. More...
 
#define __UNALIGNED_UINT16_READ
 Pointer for unaligned read of a uint16_t variable. More...
 
#define __UNALIGNED_UINT16_WRITE
 Pointer for unaligned write of a uint16_t variable. More...
 
#define __UNALIGNED_UINT32_READ
 Pointer for unaligned read of a uint32_t variable. More...
 
#define __UNALIGNED_UINT32_WRITE
 Pointer for unaligned write of a uint32_t variable. More...
 
#define __ALIGNED
 Minimum alignment for a variable. More...
 

Description

The CMSIS-Core provides the header file cmsis_compiler.h with consistent #define symbols for generate C or C++ source files that should be compiler agnostic. Each CMSIS compliant compiler should support the functionality described in this section.

The header file cmsis_compiler.h is also included by each Device Header File <device.h> so that these definitions are available.

Macro Definition Documentation

#define __ALIGNED

Specifies a minimum alignment for a variable or structure field, measured in bytes.

Code Example:

uint32_t stack_space[0x100] __ALIGNED(8); // 8-byte alignment required
#define __ARM_ARCH_6M__

The #define ARM_ARCH_6M is set to 1 when generating code for the Armv6-M architecture. This architecture is for example used by the Cortex-M0, Cortex-M0+, and Cortex-M1 processor.

#define __ARM_ARCH_7EM__

The #define ARM_ARCH_7EM is set to 1 when generating code for the Armv7-M architecture with floating point extension. This architecture is for example used by the Cortex-M4 processor with FPU

#define __ARM_ARCH_7M__

The #define ARM_ARCH_7M is set to 1 when generating code for the Armv7-M architecture. This architecture is for example used by the Cortex-M3 processor.

#define __ARM_ARCH_8M_BASE__

The #define ARM_ARCH_8M_BASE is set to 1 when generating code for the Armv8-M architecture baseline variant.

#define __ARM_ARCH_8M_MAIN__

The #define ARM_ARCH_8M_MAIN is set to 1 when generating code for the Armv8-M architecture mainline variant.

#define __ASM

The __ASM keyword can declare or define an embedded assembly function or incorporate inline assembly into a function (shown in the code example below).

Code Example:

// Reverse bit order of value
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
uint32_t result;
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
#define __INLINE

Inline functions offer a trade-off between code size and performance. By default, the compiler decides during optimization whether to inline code or not. The __INLINE attribute gives the compiler an hint to inline this function. Still, the compiler may decide not to inline the function. As the function is global an callable function is also generated.

Code Example:

const uint32_t led_mask[] = {1U << 4, 1U << 5, 1U << 6, 1U << 7};
/*------------------------------------------------------------------------------
Switch on LEDs
*------------------------------------------------------------------------------*/
__INLINE static void LED_On (uint32_t led) {
PTD->PCOR = led_mask[led];
}
#define __NO_RETURN

Informs the compiler that the function does not return. The compiler can then perform optimizations by removing code that is never reached.

Code Example:

// OS idle demon (running when no other thread is ready to run).
__NO_RETURN void os_idle_demon (void);
#define __PACKED

Specifies that a type must have the smallest possible alignment.

Code Example:

struct foo {
uint8_t u8;
uint32_t u32[2] __PACKED;
};
#define __PACKED_STRUCT

Specifies that a structure must have the smallest possible alignment.

Code Example:

uint8_t u8;
uint32_t u32;
uint16_t u16;
};
#define __STATIC_INLINE

Defines a static function that may be inlined by the compiler. If the compiler generates inline code for all calls to this functions, no additional function implementation is generated which may further optimize space.

Code Example:

\\ Get Interrupt Vector
{
uint32_t *vectors = (uint32_t *)SCB->VTOR;
return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
}
#define __UNALIGNED_UINT16_READ

Defines a pointer to a uint16_t from an address that does not need to be aligned. This can then be used in read operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint16_t val16;
void test (uint8_t *ptr) {
}
#define __UNALIGNED_UINT16_WRITE

Defines a pointer to a uint16_t from an address that does not need to be aligned. This can then be used in write operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint16_t val16 = 0U;
void test (uint8_t *ptr) {
}
#define __UNALIGNED_UINT32
Deprecated:
Do not use this macro. It has been superseded by __UNALIGNED_UINT32_READ, __UNALIGNED_UINT32_WRITE and will be removed in the future.

Defines a pointer to a uint32_t from an address that does not need to be aligned. This can then be used in read/write operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint32_t val32;
void test (uint8_t *ptr) {
__UNALIGNED_UINT32(ptr) = val32;
}
#define __UNALIGNED_UINT32_READ

Defines a pointer to a uint32_t from an address that does not need to be aligned. This can then be used in read operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint32_t val32;
void test (uint8_t *ptr) {
}
#define __UNALIGNED_UINT32_WRITE

Defines a pointer to a uint32_t from an address that does not need to be aligned. This can then be used in write operations. The compiler will generate the appropriate access (aligned or non-aligned) depending on the underlying Arm processor core and compiler settings.

Code Example:

uint32_t val32 = 0U;
void test (uint8_t *ptr) {
}
#define __USED

Definitions tagged with __USED in the source code should be not removed by the linker when detected as unused.

Code Example:

/* Export following variables for debugging */
__USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS;
__USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX;
__USED uint32_t const os_clockrate = OS_TICK;
__USED uint32_t const os_timernum = 0;
#define __WEAK

Functions defined with __WEAK export their symbols weakly. A weakly defined function behaves like a normally defined function unless a non-weakly defined function of the same name is linked into the same image. If both a non-weakly defined function and a weakly defined function exist in the same image then all calls to the function resolve to call the non-weak function.

Functions declared with __WEAK and then defined without __WEAK behave as non-weak functions.

Code Example:

__WEAK void SystemInit(void)
{
SystemCoreSetup();
SystemCoreClockSetup();
}