2021-05-10 05:33 AM
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.
2021-05-10 06:00 AM
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);
}
2021-05-10 06:03 AM
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.
2021-05-10 06:19 AM
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?
2021-05-10 06:33 AM
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.