Arduino:命令Serial.print("some string text")是否占用SRAM? [英] Arduino: Is the command Serial.print("some string text") occupying SRAM?

查看:107
本文介绍了Arduino:命令Serial.print("some string text")是否占用SRAM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的Arduino项目(在eclipse中),使用Serial.print("some string text")命令处理许多调试消息,这样我就可以一路调试.

I have quite a big Arduino project (in eclipse) going on with a lot of debug messages using the Serial.print("some string text") commands so that I can debug along the way.

我注意到的一件事是我达到了我在项目中可以拥有的数量的极限.如果我放太多,该程序将在非常奇怪的地方停止. 即:通常应该在我最新添加的打印命令执行之前很久.

One thing that I have noticed is that I reach a limit for how many of these I can have in the project. If i put too many, the program halts at very strange places. Ie: often long before my newest addition of a print command is supposed to execute.

目前,我的项目.hex文件约为20k. Arduino Uno的限制大约为30kb,对吧? 因此它不应太大.

My project .hex file is around 20k at the moment. The Arduino Uno limits around 30kb right? So it should not be too big.

因此,我认为实际的问题可能是这些串行命令可能正在填满我的sram.仅2kb.我正在使用很多图书馆.

So I feel that the actual problem is probably that maybe these serial commands are filling up my sram. Which is just 2kb. I am using a lot of libraries.

命令Serial.print("some string text")是否占用SRAM? gcc肯定会将这些字符串cnstant放在程序空间中吗?但也许不是吗?

Is the command Serial.print("some string text") occupying SRAM? Surely gcc puts these string cnstants are in program space? but maybe they are not?

还是其他东西?我有另一种理论,即某个地方有一个serial.print缓冲区,我可能只是用太多的消息填充了它.

Or is it something else? I have an alternative theory that there is a serial.print buffer somewhere, and I am probably just filling it up with too many messages.

推荐答案

是的,默认情况下,字符串存储在RAM中.尽管它们也位于闪存中,但是当Arduino引导时它们已加载到RAM中.

Yup, string are stored in RAM by default. Although they're in the Flash memory too, but they're loaded into RAM when the Arduino boots.

但是,如果您使用的是Arduino IDE版本1.0或更高版本,则可以告诉编译器直接从Flash中读取字符串,而不必使用F()宏将它们加载到RAM中:

However, if you use The Arduino IDE version 1.0 or later you can tell the compiler to read strings directly from Flash and not to bother loading them into RAM with the F() macro:

Serial.Println(F("This string is read from Flash!"));

这将节省RAM,这是一件好事,因为RAM比Flash少得多.请参阅此处以获取更多详细信息: * http://www.arduino.cc/playground/Main/Printf

This will save RAM which is a good thing as there's much less RAM than Flash. See here for more details: * http://www.arduino.cc/playground/Main/Printf

这篇关于Arduino:命令Serial.print("some string text")是否占用SRAM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆