Howto: Building the espruino code

Posted on
Page
of 2
Prev
/ 2
  • Regardless of the processor, as long as it's linux and you can install git, python and gcc, all you need to do is run:

    git clone https://github.com/espruino/Espruino.git­
    cd Espruino
    make
    

    (just like normal)

  • But what do you end up with? A firmware, an actual executable program ... ?

  • Yes, just a Linux executable that yo run with ./espruino

  • Brilliant, thanks. Hadn't tried that yet and sounds extremely helpful.

  • Just a quick FYI that current code compiles with no changes on Cygwin for Windows and so far is running perfectly. See http://conoroneill.net/run-the-espruino-­js-interpreter-on-windows/

  • That's great news - thanks! And thanks for the writeup :)

  • I am trying to compile the espruino source. Everything works fine under linux.
    However when I compile for the espruino board I get the following messages and compilation fails. I am using the latest version of codebench arm-2013.11-24-arm-none-eabi.
    Any ideas where I am going wrong?

    arthur@SZ71:~/Espruino$ ESPRUINO_1V3=1 make
    CC libs/fat_sd/spi_diskio.o
    CC libs/math/atanh.o
    CC libs/math/cbrt.o
    libs/math/cbrt.c:46:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration]
     const static double CBRT2  = 1.2599210498948731647672;
     ^
    libs/math/cbrt.c:47:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration]
     const static double CBRT4  = 1.5874010519681994747517;
     ^
    libs/math/cbrt.c:48:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration]
     const static double CBRT2I = 0.79370052598409973737585;
     ^
    libs/math/cbrt.c:49:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration]
     const static double CBRT4I = 0.62996052494743658238361;
     ^
    libs/math/atanh.c:46:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration]
     const static double P[] = {
     ^
    In file included from libs/fat_sd/spi_diskio.c:38:0:
    /home/arthur/Espruino/src/jshardware.h:2­53:38: error: unknown type name 'uint16_t'
     void jshSPIPush(IOEventFlags device, uint16_t data);
                                          ^
    libs/fat_sd/spi_diskio.c: In function 'stm32_spi_rw':
    libs/math/atanh.c:53:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration]
     const static double Q[] = {
     ^
    libs/math/atanh.c: In function 'atanh':
    libs/fat_sd/spi_diskio.c:100:24: error: 'SD_SPI' undeclared (first use in this function)
         int b = jshSPISend(SD_SPI, (unsigned char)out);
                            ^
    libs/fat_sd/spi_diskio.c:100:24: note: each undeclared identifier is reported only once for each function it appears in
    libs/fat_sd/spi_diskio.c: In function 'release_spi':
    libs/fat_sd/spi_diskio.c:70:38: error: 'SD_CS_PIN' undeclared (first use in this function)
     [#define](http://forum.espruino.com/sear­ch/?q=%23define) DESELECT()      jshPinOutput(SD_CS_PIN, 1)      /* MMC CS = H */
                                          ^
    libs/fat_sd/spi_diskio.c:154:2: note: in expansion of macro 'DESELECT'
      DESELECT();
      ^
    libs/fat_sd/spi_diskio.c: In function 'power_on':
    libs/fat_sd/spi_diskio.c:70:38: error: 'SD_CS_PIN' undeclared (first use in this function)
     [#define](http://forum.espruino.com/sear­ch/?q=%23define) DESELECT()      jshPinOutput(SD_CS_PIN, 1)      /* MMC CS = H */
                                          ^
    libs/fat_sd/spi_diskio.c:168:2: note: in expansion of macro 'DESELECT'
      DESELECT();
      ^
    libs/math/atanh.c:151:2: warning: passing argument 2 of 'polevl' discards 'const' qualifier from pointer target type [enabled by default]
      s = x   +  x * z * (polevl(z, P, 4) / p1evl(z, Q, 5));
      ^
    libs/math/atanh.c:118:15: note: expected 'void *' but argument is of type 'const double *'
     extern double polevl ( double x, void *P, int N );
                   ^
    libs/math/atanh.c:151:2: warning: passing argument 2 of 'p1evl' discards 'const' qualifier from pointer target type [enabled by default]
      s = x   +  x * z * (polevl(z, P, 4) / p1evl(z, Q, 5));
      ^
    libs/math/atanh.c:119:15: note: expected 'void *' but argument is of type 'const double *'
     extern double p1evl ( double x, void *P, int N );
                   ^
    libs/fat_sd/spi_diskio.c:173:16: error: 'SD_DO_PIN' undeclared (first use in this function)
      inf.pinMISO = SD_DO_PIN;
                    ^
    libs/fat_sd/spi_diskio.c:174:16: error: 'SD_DI_PIN' undeclared (first use in this function)
      inf.pinMOSI = SD_DI_PIN;
                    ^
    libs/fat_sd/spi_diskio.c:175:15: error: 'SD_CLK_PIN' undeclared (first use in this function)
      inf.pinSCK = SD_CLK_PIN;
                   ^
    libs/fat_sd/spi_diskio.c:177:14: error: 'SD_SPI' undeclared (first use in this function)
      jshSPISetup(SD_SPI, &inf);
                  ^
    libs/fat_sd/spi_diskio.c: In function 'power_off':
    libs/fat_sd/spi_diskio.c:69:38: error: 'SD_CS_PIN' undeclared (first use in this function)
     [#define](http://forum.espruino.com/sear­ch/?q=%23define) SELECT()        jshPinOutput(SD_CS_PIN, 0)    /* MMC CS = L */
                                          ^
    libs/fat_sd/spi_diskio.c:184:3: note: in expansion of macro 'SELECT'
       SELECT();
       ^
    libs/fat_sd/spi_diskio.c:192:14: error: 'SD_DO_PIN' undeclared (first use in this function)
      jshPinInput(SD_DO_PIN);
                  ^
    libs/fat_sd/spi_diskio.c:193:14: error: 'SD_DI_PIN' undeclared (first use in this function)
      jshPinInput(SD_DI_PIN);
                  ^
    libs/fat_sd/spi_diskio.c:194:14: error: 'SD_CLK_PIN' undeclared (first use in this function)
      jshPinInput(SD_CLK_PIN);
                  ^
    libs/fat_sd/spi_diskio.c: In function 'send_cmd':
    libs/fat_sd/spi_diskio.c:70:38: error: 'SD_CS_PIN' undeclared (first use in this function)
     [#define](http://forum.espruino.com/sear­ch/?q=%23define) DESELECT()      jshPinOutput(SD_CS_PIN, 1)      /* MMC CS = H */
                                          ^
    libs/fat_sd/spi_diskio.c:292:2: note: in expansion of macro 'DESELECT'
      DESELECT();
      ^
    libs/fat_sd/spi_diskio.c: In function 'disk_initialize':
    libs/fat_sd/spi_diskio.c:373:8: warning: conversion to 'DSTATUS' from 'int' may alter its value [-Wconversion]
       Stat &= ~STA_NOINIT;  /* Clear STA_NOINIT */
            ^
    libs/fat_sd/spi_diskio.c: In function 'disk_ioctl':
    libs/fat_sd/spi_diskio.c:69:38: error: 'SD_CS_PIN' undeclared (first use in this function)
     [#define](http://forum.espruino.com/sear­ch/?q=%23define) SELECT()        jshPinOutput(SD_CS_PIN, 0)    /* MMC CS = L */
                                          ^
    libs/fat_sd/spi_diskio.c:526:4: note: in expansion of macro 'SELECT'
        SELECT();
        ^
    libs/fat_sd/spi_diskio.c:534:43: warning: conversion to 'WORD' from 'int' may alter its value [-Wconversion]
          csize = csd[9] + ((WORD)csd[8] << 8) + 1;
                                               ^
    libs/fat_sd/spi_diskio.c:537:71: warning: conversion to 'BYTE' from 'int' may alter its value [-Wconversion]
          n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2;
                                                                           ^
    libs/fat_sd/spi_diskio.c:538:79: warning: conversion to 'WORD' from 'int' may alter its value [-Wconversion]
          csize = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1;
                                                                                   ^
    libs/fat_sd/spi_diskio.c:563:82: warning: conversion to 'DWORD' from 'int' may change the sign of the result [-Wsign-conversion]
           *(DWORD*)buff = (((csd[10] & 63) << 1) + ((WORD)(csd[11] & 128) >> 7) + 1) << ((csd[13] >> 6) - 1);
                                                                                      ^
    libs/fat_sd/spi_diskio.c:565:58: warning: conversion to 'DWORD' from 'int' may change the sign of the result [-Wsign-conversion]
           *(DWORD*)buff = ((WORD)((csd[10] & 124) >> 2) + 1) * (((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1);
                                                              ^
    make: *** [libs/fat_sd/spi_diskio.o] Error 1
    make: *** Waiting for unfinished jobs....
    
  • Strange. Never seen this before... anyone else?

  • Problem solved. I had first compiled espruino to run on Linux.
    I then tried to compile for the espruino hardware. I have found that I need to give make the -B switch to recompile everything and then it works. I now get -

    GEN espruino_1v60_espruino_1r3.bin
    bash scripts/check_size.sh espruino_1v60_espruino_1r3.bin
    FAIL - size of 225996 is over 215040 bytes
    make: *** [espruino_1v60_espruino_1r3.bin] Error 1

    I guess I need to change some configuration files. I assumed espruino would have been the default.

    Also is it possible to program the espruino from the web IDE using a .bin file from the local file system?

  • There's a bit of info on this here: https://github.com/espruino/Espruino/blo­b/master/README.md#for-arm-boards-incl-e­spruino-board

    At the moment I use a very specific compiler to keep the code size down, and some other compilers push it up too much. It's not a big deal though - just change the Makefile to use -Os instead of -O3. You can still use the binary as it is too, it just means that save() won't work.

    Right now I don't think it is possible to use the Web IDE to program from the local filesystem. Also the code that you get from the compiler won't include the bootloader, so it needs to be written to a different address.

    BUT it's nice and easy from the makefile. Just put the board into bootloader mode and do ESPRUINO_1V3=1 make serialflash, and it'll program it for you.

  • I'm trying to build the Espruino on Linux...

    I've installed the codesourcery compiler, and I can run:

    ESPRUINO_1V3=1 make

    And I get a deluge of warnings. But at the end, it checks the size, and gives pass/fail depending on the compiler flags I use, and I get my .bin file.

    So everything's grand right?

    I pull the .bin file down from the linux system via SCP, put it in the root of my local webserver.

    I use the webIDE to flash it (pointed at http://127.0.0.1/espruino_1v63_espruino_­1r3.bin ). Flash goes normally and reports success.

    Then I press reset, and the blue and red LEDs stay on at about half brightness, and nothing else happens. Computer does not detect USB device. I can get it back into bootloader mode by mashing reset and btn1, and flash a working firmware to it, so that's not a problem.... but I'd like to be able to build Espruino firmwares myself.

    What am I doing wrong?

    I've tried with O3 and Os flags, and either way gives same result. This is using the code obtained via git clone https://github.com/espruino/Espruino.git­ - only thing I've changed is CCPREFIX in the makefile...

  • Right, you're basically sorted then! Try running scripts/create_espruino_image_1v3.sh and use the image file that it creates instead...

    The issue is that ESPRUINO_1V3=1 make builds the Espruino binary - but that sits after the bootloader (which is 10240 bytes). The images that the Web IDE expects are images of the complete memory, which contain the bootloader and the Espruino binary.

    If you can communicate with the board from the build environment, you should be able to just do ESPRUINO_1V3=1 make serialflash which will skip the bootloader bit and will just write the Espruino image directly to the correct address.

  • Oh sweet! I'll give that a try today!

  • Huzzah! It worked!

  • UPDATE: There is now a new instance

    I've got an Amazon Web Services AMI for building Espruino code, if anyone wants it. If you're familiar with AWS, using this will be a snap. If you've got linux machines at home and aren't familiar with AWS, this is probably more work :-P

    ami-7022c018
    

    From EC2 Control Panel:

    • Instances, click Launch Instance.
    • On left, choose "Community AMIs"
    • Search for ami-7022c018, and one result will show, select it.
    • On next screen, make sure Micro Instances is selected (these are cheapest - and eligible for free tier if you're in your first year of AWS).
    • Skip ahead to step 6: Configure security group. Make sure that port 22 is open for SSH, and nothing else is open.
    • Then launch the instance and select (or create, if you don't have one) the keypair for authentication (Click the help links on the keypair screen for more info - Amazon has a nice explanation of how these work). The instance will start deploying.
    • From EC2 control panel, choose Elastic IPs. Click Allocate New Address. Select that address, and click Associate Address, and select the instance you deployed above.
    • Connect to your instance via PuTTY (or equiv - again, see the keypair help if you don't know how to use the private key for authentication), transfer files using SCP (I use WinSCP). Username is ec2-user (the default for Amazon EC2 instances) and has sudo if you need it.

    Everything is then set up to build Espruino. You do not need to adjust the CCPREFIX or anything - though you may need to tweak the CCFLAGS in the Makefile (see above), plus making any changes you might need.

    Just do something like:

    git clone https://github.com/espruino/Espruino.git­
    cd Espruino
    scripts/scripts/create_espruino_image_1v­3.sh
    
  • @DrAzzy - this is awesome, thanks! It should make it a lot easier for people to get started!

    Would you mind if I stuck this in the build instructions that are on GitHub?

  • Go for it :)

  • Dear Espruino Fans,

    after some quick wins with my Espruino I thought "now let's use it for real things" and ordered some Wiznet LAN modules to get connected. Connecting the pins seems quite simple but I'm struggling quite some time to get the Firmware compiled.

    I used - like Gordon told - :
    git clone https://github.com/espruino/Espruino.git­
    cd Espruino
    make
    And this works, but (as http://www.espruino.com/WIZnet says)...
    WIZNET=1 RELEASE=1 ESPRUINO_1V3=1 make
    is not working.

    CC libs/filesystem/fat_sd/fattime.o make: arm-none-eabi-gcc: Command
    not found make: *** [libs/filesystem/fat_sd/fattime.o] Error 127

    I downloaded the Compiler from the first post of this thread (mentor.com/embedded-software/sourcery-t­ools/sourcery-codebench/editions/lite-ed­ition/).
    Now it builds correctly, but fails because it gets too big:

    LD espruino_1v68_espruino_1r3.elf GEN espruino_1v68_espruino_1r3.lst
    GEN espruino_1v68_espruino_1r3.bin bash scripts/check_size.sh
    espruino_1v68_espruino_1r3.bin FAIL - size of 224324 is over 215040
    bytes make: *** [espruino_1v68_espruino_1r3.bin] Error 1 make: ***
    Waiting for unfinished jobs.... Build failed

    I'd be happy if someone could help me figure out how to get WizNet LAN working on my Espruino.

    Best regards, Jack

  • Hi Jack,

    I should have updated the WIZnet docs, but there are pre-compiled WIZnet binaries under: http://www.espruino.com/binaries/

    Having said that, you're pretty close. I use a specific codesourcery compiler from that page (codesourcery-2013.05-23-arm-none-eabi) - and it makes the code small enough to go into the available memory.

    If you don't want to do that, edit the Makefile, scroll down to where it says ifdef ESPRUINO_1V3 and change the optimisation flags from -O3 to -Os - that'll optimise for size and that'll work too.

  • Dear Gordon,

    thanks very much for the great project and the quick answer. Fortunately I now have a working version.

    Maybe some hints for anyone struggling to make wiznet working:
    I have to tell it was a little more tricky than I had expected (my ubuntu phyton had no clue what serial Module is (so i had to sudo apt-get install python-pip and afterwards sudo pip install pyserial) to make all phyton dependencies working.
    That being said it was able to build the new firmware which I desperately put on a webserver in order to get an url to use for the ChromeApp Firmware Updater. Didn't work this way (and crashed Espruino), but was able to restore original firmware. Afterwards using make serialflash worked perfectly...

    http://www.espruino.com/WIZnet says to use dhcp you only need:

    eth.setIP();

    This didn't work for me (no connection was set up, there was an error "no sockets free" and App and Esprunio need a restart to work again afterwards), so I finally put in all params by hand (see below), which is my solution after some hours and a little bumpy ride this time.

    var eth = require("WIZnet").connect();
    eth.setIP({    
      ip: "192.168.0.205",   
      dns : "8.8.8.8",   
      subnet: "255.255.255.0",   
      gateway: "192.168.0.254"
    });
    
    setTimeout(function() {   
      console.log(eth.getIP());   
      var http = require("http");     
      http.createServer(function (req, res) {
        res.writeHead(200);
        res.end("Hello World, here may come some json!");   }).listen(80); 
    }, 10000);
    

    Thanks for all the hard work, maybe there is a little room for improvement to get wiznet Moduls working as easy as reading temperatures via ADC or the one-wire sensors (which is insanely genius) .

  • The reason the build you made first didn't work is that binaries flashed using the WebIDE need to have the bootloader included (the documentation doesn't hit you over the head with this like it ought to). Use the create_espruino_image_1v3.sh script

    Like this:

    WIZNET=1 ./scripts/create_espruino_image_1v3.sh
    

    I've not had the problem you do with setIP() not working - mine just works. I suspect it's down to different network conditions.

  • @DrAzzy: Thanks I'll definitely try your solution next time.
    Sure networking has lots of different conditions which adds many layers of possible issues. I'm glad it's that easy to set IP's manually though, which works under my circumstances.

  • There is now some better documentation about building with a VM at https://github.com/espruino/Espruino#bui­lding-under-windowsmacos-with-a-vm

    However @DrAzzy's Amazon EC2 Instance may still be easier if you don't want to do any big downloads.

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

Howto: Building the espruino code

Posted by Avatar for tickTock @tickTock

Actions