Update Zephyr target to 2.7.0 (#4838)

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs roland.takacs@h-lab.eu
This commit is contained in:
Roland Takacs
2021-12-02 15:33:29 +01:00
committed by GitHub
parent d69ac0e070
commit a1c1d42710
9 changed files with 553 additions and 329 deletions
+78 -77
View File
@@ -1,128 +1,129 @@
### About
This folder contains files to integrate JerryScript with Zephyr RTOS
(https://zephyrproject.org/).
This folder contains files to run JerryScript on
[STM32F4-Discovery board](https://www.st.com/en/evaluation-tools/stm32f4discovery.html) with
[Zephyr](https://zephyrproject.org/).
The document had been validated on Ubuntu 20.04 operating system.
### How to build
#### 1. Setup the build environment
#### 1. Preface
Clone the necessary projects into a `jerry-zephyr` directory.
The latest tested working version of Zephyr is `v2.7.0`.
1. Directory structure
```sh
mkdir jerry-zephyr && cd jerry-zephyr
Assume `harmony` as the path to the projects to build.
The folder tree related would look like this.
git clone https://github.com/jerryscript-project/jerryscript.git
git clone https://github.com/zephyrproject-rtos/zephyr -b v2.7.0
# Zephyr requires its toolchain.
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.13.2/zephyr-toolchain-arm-0.13.2-linux-x86_64-setup.run
```
The following directory structure has been created:
```
harmony
jerry-zephyr
+ jerryscript
| + targets
| + zephyr
+ zephyr-project
| + zephyr
+ zephyr
+ zephyr-toolchain-arm-0.13.2-linux-x86_64-setup.run
```
#### 2. Install dependencies of the projects
2. Target boards/emulations
```sh
# Assuming you are in jerry-zephyr folder.
jerryscript/tools/apt-get-install-deps.sh
Following Zephyr boards are known to work: qemu_x86, qemu_cortex_m3,
frdm_k64f. But generally, any board supported by Zephyr should work,
as long as it has enough Flash and RAM (boards which don't have
enough of those, will simply have link-time errors of ROM/RAM
overflow).
# Tool dependencies of Zephyr.
sudo apt install --no-install-recommends \
git cmake ninja-build gperf ccache dfu-util device-tree-compiler \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel \
xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev
# Install Python dependencies of Zephyr.
pip3 install --user -r zephyr/scripts/requirements.txt
#### 2. Prepare Zephyr
Follow [this](https://www.zephyrproject.org/doc/getting_started/getting_started.html) page to get
the Zephyr source and configure the environment.
If you just start with Zephyr, you may want to follow "Building a Sample
Application" section in the doc above and check that you can flash your
target board.
Remember to source the Zephyr environment as explained in the zephyr documentation:
```
cd zephyr-project
source zephyr-env.sh
export ZEPHYR_GCC_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory>
# Install Zephyr toolchain.
chmod +x zephyr-toolchain-arm-0.13.2-linux-x86_64-setup.run
./zephyr-toolchain-arm-0.13.2-linux-x86_64-setup.run -- -y -d ${PWD}/zephyr-toolchain-0.13.2
```
#### 3. Build JerryScript for Zephyr QEMU
Note: CMake 3.20 is required. If the installed CMake is older, upgrade it for example [this way](https://apt.kitware.com/).
The easiest way is to build and run on a QEMU emulator:
For x86 architecture:
#### 3. Initialize west meta-tool for Zephyr
```
make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_x86 run
# Assuming you are in jerry-zephyr folder.
west init -l zephyr
west update hal_stm32 cmsis
west zephyr-export
```
For ARM (Cortex-M) architecture:
#### 4. Build Zephyr (with JerryScript)
```
make -f ./targets/zephyr/Makefile.zephyr BOARD=qemu_cortex_m3 run
# Assuming you are in jerry-zephyr folder.
west build -p auto -b stm32f4_disco jerryscript/targets/zephyr/
```
#### 4. Build for a real board
The created binary is a `zephyr.elf` named file located in `jerry-zephyr/build/zephyr/bin/` folder.
Below, we build for NXP FRDM-K64F board (`frdm_k64f` Zephyr board
identifier). Building for other boards is similar. You are expected
to read [Supported Boards](https://docs.zephyrproject.org/latest/boards/index.html)
section in the Zephyr documentation for more information about
Zephyr's support for a particular board, means to flash binaries,
etc.
#### 5. Flash
Install `udev` rules which allows to flash STM32F4-Discovery as a regular user:
```
# assuming you are in top-level folder
cd jerryscript
make -f ./targets/zephyr/Makefile.zephyr BOARD=frdm_k64f
# Assuming you are in jerry-zephyr folder.
sudo cp zephyr-toolchain-0.13.2/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload
```
At the end of the build, you will be given a path to and stats about
the ELF binary:
Connect Mini-USB for charging and flasing the device.
```
...
Finished
text data bss dec hex filename
117942 868 24006 142816 22de0 build/frdm_k64f/zephyr/zephyr/zephyr.elf
# Assuming you are in jerry-zephyr folder.
west flash
```
Flashing the binary depends on a particular board used (see links above).
For the FRDM-K64F used as the example, you should copy the *raw* binary
file corresponding to the ELF file above (at
`build/frdm_k64f/zephyr/zephyr/zephyr.bin`) to the USB drive appearing
after connecting the board to a computer:
#### 6. Connect to the device
Use `USB To TTL Serial Converter` for serial communication. STM32F4-Discovery pins are mapped by Zephyr as follows:
```
cp build/frdm_k64f/zephyr/zephyr/zephyr.bin /media/pfalcon/DAPLINK/
STM32f4-Discovery PA2 pin is configured for TX.
STM32f4-Discovery PA3 pin is configured for RX.
```
To interact with JerryScript, connect to a board via serial connection
and press Reset button (you first should wait while LEDs on the board
stop blinking). For `frdm_k64f`:
* Connect `STM32f4-Discovery` **PA2** pin to **RX** pin of `USB To TTL Serial Converter`
* Connect `STM32f4-Discovery` **PA3** pin to **TX** pin of `USB To TTL Serial Converter`
* Connect `STM32f4-Discovery` **GND** pin to **GND** pin of `USB To TTL Serial Converter`
```
picocom -b115200 /dev/ttyACM0
The device should be visible as `/dev/ttyUSB0`. Use `minicom` communication program with `115200`.
* In `minicom`, set `Add Carriage Ret` to `off` in by `CTRL-A -> Z -> U` key combinations.
* In `minicom`, set `Hardware Flow Control` to `no` by `CTRL-A -> Z -> O -> Serial port setup -> F` key combinations.
```sh
sudo minicom --device=/dev/ttyUSB0 --baud=115200
```
You should see something similar to this:
Press `RESET` on the board to get the initial message with JerryScript command prompt:
```
JerryScript build: Aug 11 2021 16:03:07
*** Booting Zephyr OS build v2.7.99-1786-ga08b65ef42db ***
JerryScript build: Nov 25 2021 14:17:17
JerryScript API 3.0.0
Zephyr version 2.6.99
Zephyr version 2.7.99
js>
```
Run the example javascript command test function
```
js> var test=0; for (t=100; t<1000; t++) test+=t; print ('Hi JS World! '+test);
Hi JS World! 494550
```
Run the following JavaScript example:
Try a more complex function:
```
js> function hello(t) {t=t*10;return t}; print("result"+hello(10.5));
js> var test = 0; for (t = 100; t < 1000; t++) test += t; print ('Hello World! ' + test);
Hello World! 494550
undefined
```