Skip to content

out of memory running code that works on micro:bit #9

@smartyw

Description

@smartyw

Code which I can build and run on micro:bit appears to generate Out of Memory conditions (crash code 020 on the LED display) when built for and run on Calliope Mini. Here's part of the test code, which involves instantiating the three Bluetooth services Accelerometer, Magnetometer and Temperature alongside others instantiated via config.json (Event, DFU, Device Info).

int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();
    uBit.display.scroll("BDL-NP 1");
    uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected);
    uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);
    uBit.messageBus.listen(BDL_PIN_SELECTION_EVENT, 0, onPinSelectionEvent);
    uBit.messageBus.listen(BDL_SAMPLING_FREQUENCY_EVENT, 0, onSamplingFrequencyEvent);
    uBit.messageBus.listen(BDL_START_SAMPLING_EVENT, 0, sampleLoop);

    uBit.accelerometer.setRange(8);
    new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer);
    new MicroBitMagnetometerService(*uBit.ble, uBit.compass);
    new MicroBitTemperatureService(*uBit.ble, uBit.thermometer);

    // workaround for Calliope accelerometer service bug
    uBit.messageBus.listen(MICROBIT_ID_ACCELEROMETER, MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE, onAccelerometerUpdate);

    release_fiber();
}

The Out of Memory condition arises when the magnetometer calibration procedure completes.

Using a process of elimination, it looks like the magnetometer service is the issue. I can get all the other services in place OK, but even with tweaking memory settings like GATT table size in config.json, I cannot squeeze the magnetometer service in as well, which I can on a micro:bit.

Obviously I'd expect differences between Calliope and micro:bit but I'm wondering if there are opportunities to do some memory optimisation so that code that works on micro:bit can generally be expected to work on Calliope Mini. It would be a disadvantage for Calliope if that were not the case, I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions