This is an automated email from the ASF dual-hosted git repository. utzig pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 838cee6d153a9373dfe7f16ec0fd0dbe6eb8e8b5 Author: Casper Meijn <cas...@meijn.net> AuthorDate: Sat Aug 22 15:03:06 2020 +0200 apps/rust_blinky: Add blinky app using Rust language As explained in https://mynewt.apache.org/latest/tutorials/other/rust.html --- apps/rust_blinky/Cargo.toml | 27 ++++++++++++++++++++++ apps/rust_blinky/cargo_build.sh | 36 +++++++++++++++++++++++++++++ apps/rust_blinky/pkg.yml | 34 +++++++++++++++++++++++++++ apps/rust_blinky/src/lib.rs | 51 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) diff --git a/apps/rust_blinky/Cargo.toml b/apps/rust_blinky/Cargo.toml new file mode 100644 index 0000000..1c583ae --- /dev/null +++ b/apps/rust_blinky/Cargo.toml @@ -0,0 +1,27 @@ +# +# Copyright 2020 Casper Meijn <cas...@meijn.net> +# +# 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. +# + +[package] +name = "rust_blinky" +version = "0.1.0" +authors = ["Casper Meijn <cas...@meijn.net>"] +edition = "2018" + +[dependencies] +panic-halt = "0.2.0" + +[lib] +crate-type = ["staticlib"] diff --git a/apps/rust_blinky/cargo_build.sh b/apps/rust_blinky/cargo_build.sh new file mode 100755 index 0000000..2ae27a8 --- /dev/null +++ b/apps/rust_blinky/cargo_build.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -eu + +# +# Copyright 2020 Casper Meijn <cas...@meijn.net> +# +# 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. +# + +if [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m0"' ]]; then + TARGET="thumbv6m-none-eabi" +elif [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m3"' ]]; then + TARGET="thumbv7m-none-eabi" +elif [[ ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m4"' || ${MYNEWT_VAL_ARCH_NAME} == '"cortex_m7"' ]]; then + if [[ $MYNEWT_VAL_HARDFLOAT -eq 1 ]]; then + TARGET="thumbv7em-none-eabihf" + else + TARGET="thumbv7em-none-eabi" + fi +else + echo "The ARCH_NAME ${MYNEWT_VAL_ARCH_NAME} is not supported" + exit 1 +fi + +cargo build --target="${TARGET}" --target-dir="${MYNEWT_PKG_BIN_DIR}" +cp "${MYNEWT_PKG_BIN_DIR}"/${TARGET}/debug/*.a "${MYNEWT_PKG_BIN_ARCHIVE}" diff --git a/apps/rust_blinky/pkg.yml b/apps/rust_blinky/pkg.yml new file mode 100644 index 0000000..cace556 --- /dev/null +++ b/apps/rust_blinky/pkg.yml @@ -0,0 +1,34 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +pkg.name: "apps/rust_blinky" +pkg.type: app +pkg.description: "Example application which uses the Rust programming language" +pkg.author: "Apache Mynewt <d...@mynewt.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.pre_build_cmds: + './cargo_build.sh': 1 + +pkg.deps: + - "@apache-mynewt-core/kernel/os" + - "@apache-mynewt-core/sys/console/stub" + - "@apache-mynewt-core/sys/log/stub" + - "@apache-mynewt-core/sys/stats/stub" diff --git a/apps/rust_blinky/src/lib.rs b/apps/rust_blinky/src/lib.rs new file mode 100644 index 0000000..c36920f --- /dev/null +++ b/apps/rust_blinky/src/lib.rs @@ -0,0 +1,51 @@ +/* + * Copyright 2020 Casper Meijn <cas...@meijn.net> + * + * 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. + */ + +#![no_std] + +extern "C" { + fn sysinit_start(); + fn sysinit_app(); + fn sysinit_end(); + fn hal_gpio_init_out(pin: i32, val: i32) -> i32; + fn hal_gpio_toggle(pin: i32); + fn os_time_delay(osticks: u32); +} + +extern crate panic_halt; + +const OS_TICKS_PER_SEC: u32 = 128; + +const LED_BLINK_PIN: i32 = 23; + + +#[no_mangle] +pub extern "C" fn main() { + /* Initialize all packages. */ + unsafe { sysinit_start(); } + unsafe { sysinit_app(); } + unsafe { sysinit_end(); } + + unsafe { hal_gpio_init_out(LED_BLINK_PIN, 1); } + + loop { + /* Wait one second */ + unsafe { os_time_delay(OS_TICKS_PER_SEC); } + + /* Toggle the LED */ + unsafe { hal_gpio_toggle(LED_BLINK_PIN); } + } +}