Separate targets into os and baremetal-sdk parts (#4842)
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs roland.takacs@h-lab.eu
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
# 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.
|
||||
|
||||
# application name
|
||||
APPLICATION = riot_jerryscript
|
||||
|
||||
# default BOARD enviroment
|
||||
BOARD ?= stm32f4discovery
|
||||
|
||||
# path to jerryscript/targets/os/riot
|
||||
TARGET_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
|
||||
# path to the JERRYSCRIPT directory
|
||||
JERRYDIR ?= $(TARGET_DIR)/../../..
|
||||
|
||||
# path to the RIOT base directory
|
||||
RIOTBASE ?= $(JERRYDIR)/../RIOT
|
||||
|
||||
# path to the application directory
|
||||
APPDIR ?= $(JERRYDIR)/targets/os/riot/source
|
||||
|
||||
# path to the binary directory
|
||||
BUILDDIR ?= $(JERRYDIR)/build/riot-stm32f4
|
||||
|
||||
# path to the binary directory
|
||||
BINDIR ?= $(BUILDDIR)/bin
|
||||
|
||||
# Change this to 0 show compiler invocation lines by default:
|
||||
QUIET ?= 1
|
||||
|
||||
INCLUDES += -I$(JERRYDIR)/jerry-core/include
|
||||
INCLUDES += -I$(JERRYDIR)/jerry-ext/include
|
||||
|
||||
ARCHIVES += $(JERRYDIR)/build/lib/libjerry-core.a
|
||||
ARCHIVES += $(JERRYDIR)/build/lib/libjerry-ext.a
|
||||
ARCHIVES += $(JERRYDIR)/build/lib/libjerry-port-default.a
|
||||
|
||||
USEMODULE += shell
|
||||
USEMODULE += shell_commands
|
||||
USEMODULE += posix_sleep
|
||||
|
||||
.PHONY: libjerry
|
||||
libjerry:
|
||||
$(JERRYDIR)/tools/build.py \
|
||||
--clean \
|
||||
--lto=OFF \
|
||||
--jerry-cmdline=OFF \
|
||||
--jerry-math=ON \
|
||||
--amalgam=ON \
|
||||
--mem-heap=70 \
|
||||
--profile=es.next \
|
||||
--compile-flag=-fshort-enums \
|
||||
--toolchain=$(abspath $(JERRYDIR)/cmake/toolchain_mcu_stm32f4.cmake)
|
||||
|
||||
.PHONY: clear-cflags
|
||||
clear-cflags:
|
||||
$(eval BACKUP := $(CFLAGS))
|
||||
$(eval CFLAGS := )
|
||||
|
||||
.PHONY: restore-cflags
|
||||
restore-cflags:
|
||||
$(eval CFLAGS := $(BACKUP))
|
||||
|
||||
# CFLAGS is filled by Makefile.include that is only for RIOT.
|
||||
# Clear CFLAGS temporarily while compiling JerryScript.
|
||||
all: clear-cflags libjerry restore-cflags
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
@@ -0,0 +1,40 @@
|
||||
# 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 RIOT JerryScript target.
|
||||
|
||||
# Install cross-compiler via apt.
|
||||
install-apt-get-deps:
|
||||
sudo apt-get install -q -y clang gcc-arm-embedded gcc-multilib
|
||||
|
||||
# Fetch RIOT OS repository.
|
||||
install-clone-riot:
|
||||
git clone git://github.com/RIOT-OS/RIOT.git ../RIOT -b 2021.10
|
||||
|
||||
# Perform all the necessary (JerryScript-independent) installation steps.
|
||||
install-noapt: install-clone-riot
|
||||
install: install-apt-get-deps install-noapt
|
||||
|
||||
## Targets for building RIOT with JerryScript.
|
||||
|
||||
# Build the firmware (RIOT with JerryScript).
|
||||
script:
|
||||
$(MAKE) -f ./targets/os/riot/Makefile
|
||||
@@ -0,0 +1,117 @@
|
||||
### About
|
||||
|
||||
This folder contains files to run JerryScript on
|
||||
[STM32F4-Discovery board](https://www.st.com/en/evaluation-tools/stm32f4discovery.html) with
|
||||
[RIOT](https://www.riot-os.org/).
|
||||
The document had been validated on Ubuntu 20.04 operating system.
|
||||
|
||||
### How to build
|
||||
|
||||
#### 1. Setup the build environment for STM32F4-Discovery board
|
||||
|
||||
Clone the necessary projects into a `jerry-riot` directory.
|
||||
The latest tested working version of RIOT is `2021.10`.
|
||||
|
||||
```sh
|
||||
# Create a base folder for all the projects.
|
||||
mkdir jerry-riot && cd jerry-riot
|
||||
|
||||
git clone https://github.com/jerryscript-project/jerryscript.git
|
||||
git clone https://github.com/RIOT-OS/RIOT.git -b 2021.10
|
||||
```
|
||||
|
||||
#### 2. Install dependencies of the projects
|
||||
|
||||
```
|
||||
# Assuming you are in jerry-riot folder.
|
||||
jerryscript/tools/apt-get-install-deps.sh
|
||||
|
||||
sudo apt install gcc-arm-none-eabi openocd minicom
|
||||
```
|
||||
|
||||
The following directory structure has been created:
|
||||
|
||||
```
|
||||
jerry-riot
|
||||
+ jerryscript
|
||||
| + targets
|
||||
| + os
|
||||
| + riot
|
||||
+ RIOT
|
||||
```
|
||||
|
||||
#### 3. Build RIOT (with JerryScript)
|
||||
|
||||
```
|
||||
# Assuming you are in jerry-riot folder.
|
||||
make BOARD=stm32f4discovery -f jerryscript/targets/os/riot/Makefile
|
||||
```
|
||||
|
||||
The created binary is a `riot_jerryscript.elf` named file located in `jerryscript/build/riot-stm32f4/bin/` folder.
|
||||
|
||||
#### 4. Flash the device
|
||||
|
||||
Connect Mini-USB for charging and flashing the device.
|
||||
|
||||
```
|
||||
# Assuming you are in jerry-riot folder.
|
||||
make BOARD=stm32f4discovery -f jerryscript/targets/os/riot/Makefile flash
|
||||
```
|
||||
|
||||
Note: `ST-LINK` also can be used that is described at [this page](https://github.com/RIOT-OS/RIOT/wiki/ST-LINK-tool).
|
||||
|
||||
#### 5. Connect to the device
|
||||
|
||||
Use `USB To TTL Serial Converter` for serial communication. STM32F4-Discovery pins are mapped by RIOT as follows:
|
||||
|
||||
```
|
||||
STM32f4-Discovery PA2 pin is configured for TX.
|
||||
STM32f4-Discovery PA3 pin is configured for RX.
|
||||
```
|
||||
|
||||
* 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`
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
RIOT prompt looks like as follows:
|
||||
|
||||
```
|
||||
main(): This is RIOT! (Version: 2021.10)
|
||||
You are running RIOT on a(n) stm32f4discovery board.
|
||||
This board features a(n) stm32 MCU.
|
||||
>
|
||||
```
|
||||
|
||||
You may have to press `RESET` on the board and press `Enter` key on the console several times to make RIOT prompt visible.
|
||||
|
||||
#### 6. Run JerrySript
|
||||
|
||||
Type `help` to list shell commands:
|
||||
|
||||
```
|
||||
> help
|
||||
Command Description
|
||||
---------------------------------------
|
||||
test Jerryscript Hello World test
|
||||
reboot Reboot the node
|
||||
version Prints current RIOT_VERSION
|
||||
pm interact with layered PM subsystem
|
||||
```
|
||||
|
||||
Type `test` to execute JerryScript:
|
||||
|
||||
```
|
||||
> test
|
||||
This test run the following script code: [print ('Hello, World!');]
|
||||
|
||||
Hello, World!
|
||||
```
|
||||
@@ -0,0 +1,117 @@
|
||||
/* 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 <string.h>
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#include "jerryscript-ext/handler.h"
|
||||
#include "shell.h"
|
||||
|
||||
/**
|
||||
* Standalone Jerry exit codes
|
||||
*/
|
||||
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
|
||||
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
|
||||
|
||||
/**
|
||||
* Register a JavaScript function in the global object.
|
||||
*/
|
||||
static void
|
||||
register_js_function (const char *name_p, /**< name of the function */
|
||||
jerry_external_handler_t handler_p) /**< function callback */
|
||||
{
|
||||
jerry_value_t result_val = jerryx_handler_register_global (name_p, handler_p);
|
||||
|
||||
if (jerry_value_is_exception (result_val))
|
||||
{
|
||||
printf ("Warning: failed to register '%s' method.", name_p);
|
||||
}
|
||||
|
||||
jerry_value_free (result_val);
|
||||
} /* register_js_function */
|
||||
|
||||
/**
|
||||
* Jerryscript simple test
|
||||
*/
|
||||
int
|
||||
test_jerry (int argc, char **argv)
|
||||
{
|
||||
/* Suppress compiler errors */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
jerry_value_t ret_value = jerry_undefined ();
|
||||
|
||||
const jerry_char_t script[] = "print ('Hello, World!');";
|
||||
printf ("This test run the following script code: [%s]\n\n", script);
|
||||
|
||||
/* Initialize engine */
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
/* Register the print function in the global object. */
|
||||
register_js_function ("print", jerryx_handler_print);
|
||||
|
||||
/* Setup Global scope code */
|
||||
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))
|
||||
{
|
||||
printf ("Script Error!");
|
||||
|
||||
ret_code = JERRY_STANDALONE_EXIT_CODE_FAIL;
|
||||
}
|
||||
|
||||
jerry_value_free (ret_value);
|
||||
|
||||
/* Cleanup engine */
|
||||
jerry_cleanup ();
|
||||
|
||||
return ret_code;
|
||||
|
||||
} /* test_jerry */
|
||||
|
||||
const shell_command_t shell_commands[] = { { "test", "Jerryscript Hello World test", test_jerry },
|
||||
{ NULL, NULL, NULL } };
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
union
|
||||
{
|
||||
double d;
|
||||
unsigned u;
|
||||
} now = { .d = jerry_port_get_current_time () };
|
||||
srand (now.u);
|
||||
printf ("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
|
||||
printf ("This board features a(n) %s MCU.\n", RIOT_MCU);
|
||||
|
||||
/* start the shell */
|
||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||
shell_run (shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user