C语言 已禁用缓存器优化,< util/delay.h>中的函数将无法按设计工作

a11xaf1n  于 11个月前  发布在  其他
关注(0)|答案(3)|浏览(132)

我正在开发Firebird 5模块。它有Atmega2560,我试图编译此代码并得到此警告。

(base) pawansrinivas@Pawans-MacBook-Air Experiment-3 % mkdir -p build
(base) pawansrinivas@Pawans-MacBook-Air Experiment-3 % avr-gcc -g -Wall -O0 -mmcu=atmega328p -c Experiment-3.c -o build/Experiment-3.o
In file included from Experiment-3.c:25:
/opt/homebrew/Cellar/avr-gcc@9/9.3.0_3/avr/include/util/delay.h:112:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
  112 | # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
      |   ^~~~~~~
(base) pawansrinivas@Pawans-MacBook-Air Experiment-3 %

字符串

dfuffjeb

dfuffjeb1#

您可能正在使用AVRGCC和avr-libc?
请参阅<util/delay.h>

为了使这些函数按预期工作,必须启用编译器优化,并且延迟时间必须是在编译时为已知常量的表达式。如果不满足这些要求,则导致的延迟将更长(基本上不可预测),而不使用浮点计算的应用程序将经历严重的代码膨胀,链接到应用程序的点库例程。

w8ntj3qf

w8ntj3qf2#

=在嵌入式系统中,如果您使用AVR,则使用交叉目标编译器编译器“AVR-GCC Toolchain
因此,如果你想使用延迟函数,你将包括<avr/delay.h>,因为你使用AVR处理器家族编译器。
我希望我的叔叔能帮助你。

cbeh67ev

cbeh67ev3#

您需要在编译器中启用优化,即使用标志-O1或更高的标志调用avr-gcc,以使util/delay.h函数正确工作(并使警告消失)。
例如:

$ # with -O0 (same as with -O flag not provided at all)
$ avr-gcc -O0 -mmcu=atmega328p -c ./test.cpp -o ./test.o
In file included from ./src/main.cpp:8:0:
/usr/avr/sys-root/include/util/delay.h:112:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
   ^~~~~~~
$ # with -O1
$ avr-gcc -O1 -mmcu=atmega328p -c ./test.cpp -o ./test.o
$

字符串
more on different optimization levels in GCC

相关问题