-
-
Notifications
You must be signed in to change notification settings - Fork 3
Logging a perennial memory issue #9
Comments
Two things immediately stand out to me...
|
@dev-zzo The function name is indicative of what it should be doing. Based on my read of the function Now that you mention it, I am usually writing block-wise jagged data. So the issue is probably the subtraction without a check for unsigned arithmetic over/underflow. Thank you for pointing that out. It really helps to have a second set of eyes on the code! My proposed fix is as follows: void MemsetBlockBytes(uint8_t initValue, SIZET startBlock, SIZET byteCount) {
BYTE fillerBuf[DESFIRE_EEPROM_BLOCK_SIZE];
memset(fillerBuf, initValue, DESFIRE_EEPROM_BLOCK_SIZE);
SIZET writeAddr = startBlock * DESFIRE_EEPROM_BLOCK_SIZE;
while(byteCount > 0) {
MemoryWriteBlock(fillerBuf, writeAddr, MIN(DESFIRE_EEPROM_BLOCK_SIZE, byteCount));
writeAddr += DESFIRE_EEPROM_BLOCK_SIZE / sizeof(SIZET);
if(byteCount > DESFIRE_EEPROM_BLOCK_SIZE) {
byteCount -= DESFIRE_EEPROM_BLOCK_SIZE;
}
else {
break;
}
}
} I will try testing this out later when I circle back to the firmware project and testing. |
I changed the implementation to the following: /* TODO: Why doesn't this work ??? -- It freezes the AVR chip when run !! */
void MemsetBlockBytes(uint8_t initValue, SIZET startBlock, SIZET byteCount) {
BYTE fillerBuf[DESFIRE_EEPROM_BLOCK_SIZE];
memset(fillerBuf, initValue, DESFIRE_EEPROM_BLOCK_SIZE);
SIZET writeAddr = startBlock;
while(byteCount > 0) {
WriteBlockBytes(fillerBuf, writeAddr, MIN(DESFIRE_EEPROM_BLOCK_SIZE, byteCount));
++writeAddr;
if(byteCount > DESFIRE_EEPROM_BLOCK_SIZE) {
byteCount -= DESFIRE_EEPROM_BLOCK_SIZE;
}
else {
break;
}
}
} It still doesn't seem to be initializing things in FRAM correctly ... |
i dunno, try printing out the arguments you're passing and see if they make any sense at all? then capture bus traffic and see if that provides any insight? |
I thought it might be something weird with the |
I also do not know how to fix this. Pretty much stuck for a while. This only seems to be relevant when writing and initializing the file system commands. Everywhere else in the code, this seems to be working correctly based on preliminary testing. |
Have you tried to change the BASISTR ISR to maybe blink a led or something like that? It could help you to determine wether it's a stack corruption issue or due to never reaching the loop exit condition. |
@ceres-c |
@ceres-c |
I don't think that's possible. Those macro are expanded by the preprocessor at compile time, given the ISR will be called at unexpected times it does not seem possible to me to access those values |
@ceres-c Just FYI, the reason I asked about something like this is that when I have debugged some of the DESFire related memory routines with my CMLD app, there is a need to store the (say), void WriteBlockBytesMain(const void *Buffer, SIZET StartBlock, SIZET Count);
#define WriteBlockBytes(Buffer, StartBlock, Count) ({ \
snprintf_P(__InternalStringBuffer2, DATA_BUFFER_SIZE_SMALL, \
PSTR("%s @ %d"), __func__, __LINE__); \
__InternalStringBuffer2[DATA_BUFFER_SIZE_SMALL - 1] = '\0'; \
WriteBlockBytesMain(Buffer, StartBlock, Count); \
}) |
I guess you could use a global string, update it accordingly everywhere you need it and print in the BADISTR ISR. But I'm not sure you'd be able to, since, once you land there, the stack is toast and you probably lost the USB altogether... |
@ceres-c I was reading some documentation about |
Perhaps @dev-zzo can shed some light into this. I had to remove some similar code from his original repo sources to get things working correctly. I have a stub (with comments) for this point. Basically, I do not exactly understand why running the following code to initialize a new chunk of FRAM real estate to zero (or whatever it should be) freezes the AVR:
My best estimate is that things need to be aligned along block (defined at 32 bytes here) sizes. But then this can cause many an issue with having to write jagged data.
Why doesn't this work? I guess I should tag/ask @ceres-c too since he does so much of the development and PR merging over at emsec. A solution to this may very well stabilize some code that has gone a awry so far in my sources!
Thanks for the input. :)
The text was updated successfully, but these errors were encountered: