TensorFlow lite for the MDBT42Q 2v04

Posted on
  • Does the latest firmware 2v04 include TensorFlow lite for the MDBT42Q?

  • No, I'm afraid not. It's something that you'd have to compile in yourself (just adding TENSORFLOW to the MDBT42Q.py and rebuilding is enough, although you may need to remove networking to have enough space for it);

  • Thanks for the quick response Gordon. I’ll give it a try.

    To check for a custom build example cli is below.

    python MDBT42Q.py -k -p MySerialPort -evw espruino_for_your_device.bin.

    For the original Espruino is the build file ESPRUINOBOARD.py

    Finally is the entry point for the TensorFlow api var tf = require("tensorflow").create(2048, model). I had a look at the documentation on the website but couldn’t see anything for TensorFlow.

    Looking forward to getting the Bangle board, tensorflow addition is exciting.

  • python MDBT42Q.py -k -p MySerialPort -evw espruino_for_your_device.bin.

    That doesn't look right at all...

    Loads of info on building here: https://github.com/espruino/Espruino/blo­b/master/README_Building.md

    And Tensorflow usage here:
    https://github.com/espruino/Espruino/blo­b/master/libs/tensorflow/README.md

    If you just want to try it out, have a go with the emulator, which has Tensorflow built in:

    https://www.espruino.com/ide/emulator.ht­ml?gist=c0404a867b3531527428a1843c5fd5fc­&upload

  • Gordon, update on this removed networking most other libraries (FILESYSTEM, NFC, NEOPIXEL) and still having difficulty getting this to fit. The only way i'm able to get it to fit is if tensorflow is the only library. Error below.

    python scripts/check_elf_size.py MDBT42Q espruino_2v05.22_mdbt42q.elf
    Testing espruino_2v05.22_mdbt42q.elf for MDBT42Q
    STORAGE: 442368 -> 483328
    CODE: 126976 -> 448108 (321132 bytes)
    CODE AND STORAGE OVERLAP
    make: *** [espruino_2v05.22_mdbt42q.app_hex] Error 1

  • The MDBT42Q also uses 40k of internal flash to store saved JS code compared to the Bangle. You could try to reduce that in the MDBT42's board file, but if you remove too much, well, you won't be able to save JS code:

      'saved_code' : {
        'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
        'page_size' : 4096,
        'pages' : 10,
    

    The Bangle has external flash, so doesn't use internal flash to store saved code. But you can compare the two board files. Or solder an external flash on the MDBT42Q :)

  • Without external flash you can also save a bit by downgrading to SDK11 - gives you 0x1f000-0x1c000=12KB and also the bootloader can be moved by 8KB 0x78000 to 0x7a000 - giving you 20KB in total, not much and quite tricky to do. Also you can do build without bootloader if you use SWD debugger to upload the firmware. This gives you 32KB more compared to current state.

  • Are you definitely building with RELEASE=1 on the command-line? Without that, the assertions are left in and it really pushes the size up

  • Thanks for the info.

    > You could try to reduce that in the MDBT42's board file

    With number of pages reduced to 6 from 10 I was to include the bluetooth and graphics. Not sure as yet of consequence tho as aware that importing modules such sensor drivers are stored in flash.

    Using external flash likely a better solution just not sure of the workflow. Is there a way through the IDE to save js application directly to external flash (assuming storage/flash object only work with internal flash). Or will I have to save it to external flash manually, for example convert a module / function to templated string then use SPI flash(https://www.espruino.com/W25), and potentially split to store into pages sectors. I will likely need to leave some room on internal flash to manage this.

    > Without external flash you can also save a bit by downgrading to SDK11 - gives you 0x1f000-0x1c000=12KB and also the bootloader can be moved by 8KB 0x78000 to 0x7a000
    Looks interesting. Assuming not just straight forward as updating start address in Linker script?

    > Are you definitely building with RELEASE=1 on the command-line? Without that, the assertions are left in and it really pushes the size up

    this is the command i'm running.
    make clean && DFU_UPDATE_BUILD=1 BOARD=MDBT42Q RELEASE=1 make

  • make clean && DFU_UPDATE_BUILD=1 BOARD=MDBT42Q RELEASE=1 make

    That definitely should be fine. I guess you're just limited by the size of Tensorflow then.

    You could definitely use external flash. Actually as you're building your own firmware you could look at what Bangle.js does with spiflash to actually move all storage onto the flash memory

  • to actually move all storage onto the flash memory

    Was thinking about actually move only some storage to external memory. How easy is to have code in Storage in internal flash and then have second instance of Storage object/module for data in external SPI memory? Or maybe have one Storage but multiple drives or paths like ".boot0" in internal as before and "ext:data.bin" or "ext/data.bin" in external? But two instances like e.g. SPI objects could be easier - just a flag which one it is. I guess modules cannot have parameters like require.("Storage","internal") or require("Storage")("internal") like described here?

    Idea is that code is relatively small and can run in-place in internal flash but data can be large. Also running code in internal flash may draw less power when javascript source is not continuously interpreted by reading over SPI.

  • Assuming not just straight forward as updating start address in Linker script?

    If uploading over SWD then basically yes, look how banglejs is done.

    With only using DFU package it is more complicated to install such moved bootloader. You first need custom build of espruino with one more line added to as per comment here then you need to erase UICR area in NRF.onRestart method, write bootloader via espruino Flash module and then write new bootloader location to UICR. I have done it few days ago, several times, have scripts for this. Not hard and not even that much dangerous unless the bootloader binary you flash is not working.

    This was all only about moving bootloader, downgrading SDK is more complex if you need bootloader as there is no bootloader for SDK11 in espruino source so you need to get another one, e.g. from nordic examples. Without bootloader, with SWD flashing it is quite easy as the source builds as is with this extracted and you get 12+32KB

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

TensorFlow lite for the MDBT42Q 2v04

Posted by Avatar for user106664 @user106664

Actions