lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
43 stars 52 forks source link

Data log "full" marker is not being written to interface storage #406

Closed microbit-carlos closed 1 month ago

microbit-carlos commented 7 months ago

Running this programme on tag v0.2.63, which writes to the data log one byte at a time until the log is full:

#include "MicroBit.h"

MicroBit uBit;

int main() {
    uBit.init();

    uBit.display.print("?");

    while (true) {
        uBit.log.logString("X");
        uBit.sleep(1);

        if (uBit.log.isFull()) {
            uBit.display.print("D");
            uBit.sleep(100);
        }
    }
}

MICROBIT.hex.zip

We should expect the last 4 bytes, which are reserved for this marker, to contain FULL: https://github.com/lancaster-university/codal-microbit-v2/blob/d54ce9b784ef1bba22c075b281bb877abf53ea18/source/MicroBitLog.cpp#L258 https://github.com/lancaster-university/codal-microbit-v2/blob/d54ce9b784ef1bba22c075b281bb877abf53ea18/source/MicroBitLog.cpp#L738-L742

However, the last 4 bytes are left untouched: MY_DATA.HTM.txt

image
jaustin commented 4 months ago

This is odd - do you know whether the byte-by-byte case ever wrote 'log full'? Does it still work if logging longer lengths? From MakeCode?

microbit-carlos commented 4 months ago

It must have worked at some point, as I believe that's how the "log full" message is meant to be displayed:

I haven't tried it in MakeCode yet.

martinwork commented 2 months ago

@microbit-carlos It does get to this point (even with a long string to fill memory more quickly) https://github.com/lancaster-university/codal-microbit-v2/blob/master/source/MicroBitLog.cpp#L740

But I think the last byte before flash.getFlashEnd() is blocked by the equals in this test https://github.com/lancaster-university/codal-microbit-v2/blob/master/source/FSCache.cpp#L119 and https://github.com/lancaster-university/codal-microbit-v2/blob/master/source/FSCache.cpp#L87

With ">=" changed to ">" in the FSCache test, the I2C transaction seems OK, but it still seems to be zeros in the file. https://github.com/lancaster-university/codal-microbit-v2/blob/master/source/MicroBitUSBFlashManager.cpp#L369

FSCache::write address 0x1EFFD length 3 getFlashEnd 0x1F000
FUL
MicroBitUSBFlashManager::write 0x1EFFC 4
request 0xB 0x1 0xEF 0xFC 0x0 0x0 0x0 0x4 0xFF 0x46 0x55 0x4C
response 0xB 0x1 0xEF 0xFC 0x0  0x0 0x0 0x4 0xFF
martinwork commented 2 months ago

Ah! I forgot the USB must be reconnected to see the latest data... FUL is there!

martinwork commented 2 months ago

FUL is saved when the FSCache::write test is changed to ">", image but it doesn't always make LOG FULL appear. image MY_DATA.HTM.txt

microbit-carlos commented 2 months ago

Great debugging Martin! Could you submit a PR with the fix? Or do you think there is additional testing we should do before that?

martinwork commented 2 months ago

Will do!