Why would increasing array size slightly cause a "RAM overflowed" error
- August 19, 2022
- 6 replies
- 2710 views
I wrote my own FIFO class that doesn't use dynamic memory allocation as far as I can tell. It has been working fine until I tried to increase the size of an array in the struct that my class puts in the FIFO. Here's the FIFO.hpp file:
#pragma once
#include
#include
using namespace std;
#include "main.hpp"
//#include "C:\Users\gene\Documents\CPF\ElecEngr\cpfSTM32H7A3_SOM\Code\CPF_H7A3\CPF\ETL\include\etl\string.h"
//#include "C:\Users\gene\Documents\CPF\ElecEngr\cpfSTM32H7A3_SOM\Code\CPF_H7A3\CPF\ETL\include\etl\queue.h"
//From https://www.techiedelight.com/queue-implementation-cpp/
class FIFO
{
public:
FIFO(string qID) //TODO might want to pass struct to be queued in constructor instead of forcing it to be FIFORecord
{
head = 0;
tail = -1;
count = 0;
qName = qID;
//etlTest();
}
struct FIFORecord //TODO it would be better to figure out a way to set the queue width and depth through the constructor
{
uint64_t tickstamp;
uint8_t message[161];
};
~FIFO() // destructor
{
//delete[] arr;
}
int32_t dequeue(uint64_t &tickstamp, MainFIFORecordIDs &id, uint8_t deQBytes[]);
int32_t dequeue(uint64_t &tickstamp, uint8_t deQBytes[]);
int32_t enqueue(uint64_t tickstamp, MainFIFORecordIDs id, uint8_t enQBytes[]);
int32_t enqueue(uint64_t tickstamp, uint8_t enQBytes[]);
int32_t dequeue(FIFORecord &deQueueRecord);
int32_t enqueue(FIFORecord enQueueRecord);
int peek();
int getCount();
bool isEmpty();
bool isFull();
void clearRecord(FIFORecord &inRecord);
uint32_t qWidth;
protected:
uint32_t capacity; // maximum capacity of the queue
int32_t head; // points to front element in the queue (if any)
int32_t tail; // points to last element in the queue
int32_t count; // current size of the queue
string qName;
FIFORecord fifoRecords[32];
private :
void etlTest();
//Just to see how much memory a stl queue takes.
//queue stlQ;
};The FIFO class allows for up to 32 FIFORecord structs (line 59) to be put in the FIFO. The FIFORecord struct has a uint64_t tickstamp (line 29) and a uint8_t message[***] (line 30). And I have 3 FIFOs instantiated in my program. Normally the message[***] size is an integer multiple of 2 but I'm trying to figure out exactly where the problem is. With uint8_t message[160], it compiles fine with this memory usage:
------------------- Memory utilization report -------------------
Used FLASH: 274KB out of 2048KB (13%)
Used SRAM: 127KB out of 1024KB (12%)
Used DTCMRAM: 0 bytes out of 128KB (0%)
Used ITCMRAM: 0 bytes out of 64KB (0%)
========== Project Rebuild Summary ==========
CPF rebuilt in 00:11
========== Rebuild: 1 Succeeded, 0 Failed, 0 Skipped ==========
With uint8_t message[161] as shown above, I get this error:
../VisualGDB/Debug/CPF section `._user_heap_stack' will not fit in region `RAM' CPF 1
Note region `RAM' overflowed by 4744 bytes CPF 1
Error Build failed: arm-none-eabi-g++.exe exited with code 1 CPF 1
Error ld returned 1 exit status CPF C:\Users\gene\Documents\CPF\ElecEngr\cpfSTM32H7A3_SOM\Code\CPF_H7A3\CPF\collect2.exe 0 Seems like there's plenty of memory available to increase the message array size from 160 to 161. And the overflow of 4744 bytes doesn't seem to be evenly divisible by 32, 160 or 161. I've been reviewing the .map file (attached) but haven't been able to figure out what I'm doing wrong. Any help will be greatly appreciated.
