From 6692de9e80725c3c8a40c6913f12d7b463f3e871 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Thu, 6 Aug 2020 11:55:42 +0200 Subject: [PATCH] changes to frozen --- content/advance/frozen.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/content/advance/frozen.md b/content/advance/frozen.md index 5dd4e5a..cc0bcd4 100644 --- a/content/advance/frozen.md +++ b/content/advance/frozen.md @@ -5,24 +5,21 @@ In this section, we discuss the usage of so called `Frozen` code. This is only u What we call `Frozen` code, relates to a principle in MicroPython where you can include specific codeblocks or python module inside the firmware, such that you do not have to manually upload them. This can be very useful if you have a specific section of code you want to include on all your devices, without manually uploading it every time and risk losing it when formatting the file system. -## How To use the Frozen section -1. Download the (latest) source code from our [Github Repository](https://github.com/pycom/pycom-micropython-sigfox) and extract the archive, or use the GitHub desktop tool. -2. Inside the folder `pycom-micropython-sigfox/esp32/frozen` you will find the `frozen` section. We already have frozen some of the python modules into the firmware, such as `sqnsupgrade.py` and `OTA.py`. -3. In here, you can also find `_main.py` and `_boot.py` files under `Base`. These are alternative `main.py` and `boot.py` files you can build into the source code, and they will run like you would expect. - > Note that if you add anything in the `_boot.py`, it will also run in safeboot mode, and you can only change it by reflashing the firmware. +## How To use the Frozen section (Without Pybytes) +1. Download the (latest) source code from our [Github Repository](https://github.com/pycom/pycom-micropython-sigfox) and extract the archive, or use the GitHub desktop tool. If you have never build firmware from the sourcecode before, you can find the setup guide on GitHub as well. - > The code already in `_boot.py` is pretty important to make the REPL show up, do not remove that - >```python - >import os - >from machine import UART - >os.dupterm(UART(0, 115200)) - >``` -4. For example add to the `_main.py`: +2. Inside the folder `pycom-micropython-sigfox/esp32/frozen` you will find the `frozen` section. We already have frozen some of the python modules into the firmware, such as `sqnsupgrade.py` and `OTA.py`. +3. In here, you can find the `_main.py` and `_boot.py` files in the `frozen/Base/` folder. These are similar to `main.py` and `boot.py` files you can build into the source code, with the exception that `_boot.py` will also run in safeboot mode. Moreover can only change the behaviour by rebuilding and reflashing the firmware. + > Note that if you add anything in the `_boot.py`, keep the code already in the boot file, as that enables the output to REPL. + + > When building firmware with `VARIANT=PYBYTES`, you can find the `_boot.py` and `_main.py` in the `frozen/Pybytes/` folder and the files in `Base` will **NOT** be used + +4. For example, add to the `_main.py`: ```python # _main.py print("Hello from _main.py") ``` -5. Now rebuild and reflashing the firmware. After reboot, the line will be printed in the REPL +5. Now rebuild and reflash the firmware. After reboot, the line will be printed in the REPL. 6. You can also add files to the `Custom` folder, in this example, we make a `Block.py` with the following code: ```python # block.py @@ -34,4 +31,6 @@ What we call `Frozen` code, relates to a principle in MicroPython where you can >>> from block import Block >>> Block() My Frozen codeblock - ``` \ No newline at end of file + ``` + +This concludes the section about Frozen code. You should now be able to include Frozen python code inside the firmware. \ No newline at end of file