Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NuttX RV32 (QEMU) - Example #64

Merged
merged 7 commits into from
Jan 3, 2025
Merged

NuttX RV32 (QEMU) - Example #64

merged 7 commits into from
Jan 3, 2025

Conversation

kassane
Copy link
Contributor

@kassane kassane commented Oct 12, 2024

cc: @rauhul

The cmakelists was adapted to download, extract and build the automated NuttX to make it easier for experimental Swift-embedded use.
The NuttX version used is the most recent with Swift 6 support.

Requirements

How to build

# 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
build-output
$ cmake -B build -GNinja -DBOARD_CONFIG=rv-virt:leds_swift
-- The Swift compiler identification is Apple 6.1
-- Check for working Swift compiler: /home/kassane/.local/bin/swiftc
-- Check for working Swift compiler: /home/kassane/.local/bin/swiftc - works
Cloning into 'apps'...
HEAD is now at ac11e3cba Adapt the new header file path of va_format.
Cloning into 'nuttx'...
HEAD is now at 10e44f8915 riscv_fork.c: Fix race condition when handling parent integer registers
-- BOARD_CONFIG: rv-virt:leds_swift
  Copy files
  Select CONFIG_HOST_LINUX=y
  Refreshing...
CP: arch/dummy/Kconfig to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/arch/dummy/dummy_kconfig
CP: boards/dummy/Kconfig to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/boards/dummy/dummy_kconfig
LN: platform/board to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/platform/dummy
LN: include/arch to arch/risc-v/include
LN: include/arch/board to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/boards/risc-v/qemu-rv/rv-virt/include
LN: drivers/platform to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/drivers/dummy
LN: include/arch/chip to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/arch/risc-v/include/qemu-rv
LN: arch/risc-v/src/chip to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/arch/risc-v/src/qemu-rv
LN: arch/risc-v/src/board to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/boards/risc-v/qemu-rv/rv-virt/src
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/audioutils
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/benchmarks
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/boot
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/canutils
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/crypto
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/database
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/examples/mcuboot
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/examples
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/fsutils
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/games
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/graphics
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/industry
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/inertial
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/interpreters/luamodules
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/interpreters
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/logging
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/lte
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/math
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/mlearning
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/netutils
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/sdr
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/system
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/testing
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/videoutils
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/wireless/bluetooth
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/wireless/ieee802154
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/wireless
mkkconfig in /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps
Loaded configuration '.config'
Configuration saved to '.config'
-- Configuring done (133.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build

$ cmake --build build
[2/3] Building NuttX
Create version.h
LN: platform/board to /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/apps/platform/dummy
Register: leds
Register: nsh
Register: sh
Register: ostest
Register: getprime
Register: leds_swift
Archive:  fdt/dtc.zip
039a99414e778332d8f9c04cbd3072e1dcc62798
# [...] Creating and inflating files

Hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension (ignoring target-abi)
CPP:  /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/boards/risc-v/qemu-rv/rv-virt/scripts/ld.script-> /home/kassane/swift-embedded-exLD: nuttx
riscv-none-elf-ld: warning: /home/kassane/swift-embedded-examples/nuttx-riscv-blink/build/nuttx/nuttx has a LOAD segment with RWX permissions
[3/3] Running utility command for build_nuttx
Output
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

@rauhul
Copy link
Collaborator

rauhul commented Oct 24, 2024

Heads up im extremely oversubscribed until early November, I did see this PR but won't be able to give you a good review until then. I do really want to include a sample using Nuttx if possible :)

@rauhul
Copy link
Collaborator

rauhul commented Nov 11, 2024

I think the example makes sense to add. However Im trying to get CI setup for this repo before adding additional examples, so avoid hosting broken code!

@kassane
Copy link
Contributor Author

kassane commented Nov 11, 2024

I think the example makes sense to add. However Im trying to get CI setup for this repo before adding additional examples, so avoid hosting broken code!

I believe that putting all the required dependencies in is not a problem.
Sadly, NuttX cmake support is not fully featured like make.

@rauhul
Copy link
Collaborator

rauhul commented Dec 12, 2024

@kassane we now have some basic CI for the examples (excluding the current ones that only build for macho) Can you try to extend this CI to the new content in this PR?

@kassane
Copy link
Contributor Author

kassane commented Dec 12, 2024

@rauhul, based in my tests on CI [another branch] - this sample works since 6.1 or greater. swiftc 6.0.x not working (default in GH runners).
see - https://github.com/kassane/swift-embedded-examples/actions

raw log - swift 6.0.2 get errors
2024-12-12T13:51:50.8473821Z leds_swift.swift:21:3: error: unexpected ',' separator
2024-12-12T13:51:50.8474095Z 19 |     led_daemon,
2024-12-12T13:51:50.8474279Z 20 |     nil,
2024-12-12T13:51:50.8474436Z 21 |   )
2024-12-12T13:51:50.8474616Z    |   `- error: unexpected ',' separator
2024-12-12T13:51:50.8474918Z 22 | 
2024-12-12T13:51:50.8475078Z 23 |   if ret < 0 {
2024-12-12T13:51:50.8475185Z 
2024-12-12T13:51:50.8475381Z leds_swift.swift:16:5: error: 'String' is unavailable: unavailable in embedded Swift
2024-12-12T13:51:50.8475731Z 14 | {
2024-12-12T13:51:50.8475895Z 15 |   let ret = task_create(
2024-12-12T13:51:50.8476104Z 16 |     "led_daemon",
2024-12-12T13:51:50.8476366Z    |     `- error: 'String' is unavailable: unavailable in embedded Swift
2024-12-12T13:51:50.8476668Z 17 |     LEDS_PRIORITY,
2024-12-12T13:51:50.8476883Z 18 |     LEDS_STACKSIZE,
2024-12-12T13:51:50.8477011Z 
2024-12-12T13:51:50.8477191Z Swift.String:2:15: note: 'String' has been explicitly marked unavailable here
2024-12-12T13:51:50.8477622Z 1 | @available(*, unavailable, message: "unavailable in embedded Swift")
2024-12-12T13:51:50.8477963Z 2 | public struct String : Hashable {
2024-12-12T13:51:50.8478265Z   |               `- note: 'String' has been explicitly marked unavailable here
2024-12-12T13:51:50.8478739Z 3 |     public var utf8CString: ContiguousArray<CChar> { get }
2024-12-12T13:51:50.8479038Z 4 |     public init()
2024-12-12T13:51:50.8479155Z 
2024-12-12T13:51:50.8479262Z CC:  stdio/lib_vsscanf.c echo -ne "\033[1K\r"

@kassane
Copy link
Contributor Author

kassane commented Dec 19, 2024

@rauhul, only lint has a problem. I tried ignore file but it didn't work.

@rauhul rauhul force-pushed the nuttx-swift6 branch 4 times, most recently from 018b662 to 7b5f247 Compare January 3, 2025 05:56
@rauhul rauhul merged commit 8815c9a into apple:main Jan 3, 2025
7 checks passed
@kassane kassane deleted the nuttx-swift6 branch January 3, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants