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

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)

| ^~~~~

点评

感觉您安装时的库文件与CUBE不一致,或安装路径移动了没有重新更改路径  发表于 2025-3-17 12:59
赞 收藏 评论9 发布时间:2025-2-14 14:48

举报

9个回答
老牛洋车 回答时间:2025-2-14 14:54:37

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

ifndef __ASM

define __ASM

......

endif

asn111 回答时间:2025-2-14 15:26:41

<br /> <br />

谢谢 这样试了不行

../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");

| ^~~~~

老牛洋车 回答时间:2025-2-14 16:18:51

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

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

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

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

建议复制下列代码:

老牛洋车 回答时间:2025-2-14 16:22:17
#ifndef __ASM

#define __ASM

...

#endif
asn111 回答时间:2025-2-14 16:35:29

<br /> <br />

你好

代码如下 还是一样报错

谢谢

ifndef __ASM

define ASM asm

endif

asn111 回答时间:2025-2-14 17:03:10

<br /> <br />

改成这样会多出来其他的很多报错

谢谢

../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");

| ^~~~~

老牛洋车 回答时间:2025-2-14 17:11:24

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

asn111 回答时间:2025-2-15 18:47:55

<br /> <br />

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

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版