简体   繁体   English

MSP430 Ram溢出

[英]MSP430 Ram Overflow

The MSP430G2553 only has 512 Bytes of RAM but 16KB of FLASH memory. MSP430G2553仅具有512字节的RAM,但具有16KB的闪存。 On this microcontroller, all static/global variables are assigned in RAM under .bss section. 在该微控制器上,所有静态/全局变量都在.bss部分下的RAM中分配。 All local variables are assigned in RAM under .stack section. 所有局部变量均在.stack部分下的RAM中分配。 All dynamically allocated memory variables (malloc) are assigned in RAM under .sysmem section. 所有动态分配的内存变量(malloc)在.sysmem部分的RAM中分配。

I have a need for this MSP430 to keep track of connected devices via wifi. 我需要此MSP430跟踪通过wifi连接的设备。 I have a struct as such: 我有这样的结构:

struct dev
{
    char type[20];
    char ipAddress[13];
    char name[20];
    char status[1];
};

This struct takes up 54 bytes of memory for each device. 该结构为每个设备占用54个字节的内存。 I am planning on having 20+ devices connected that this MSP430 and need to have 20 of these structs. 我计划为此MSP430连接20多个设备,并且需要20个这些结构。 20 x 54 bytes = 1080 bytes. 20 x 54字节= 1080字节 This is obviously too big for the 512 bytes of ram. 对于512字节的ram来说,这显然太大了。

Is there any way to write these structs into FLASH since I have 16KB of memory to use? 由于我要使用16KB的内存,有什么方法可以将这些结构写入FLASH? My understanding of FLASH is variables that are only read-only. 我对FLASH的理解是仅只读的变量。 These structs will obviously be getting assigned so it is read-write and I am not sure if it is possible. 这些结构显然将被分配,因此它是可读写的,我不确定是否可能。

I don't quite understand why TI would make a device which has 16 KB FLASH and only 512 Bytes of RAM, when all variables requiring read-write operations are stored in RAM. 我不太明白为什么当所有需要读写操作的变量都存储在RAM中时,TI为什么会制造出具有16 KB FLASH和仅512 Bytes RAM的设备。 Seems like it is a waste of space. 好像是在浪费空间。

I have tried to change these sections .bss/.stack/.sysmem to FLASH in the linker file and the MSP430 will not run like this. 我试图将这些节.bss / .stack / .sysmem更改为链接文件中的FLASH,MSP430将无法像这样运行。 I have also tried to change the size of the RAM and in linker file and change the memory locations adding another 512 Bytes, but it will not run like this either. 我还尝试过更改RAM和链接器文件中的大小,并更改内存位置,再添加512字节,但它也不会这样运行。

Do I have any options here? 我这里有什么选择吗?

You can store a constant data in the flash/program memory. 您可以将恒定数据存储在闪存/程序存储器中。 If you know that some variables/arrays are actually not changing once initialized, you can declare them as static const in your code and the compiler will place them in the .text section, which is usually going to the FLASH memory. 如果您知道某些变量/数组在初始化后实际上并没有改变,则可以在代码中将它们声明为static const ,然后编译器会将它们放在.text节中,该节通常会进入FLASH存储器。 If you have dynamic data that doesn't fit in the memory.. well. 如果您有无法容纳在内存中的动态数据。 You are screwed, unless you can think of optimization (like reusing the same space for different things at different times..). 除非您想到优化(例如,在不同的时间为不同的事情重用相同的空间..),否则您会一头雾水。 Of course there is a possibility to implement some kind of "swapping" functionality with FLASH, if your part has a programmatic access to the FLASH writing. 当然,如果您的部件可以通过编程方式访问FLASH写入,则可以用FLASH实现某种“交换”功能。 But it is really not that simple. 但这真的不是那么简单。

And for this: 为此:

I don't quite understand why TI would make a device which has 16 KB FLASH and only 512 Bytes of RAM, when all variables requiring read-write operations are stored in RAM. 我不太明白为什么当所有需要读写操作的变量都存储在RAM中时,TI为什么会制造出具有16 KB FLASH和仅512 Bytes RAM的设备。 Seems like it is a waste of space. 好像是在浪费空间。

You are getting what you are paying for. 您正在得到您所支付的。 Every micro has a specific range of applications it is intended for. 每个微型都有其特定的应用范围。 If this specific micro is not good for your application, probably it is not in that range. 如果此特定的Micro不适用于您的应用程序,则可能不在该范围内。

Yes, you can write data into the flash memory. 是的,您可以将数据写入闪存。 The only problem arises when you want to change the data. 唯一的问题出现在您想要更改数据时。 You can only erase sectors, which have a size of 512 bytes. 您只能擦除大小为512字节的扇区。 So you could take two flash sectors from the flash and store data for 10 devices in each sector. 因此,您可以从闪存中获取两个闪存扇区,并在每个扇区中存储10个设备的数据。 The flash can be read like RAM though, so you don't need some kind of swapping code, you just address each device entry with a pointer. 闪存可以像RAM一样读取,因此您不需要某种交换代码,只需使用指针寻址每个设备条目即可。 The last problem is that flash memory has a limit of erase cycles, here around 10000 cycles. 最后一个问题是闪存具有擦除周期的限制,此处约为10000个周期。 So you might also have to write code to distribute the data to different sectors over time, depending on the amount of expected changes and the desired service durability. 因此,您可能还必须编写代码,以便随着时间的推移将数据分发到不同的扇区,具体取决于预期的更改量和所需的服务持久性。

There's a good bit of extra room you can free up in this struct. 您可以在此结构中释放很多额外的空间。

Type type field probably doesn't need to be a char array. 类型type字段可能不必是char数组。 You can use a set of symbolic constants with all the possible types. 您可以对所有可能的类型使用一组符号常量。

The IP address also doesn't need to be stored as a string. IP地址也不需要存储为字符串。 Assuming IPv4, you only need four bytes. 假设使用IPv4,则只需四个字节。

status doesn't need to be an array of size 1. A simple char will suffice. status不必是大小为1的数组。一个简单的char就足够了。

So now you have something like this: 所以现在您有了这样的事情:

struct dev
{
    uint32_t ipAddress;   // 4 bytes
    char name[20];        // 20 bytes
    char type;            // 1 byte
    char status;          // 1 byte
};                        // 2 bytes padding, total = 28 bytes

It's still not quite enough to fit 20 of these into 512 bytes of memory, but it's better that what you had. 仍不足以将其中20个容纳到512字节的内存中,但是最好还是拥有的内存。

Honestly, your best option is probably to switch to a more capable chipset. 老实说,您最好的选择可能是切换到功能更强大的芯片组。 The MSP430 G-line is really meant for extremely low power and low performance applications, Ethernet being neither of those (and certainly not multiple TCP/IP connections at the same time!). MSP430 G线实际上是为极低功耗和低性能的应用程序而设计的,以太网都不是其中的一种(当然也不能同时具有多个TCP / IP连接!)。

As for why they'd make a chip with a huge Flash space and tiny SRAM, well, Flash is cheap and compact, where SRAM is space-expensive on the die, so TI had to make compromises to deliver that MCU for less than $1. 至于为什么要制造具有巨大闪存空间和微小SRAM的芯片,那么闪存又便宜又紧凑,而SRAM在裸片上的空间却很昂贵,因此TI必须做出让步,以不到1美元的价格交付该MCU。 。 As some of the other answers alluded to, you can use that large amount of Flash to write more code, that can encode/compress/decode/decompress data to/from SRAM. 正如其他一些答案所暗示的那样,您可以使用大量的Flash编写更多代码,从而可以对SRAM中的数据进行编码/压缩/解码/解压缩。

Another option is to use one of the "Wolverine" series of MSP430 chips. 另一种选择是使用MSP430芯片的“金刚狼”系列之一。 Those use a unified FRAM bank rather than separate Flash and SRAM banks. 那些使用统一的FRAM库,而不是单独的Flash和SRAM库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM