Using flash memory to store strings - arduino restart
hi,
i'm using arduino mega wrote lot of libraries. 1 of library logger 1 being used in other libs print data.
all strings being stored in flash memory arduino mega have 256kb
here usage:
device: atmega2560
program: 37922 bytes (14.5% full)
(.text + .data + .bootloader)
data: 3262 bytes (39.8% full)
(.data + .bss + .noinit)
so looks have lot of free space when i'm trying add new logger or extend debug info arduino rebooting looks flash space lake. happening when im using logger.debugf() method class below.
in addition have lot of free ram.
below i'm attaching logger class code , usage example:
example usage:
any idea why arduino being restarted when i'm trying extend logging ?
when i'm print directly serial not thru logger class arduino not being restarted.
thanks hints.
i'm using arduino mega wrote lot of libraries. 1 of library logger 1 being used in other libs print data.
all strings being stored in flash memory arduino mega have 256kb
here usage:
device: atmega2560
program: 37922 bytes (14.5% full)
(.text + .data + .bootloader)
data: 3262 bytes (39.8% full)
(.data + .bss + .noinit)
so looks have lot of free space when i'm trying add new logger or extend debug info arduino rebooting looks flash space lake. happening when im using logger.debugf() method class below.
in addition have lot of free ram.
below i'm attaching logger class code , usage example:
code: [select]
// header
#ifndef logger_h
#define logger_h
#include <arduino.h>
#include <memoryvariables.h>
#include <mymemoryfree.h>
class logger
{
public:
logger();
void info(string log);
void debugf(const __flashstringhelper* log);
void debugs(string log);
void debugc(char* log);
void tracef(const __flashstringhelper* log);
void traces(string log);
void errorf(const __flashstringhelper* log);
void errors(string log);
private:
memoryvariables memoryvariables;
mymemoryfree mymemoryfree;
bool isdebugenable();
bool istraceenable();
string arduinoname;
};
#endif
// body
#include "logger.h"
logger::logger()
{
char arduino[20];
arduinoname = string(strcpy_p(arduino, (char*)pgm_read_word(&(arduino_names[memoryvariables.getarduinoid()]))));
}
void logger::info(string log)
{
serial.println(log);
}
void logger::debugf(const __flashstringhelper* log)
{
if (isdebugenable())
{
serial.print(f("debug "));
serial.print(arduinoname);
serial.print(" (m:" + string(mymemoryfree.getmemoryusage()) + " t:" + millis()/1000 + "s):");
serial.print(" ");
serial.println(log);
}
}
void logger::debugs(string log)
{
if (isdebugenable())
{
serial.print("debug ");
serial.print(arduinoname);
serial.print(" (m:" + string(mymemoryfree.getmemoryusage()) + " t:" + millis()/1000 + "s):");
serial.print(" ");
serial.println(log);
}
}
void logger::debugc(char* log)
{
if (isdebugenable())
{
serial.print("debug ");
serial.print("- ");
serial.println(log);
}
}
void logger::tracef(const __flashstringhelper* log)
{
if (istraceenable())
{
serial.print("trace ");
serial.print(arduinoname);
serial.print(" (m:" + string(mymemoryfree.getmemoryusage()) + " t:" + millis()/1000 + "s):");
serial.print(" ");
serial.println(log);
}
}
void logger::traces(string log)
{
if (istraceenable())
{
serial.print("trace ");
serial.print(arduinoname);
serial.print(" (m:" + string(mymemoryfree.getmemoryusage()) + " t:" + millis()/1000 + "s):");
serial.print(" ");
serial.println(log);
}
}
void logger::errorf(const __flashstringhelper* log)
{
if (isdebugenable())
{
serial.print("error ");
serial.print(arduinoname);
serial.print(" (m:" + string(mymemoryfree.getmemoryusage()) + " t:" + millis()/1000 + "s):");
serial.print(" ");
serial.println(log);
}
}
void logger::errors(string log)
{
if (isdebugenable())
{
serial.print("error ");
serial.print(arduinoname);
serial.print(" (m:" + string(mymemoryfree.getmemoryusage()) + " t:" + millis()/1000 + "s):");
serial.print(" ");
serial.println(log);
}
}
bool logger::isdebugenable()
{
return memoryvariables.isdebugenable();
}
bool logger::istraceenable()
{
return memoryvariables.istraceenable();
}
example usage:
code: [select]
logger.debugf(f("some information."));
any idea why arduino being restarted when i'm trying extend logging ?
when i'm print directly serial not thru logger class arduino not being restarted.
code: [select]
serial.print(f("some information."));
thanks hints.
just noticed (not answer looking for)
you should millis() * 1000 not divided if want seconds.
where libs include @ beginning coming from?
code: [select]
serial.print(" (m:" + string(mymemoryfree.getmemoryusage()) + " t:" + millis()/1000 + "s):");
you should millis() * 1000 not divided if want seconds.
where libs include @ beginning coming from?
code: [select]
#include <memoryvariables.h>
#include <mymemoryfree.h>
Arduino Forum > Using Arduino > Programming Questions > Using flash memory to store strings - arduino restart
arduino
Comments
Post a Comment