diff --git a/.github/workflows/gh-actions.yml b/.github/workflows/gh-actions.yml index 2246caf19..70eefae94 100644 --- a/.github/workflows/gh-actions.yml +++ b/.github/workflows/gh-actions.yml @@ -225,7 +225,7 @@ jobs: $RUNNER -q --jerry-tests --build-debug --buildoptions=--toolchain=cmake/toolchain_linux_aarch64.cmake,--linker-flag=-static - MbedOS5_K64F_Build_Test: + MbedOS_K64F_Build_Test: runs-on: ubuntu-18.04 # needed due to ppa:team-gcc-arm-embedded/ppa steps: - uses: actions/checkout@v2 @@ -235,8 +235,8 @@ jobs: - run: sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa - run: sudo apt update - run: sudo apt install gcc-arm-embedded python3-setuptools mercurial - - run: make -f ./targets/os/mbedos5/Makefile.travis install - - run: make -f ./targets/os/mbedos5/Makefile.travis script + - run: make -f ./targets/os/mbedos/Makefile.travis install + - run: make -f ./targets/os/mbedos/Makefile.travis script Zephyr_STM32F4_Build_Test: runs-on: ubuntu-latest diff --git a/targets/os/mbedos5/.gitignore b/targets/os/mbedos/.gitignore similarity index 100% rename from targets/os/mbedos5/.gitignore rename to targets/os/mbedos/.gitignore diff --git a/targets/os/mbedos5/Makefile b/targets/os/mbedos/Makefile similarity index 61% rename from targets/os/mbedos5/Makefile rename to targets/os/mbedos/Makefile index ce495434c..76637925f 100644 --- a/targets/os/mbedos5/Makefile +++ b/targets/os/mbedos/Makefile @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# default board: STM32F4-Discovery -BOARD ?= DISCO_F407VG +# default board: FRDM-K64F +BOARD ?= K64F # defult toolchain TOOLCHAIN ?= GCC_ARM @@ -30,28 +30,44 @@ 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: .mbedignore-copy .mbed-build .mbedignore-remove +all: .build .PHONY: clean -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 \ - --clean \ - --build $(BUILD_DIR) \ - --source $(MBED_OS_DIR) \ - --source $(JERRY_ROOT_DIR) \ - --source $(JERRY_TARGET_DIR) \ - --toolchain $(TOOLCHAIN) \ - --target $(BOARD) \ - --macro JERRY_GLOBAL_HEAP_SIZE=$(JERRY_HEAP_SIZE) + mbed compile $(strip $(MBED_CLI_FLAGS)) +.PHONY: .mbedignore-copy .mbedignore-copy: - cp .mbedignore $(JERRY_ROOT_DIR) + cp mbedignore.txt $(JERRY_ROOT_DIR)/.mbedignore +.PHONY: .mbedignore-remove .mbedignore-remove: - rm $(JERRY_ROOT_DIR)/.mbedignore + rm -f $(JERRY_ROOT_DIR)/.mbedignore diff --git a/targets/os/mbedos5/Makefile.travis b/targets/os/mbedos/Makefile.travis similarity index 78% rename from targets/os/mbedos5/Makefile.travis rename to targets/os/mbedos/Makefile.travis index 0bb6067fe..b3a02d1c9 100644 --- a/targets/os/mbedos5/Makefile.travis +++ b/targets/os/mbedos/Makefile.travis @@ -19,10 +19,10 @@ all: $(MAKE) script -## Targets for installing build dependencies of the Mbed OS 5 JerryScript target. +## 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-5.15 + 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: @@ -31,8 +31,8 @@ install-mbedos-deps: install: install-mbedos install-mbedos-deps -## Targets for building Mbed OS 5 with JerryScript. +## Targets for building Mbed OS with JerryScript. -# Build the firmware (Mbed OS 5 with JerryScript). +# Build the firmware (Mbed OS with JerryScript). script: - $(MAKE) -C targets/os/mbedos5 BOARD=K64F MBED_OS_DIR=$(realpath ../mbed-os) + $(MAKE) -C targets/os/mbedos MBED_OS_DIR=$(realpath ../mbed-os) diff --git a/targets/os/mbedos/README.md b/targets/os/mbedos/README.md new file mode 100644 index 000000000..227f2add2 --- /dev/null +++ b/targets/os/mbedos/README.md @@ -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! +``` diff --git a/targets/os/mbedos5/jerry-main.cpp b/targets/os/mbedos/jerry-main.cpp similarity index 89% rename from targets/os/mbedos5/jerry-main.cpp rename to targets/os/mbedos/jerry-main.cpp index 43ee09b90..4db968513 100644 --- a/targets/os/mbedos5/jerry-main.cpp +++ b/targets/os/mbedos/jerry-main.cpp @@ -26,12 +26,16 @@ #define JERRY_STANDALONE_EXIT_CODE_OK (0) #define JERRY_STANDALONE_EXIT_CODE_FAIL (1) -int -main () -{ - Serial device (USBTX, USBRX); // tx, rx - device.baud (115200); +#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); diff --git a/targets/os/mbedos5/jerry-port.cpp b/targets/os/mbedos/jerry-port.cpp similarity index 100% rename from targets/os/mbedos5/jerry-port.cpp rename to targets/os/mbedos/jerry-port.cpp diff --git a/targets/os/mbedos5/.mbedignore b/targets/os/mbedos/mbedignore.txt similarity index 100% rename from targets/os/mbedos5/.mbedignore rename to targets/os/mbedos/mbedignore.txt diff --git a/targets/os/mbedos5/README.md b/targets/os/mbedos5/README.md deleted file mode 100644 index 79d865c50..000000000 --- a/targets/os/mbedos5/README.md +++ /dev/null @@ -1,89 +0,0 @@ -### About - -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. - -#### 1. Setup the build environment - -Clone the necessary projects into a `jerry-mbedos` directory. -The latest tested working version of Mbed is `5.15`. - -```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-5.15 -``` - -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! -```