Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smartyw opened this issue Jun 1, 2018 · 0 comments
Open

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

smartyw opened this issue Jun 1, 2018 · 0 comments

Comments

@smartyw
Copy link

smartyw commented Jun 1, 2018

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.

thinkberg pushed a commit that referenced this issue Jan 8, 2019
* Memory Map + Partial Flash Service

* Moved Partial Flash Service to Management Mode

* PF Service appears in YT Build not PXT

* PF in PXT

* Swapped DFU and PF Services

* Fixing Flash Writew

* write flash via bluetooth

* Partial Flash -  Fixed Address

* Update module.json

* Adjust flash pointer

* Adjust flash start

* Adjust Flash Pointer

* Added offset to xfer

* Writing to FLASH_END

* Writing to FLASH_END

* Modified PFS read callback

* Reenable BLE Security

* removed pf

* Check diff

* Check diff

* Replaced ContextSwitch

* PF

* Test. Writing Hex File to 0x30000

* Writing to PXT empty space

* Reversed byte order

* Flash 16 bytes at once

* Copy data from static var to local var

* blocks -> bytes

* Fixed offset

* Fixed Offset

* Flash to 0x30000 + offset

* Bypass scratch page

* Changed byte order

* Write Without Response

* Without Fast BLE

* Added fast BLE

* Updated Connection Parameters

* Iterate through BLE data bytes

* Get Hashes From PXT Build

* Copy Hash from Flash

* Testing FLASH_END

* Read Hash From Flash

* Read Hash from Flash

* Reading correct hash from mem

* Endianess

* Modified MAGIC

* Fix Start Address

* Sequence #

* Write 0xdeadbeef to 0x36000 on PF Seq # error

* Group 4 packet blocks for writing

* Added error case

* Increased flash write size

* Blocks

* Fire event to write

* Decreased flash time

* Reformat

* Reduced hash size in MemoryMap

* Partial Flashing w/ Notifications

* One Characteristic - WRITE/WRITE_WOUT_RESP/NOTIFY

* Modified WRITE Notification

* Tidied - Moved end of transfer logic

* Removed VI Swap files

* Added Pairing Mode Event ID

* Modified Retransmit behaviour

* updateFlash caused stack overflow

* Removed flash write from memory map

* Instantiate Memory Map where used

* Word aligned. Added Status and Reset commands

* Fixed: storage. becomes storage->

* Fixed warnings: switch case fall through

* Fix Hash

* Rebuild Map everytime

* Hash Error

* Edited animation. Hash testing

* persistent memory map issues

* Moved EOT

* Modified BLE animation. Removed globals from PFS

* Updated MM

* Added incomplete flash flag

* Re added CCS.s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant