lancaster-university / codal-microbit-v2

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

Datalog: Enabling debug breaks the long reset button press #163

Open microbit-carlos opened 2 years ago

microbit-carlos commented 2 years ago

With a new git clone of microbit-v2-samples repo and this code:

#include "MicroBit.h"

MicroBit uBit;

int  main() {
    uint32_t show = 0;
    uBit.init();
    uBit.log.setTimeStamp(TimeStampFormat::Milliseconds);

    while (true) {
        uBit.display.printChar(show++ % 2 ? '.': ' ');
        uBit.sleep(20);
    }
}

This works fine in a micro:bit V2.0 and V2.2 with their factory DAPLink images. The target blinks an LED in the matrix display, then when the reset button is long pressed (keeping it pressed down until the red LED is turned OFF) it puts the board in "stand-by" mode (USB connected, red LED blinking, target MCU in sleep).

But if the "DMESG_SERIAL_DEBUG": 1 option is added to codal.json to enable debug messages, the long reset button press doesn't work anymore. After releasing it the red LED is steady ON and the target starts running the programme again:

{
    "target": {
        "name": "codal-microbit-v2",
        "url": "https://github.com/lancaster-university/codal-microbit-v2",
        "branch": "master",
        "type": "git",
        "test_ignore": true,
        "dev": true
    } ,
    "config":{
        "NO_BLE": 1,
        "MICROBIT_BLE_ENABLED" : 0,
        "MICROBIT_BLE_PAIRING_MODE": 0,
        "DMESG_SERIAL_DEBUG": 1
    }
}
martinwork commented 2 years ago

@microbit-carlos I suspect that transferring "relocate vtor to 0x0 -> 0x20002200 0x20002200" to serial takes up enough time, that the sleep(10) in MicroBit::init() is not long enough for MicroBitPowerManager::idleCallback() to get called 30 times, then uBit.log.setTimeStamp overwrites the shutdown request, as would any other I2C interface request.

microbit-carlos commented 2 years ago

Good thinking! Adding a uBit.sleep(30); between init() and log.setTimeStamp() does seem to help (at least on V2.20 with factory DAPLink).

microbit-carlos commented 2 years ago

I'd be good to check if a C++ progamme without debug can trigger this.

If something like this works fine, and it doesn't stop the long reset button press from working, then I'd leave this to the bottom of the backlog:

void main() {
  uBit.init();
  // Some I2c transaction here, maybe a datalogging call

  while(true);
}