我的 AVR 闪存是否因程序太大而溢出?

发布于 2024-08-07 17:23:04 字数 416 浏览 18 评论 0原文

我有一个项目,其中 ATtiny2313V 控制 7x5 LED 矩阵来显示滚动文本。为了显示文本,我构建了一种字体,该字体与程序的其余部分一起存储在闪存中。

整个程序,包括整个字体,占用1106字节。但是当我将它加载到芯片中时,它似乎并没有运行;相反,它只是点亮几个 LED,仅此而已。

然而,当我删除大部分字体并仅使用字母 A 到 J 进行编译时,程序大小为 878 字节,并且运行良好。

这是因为 AVR 闪存溢出吗?

ATtiny2313V 的数据表显示它有 2KByte 的闪存! 1106字节怎么会太多呢?

更新:需要明确的是,我使用的工具链是AVR Studio(编译代码),然后是AVRDude将其上传到微控制器。据我所知,AVR Studio 使用 avr-gcc 版本来编译代码。

I have a project where an ATtiny2313V is controlling a 7x5 LED matrix to display scrolling text. To display the text, I built a font which is stored in the flash with the rest of the program.

The whole program, including the entire font, takes up 1106 bytes. But when I load it into the chip, it doesn't seem to run; instead it just lights up a couple of the LED and that's it.

However, when I remove most of the font, and compile with only the letters A to J, the program is 878 bytes in size, and runs just fine.

Is this because of some kind of overflow of the AVR flash memory?

The datasheet for the ATtiny2313V says it has 2KByte of flash! How can 1106 bytes be too much?

UPDATE: Just to be clear, the tool chain I'm using is AVR Studio (to compile the code) and then AVRDude to upload it to the micro-controller. As far as I know, AVR Studio uses a version of avr-gcc to compile the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮色兮凉城 2024-08-14 17:23:04

我不确定您使用的是什么工具链,但在 avr-gcc 中,您需要使用 标头来存储 &访问闪存中的数据 - 仅仅声明数据 const 是不够的,因为它仍然在运行时加载到内存中,因此占用闪存和 RAM 中的空间(就像任何其他初始化变量一样) 。

查看用户手册标题文档了解更多信息。用法相当简单,要在闪存中声明一个字符数组,请使用 PROGMEM 宏:

char data[] PROGMEM = {0xc4, 0x77}; // etc

然后为了访问数据,您需要使用提供的宏

char d = pgm_read_byte(&(data[i]));

编辑:另请记住 avrdude 仅报告ram 的静态分配部分(.data 和 .bss)用于全局变量和静态变量等。您需要为堆栈留出空间 - 多少具体取决于您的程序(提示:递归不好)。

I'm not sure what tool chain you're using, but in avr-gcc you'll need to use the <avr/pgmspace.h> header to store & access data in flash - it's not enough just to declare your data const as it is still loaded into memory at runtime, and as such takes up space in both flash and ram (just as any other initialised variable).

Check out the User Manual and the Header Docs for more information. Useage is fairly simple, to declare a char array in flash, use the PROGMEM macro:

char data[] PROGMEM = {0xc4, 0x77}; // etc

Then in order to access the data, you need to use the supplied macros

char d = pgm_read_byte(&(data[i]));

Edit: Also keep in mind that avrdude only reports the statically allocated portions of ram (.data and .bss) for globals and static variables etc. You need to leave room for the stack - how much exactly depends on your program (hint: recursion is bad).

故事灯 2024-08-14 17:23:04

我发誓SO有一些神奇的东西;我已经绞尽脑汁好几个星期了,试图解决这个问题,在这里提出这个问题之后——我终于能看到是什么在盯着我了!

下面是仅使用字体中的 AJ 字母进行编译时的内存使用情况:

AVR Memory Usage
----------------
Device: attiny2313

Program:     872 bytes (42.6% Full)
(.text + .data + .bootloader)

Data:         82 bytes (64.1% Full)
(.data + .bss + .noinit)

这里又是使用字母 AZ 的情况:

AVR Memory Usage
----------------
Device: attiny2313

Program:     952 bytes (46.5% Full)
(.text + .data + .bootloader)

Data:        162 bytes (126.6% Full)
(.data + .bss + .noinit)

看到数据中的 126.6% 了吗?哎呀!我真的溢出了!

I swear there's something magical about SO; I've been wracking my brains for weeks, trying to figure this out, and after asking the question here - I finally can see what's been staring me in the face!

Below is the memory usage for compiling with only the A-J letters in the font:

AVR Memory Usage
----------------
Device: attiny2313

Program:     872 bytes (42.6% Full)
(.text + .data + .bootloader)

Data:         82 bytes (64.1% Full)
(.data + .bss + .noinit)

And here it is again, with the letters A-Z:

AVR Memory Usage
----------------
Device: attiny2313

Program:     952 bytes (46.5% Full)
(.text + .data + .bootloader)

Data:        162 bytes (126.6% Full)
(.data + .bss + .noinit)

See the 126.6% in the Data? Oops! I really did overflow!

苏佲洛 2024-08-14 17:23:04

检查一下你的堆栈没有溢出吗?这可能会产生难以检测的崩溃。您可以在编译器/链接器设置中的某个位置设置堆栈大小,也可以将一些局部变量转换为全局变量。嵌入式处理器通常不会对堆栈溢出进行任何检查,它只会崩溃。

Check that you're not overflowing your stack? That can produce crashes that are hard to detect. You can either set your stack size somewhere in the compiler/linker settings, or you can convert some local variables to global variables. An embedded processor usually doesn't have any checks for a stack overflow, it just crashes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文