Minimize mbedos5 target (#4905)

* Removed hardware specific implementations
  * Added simple 'hello world' demo code to be aligned to other targets
  * Added ability to use external resources from outside JerryScript folder

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs roland.takacs@h-lab.eu
This commit is contained in:
Roland Takacs
2021-12-15 12:52:40 +01:00
committed by GitHub
parent d650390e47
commit c51b268276
46 changed files with 248 additions and 2846 deletions
+82 -67
View File
@@ -1,74 +1,89 @@
# JerryScript with mbed OS 5
### About
TL;DR? jump straight to [quickstart](#quick-start)
This folder contains files to run JerryScript on
[STM32F4-Discovery board](https://www.st.com/en/evaluation-tools/stm32f4discovery.html) with
[Mbed OS 5](https://os.mbed.com/).
The document had been validated on Ubuntu 20.04 operating system.
## Introduction
#### 1. Setup the build environment
This directory contains the necessary code to build JerryScript for devices
capable of running mbed OS 5. It has been tested with the following boards
so far:
Clone the necessary projects into a `jerry-mbedos` directory.
The latest tested working version of Mbed is `5.15`.
- [Nordic Semiconductor NRF52 Development Kit](https://developer.mbed.org/platforms/Nordic-nRF52-DK/)
- [NXP Freedom K64F](https://developer.mbed.org/platforms/FRDM-K64F/)
- [STM NUCLEO F401RE](https://developer.mbed.org/platforms/ST-Nucleo-F401RE/)
- [Silicon Labs EFM32 Giant Gecko](https://developer.mbed.org/platforms/EFM32-Giant-Gecko/)
```sh
mkdir jerry-mbedos && cd jerry-mbedos
## Features
### Peripheral Drivers
Peripheral Drivers are intended as a 1-to-1 mapping to mbed C++ APIs, with a few
differences (due to differences between JavaScript and C++ like lack of operator
overloading).
- [DigitalOut](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/io/DigitalOut/)
- [InterruptIn](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/io/InterruptIn/)
- [I2C](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/interfaces/digital/I2C/)
- setInterval and setTimeout using [mbed-event](https://github.com/ARMmbed/mbed-events)
## Dependencies
### mbed CLI
mbed CLI is used as the build tool for mbed OS 5. You can find out how to install
it in the [official documentation](https://docs.mbed.com/docs/mbed-os-handbook/en/5.1/dev_tools/cli/#installing-mbed-cli).
### arm-none-eabi-gcc
arm-none-eabi-gcc is the only currently tested compiler for jerryscript on mbed,
and instructions for building can be found as part of the mbed-cli installation
instructions above.
### make
make is used to automate the process of fetching dependencies, and making sure that
mbed-cli is called with the correct arguments.
### nodejs
npm is used to install the dependencies in the local node_modules folder.
### gulp
gulp is used to automate tasks, like cloning repositories or generate source files.
If you create an own project, for more info see [mbed-js-gulp](https://github.com/ARMmbed/mbed-js-gulp).
### (optional) jshint
jshint is used to statically check your JavaScript code, as part of the build process.
This ensures that pins you are using in your code are available on your chosen target
platform.
## Quick Start
Once you have all of your dependencies installed, you can build the example project as follows:
```bash
git clone https://github.com/ARMmbed/mbed-js-example
cd mbed-js-example
npm install
gulp --target=YOUR_TARGET_NAME
git clone https://github.com/jerryscript-project/jerryscript.git
git clone https://github.com/ARMmbed/mbed-os.git -b mbed-os-5.15
```
The produced file (in build/out/YOUR_TARGET_NAME) can then be uploaded to your board, and will
run when you press reset.
The following directory structure has been created:
```
jerry-mbedos
+ jerryscript
| + targets
| + os
| + mbedos5
+ 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 mbed-cli
# Install Python dependencies of Mbed OS.
pip install --user -r mbed-os/requirements.txt
```
#### 4. Build Mbed OS (with JerryScript)
```
# Assuming you are in jerry-mbedos folder.
make -C jerryscript/targets/os/mbedos5 MBED_OS_DIR=${PWD}/mbed-os
```
The created binary is a `mbed-os.bin` named file located in `jerryscript/build/mbed-os` folder.
#### 5. Flash
Connect Mini-USB for charging and flashing the device.
```
# Assuming you are in jerry-riot folder.
sudo st-flash write jerryscript/build/mbed-os/mbed-os.bin 0x8000000
```
#### 6. Connect to the device
Use `USB To TTL Serial Converter` for serial communication. STM32F4-Discovery pins are mapped by Mbed OS 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
```
Press `RESET` on the board to get the output of JerryScript application:
```
This test run the following script code: [print ('Hello, World!');]
Hello, World!
```