From 33b102a3002cf6897f612d71a52384066ffb7fa3 Mon Sep 17 00:00:00 2001 From: Matheus Catarino Date: Thu, 10 Oct 2024 13:56:15 -0300 Subject: [PATCH 1/7] NuttX - RV32 blink_leds (QEMU) example --- nuttx-riscv-blink/CMakeLists.txt | 140 ++++++++++++++++++ nuttx-riscv-blink/README.md | 71 +++++++++ nuttx-riscv-blink/defconfig | 76 ++++++++++ nuttx-riscv-blink/leds_swift/BridgingHeader.h | 124 ++++++++++++++++ nuttx-riscv-blink/leds_swift/Kconfig | 30 ++++ nuttx-riscv-blink/leds_swift/Make.defs | 24 +++ nuttx-riscv-blink/leds_swift/Makefile | 38 +++++ nuttx-riscv-blink/leds_swift/leds_swift.swift | 30 ++++ 8 files changed, 533 insertions(+) create mode 100644 nuttx-riscv-blink/CMakeLists.txt create mode 100644 nuttx-riscv-blink/README.md create mode 100644 nuttx-riscv-blink/defconfig create mode 100644 nuttx-riscv-blink/leds_swift/BridgingHeader.h create mode 100644 nuttx-riscv-blink/leds_swift/Kconfig create mode 100644 nuttx-riscv-blink/leds_swift/Make.defs create mode 100644 nuttx-riscv-blink/leds_swift/Makefile create mode 100644 nuttx-riscv-blink/leds_swift/leds_swift.swift diff --git a/nuttx-riscv-blink/CMakeLists.txt b/nuttx-riscv-blink/CMakeLists.txt new file mode 100644 index 00000000..a740bdc9 --- /dev/null +++ b/nuttx-riscv-blink/CMakeLists.txt @@ -0,0 +1,140 @@ +cmake_minimum_required(VERSION 3.14...3.30) + +project(blink + VERSION 1.0 + DESCRIPTION "Blink on NuttX" + LANGUAGES Swift +) + +if("${CMAKE_Swift_COMPILER_VERSION}" VERSION_LESS 6.0) + message(FATAL_ERROR "Swift 6.0 or later is required") +endif() + +if(POLICY CMP0169) + # allow to call FetchContent_Populate directly + cmake_policy(SET CMP0169 OLD) +endif() + +option(LIST_ALL_BOARDS "List all available boards" OFF) +option(ENABLE_NUTTX_TRACE "Enable NuttX trace" OFF) + +if(ENABLE_NUTTX_TRACE) + set(TRACEFLAG "--trace") +else() + set(TRACEFLAG "") +endif() + +set(FETCHCONTENT_QUIET FALSE) +include(FetchContent) +FetchContent_Declare( + apps + GIT_REPOSITORY https://github.com/apache/nuttx-apps.git + GIT_TAG nuttx-12.7.0-RC0 + SOURCE_DIR ${CMAKE_BINARY_DIR}/apps + FIND_PACKAGE_ARGS +) +FetchContent_GetProperties(apps) +if(NOT apps_POPULATED) + FetchContent_Populate(apps) +endif() + +FetchContent_Declare( + nuttx + GIT_REPOSITORY https://github.com/apache/nuttx.git + GIT_TAG nuttx-12.7.0-RC0 + SOURCE_DIR ${CMAKE_BINARY_DIR}/nuttx + FIND_PACKAGE_ARGS +) +FetchContent_GetProperties(nuttx) +if(NOT nuttx_POPULATED) + FetchContent_Populate(nuttx) +endif() + + +if(NOT "${nuttx_SOURCE_DIR}" STREQUAL "") + list(APPEND CMAKE_MODULE_PATH ${apps_SOURCE_DIR}/cmake) + list(APPEND CMAKE_MODULE_PATH ${nuttx_SOURCE_DIR}/cmake) +endif() + +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(SCRIPT_SUFFIX .bat) +else() + set(SCRIPT_SUFFIX .sh) +endif() + +if(LIST_ALL_BOARDS) + execute_process( + COMMAND ${CMAKE_COMMAND} -E chdir ${nuttx_SOURCE_DIR} + ${CMAKE_COMMAND} -E env PATH=${nuttx_SOURCE_DIR}/tools:$ENV{PATH} + ${nuttx_SOURCE_DIR}/tools/configure${SCRIPT_SUFFIX} -L + RESULT_VARIABLE result + ) + if(result) + message(FATAL_ERROR "Failed to run tools/configure") + endif() +else() + if(NOT DEFINED BOARD_CONFIG) + message(FATAL_ERROR "Please define configuration with BOARD_CONFIG") + else() + message(STATUS "BOARD_CONFIG: ${BOARD_CONFIG}") + endif() + + # Send swift-blinky example to nuttx-apps path + file(COPY ${CMAKE_SOURCE_DIR}/leds_swift DESTINATION ${apps_SOURCE_DIR}/examples) + file(COPY ${CMAKE_SOURCE_DIR}/defconfig DESTINATION ${nuttx_SOURCE_DIR}/boards/risc-v/qemu-rv/rv-virt/configs/leds_swift) + + add_custom_target(distclean + COMMAND ${CMAKE_COMMAND} -E chdir ${nuttx_SOURCE_DIR} + ${CMAKE_COMMAND} -E env PATH=${nuttx_SOURCE_DIR}/tools:$ENV{PATH} + make distclean + COMMENT "Clean NuttX" + ) + + execute_process( + COMMAND ${CMAKE_COMMAND} -E chdir ${nuttx_SOURCE_DIR} + ${CMAKE_COMMAND} -E env PATH=${nuttx_SOURCE_DIR}/tools:$ENV{PATH} + ${nuttx_SOURCE_DIR}/tools/configure${SCRIPT_SUFFIX} -l ${BOARD_CONFIG} + RESULT_VARIABLE result + ) + if(result) + message(FATAL_ERROR "Failed to run tools/configure") + endif() + + add_custom_target(copy_swift_example + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/leds_swift ${apps_SOURCE_DIR}/examples/leds_swift + COMMENT "Copying leds_swift example to nuttx-apps" + ) + + add_custom_target(build_nuttx ALL + COMMAND ${CMAKE_COMMAND} -E chdir ${nuttx_SOURCE_DIR} + ${CMAKE_COMMAND} -E env PATH=${nuttx_SOURCE_DIR}/tools:$ENV{PATH} + make ${TRACEFLAG} -j ${JOB_POOLS} + DEPENDS copy_swift_example + COMMENT "Building NuttX" + ) + + add_custom_command( + TARGET build_nuttx + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${nuttx_SOURCE_DIR}/nuttx ${CMAKE_BINARY_DIR}/nuttx.elf + ) + + add_custom_target(export_nuttx + COMMAND ${CMAKE_COMMAND} -E chdir ${nuttx_SOURCE_DIR} + ${CMAKE_COMMAND} -E env PATH=${nuttx_SOURCE_DIR}/tools:$ENV{PATH} + make export + COMMENT "Exporting NuttX" + ) + + add_custom_target(extract_nuttx_export + COMMAND ${CMAKE_COMMAND} -E tar xzf ${nuttx_SOURCE_DIR}/nuttx-export-12.7.0.tar.gz + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E remove ${nuttx_SOURCE_DIR}/nuttx-export-12.7.0.tar.gz + DEPENDS export_nuttx + COMMENT "Extracting NuttX export" + ) + + add_custom_target(nuttx-libs + DEPENDS build_nuttx export_nuttx extract_nuttx_export + ) +endif() diff --git a/nuttx-riscv-blink/README.md b/nuttx-riscv-blink/README.md new file mode 100644 index 00000000..5c037d26 --- /dev/null +++ b/nuttx-riscv-blink/README.md @@ -0,0 +1,71 @@ +# Swift 6 on NuttX RTOS using CMake + +## Description + +Run blink rv32-blink_leds (QEMU) example on NuttX RTOS. + +> [!NOTE] +> CMake is adapted to build NuttX and NuttX-apps (Makefiles) with Swift 6. + +## Requirements + +- [NuttX](https://github.com/apache/nuttx) & [NuttX-apps](https://github.com/apache/nuttx-apps) +- [kconfig-frontends](https://bitbucket.org/nuttx/tools) +- [CMake](https://cmake.org/download/) +- [QEMU](https://www.qemu.org/) +- [Swift 6](https://swift.org/download/) +- [RISC-V GNU Toolchain](https://github.com/riscv-collab/riscv-gnu-toolchain/releases) + +## How to build + +```bash +# list all supported boards +cmake -B build -DLIST_ALL_BOARDS=ON | less +# build configuration +cmake -B build -GNinja -DBOARD_CONFIG=rv-virt:leds_swift -DENABLE_NUTTX_TRACE=[ON|OFF] +# build +cmake --build build +# clean +cmake --build build -t distclean +# export NuttX as library +cmake --build build -t nuttx-libs +``` + +- **Output** +```bash +qemu-system-riscv32 \ + -semihosting \ + -M virt,aclint=on \ + -cpu rv32 -smp 8 \ + -bios none \ + -kernel build/nuttx.elf -nographic +NuttShell (NSH) NuttX-12.7.0 +nsh> leds_swift +leds_main: led_daemon started + +led_daemon (pid# 4): Running +led_daemon: Opening /dev/userleds +led_daemon: Supported LEDs 0x7 +led_daemon: LED set 0x1 +board_userled: LED 1 set to 1 +board_userled: LED 2 set to 0 +board_userled: LED 3 set to 0 +nsh> led_daemon: LED set 0x0 +board_userled: LED 1 set to 0 +board_userled: LED 2 set to 0 +board_userled: LED 3 set to 0 +led_daemon: LED set 0x1 +board_userled: LED 1 set to 1 +board_userled: LED 2 set to 0 +board_userled: LED 3 set to 0 +led_daemon: LED set 0x0 +# [...] see output in QEMU +``` + +Quit from QEMU: `Ctrl-a x` + +## References + +- [Nuttx - Compiling with CMake](https://nuttx.apache.org/docs/latest/quickstart/compiling_cmake.html) +- [NuttX - C++ Example using CMake](https://nuttx.apache.org/docs/latest/guides/cpp_cmake.html) +- [NuttX - leds_rust](https://lupyuen.github.io/articles/rust6) \ No newline at end of file diff --git a/nuttx-riscv-blink/defconfig b/nuttx-riscv-blink/defconfig new file mode 100644 index 00000000..5091081e --- /dev/null +++ b/nuttx-riscv-blink/defconfig @@ -0,0 +1,76 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_DISABLE_OS_API is not set +# CONFIG_NSH_DISABLE_LOSMART is not set +CONFIG_16550_ADDRWIDTH=0 +CONFIG_16550_UART0=y +CONFIG_16550_UART0_BASE=0x10000000 +CONFIG_16550_UART0_CLOCK=3686400 +CONFIG_16550_UART0_IRQ=37 +CONFIG_16550_UART0_SERIAL_CONSOLE=y +CONFIG_16550_UART=y +CONFIG_ARCH="risc-v" +CONFIG_ARCH_BOARD="rv-virt" +CONFIG_ARCH_BOARD_QEMU_RV_VIRT=y +CONFIG_ARCH_CHIP="qemu-rv" +# CONFIG_ARCH_CHIP_QEMU_RV64=y +CONFIG_ARCH_CHIP_QEMU_RV=y +CONFIG_ARCH_CHIP_QEMU_RV_ISA_A=y +CONFIG_ARCH_CHIP_QEMU_RV_ISA_C=y +CONFIG_ARCH_CHIP_QEMU_RV_ISA_M=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BCH=y +CONFIG_BOARDCTL_POWEROFF=y +CONFIG_BOARD_LATE_INITIALIZE=y +CONFIG_BOARD_LOOPSPERMSEC=6366 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEVICE_TREE=y +CONFIG_DEV_ZERO=y +CONFIG_ELF=y +# CONFIG_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_LEDS=y +CONFIG_EXAMPLES_LEDS_SWIFT=y +CONFIG_FS_HOSTFS=y +CONFIG_FS_PROCFS=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 +CONFIG_LIBC_ENVPATH=y +CONFIG_LIBC_EXECFUNCS=y +CONFIG_LIBC_PERROR_STDOUT=y +CONFIG_LIBC_STRERROR=y +CONFIG_LIBM=y +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_PATH_INITIAL="/system/bin" +CONFIG_RAM_SIZE=33554432 +CONFIG_RAM_START=0x80000000 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RISCV_SEMIHOSTING_HOSTFS=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SERIAL_UART_ARCH_MMIO=y +CONFIG_STACK_COLORATION=y +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2021 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_STACKSIZE=3072 +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_USEC_PER_TICK=1000 +CONFIG_USERLED=y +CONFIG_USERLED_LOWER=y diff --git a/nuttx-riscv-blink/leds_swift/BridgingHeader.h b/nuttx-riscv-blink/leds_swift/BridgingHeader.h new file mode 100644 index 00000000..7b2ceba1 --- /dev/null +++ b/nuttx-riscv-blink/leds_swift/BridgingHeader.h @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors. +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LED_DEVPATH "/dev/userleds" + +const int LEDS_PRIORITY = CONFIG_EXAMPLES_LEDS_PRIORITY; +const int LEDS_STACKSIZE = CONFIG_EXAMPLES_LEDS_STACKSIZE; + +static bool g_led_daemon_started = false; + +static void sigterm_action(int signo, siginfo_t *siginfo, void *arg) { + if (signo == SIGTERM) { + printf("SIGTERM received\n"); + g_led_daemon_started = false; + printf("led_daemon: Terminated.\n"); + } else { + printf("\nsigterm_action: Received signo=%d siginfo=%p arg=%p\n", signo, + (void *)siginfo, arg); + } +} + +int led_daemon(int argc, char *argv[]) { + userled_set_t supported = 0; + userled_set_t ledset = 0; + bool incrementing = true; + + struct sigaction act = {.sa_sigaction = sigterm_action, + .sa_flags = SA_SIGINFO}; + + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGTERM); + + if (sigaction(SIGTERM, &act, NULL) != 0) { + printf("Failed to install SIGTERM handler, errno=%d\n", errno); + return EXIT_FAILURE; + } + + pid_t mypid = getpid(); + g_led_daemon_started = true; + printf("\nled_daemon (pid# %d): Running\n", mypid); + + printf("led_daemon: Opening %s\n", CONFIG_EXAMPLES_LEDS_DEVPATH); + int fd = open(CONFIG_EXAMPLES_LEDS_DEVPATH, O_WRONLY); + if (fd < 0) { + printf("led_daemon: ERROR: Failed to open %s: %d\n", + CONFIG_EXAMPLES_LEDS_DEVPATH, errno); + g_led_daemon_started = false; + return EXIT_FAILURE; + } + + int ret = ioctl(fd, ULEDIOC_SUPPORTED, (unsigned long)&supported); + if (ret < 0) { + printf("led_daemon: ERROR: ioctl(ULEDIOC_SUPPORTED) failed: %d\n", errno); + close(fd); + g_led_daemon_started = false; + return EXIT_FAILURE; + } + + printf("led_daemon: Supported LEDs 0x%x\n", supported); + supported &= CONFIG_EXAMPLES_LEDS_LEDSET; + + while (g_led_daemon_started) { + userled_set_t newset = 0; + userled_set_t tmp = 0; + + if (incrementing) { + tmp = ledset; + while (newset == ledset) { + tmp++; + newset = tmp & supported; + } + + if (newset == 0) { + incrementing = false; + continue; + } + } else { + if (ledset == 0) { + incrementing = true; + continue; + } + + tmp = ledset; + while (newset == ledset) { + tmp--; + newset = tmp & supported; + } + } + + ledset = newset; + printf("led_daemon: LED set 0x%x\n", ledset); + + ret = ioctl(fd, ULEDIOC_SETALL, (unsigned long)ledset); + if (ret < 0) { + printf("led_daemon: ERROR: ioctl(ULEDIOC_SETALL) failed: %d\n", errno); + close(fd); + g_led_daemon_started = false; + return EXIT_FAILURE; + } + + usleep(500 * 1000); + } + + close(fd); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/nuttx-riscv-blink/leds_swift/Kconfig b/nuttx-riscv-blink/leds_swift/Kconfig new file mode 100644 index 00000000..e39ce088 --- /dev/null +++ b/nuttx-riscv-blink/leds_swift/Kconfig @@ -0,0 +1,30 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_LEDS_SWIFT + tristate "\"LEDs Swift\" example" + default y + depends on USERLED + ---help--- + Enable the \"LEDs Swift\" example + +if EXAMPLES_LEDS_SWIFT + +config EXAMPLES_LEDS_SWIFT_PROGNAME + string "Program name" + default "leds_swift" + ---help--- + This is the name of the program that will be used when the NSH ELF + program is installed. + +config EXAMPLES_LEDS_SWIFT_PRIORITY + int "LEDs Swift task priority" + default 100 + +config EXAMPLES_LEDS_SWIFT_STACKSIZE + int "LEDs Swift stack size" + default DEFAULT_TASK_STACKSIZE + +endif diff --git a/nuttx-riscv-blink/leds_swift/Make.defs b/nuttx-riscv-blink/leds_swift/Make.defs new file mode 100644 index 00000000..9070565f --- /dev/null +++ b/nuttx-riscv-blink/leds_swift/Make.defs @@ -0,0 +1,24 @@ +############################################################################ +# apps/examples/leds_swift/Make.defs +# +# Copyright (c) 2024 Apple Inc. and the Swift project authors. +# 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. +# +############################################################################ + +ifneq ($(CONFIG_EXAMPLES_LEDS_SWIFT),) +CONFIGURED_APPS += $(APPDIR)/examples/leds_swift +endif diff --git a/nuttx-riscv-blink/leds_swift/Makefile b/nuttx-riscv-blink/leds_swift/Makefile new file mode 100644 index 00000000..e2fc7df4 --- /dev/null +++ b/nuttx-riscv-blink/leds_swift/Makefile @@ -0,0 +1,38 @@ +############################################################################ +# apps/examples/leds_swift/Makefile +# +# Copyright (c) 2024 Apple Inc. and the Swift project authors. +# 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. +# +############################################################################ + +include $(APPDIR)/Make.defs + +# Blink in Swift Embedded Example + +MAINSRC = $(wildcard *.swift) $(wildcard *.h) + +# leds_swift built-in application info + +SWIFTFLAGS += -import-bridging-header BridgingHeader.h -I$(TOPDIR)/include +SWIFTFLAGS += -Xfrontend -function-sections -Xfrontend -disable-stack-protector +SWIFTFLAGS += -Xfrontend -enable-single-module-llvm-emission +PROGNAME = $(CONFIG_EXAMPLES_LEDS_SWIFT_PROGNAME) +PRIORITY = $(CONFIG_EXAMPLES_LEDS_SWIFT_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_LEDS_SWIFT_STACKSIZE) +MODULE = $(CONFIG_EXAMPLES_LEDS_SWIFT) + +include $(APPDIR)/Application.mk diff --git a/nuttx-riscv-blink/leds_swift/leds_swift.swift b/nuttx-riscv-blink/leds_swift/leds_swift.swift new file mode 100644 index 00000000..346ba840 --- /dev/null +++ b/nuttx-riscv-blink/leds_swift/leds_swift.swift @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors. +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +@_cdecl("leds_swift_main") +public func cMain(_ argc: Int32, _ argv: UnsafeMutablePointer?>) -> Int32 +{ + let ret = task_create( + "led_daemon", + LEDS_PRIORITY, + LEDS_STACKSIZE, + led_daemon, + nil, + ) + + if ret < 0 { + print("leds_main: ERROR: Failed to start led_daemon") + return ret + } + + print("leds_main: led_daemon started") + return 0 +} From c15084ce65600d195db83c974c4af651b7193d15 Mon Sep 17 00:00:00 2001 From: Matheus Catarino Date: Thu, 12 Dec 2024 10:57:19 -0300 Subject: [PATCH 2/7] Add CI/CD --- .github/workflows/build-nuttx.yml | 66 +++++++++++++++++++++++++++++++ nuttx-riscv-blink/CMakeLists.txt | 10 +---- 2 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/build-nuttx.yml diff --git a/.github/workflows/build-nuttx.yml b/.github/workflows/build-nuttx.yml new file mode 100644 index 00000000..b00a3616 --- /dev/null +++ b/.github/workflows/build-nuttx.yml @@ -0,0 +1,66 @@ +name: Build NuttX Examples + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + schedule: + # Build on Mondays at 9am PST every week + - cron: '0 17 * * 1' + +jobs: + build-nuttx: + runs-on: ubuntu-24.04 + + strategy: + fail-fast: false + matrix: + example: [nuttx-riscv-blink] + swift: [swift-DEVELOPMENT-SNAPSHOT-2024-12-10-a] + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Set up CMake + Ninja + uses: lukka/get-cmake@latest + with: + cmakeVersion: latest + ninjaVersion: latest + + - name: Install ${{ matrix.swift }} and remove old version + run: | + sudo rm /usr/local/bin/swift* + wget -q https://download.swift.org/development/ubuntu2404/${{ matrix.swift }}/${{ matrix.swift }}-ubuntu24.04.tar.gz + tar xzf ${{ matrix.swift }}-ubuntu24.04.tar.gz + export PATH="$PATH:`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/" + echo "PATH=$PATH" >> $GITHUB_ENV + swiftc --version + + - name: Install Build tools + run: | + sudo apt -y update + sudo apt -y install \ + bison flex gettext texinfo libncurses5-dev libncursesw5-dev \ + gperf automake libtool pkg-config build-essential gperf genromfs \ + libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \ + libexpat-dev gcc-multilib g++-multilib u-boot-tools util-linux \ + kconfig-frontends + + - name: Install RISC-V toolchain + run: | + mkdir -p riscv-none-elf-gcc && \ + curl -s -L "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz" \ + | tar -C riscv-none-elf-gcc --strip-components 1 -xz + export PATH="$PATH:`pwd`/riscv-none-elf-gcc/bin/" + echo "PATH=$PATH" >> $GITHUB_ENV + riscv-none-elf-gcc --version + + - name: Config ${{ matrix.example }} + working-directory: ${{ matrix.example }} + run: cmake -B build -GNinja -DBOARD_CONFIG=rv-virt:leds_swift -DENABLE_NUTTX_TRACE=ON + + - name: Build ${{ matrix.example }} + working-directory: ${{ matrix.example }} + run: cmake --build build diff --git a/nuttx-riscv-blink/CMakeLists.txt b/nuttx-riscv-blink/CMakeLists.txt index a740bdc9..4332ec66 100644 --- a/nuttx-riscv-blink/CMakeLists.txt +++ b/nuttx-riscv-blink/CMakeLists.txt @@ -29,7 +29,7 @@ include(FetchContent) FetchContent_Declare( apps GIT_REPOSITORY https://github.com/apache/nuttx-apps.git - GIT_TAG nuttx-12.7.0-RC0 + GIT_TAG nuttx-12.7.0 SOURCE_DIR ${CMAKE_BINARY_DIR}/apps FIND_PACKAGE_ARGS ) @@ -41,7 +41,7 @@ endif() FetchContent_Declare( nuttx GIT_REPOSITORY https://github.com/apache/nuttx.git - GIT_TAG nuttx-12.7.0-RC0 + GIT_TAG nuttx-12.7.0 SOURCE_DIR ${CMAKE_BINARY_DIR}/nuttx FIND_PACKAGE_ARGS ) @@ -50,12 +50,6 @@ if(NOT nuttx_POPULATED) FetchContent_Populate(nuttx) endif() - -if(NOT "${nuttx_SOURCE_DIR}" STREQUAL "") - list(APPEND CMAKE_MODULE_PATH ${apps_SOURCE_DIR}/cmake) - list(APPEND CMAKE_MODULE_PATH ${nuttx_SOURCE_DIR}/cmake) -endif() - if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(SCRIPT_SUFFIX .bat) else() From 0b7af00b9a11761817163dd7c4adede9f9a515a8 Mon Sep 17 00:00:00 2001 From: Matheus Catarino Date: Thu, 12 Dec 2024 11:10:36 -0300 Subject: [PATCH 3/7] Change Swift min. version --- nuttx-riscv-blink/CMakeLists.txt | 4 ++-- nuttx-riscv-blink/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nuttx-riscv-blink/CMakeLists.txt b/nuttx-riscv-blink/CMakeLists.txt index 4332ec66..da191f00 100644 --- a/nuttx-riscv-blink/CMakeLists.txt +++ b/nuttx-riscv-blink/CMakeLists.txt @@ -6,8 +6,8 @@ project(blink LANGUAGES Swift ) -if("${CMAKE_Swift_COMPILER_VERSION}" VERSION_LESS 6.0) - message(FATAL_ERROR "Swift 6.0 or later is required") +if("${CMAKE_Swift_COMPILER_VERSION}" VERSION_LESS 6.1) + message(FATAL_ERROR "Swift 6.1 or later is required") endif() if(POLICY CMP0169) diff --git a/nuttx-riscv-blink/README.md b/nuttx-riscv-blink/README.md index 5c037d26..506b99ce 100644 --- a/nuttx-riscv-blink/README.md +++ b/nuttx-riscv-blink/README.md @@ -13,7 +13,7 @@ Run blink rv32-blink_leds (QEMU) example on NuttX RTOS. - [kconfig-frontends](https://bitbucket.org/nuttx/tools) - [CMake](https://cmake.org/download/) - [QEMU](https://www.qemu.org/) -- [Swift 6](https://swift.org/download/) +- [Swift 6](https://swift.org/download/) - Swift 6.1 or greater - [RISC-V GNU Toolchain](https://github.com/riscv-collab/riscv-gnu-toolchain/releases) ## How to build From 9b701d6cb1282ffa5e51dec889603e73a67114f3 Mon Sep 17 00:00:00 2001 From: Matheus Catarino Date: Fri, 13 Dec 2024 14:50:59 -0300 Subject: [PATCH 4/7] lint bypass ignore file --- nuttx-riscv-blink/leds_swift/leds_swift.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nuttx-riscv-blink/leds_swift/leds_swift.swift b/nuttx-riscv-blink/leds_swift/leds_swift.swift index 346ba840..85d3200e 100644 --- a/nuttx-riscv-blink/leds_swift/leds_swift.swift +++ b/nuttx-riscv-blink/leds_swift/leds_swift.swift @@ -9,6 +9,8 @@ // //===----------------------------------------------------------------------===// +// swift-format-ignore-file + @_cdecl("leds_swift_main") public func cMain(_ argc: Int32, _ argv: UnsafeMutablePointer?>) -> Int32 { From 75a8c65c84583ae7cac63c4b71d6794bb2340f36 Mon Sep 17 00:00:00 2001 From: Rauhul Varma Date: Thu, 2 Jan 2025 21:15:33 -0800 Subject: [PATCH 5/7] maintainer updates --- .github/workflows/build-nuttx.yml | 16 ++++++++-------- nuttx-riscv-blink/README.md | 2 +- nuttx-riscv-blink/leds_swift/leds_swift.swift | 10 ++++------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build-nuttx.yml b/.github/workflows/build-nuttx.yml index b00a3616..3b8c326e 100644 --- a/.github/workflows/build-nuttx.yml +++ b/.github/workflows/build-nuttx.yml @@ -42,21 +42,21 @@ jobs: run: | sudo apt -y update sudo apt -y install \ - bison flex gettext texinfo libncurses5-dev libncursesw5-dev \ - gperf automake libtool pkg-config build-essential gperf genromfs \ - libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \ - libexpat-dev gcc-multilib g++-multilib u-boot-tools util-linux \ - kconfig-frontends - + bison flex gettext texinfo libncurses5-dev libncursesw5-dev \ + gperf automake libtool pkg-config build-essential gperf genromfs \ + libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \ + libexpat-dev gcc-multilib g++-multilib u-boot-tools util-linux \ + kconfig-frontends + - name: Install RISC-V toolchain run: | mkdir -p riscv-none-elf-gcc && \ curl -s -L "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz" \ - | tar -C riscv-none-elf-gcc --strip-components 1 -xz + | tar -C riscv-none-elf-gcc --strip-components 1 -xz export PATH="$PATH:`pwd`/riscv-none-elf-gcc/bin/" echo "PATH=$PATH" >> $GITHUB_ENV riscv-none-elf-gcc --version - + - name: Config ${{ matrix.example }} working-directory: ${{ matrix.example }} run: cmake -B build -GNinja -DBOARD_CONFIG=rv-virt:leds_swift -DENABLE_NUTTX_TRACE=ON diff --git a/nuttx-riscv-blink/README.md b/nuttx-riscv-blink/README.md index 506b99ce..4a472393 100644 --- a/nuttx-riscv-blink/README.md +++ b/nuttx-riscv-blink/README.md @@ -68,4 +68,4 @@ Quit from QEMU: `Ctrl-a x` - [Nuttx - Compiling with CMake](https://nuttx.apache.org/docs/latest/quickstart/compiling_cmake.html) - [NuttX - C++ Example using CMake](https://nuttx.apache.org/docs/latest/guides/cpp_cmake.html) -- [NuttX - leds_rust](https://lupyuen.github.io/articles/rust6) \ No newline at end of file +- [NuttX - leds_rust](https://lupyuen.github.io/articles/rust6) diff --git a/nuttx-riscv-blink/leds_swift/leds_swift.swift b/nuttx-riscv-blink/leds_swift/leds_swift.swift index 85d3200e..1cadcf47 100644 --- a/nuttx-riscv-blink/leds_swift/leds_swift.swift +++ b/nuttx-riscv-blink/leds_swift/leds_swift.swift @@ -9,18 +9,16 @@ // //===----------------------------------------------------------------------===// -// swift-format-ignore-file - @_cdecl("leds_swift_main") -public func cMain(_ argc: Int32, _ argv: UnsafeMutablePointer?>) -> Int32 -{ +public func cMain( + _ argc: Int32, _ argv: UnsafeMutablePointer?> +) -> Int32 { let ret = task_create( "led_daemon", LEDS_PRIORITY, LEDS_STACKSIZE, led_daemon, - nil, - ) + nil) if ret < 0 { print("leds_main: ERROR: Failed to start led_daemon") From 28f7fab5d8c2837923a57e7ac9d789527ddd953f Mon Sep 17 00:00:00 2001 From: Rauhul Varma Date: Thu, 2 Jan 2025 21:29:01 -0800 Subject: [PATCH 6/7] attempt to match other build ymls --- .github/workflows/build-nuttx.yml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-nuttx.yml b/.github/workflows/build-nuttx.yml index 3b8c326e..6a5d30a0 100644 --- a/.github/workflows/build-nuttx.yml +++ b/.github/workflows/build-nuttx.yml @@ -17,36 +17,37 @@ jobs: fail-fast: false matrix: example: [nuttx-riscv-blink] - swift: [swift-DEVELOPMENT-SNAPSHOT-2024-12-10-a] + swift: [swift-DEVELOPMENT-SNAPSHOT-2024-12-22-a] steps: - name: Checkout repo uses: actions/checkout@v4 - - name: Set up CMake + Ninja - uses: lukka/get-cmake@latest - with: - cmakeVersion: latest - ninjaVersion: latest - - - name: Install ${{ matrix.swift }} and remove old version + - name: Install ${{ matrix.swift }} run: | - sudo rm /usr/local/bin/swift* wget -q https://download.swift.org/development/ubuntu2404/${{ matrix.swift }}/${{ matrix.swift }}-ubuntu24.04.tar.gz tar xzf ${{ matrix.swift }}-ubuntu24.04.tar.gz - export PATH="$PATH:`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/" + export PATH="`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/:$PATH" echo "PATH=$PATH" >> $GITHUB_ENV swiftc --version - - name: Install Build tools + - name: Install apt dependencies run: | - sudo apt -y update - sudo apt -y install \ + sudo apt-get -qq update && sudo apt-get -qq -y install \ bison flex gettext texinfo libncurses5-dev libncursesw5-dev \ gperf automake libtool pkg-config build-essential gperf genromfs \ libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \ libexpat-dev gcc-multilib g++-multilib u-boot-tools util-linux \ - kconfig-frontends + kconfig-frontends ninja-build + + - name: Install CMake 3.30.2 + run: | + ARCH=`uname -m` + curl -sL https://github.com/Kitware/CMake/releases/download/v3.30.2/cmake-3.30.2-linux-$ARCH.tar.gz -O + tar xzf cmake-3.30.2-linux-$ARCH.tar.gz + export PATH="`pwd`/cmake-3.30.2-linux-$ARCH/bin:$PATH" + echo "PATH=$PATH" >> $GITHUB_ENV + cmake --version - name: Install RISC-V toolchain run: | From 26030ad690a99cdf3627be5fcbdb2ea579a907b9 Mon Sep 17 00:00:00 2001 From: Rauhul Varma Date: Thu, 2 Jan 2025 23:30:18 -0800 Subject: [PATCH 7/7] update readme --- .github/workflows/build-nuttx.yml | 16 ++++++++-------- README.md | 17 +++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-nuttx.yml b/.github/workflows/build-nuttx.yml index 6a5d30a0..952fc7ec 100644 --- a/.github/workflows/build-nuttx.yml +++ b/.github/workflows/build-nuttx.yml @@ -23,14 +23,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Install ${{ matrix.swift }} - run: | - wget -q https://download.swift.org/development/ubuntu2404/${{ matrix.swift }}/${{ matrix.swift }}-ubuntu24.04.tar.gz - tar xzf ${{ matrix.swift }}-ubuntu24.04.tar.gz - export PATH="`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/:$PATH" - echo "PATH=$PATH" >> $GITHUB_ENV - swiftc --version - - name: Install apt dependencies run: | sudo apt-get -qq update && sudo apt-get -qq -y install \ @@ -58,6 +50,14 @@ jobs: echo "PATH=$PATH" >> $GITHUB_ENV riscv-none-elf-gcc --version + - name: Install ${{ matrix.swift }} + run: | + wget -q https://download.swift.org/development/ubuntu2404/${{ matrix.swift }}/${{ matrix.swift }}-ubuntu24.04.tar.gz + tar xzf ${{ matrix.swift }}-ubuntu24.04.tar.gz + export PATH="`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/:$PATH" + echo "PATH=$PATH" >> $GITHUB_ENV + swiftc --version + - name: Config ${{ matrix.example }} working-directory: ${{ matrix.example }} run: cmake -B build -GNinja -DBOARD_CONFIG=rv-virt:leds_swift -DENABLE_NUTTX_TRACE=ON diff --git a/README.md b/README.md index bbf6289b..ff7051a8 100644 --- a/README.md +++ b/README.md @@ -32,19 +32,20 @@ Each example in this repository contains build and deployment instructions, howe | Name | Platform | SDK | Description | Photo | | ---- | -------- | --- | ----------- | ----- | +| [esp32-led-blink-sdk](./esp32-led-blink-sdk) | ESP32-C6-Bug | ESP-IDF SDK | Blink an LED repeatedly with Swift & the ESP-IDF. | | +| [esp32-led-strip-sdk](./esp32-led-strip-sdk) | ESP32-C6-DevKitC-1 | ESP-IDF SDK | Control NeoPixel LEDs with Swift & the ESP-IDF. | | +| [nrfx-blink-sdk](./nrfx-blink-sdk) | nRF52840-DK | Zephyr SDK | Blink an LED repeatedly with Swift & Zephyr. | | +| [nuttx-riscv-blink] | QEMU | NuttX | Blink a virualized led in QEMU using the Apache NuttX RTOS | | +| [pico-blink-sdk](./pico-blink-sdk) | Raspberry Pi Pico, Pico 2 | Pico SDK | Blink an LED repeatedly with Swift & the Pico SDK. | | +| [pico-blink](./pico-blink) | Raspberry Pi Pico | None | Blink an LED repeatedly. | | +| [pico-w-blink-sdk](./pico-w-blink-sdk) | Raspberry Pi Pico W | Pico SDK | Blink an LED to signal 'SOS' in Morse code repeatedly with Swift & the Pico SDK. | | +| [pico2-neopixel](./pico2-neopixel) | Raspberry Pi Pico 2 | None | Control Neopixel LEDs using the RP2350 PIO. | | | [stm32-blink](./stm32-blink) | STM32F746G-DISCO | None | Blink an LED repeatedly. | | | [stm32-lcd-logo](./stm32-lcd-logo) | STM32F746G-DISCO | None | Animate the Swift Logo on the built-in LCD. | | | [stm32-neopixel](./stm32-neopixel) | STM32F746G-DISCO | None | Control NeoPixel LEDs using SPI. | | | [stm32-uart-echo](./stm32-uart-echo) | STM32F746G-DISCO | None | Echo user input using UART. | | -| [pico-blink](./pico-blink) | Raspberry Pi Pico | None | Blink an LED repeatedly. | | -| [pico-blink-sdk](./pico-blink-sdk) | Raspberry Pi Pico, Pico 2 | Pico SDK | Blink an LED repeatedly with Swift & the Pico SDK. | | -| [pico-w-blink-sdk](./pico-w-blink-sdk) | Raspberry Pi Pico W | Pico SDK | Blink an LED to signal 'SOS' in Morse code repeatedly with Swift & the Pico SDK. | | -| [pico2-neopixel](./pico2-neopixel) | Raspberry Pi Pico 2 | None | Control Neopixel LEDs using the RP2350 PIO. | | -| [nrfx-blink-sdk](./nrfx-blink-sdk) | nRF52840-DK | Zephyr SDK | Blink an LED repeatedly with Swift & Zephyr. | | -| [esp32-led-strip-sdk](./esp32-led-strip-sdk) | ESP32-C6-DevKitC-1 | ESP-IDF SDK | Control NeoPixel LEDs with Swift & the ESP-IDF. | | -| [esp32-led-blink-sdk](./esp32-led-blink-sdk) | ESP32-C6-Bug | ESP-IDF SDK | Blink an LED repeatedly with Swift & the ESP-IDF. | | -Note that the SDK integration examples (Pico SDK, Zephyr SDK, etc.) are not recommendations or endorsement, the same is true for build system choice (Make, CMake, SwiftPM, shell scripts). Embedded Swift aims to be versatile and to allow for integration into more existing SDKs and build systems, and the example projects are merely showing the possibilities. +Note that the SDK integration examples (Pico SDK, Zephyr SDK, etc.) are not recommendations or endorsement, the same is true for build system choice (Make, CMake, SwiftPM, shell scripts). Embedded Swift aims to be versatile and allowing integration into existing SDKs and build systems, and the example projects show some of the possibilities. ## Community Examples