Default startup code in Espruino binary

Posted on
  • Hi, I use Espruino to teach children programming and robotics and recently I got an idea that it would be cool to program boards over Bluetooth or wifi. So I purchased HC-06 Bluetooth module and tested it. It is working fluently and without any issues but I want to be able to program over USB too. To solve this I created simple startup code to switch default console to Serial6 when a specific button is pressed. The boot code is as follows:

    if(digitalRead(BTN2)){Serial6.setConsole­();}
    

    Unfortunately, I can't set the Serial6 default while compiling because it can be used for programming or for data transfer to the loaded application.

    I also sometimes have to repair the boards by reflashing them. Therefore the boot code is lost and must be written again.

    My question is if it is possible to create boot code, which will be included in the binary itself? I dig in the code and I found symbols which are used for storing the boot code in memory, but I do not know, how to add my code to it.

    If anyone could give me some advice, I will be glad.
    Best regards,
    Tomas

  • Hi - I'm not sure which board you're using, but you could possibly use E.setBootCode('...',true) with your code, then could just read the data out of flash and then write that file to all the other boards?

    If you're building yourself why not just add 'default_console' : "EV_SERIAL6", in the board.py file?

    ... to add your own code you'd be better off adding your own library - for example the Wio LTE executes JS this way: https://github.com/espruino/Espruino/blo­b/master/libs/wio_lte/jswrap_wio_lte.c#L­150

  • Hi Gordon,
    thanks for a reply.
    Well, I could just read the flash, but when I merge your changes or reflash the board the command you suggested I have to run after flashing or I have to write memory by a programmer. But this I could automate with this command for example echo "E.setBootCode('...',true)" > /dev/ttyACM0

    If you're building yourself why not just add 'default_console' : "EV_SERIAL6", in the board.py file?

    I can't set it because when I unplug the USB, the console will switch and in an application which uses Bluetooth or wifi module the transported data will be evaluated by Espruino and not by application. Right?

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

Default startup code in Espruino binary

Posted by Avatar for TomasJ @TomasJ

Actions