Skip to main content
CCont.1
Associate II
May 10, 2021
Question

Embedded ARM assembly compile error on STm32F4

  • May 10, 2021
  • 2 replies
  • 1825 views

Hello,

I'm working on a library for nucleo F401RE board, with LL library, I'm trying to add some embedded ARM assembly code as written in the guide of arm Developer web site:

__asm return-type function-name(parameter-list)
{ 
 // ARM/Thumb/Thumb-2 assembler code
 instruction{;comment is optional} 
 ... 
 instruction
}

My function is :

__ASM uint8_t ARM_GET_pin(PIN_TypeDef *pin_number) {
 
	// ARM instructions 
	
}

I'm using "__ASM" instead of "__asm" just beacuse it is defined in the files "cmsis_***.h",

I write the function, but when I build the code I get the following error:

../Core/Inc/stm32f4_REGISTER_instruction.h:102:7: error: expected '(' before 'uint8_t'
 102 | __ASM uint8_t ARM_GET_pin(PIN_TypeDef *pin_number) {
 | ^~~~~~~
 | (

I have tryed to change the return-type, as well as the function arguments, or add a "( )" that contains all the code __ASM(function), but it doesn't work.

There is a way to use embedded ARM with STM32CubeIDE?

Thanks in advance.

This topic has been closed for replies.

2 replies

TDK
May 10, 2021

You can't just add __ASM to a C function to make it into assembly code. Here is an example of a function which uses assembly within it:

/**
 \brief Reverse bit order of value
 \details Reverses the bit order of the given value.
 \param [in] value Value to reverse
 \return Reversed 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);
}

"If you feel a post has answered your question, please click ""Accept as Solution""."
CCont.1
CCont.1Author
Associate II
May 10, 2021

I see thank you,

just a question, as far as I know this looks to me as "inline assembler" and it is optimized by the compiler with the C code right?

While in "embedded assmbler" it is assembled separately from the C code, or they are the same in term of code optimization?

TDK
May 10, 2021

This is inline assembly code, yes. If your entire file is in assembly, you can just write it using assembly language. For example, the startup_*.s files generated by CubeMX are assembly. But assembly language has no concept of a C identifier such as "uint8_t" or "PIN_TypeDef".

As far as optimization, for inline assembly, the compiler won't touch the assembly code, but it will try to optimize the C-specific features within the file.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
May 10, 2021

Consider that GNU's syntax is different from ARM/KEIL

Look for other examples within the CMSIS include/source files as those will likely contain both forms.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..