Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active January 9, 2020 09:06
Show Gist options
  • Select an option

  • Save mfikes/a649ee58b3e9d5c8ecb91f3dbc6be224 to your computer and use it in GitHub Desktop.

Select an option

Save mfikes/a649ee58b3e9d5c8ecb91f3dbc6be224 to your computer and use it in GitHub Desktop.

Revisions

  1. mfikes revised this gist Dec 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@ espruino out/main.js

    and confirming that it prints `3`.

    > Note: Espruino doesn't support JavaScript labels, wich GCC will emit along with `break` statements to these labels. These often look like `a:` and `break a` in the code. It turns out, this doesn't affect the above code. If you encounter this issue, it will look like `Uncaught SyntaxError: Got ':' expected EOF` in Espruino.
    > Note: Espruino doesn't [support JavaScript labels](https://github.com/espruino/Espruino/issues/434), which GCC will emit along with `break` statements to these labels. These often look like `a:` and `break a` in the code. It turns out, this doesn't affect the above code. If you encounter this issue, it will look like `Uncaught SyntaxError: Got ':' expected EOF` in Espruino.
    ## Create JavaScript Boot ROM Binary

  2. mfikes revised this gist Dec 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@ espruino out/main.js

    and confirming that it prints `3`.

    > Note: Espruino doesn't support JavaScript labels, wich GCC will emit along with `break` statements to these labels. These often look like `a:` and `break a` in the code. It turns out, this doesn't affect the above code.
    > Note: Espruino doesn't support JavaScript labels, wich GCC will emit along with `break` statements to these labels. These often look like `a:` and `break a` in the code. It turns out, this doesn't affect the above code. If you encounter this issue, it will look like `Uncaught SyntaxError: Got ':' expected EOF` in Espruino.
    ## Create JavaScript Boot ROM Binary

  3. mfikes revised this gist Dec 5, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@

    You can load ClojureScript `:advanced` code directly into an ESP32 WROVER running Espruino for execution upon boot, by creating a binary and flashing it to the JavaScript "boot ROM" area. This has the same effect as when loading code via the Espruino Web IDE, in the "Direct to Flash (execute code at boot)" mode, but flashing is much quicker and more reliable.

    > Note: To do this, you'll need an ESP32 WROVER with SPI PSRAM, as opposed to just a WROOM, as the ClojureScript in this example uses more RAM than is available in the WROOM.
    ## Create `:advanced` Code

    Here is a small program that uses enough to pull in data structures, etc, leading to nearly 100 KiB:
  4. mfikes revised this gist Dec 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Loading `:advanced` Code into an Unmodified WROVER running Espruino

    You can load ClojureScript `:advanced` code directly into an ESP32 WROVER for execution upon boot, by creating a binary and flashing it to the JavaScript "boot ROM" area. This has the same effect as when loading code via the Espruino Web IDE, in the "Direct to Flash (execute code at boot)" mode, but flashing is much quicker and more reliable.
    You can load ClojureScript `:advanced` code directly into an ESP32 WROVER running Espruino for execution upon boot, by creating a binary and flashing it to the JavaScript "boot ROM" area. This has the same effect as when loading code via the Espruino Web IDE, in the "Direct to Flash (execute code at boot)" mode, but flashing is much quicker and more reliable.

    ## Create `:advanced` Code

  5. mfikes revised this gist Dec 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Loading `:advanced` Code into an Unmodified WROVER
    # Loading `:advanced` Code into an Unmodified WROVER running Espruino

    You can load ClojureScript `:advanced` code directly into an ESP32 WROVER for execution upon boot, by creating a binary and flashing it to the JavaScript "boot ROM" area. This has the same effect as when loading code via the Espruino Web IDE, in the "Direct to Flash (execute code at boot)" mode, but flashing is much quicker and more reliable.

  6. mfikes revised this gist Dec 5, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -64,6 +64,8 @@ esptool.py --chip esp32 --port PORT write_flash 0x2C0000 main.bin

    In the above, replace `PORT` with your WROVER's serial port (something like `/dev/cu.wchusbserial620`).

    Also note that, in the above, `0x2C0000` is the address for the JavaScript BOOT ROM code (`js_code` per the [partition table](https://github.com/espruino/EspruinoBuildTools/blob/master/esp32/build/app/partitions_espruino.csv)).

    ## Connect to Your ESP32 WROVER and Confirm

    If you connect with the Espruino Web IDE or some other tool (say, `screen`), then you should see that your Espruino has printed `3`.
  7. mfikes revised this gist Dec 5, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,8 @@ espruino out/main.js

    and confirming that it prints `3`.

    > Note: Espruino doesn't support JavaScript labels, wich GCC will emit along with `break` statements to these labels. These often look like `a:` and `break a` in the code. It turns out, this doesn't affect the above code.
    ## Create JavaScript Boot ROM Binary

    In the above example `wc -c out/main.js` shows that the file is `96503` bytes.
  8. mfikes revised this gist Dec 5, 2019. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -66,4 +66,16 @@ In the above, replace `PORT` with your WROVER's serial port (something like `/de

    If you connect with the Espruino Web IDE or some other tool (say, `screen`), then you should see that your Espruino has printed `3`.

    If you press the hardware reboot button on your ESP32, you shold see that it reboots, loads the `:advanced` ClojureSript and executes it, printing `3` again in about 4 seconds.
    If you press the hardware reboot button on your ESP32, you shold see that it reboots, loads the `:advanced` ClojureSript and executes it, printing `3` again in about 4 seconds.

    Here are some memory diagnostics from the ESP32 after this:

    ```shell
    >process.memory()
    ={ free: 13500, usage: 6500, total: 20000, history: 0,
    gc: 0, gctime: 121.427 }
    >ESP32.getState()
    ={
    sdkVersion: "v3.1.3-dirty",
    freeHeap: 2629804, BLE: true, Wifi: true, minHeap: 2627732 }
    ```
  9. mfikes revised this gist Dec 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -66,4 +66,4 @@ In the above, replace `PORT` with your WROVER's serial port (something like `/de

    If you connect with the Espruino Web IDE or some other tool (say, `screen`), then you should see that your Espruino has printed `3`.

    If you press the hardware reboot button on your ESP32, you shold see that it reboots, loads the `:advanced` ClojureSript and executes it, printing `3` again, within, say 5 seconds.
    If you press the hardware reboot button on your ESP32, you shold see that it reboots, loads the `:advanced` ClojureSript and executes it, printing `3` again in about 4 seconds.
  10. mfikes revised this gist Dec 5, 2019. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -60,4 +60,10 @@ cat header.bin out/main.js > main.bin
    esptool.py --chip esp32 --port PORT write_flash 0x2C0000 main.bin
    ```

    In the above, replace `PORT` with your WROVER's serial port (something like `/dev/cu.wchusbserial620`).
    In the above, replace `PORT` with your WROVER's serial port (something like `/dev/cu.wchusbserial620`).

    ## Connect to Your ESP32 WROVER and Confirm

    If you connect with the Espruino Web IDE or some other tool (say, `screen`), then you should see that your Espruino has printed `3`.

    If you press the hardware reboot button on your ESP32, you shold see that it reboots, loads the `:advanced` ClojureSript and executes it, printing `3` again, within, say 5 seconds.
  11. mfikes revised this gist Dec 5, 2019. No changes.
  12. mfikes revised this gist Dec 5, 2019. No changes.
  13. mfikes revised this gist Dec 5, 2019. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -57,5 +57,7 @@ cat header.bin out/main.js > main.bin
    ## Flash the Boot ROM To your Espruino WROVER

    ```shell
    esptool.py --chip esp32 --port /dev/cu.wchusbserial620 write_flash 0x2C0000 main.bin
    ```
    esptool.py --chip esp32 --port PORT write_flash 0x2C0000 main.bin
    ```

    In the above, replace `PORT` with your WROVER's serial port (something like `/dev/cu.wchusbserial620`).
  14. mfikes revised this gist Dec 5, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -52,4 +52,10 @@ Concatenate this header with your `:advanced` JavaScript to create the boot ROM

    ```shell
    cat header.bin out/main.js > main.bin
    ```

    ## Flash the Boot ROM To your Espruino WROVER

    ```shell
    esptool.py --chip esp32 --port /dev/cu.wchusbserial620 write_flash 0x2C0000 main.bin
    ```
  15. mfikes revised this gist Dec 5, 2019. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -46,4 +46,10 @@ Create the first 16 bytes of the boot ROM in a file that has the size of the fil
    00000000 f7 78 01 00 ff ff ff ff 2e 62 6f 6f 74 63 64 65 |.x.......bootcde|
    ```

    Note that, in the above `f7 78 01 00` is little-endian for `0x000178f7`, the file size `96503` in decimal.
    Note that, in the above `f7 78 01 00` is little-endian for `0x000178f7`, the file size `96503` in decimal.

    Concatenate this header with your `:advanced` JavaScript to create the boot ROM binary:

    ```shell
    cat header.bin out/main.js > main.bin
    ```
  16. mfikes revised this gist Dec 5, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -46,3 +46,4 @@ Create the first 16 bytes of the boot ROM in a file that has the size of the fil
    00000000 f7 78 01 00 ff ff ff ff 2e 62 6f 6f 74 63 64 65 |.x.......bootcde|
    ```

    Note that, in the above `f7 78 01 00` is little-endian for `0x000178f7`, the file size `96503` in decimal.
  17. mfikes revised this gist Dec 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ and confirming that it prints `3`.

    In the above example `wc -c out/main.js` shows that the file is `96503` bytes.

    Create the first 16 bytes of the boot ROM in a file that has the size of the file as the first word followed by a word of all `FF`s and then the ASCII for `.bootcde`. If you create this in a file named `header.bin` it will have contents that look like the follwoing:
    Create the first 16 bytes of the boot ROM in a file that has the size of the file as the first word followed by a word of all `FF`s and then the ASCII for `.bootcde`. If you create this in a file named `header.bin` it will have contents that look like the following:

    ```
    00000000 f7 78 01 00 ff ff ff ff 2e 62 6f 6f 74 63 64 65 |.x.......bootcde|
  18. mfikes revised this gist Dec 5, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -40,5 +40,9 @@ and confirming that it prints `3`.

    In the above example `wc -c out/main.js` shows that the file is `96503` bytes.

    Create the first 16 bytes of the boot ROM in a file that has the size of the file as the first word followed by a word of all `FF`s and then the ASCII for `.bootcde`.
    Create the first 16 bytes of the boot ROM in a file that has the size of the file as the first word followed by a word of all `FF`s and then the ASCII for `.bootcde`. If you create this in a file named `header.bin` it will have contents that look like the follwoing:

    ```
    00000000 f7 78 01 00 ff ff ff ff 2e 62 6f 6f 74 63 64 65 |.x.......bootcde|
    ```

  19. mfikes revised this gist Dec 5, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -40,3 +40,5 @@ and confirming that it prints `3`.

    In the above example `wc -c out/main.js` shows that the file is `96503` bytes.

    Create the first 16 bytes of the boot ROM in a file that has the size of the file as the first word followed by a word of all `FF`s and then the ASCII for `.bootcde`.

  20. mfikes revised this gist Dec 5, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -36,5 +36,7 @@ espruino out/main.js

    and confirming that it prints `3`.

    ## Create JavaScript Boot ROM Binary

    In the above example `wc -c out/main.js` shows that the file is `96503` bytes.

  21. mfikes revised this gist Dec 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ compile this program via
    clj -m cljs.main -co '{:process-shim false}' -O advanced -c foo.core
    ```

    Confirm that Espruino can run the resulting Javascript by executing
    Confirm that Espruino can run the resulting JavaScript by executing

    ```shell
    espruino out/main.js
  22. mfikes revised this gist Dec 5, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Loading `:advanced` Code into an Unmodified WROVER

    You can load ClojureScript `:advanced` code directly into an ESP32 WROVER for execution upon boot, by creating a binary and flashing it to the JavaScript "boot ROM" area. This has the same effect as when loading code via the Espruino Web IDE, in the "Direct to Flash (execute code at boot)" mode, but flashing is much quicker and more reliable.

    ## Create `:advanced` Code

    Here is a small program that uses enough to pull in data structures, etc, leading to nearly 100 KiB:
  23. mfikes revised this gist Dec 5, 2019. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -25,3 +25,14 @@ compile this program via
    ```shell
    clj -m cljs.main -co '{:process-shim false}' -O advanced -c foo.core
    ```

    Confirm that Espruino can run the resulting Javascript by executing

    ```shell
    espruino out/main.js
    ```

    and confirming that it prints `3`.



  24. mfikes revised this gist Dec 5, 2019. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -14,3 +14,14 @@ Here is a small program that uses enough to pull in data structures, etc, leadin
    (js/print (reduce + (vals m)))
    ```

    With `deps.edn`:

    ```clojure
    {:deps {org.clojure/clojurescript {:mvn/version "1.10.597"}}}
    ```

    compile this program via

    ```shell
    clj -m cljs.main -co '{:process-shim false}' -O advanced -c foo.core
    ```
  25. mfikes revised this gist Dec 5, 2019. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,13 @@

    Here is a small program that uses enough to pull in data structures, etc, leading to nearly 100 KiB:

    `src/foo/core.cljs`:

    ```clojure
    (ns foo.core)

    (def m {:a 1, :b 2})

    (js/print (reduce + (vals m)))
    ```
    ```

  26. mfikes created this gist Dec 5, 2019.
    13 changes: 13 additions & 0 deletions ESP32-wrover-cljs-advanced.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # Loading `:advanced` Code into an Unmodified WROVER

    ## Create `:advanced` Code

    Here is a small program that uses enough to pull in data structures, etc, leading to nearly 100 KiB:

    ```clojure
    (ns foo.core)

    (def m {:a 1, :b 2})

    (js/print (reduce + (vals m)))
    ```