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

查看:28
本文介绍了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 肯定把这些字符串 cnstants 放在程序空间中吗?但也许他们不是?

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天全站免登陆