Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 9 months ago.
persist data thru watchdog reset using section(".noinit") not working
I want to create a small logging mechanism that persists the data through reset. I'm using the LPC1768 and the online compiler.
Here's my first pass, which still seems to get cleared following a watchdog event. Thought I'd post now before spending much more time on it.
#define RAMLOG_REC_COUNT 40 // How many log entries
#define RAMLOG_REC_SIZE 20 // How big is each entry
char ldat[RAMLOG_REC_COUNT * RAMLOG_REC_SIZE] __attribute__ ((section (".noinit")));
int RAMLog_index __attribute__ ((section (".noinit")));
RAMLog::RAMLog() {
enable = false;
}
RAMLog::~RAMLog() {
}
void RAMLog::Dump(void) {
int i = RAMLog_index + 1;
while (i != RAMLog_index) {
char * p = ldat + i * RAMLOG_REC_SIZE;
if (*p)
printf("%2d: %s\r\n", i, p);
i = (i + 1) % RAMLOG_REC_COUNT;
}
}
void RAMLog::Clear(void) {
memset(ldat, 0, RAMLOG_REC_COUNT * RAMLOG_REC_SIZE);
RAMLog_index = 0;
enable = false;
}
void RAMLog::Enable(void) {
enable = true;
}
void RAMLog::Log(const char * format, int value) {
if (enable) {
char * p = ldat + RAMLog_index * RAMLOG_REC_SIZE;
snprintf(p, RAMLOG_REC_SIZE, format, value);
RAMLog_index = (RAMLog_index + 1) % RAMLOG_REC_COUNT;
}
}
in main(), I have serial port debugger methods to dump the log, enable it for logging, and so on. I can prove it captures records and can dump them out, but they do not persist a watchdog induced reset.
I suspect that the ".noinit" is not a valid section name, but there are zero errors/warnings at compile time, so if that section doesn't exist, it silently ignores the failure...
Has anyone a solution?
1 Answer
8 years, 9 months ago.
Looks like you've missed a section name that needs to be in the linker script. Have a look at this
http://www.keil.com/support/docs/3480.htm
hi Sam, I guess your answer relates to using the offline compiler, and I was hoping to use the online version. Is there any noinit section defined that I can simply layer into?
For the LPC1768, with the 2nd non-contiguous 32K memory, it has always been a slight mystery how much of it the Ethernet stack uses. Perhaps the .noinit could be located in this bank - assuming they can gracefully coexist. I'm far less familiar with other variants.
posted by 26 Jan 2017