你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32 CUBEIDE 编译报error: expected identifier or '(' before '__asm'

[复制链接]
asn111 提问时间:2025-2-14 14:48 / 未解决

程序内容如下

/ CMSIS compiler specific defines /

ifndef __ASM

define ASM asm

endif

/ CMSIS compiler specific defines /

编译报错日志需要如何解决

../Drivers/CMSIS/Include/cmsis_armcc.h:58:50: error: expected identifier or '(' before '__asm'

58 | #define ASM asm

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:211:57: note: in expansion of macro '__ASM'

211 | attribute((section(".rev16_text"))) STATIC_INLINE __ASM uint32_t REV16(uint32_t value)

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:58:50: error: expected identifier or '(' before '__asm'

58 | #define ASM asm

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:226:57: note: in expansion of macro '__ASM'

226 | attribute((section(".revsh_text"))) STATIC_INLINE __ASM int16_t REVSH(int16_t value)

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:58:50: error: expected identifier or '(' before '__asm'

58 | #define ASM asm

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:413:55: note: in expansion of macro '__ASM'

413 | attribute((section(".rrx_text"))) STATIC_INLINE __ASM uint32_t RRX(uint32_t value)

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__set_CONTROL':

../Drivers/CMSIS/Include/cmsis_armcc.h:178:43: warning: implicit declaration of function '__isb' [-Wimplicit-function-declaration]

178 | #define ISB() isb(0xF)

| ^~~~~

收藏 评论8 发布时间:2025-2-14 14:48

举报

8个回答
老牛洋车 回答时间:6 天前

去年宏定义字符中间的空格,改成如下试试:

ifndef __ASM

define __ASM

......

endif

asn111 回答时间:6 天前

老牛洋车 发表于 2025-2-14 14:54
去年宏定义字符中间的空格,改成如下试试:</p>
<h1>ifndef  __ASM</h1>
<p>

[md]谢谢 这样试了不行

../Drivers/CMSIS/Include/cmsis_armcc.h:57:2: error: invalid preprocessing directive #ifndef__ASM

57 | #ifndef__ASM

| ^~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:58:4: error: invalid preprocessing directive #define__ASM

58 | #defineASM asm

| ^~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:211:57: error: unknown type name '__ASM'

211 | attribute((section(".rev16_text"))) STATIC_INLINE __ASM uint32_t REV16(uint32_t value)

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:211:72: error: expected '=', ',', ';', 'asm' or 'attribute' before '__REV16'

211 | attribute((section(".rev16_text"))) STATIC_INLINE __ASM uint32_t REV16(uint32_t value)

| ^~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:226:57: error: unknown type name '__ASM'

226 | attribute((section(".revsh_text"))) STATIC_INLINE __ASM int16_t REVSH(int16_t value)

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:226:71: error: expected '=', ',', ';', 'asm' or 'attribute' before '__REVSH'

226 | attribute((section(".revsh_text"))) STATIC_INLINE __ASM int16_t REVSH(int16_t value)

| ^~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:413:55: error: unknown type name '__ASM'

413 | attribute((section(".rrx_text"))) STATIC_INLINE __ASM uint32_t RRX(uint32_t value)

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:413:70: error: expected '=', ',', ';', 'asm' or 'attribute' before '__RRX'

413 | attribute((section(".rrx_text"))) STATIC_INLINE __ASM uint32_t RRX(uint32_t value)

| ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__get_CONTROL':

../Drivers/CMSIS/Include/cmsis_armcc.h:560:42: error: expected '=', ',', ';', 'asm' or 'attribute' before '__ASM'

560 | register uint32_t regControl ASM("control");

| ^~~~~

老牛洋车 回答时间:6 天前

宏定义命令与字符之间至少需要一个空格,字符内部不能有空格。

ifndef的判断字符要与后一句的字符相同,否则容易出现重定义的错误。

您的判断字符是"__ASM",而之后定义的却是 "ASM asm",这样前面的判断语句就失去了作用。

define ASM asm的意思是定义一个宏"ASM",其值为"asm"。您确定是要这样做吗?

建议复制下列代码:

老牛洋车 回答时间:6 天前
#ifndef __ASM

#define __ASM

...

#endif
asn111 回答时间:6 天前

老牛洋车 发表于 2025-2-14 16:22</p>
<pre><code class="language-abc">
#ifndef __ASM


[md]你好 代码如下 还是一样报错 谢谢 #ifndef __ASM #define __ASM __asm #endif
asn111 回答时间:6 天前

老牛洋车 发表于 2025-2-14 16:22</p>
<pre><code class="language-abc">
#ifndef __ASM


[md]改成这样会多出来其他的很多报错 谢谢 ../Drivers/CMSIS/Include/cmsis_armcc.h:212:3: error: unknown type name 'rev16' 212 | rev16 r0, r0 | ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:213:3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'bx' 213 | bx lr | ^~ ../Drivers/CMSIS/Include/cmsis_armcc.h:225:71: error: invalid storage class for function '__REVSH' 225 | __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value) | ^~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__REVSH': ../Drivers/CMSIS/Include/cmsis_armcc.h:227:3: error: unknown type name 'revsh' 227 | revsh r0, r0 | ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:228:3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'bx' 228 | bx lr | ^~ ../Drivers/CMSIS/Include/cmsis_armcc.h:412:70: error: invalid storage class for function '__RRX' 412 | __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) | ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__RRX': ../Drivers/CMSIS/Include/cmsis_armcc.h:414:3: error: unknown type name 'rrx' 414 | rrx r0, r0 | ^~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:415:3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'bx' 415 | bx lr | ^~ ../Drivers/CMSIS/Include/cmsis_armcc.h:557:26: error: invalid storage class for function '__get_CONTROL' 557 | __STATIC_INLINE uint32_t __get_CONTROL(void) | ^~~~~~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__get_CONTROL': ../Drivers/CMSIS/Include/cmsis_armcc.h:559:48: error: expected declaration specifiers or '...' before string constant 559 | register uint32_t __regControl __ASM("control"); | ^~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:560:10: error: '__regControl' undeclared (first use in this function) 560 | return(__regControl); | ^~~~~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:560:10: note: each undeclared identifier is reported only once for each function it appears in ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__RRX': ../Drivers/CMSIS/Include/cmsis_armcc.h:569:22: error: invalid storage class for function '__set_CONTROL' 569 | __STATIC_INLINE void __set_CONTROL(uint32_t control) | ^~~~~~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__set_CONTROL': ../Drivers/CMSIS/Include/cmsis_armcc.h:571:48: error: expected declaration specifiers or '...' before string constant 571 | register uint32_t __regControl __ASM("control"); | ^~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:572:3: error: '__regControl' undeclared (first use in this function) 572 | __regControl = control; | ^~~~~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:177:43: warning: implicit declaration of function '__isb' [-Wimplicit-function-declaration] 177 | #define __ISB() __isb(0xF) | ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:573:3: note: in expansion of macro '__ISB' 573 | __ISB(); | ^~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__RRX': ../Drivers/CMSIS/Include/cmsis_armcc.h:582:26: error: invalid storage class for function '__get_IPSR' 582 | __STATIC_INLINE uint32_t __get_IPSR(void) | ^~~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__get_IPSR': ../Drivers/CMSIS/Include/cmsis_armcc.h:584:46: error: expected declaration specifiers or '...' before string constant 584 | register uint32_t __regIPSR __ASM("ipsr"); | ^~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:585:10: error: '__regIPSR' undeclared (first use in this function); did you mean '__get_IPSR'? 585 | return(__regIPSR); | ^~~~~~~~~ | __get_IPSR ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__RRX': ../Drivers/CMSIS/Include/cmsis_armcc.h:594:26: error: invalid storage class for function '__get_APSR' 594 | __STATIC_INLINE uint32_t __get_APSR(void) | ^~~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__get_APSR': ../Drivers/CMSIS/Include/cmsis_armcc.h:596:46: error: expected declaration specifiers or '...' before string constant 596 | register uint32_t __regAPSR __ASM("apsr"); | ^~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:597:10: error: '__regAPSR' undeclared (first use in this function); did you mean '__get_APSR'? 597 | return(__regAPSR); | ^~~~~~~~~ | __get_APSR ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__RRX': ../Drivers/CMSIS/Include/cmsis_armcc.h:606:26: error: invalid storage class for function '__get_xPSR' 606 | __STATIC_INLINE uint32_t __get_xPSR(void) | ^~~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__get_xPSR': ../Drivers/CMSIS/Include/cmsis_armcc.h:608:46: error: expected declaration specifiers or '...' before string constant 608 | register uint32_t __regXPSR __ASM("xpsr"); | ^~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h:609:10: error: '__regXPSR' undeclared (first use in this function) 609 | return(__regXPSR); | ^~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__RRX': ../Drivers/CMSIS/Include/cmsis_armcc.h:618:26: error: invalid storage class for function '__get_PSP' 618 | __STATIC_INLINE uint32_t __get_PSP(void) | ^~~~~~~~~ ../Drivers/CMSIS/Include/cmsis_armcc.h: In function '__get_PSP': ../Drivers/CMSIS/Include/cmsis_armcc.h:620:53: error: expected declaration specifiers or '...' before string constant 620 | register uint32_t __regProcessStackPointer __ASM("psp"); | ^~~~~
老牛洋车 回答时间:6 天前

这些报错与宏定义关系不大,需要针对相应出错的代码进行检查,尤其是需要在IDE平台检查相应的文件路径是否包含了。宏定义是没有再报错了。

asn111 回答时间:5 天前

老牛洋车 发表于 2025-2-14 17:11
这些报错与宏定义关系不大,需要针对相应出错的代码进行检查,尤其是需要在IDE平台检查相应的文件路径 ...

[md]这么改不太对 换成iar没这个报错

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版