如何解释avr32大小的输出? [英] How to interpret avr32-size output?

查看:131
本文介绍了如何解释avr32大小的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AVR32微控制器(UC3C0512C)上运行了C程序. 发出avr32-size -A PROGRAM.elf命令将产生以下输出:

I have C program running on a AVR32 microcontroller (UC3C0512C). Issuing the avr32-size -A PROGRAM.elf command generates the following output:

PROGRAM.elf  :
section               size         addr
.reset                8200   2147483648
.rela.got                0   2147491848
.text                99512   2147491848
.exception             512   2147591680
.rodata               5072   2147592192
.dalign                  4            4
.data                 7036            8
.balign                  4         7044
.bss                  5856         7048
.heap                48536        12904
.comment                48            0
.debug_aranges        8672            0
.debug_pubnames      14476            0
.debug_info         311236            0
.debug_abbrev        49205            0
.debug_line         208324            0
.debug_frame         23380            0
.debug_str           43961            0
.debug_loc           63619            0
.debug_macinfo    94469328            0
.stack                4096        61440
.data_hram0            512   2684354560
.debug_ranges         8368            0
Total             95379957

有人可以解释如何解释这些价值吗? 如何根据此列表计算Flash和ram的使用量?

Can someone explain how to interpret these values? How can I calculate the flash and ram usage based on this list?

更新1:

没有-A标志,我得到以下信息:

Without the -A flag, I am getting the following:

   text    data     bss     dec     hex filename
 113296    7548   58496  179340   2bc8c PROGRAM.elf

更新2:

我没有使用动态内存分配,因此根据 avr- libc用户手册,可用的RAM空间应该简单地是:stackpointer减去__heap_start.

I'm not using dynamic memory allocation, so according the avr-libc user-manual, the free RAM space should be simply: stackpointer minus __heap_start.

在这种情况下:61440 - 12904 = 48536个字节的可用RAM空间.

In this case: 61440 - 12904 = 48536 byte free RAM space.

有人可以确认吗?

推荐答案

(问题中的两个输出不匹配.bss编号完全不同.)

(There is a mismatch in the two outputs in your question. The bss number is wildly different.)

如果您不使用malloc,也不计算堆栈,那么可以,RAM使用率是数据加上bss(加上一些对齐间距).数据是在声明中设置的变量,而bss是未在声明中设置的变量. C运行时可能会将它们初始化为0,但这不是必须的.

If you don't use malloc, and don't count the stack, then yes, the RAM usage is the data plus the bss (plus some alignment spacing). The data are the variables that are set in a declaration, and the bss are the variables that are not. The C runtime will probably initialize them to 0, but it doesn't have to.

Flash的用法将是文本和数据.也就是说,闪存将包括程序指令和C运行时,还包括在启动时需要复制到RAM中以初始化这些变量的值.通常将这些数据添加到程序指令的末尾.

The flash usage will be the text and the data. That is, the flash will include the program instructions and C runtime, but also the values that need to get copied into RAM on startup to initialize those variables. This data is generally tacked onto the end of the program instructions.

回复:更新2

RAM依次存储全局变量,堆和堆栈.

RAM holds global variables, the heap, and then the stack in that order.

全局变量可以在程序中初始化,也可以不初始化. .data节存储在闪存中,并且C运行时将这些值复制到RAM的开头,在此RAM中,相应的变量在代码运行之前就已存在.全局变量的.bss部分在RAM中需要空间来保存值,但是不一定要对其进行初始化.实际上,avr-gcc附带的C运行时确实将它们初始化为0.要注意的是,您不需要存储0的数组来进行复制,就像使用.data节一样.

The global variables can be initialized in the program, or not. The .data section is stored in flash, and the C runtime copies these values into the beginning of RAM where the corresponding variables live before your code runs. The .bss section of global variables needs space in RAM to hold the values, but they aren't necessarily initialized. The C runtime that comes with avr-gcc does actually initialize these to 0. The point it that your don't need to store an array of 0s to copy over, as you do with the .data section.

您没有在使用堆,而是从heap_start和heap_end之间的地址获取动态分配的内存.

You are not using heap, but dynamically allocated memory is obtained from the addresses between heap_start and heap_end.

但是堆栈不受限制.是的,堆栈指针是在启动时初始化的,但是它会随着程序的运行而改变,并且可以很好地移入堆甚至全局变量(堆栈溢出).每当调用函数或使用函数内的局部变量时,堆栈指针都会移动.例如,在函数内部声明的大型数组将进入堆栈.

But the stack is not limited. Yes, the stack-pointer is initialized at startup, but it changes as your program runs, and can move well into the heap or even into the global variables (stack overflow). The stack pointer moves whenever a function is called, or local variables within a function are used. For example, a large array declared inside a function will go on the stack.

因此,在回答您的问题时,没有保证可以保持可用的RAM.

So in answer to your question, there is no RAM that is guaranteed to remain free.

这篇关于如何解释avr32大小的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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