Add support for Mbed-OS 6.15.0 (#4909)

The default Mbed OS device (STM32F4) had been changed to FRDM-K64F that is
supported by both Mbed OS 5 and Mbed OS 6 versions. Makefile had also been
modified to have a flash recipe.

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs roland.takacs@h-lab.eu
This commit is contained in:
Roland Takacs
2022-02-22 10:29:07 +01:00
committed by GitHub
parent d00f4810b0
commit c9e9f8e818
9 changed files with 125 additions and 117 deletions
+1
View File
@@ -0,0 +1 @@
.mbed
+73
View File
@@ -0,0 +1,73 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# default board: FRDM-K64F
BOARD ?= K64F
# defult toolchain
TOOLCHAIN ?= GCC_ARM
# path to jerryscript/targets/os/mbedos5
JERRY_TARGET_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# path to the root jerryscript directory
JERRY_ROOT_DIR = $(realpath $(JERRY_TARGET_DIR)/../../..)
# default build path
BUILD_DIR ?= $(JERRY_ROOT_DIR)/build/mbed-os
# default jerry heap size (in KB)
JERRY_HEAP_SIZE ?= 70
define MBED_CLI_FLAGS
--clean
--build $(BUILD_DIR)
--source $(MBED_OS_DIR)
--source $(JERRY_ROOT_DIR)
--source $(JERRY_TARGET_DIR)
--toolchain $(TOOLCHAIN)
--target $(BOARD)
--artifact-name mbedos
--macro JERRY_GLOBAL_HEAP_SIZE=$(JERRY_HEAP_SIZE)
endef
.PHONY: all
all: .build
.PHONY: clean
clean: .mbedignore-remove
rm -rf $(JERRY_ROOT_DIR)/build/mbed-os
.PHONY: flash
flash: .mbed-set-flash-flag .build
.PHONY: .mbed-set-flash-flag
.mbed-set-flash-flag:
$(eval MBED_CLI_FLAGS += --flash)
.PHONY: .build
.build: .mbedignore-copy .mbed-build .mbedignore-remove
.PHONY: .mbed-build
.mbed-build:
mbed config -G MBED_OS_DIR $(MBED_OS_DIR)
mbed compile $(strip $(MBED_CLI_FLAGS))
.PHONY: .mbedignore-copy
.mbedignore-copy:
cp mbedignore.txt $(JERRY_ROOT_DIR)/.mbedignore
.PHONY: .mbedignore-remove
.mbedignore-remove:
rm -f $(JERRY_ROOT_DIR)/.mbedignore
+38
View File
@@ -0,0 +1,38 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Default target for running the build test outside the Travis CI environment.
all:
$(MAKE) install
$(MAKE) script
## Targets for installing build dependencies of the Mbed OS JerryScript target.
install-mbedos:
git clone https://github.com/ARMmbed/mbed-os.git ../mbed-os -b mbed-os-6.15.0
# Deploy Mbed and install Mbed Python dependencies.
install-mbedos-deps:
pip install mbed-cli
pip install -r ../mbed-os/requirements.txt
install: install-mbedos install-mbedos-deps
## Targets for building Mbed OS with JerryScript.
# Build the firmware (Mbed OS with JerryScript).
script:
$(MAKE) -C targets/os/mbedos MBED_OS_DIR=$(realpath ../mbed-os)
+77
View File
@@ -0,0 +1,77 @@
### About
This folder contains files to run JerryScript on
[FRDM-K64F board](https://os.mbed.com/platforms/frdm-k64f/) with
[Mbed OS](https://os.mbed.com/).
The document had been validated on Ubuntu 20.04 operating system.
#### 1. Setup the build environment
Clone the necessary projects into a `jerry-mbedos` directory.
The latest tested working version of Mbed is `mbed-os-6.15.0`.
```sh
mkdir jerry-mbedos && cd jerry-mbedos
git clone https://github.com/jerryscript-project/jerryscript.git
git clone https://github.com/ARMmbed/mbed-os.git -b mbed-os-6.15.0
```
The following directory structure has been created:
```
jerry-mbedos
+ jerryscript
| + targets
| + os
| + mbedos
+ mbed-os
```
#### 2. Install dependencies of the projects
```sh
# Assuming you are in jerry-mbedos folder.
jerryscript/tools/apt-get-install-deps.sh
sudo apt install stlink-tools
pip install --user mbed-cli
# Install Python dependencies of Mbed OS.
pip install --user -r mbed-os/requirements.txt
```
#### 3. Build Mbed OS (with JerryScript)
```
# Assuming you are in jerry-mbedos folder.
make -C jerryscript/targets/os/mbedos MBED_OS_DIR=${PWD}/mbed-os
```
The created binary is a `mbedos.bin` named file located in `jerryscript/build/mbed-os` folder.
#### 4. Flash
Connect Micro-USB for charging and flashing the device.
```
# Assuming you are in jerry-mbedos folder.
make -C jerryscript/targets/os/mbedos MBED_OS_DIR=${PWD}/mbed-os flash
```
#### 5. Connect to the device
The device should be visible as `/dev/ttyACM0` on the host.
You can use `minicom` communication program with `115200` baud rate.
```sh
sudo minicom --device=/dev/ttyACM0 --baud=115200
```
Set `Add Carriage Ret` option in `minicom` by `CTRL-A -> Z -> U` key combinations.
Press `RESET` on the board to get the output of JerryScript application:
```
This test run the following script code: [print ('Hello, World!');]
Hello, World!
```
+72
View File
@@ -0,0 +1,72 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jerryscript-port.h"
#include "jerryscript.h"
#include "jerryscript-ext/handlers.h"
#include "jerryscript-ext/properties.h"
#include "mbed.h"
/**
* Standalone Jerry exit codes
*/
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
#if MBED_MAJOR_VERSION == 5
static Serial serial(USBTX, USBRX, 115200);
#elif MBED_MAJOR_VERSION == 6
static BufferedSerial serial(USBTX, USBRX, 115200);
#else
#error Unsupported Mbed OS version.
#endif
int main()
{
/* Initialize engine */
jerry_init (JERRY_INIT_EMPTY);
const jerry_char_t script[] = "print ('Hello, World!');";
jerry_log (JERRY_LOG_LEVEL_DEBUG, "This test run the following script code: [%s]\n\n", script);
/* Register the print function in the global object. */
jerryx_register_global ("print", jerryx_handler_print);
/* Setup Global scope code */
jerry_value_t ret_value = jerry_parse (script, sizeof (script) - 1, NULL);
if (!jerry_value_is_exception (ret_value))
{
/* Execute the parsed source code in the Global scope */
ret_value = jerry_run (ret_value);
}
int ret_code = JERRY_STANDALONE_EXIT_CODE_OK;
if (jerry_value_is_exception (ret_value))
{
jerry_log (JERRY_LOG_LEVEL_ERROR, "[Error] Script Error!");
ret_code = JERRY_STANDALONE_EXIT_CODE_FAIL;
}
jerry_value_free (ret_value);
/* Cleanup engine */
jerry_cleanup ();
return ret_code;
}
+99
View File
@@ -0,0 +1,99 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include "jerryscript-port.h"
#include "mbed.h"
/**
* Aborts the program.
*/
void
jerry_port_fatal (jerry_fatal_code_t code)
{
exit ((int) code);
} /* jerry_port_fatal */
/**
* Provide log message implementation for the engine.
*/
void
jerry_port_log (const char *message_p) /**< message */
{
while (*message_p != '\0')
{
if (*message_p == '\n')
{
/* add CR for proper display in serial monitors */
fputc ('\r', stderr);
}
fputc (*message_p++, stderr);
}
} /* jerry_port_log */
/**
* Dummy function to get the time zone adjustment.
*
* @return 0
*/
int32_t
jerry_port_local_tza (double unix_ms)
{
(void) unix_ms;
return 0;
} /* jerry_port_local_tza */
/**
* Implementation of jerry_port_current_time.
*
* @return current timer's counter value in milliseconds
*/
double
jerry_port_current_time (void)
{
static uint64_t last_tick = 0;
static time_t last_time = 0;
static uint32_t skew = 0;
uint64_t curr_tick = us_ticker_read (); /* The value is in microseconds. */
time_t curr_time = time (NULL); /* The value is in seconds. */
double result = curr_time * 1000;
/* The us_ticker_read () has an overflow for each UINT_MAX microseconds
* (~71 mins). For each overflow event the ticker-based clock is about 33
* milliseconds fast. Without a timer thread the milliseconds part of the
* time can be corrected if the difference of two get_current_time calls
* are within the mentioned 71 mins. Above that interval we can assume
* that the milliseconds part of the time is negligibe.
*/
if (curr_time - last_time > (time_t) (((uint32_t) -1) / 1000000))
{
skew = 0;
}
else if (last_tick > curr_tick)
{
skew = (skew + 33) % 1000;
}
result += (curr_tick / 1000 - skew) % 1000;
last_tick = curr_tick;
last_time = curr_time;
return result;
} /* jerry_port_current_time */
+8
View File
@@ -0,0 +1,8 @@
cmake/*
docs/*
jerry-main/*
jerry-math/*
targets/*
tests/*
third-party/*
tools/*