Skip to content

[AVR] Initial AVR support #74818

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

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/EmbeddedSwift/UserManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ A typical setup and build + run cycle for an embedded development board involves
- (1) Getting an SDK with the C compilers, headers and libraries for the target
- (2) Building the C source code, and Swift source code into object files.
- (3) Linking all the libraries, C object files, and Swift object files.
- (4) Post-processing the linked firmware into a flashable format (UF2, BIN, or bespoke formats)
- (5) Uploading the flashable binary to the board over a USB cable using some vendor-provided JTAG/SWD tool or by copying it to a fake USB Mass Storage volume presented by the board.
- (4) Post-processing the linked firmware into a flashable format (UF2, BIN, HEX, or bespoke formats)
- (5) Uploading the flashable binary to the board over a USB cable using some vendor-provided JTAG/SWD tool, by copying it to a fake USB Mass Storage volume presented by the board or a custom platform bootloader.
- (6) Restarting the board, observing physical effects of the firmware (LEDs light up) or UART output over USB, or presence on network, etc.

Most of these steps are out of scope for this document, instead refer to the vendor provided documentation. This document only focuses on (2) from the list above, and it's important that you first get familiar with the details of firmware development for your board without Swift in the mix. Even if you want to build a completely pure Swift firmware, you are still going to need the vendor provided tooling for linking, post-processing, uploading, etc.
Expand Down
4 changes: 4 additions & 0 deletions lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationArches[] =
"s390x",
"wasm32",
"riscv64",
"avr"
};

static const SupportedConditionalValue SupportedConditionalCompilationEndianness[] = {
Expand Down Expand Up @@ -541,6 +542,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
case llvm::Triple::ArchType::riscv64:
addPlatformConditionValue(PlatformConditionKind::Arch, "riscv64");
break;
case llvm::Triple::ArchType::avr:
addPlatformConditionValue(PlatformConditionKind::Arch, "avr");
break;
default:
UnsupportedArch = true;

Expand Down
8 changes: 8 additions & 0 deletions test/Parse/ConditionalCompilation/avrTarget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %swift -typecheck %s -verify -target avr-none-none -disable-objc-interop -parse-stdlib

#if arch(avr) && os(none) && _runtime(_Native) && _endian(little)
class C {}
var x = C()
#endif
var y = x

20 changes: 10 additions & 10 deletions test/Parse/ConditionalCompilation/basicParseErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct S {

#endif

#if arch(leg) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note{{did you mean 'arm'?}} {{10-13=arm}}
#if arch(arn) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note{{did you mean 'arm'?}} {{10-13=arm}}
#endif

#if _endian(mid) // expected-warning {{unknown endianness for build configuration '_endian'}} expected-note{{did you mean 'big'?}} {{13-16=big}}
Expand Down Expand Up @@ -123,26 +123,26 @@ undefinedFunc() // expected-error {{cannot find 'undefinedFunc' in scope}}
#endif

/// Invalid platform condition arguments don't invalidate the whole condition.
#if !arch(tecture) && !os(ystem) && !_endian(ness)
#if !arch(arn) && !os(ystem) && !_endian(ness)
// expected-warning@-1 {{unknown architecture for build configuration 'arch'}}
// expected-note@-2 {{did you mean 'arm'?}} {{11-18=arm}}
// expected-note@-2 {{did you mean 'arm'?}} {{11-14=arm}}
// expected-warning@-3 {{unknown operating system for build configuration 'os'}}
// expected-note@-4 {{did you mean 'OSX'?}} {{27-32=OSX}}
// expected-note@-5 {{did you mean 'PS4'?}} {{27-32=PS4}}
// expected-note@-6 {{did you mean 'none'?}} {{27-32=none}}
// expected-note@-4 {{did you mean 'OSX'?}} {{23-28=OSX}}
// expected-note@-5 {{did you mean 'PS4'?}} {{23-28=PS4}}
// expected-note@-6 {{did you mean 'none'?}} {{23-28=none}}
// expected-warning@-7 {{unknown endianness for build configuration '_endian'}}
// expected-note@-8 {{did you mean 'big'?}} {{46-50=big}}
// expected-note@-8 {{did you mean 'big'?}} {{42-46=big}}
func fn_k() {}
#endif
fn_k()

#if os(cillator) || arch(ive)
#if os(cillator) || arch(i3rm)
// expected-warning@-1 {{unknown operating system for build configuration 'os'}}
// expected-note@-2 {{did you mean 'macOS'?}} {{8-16=macOS}}
// expected-note@-3 {{did you mean 'iOS'?}} {{8-16=iOS}}
// expected-warning@-4 {{unknown architecture for build configuration 'arch'}}
// expected-note@-5 {{did you mean 'arm'?}} {{26-29=arm}}
// expected-note@-6 {{did you mean 'i386'?}} {{26-29=i386}}
// expected-note@-5 {{did you mean 'arm'?}} {{26-30=arm}}
// expected-note@-6 {{did you mean 'i386'?}} {{26-30=i386}}
// expected-note@-7 {{did you mean 'visionOS'?}} {{8-16=visionOS}}
func undefinedFunc() // ignored.
#endif
Expand Down
2 changes: 1 addition & 1 deletion utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ build-subdir=buildbot_incremental
release
assertions

llvm-targets-to-build=X86;ARM;AArch64;PowerPC;RISCV
llvm-targets-to-build=X86;ARM;AArch64;PowerPC;RISCV;AVR

libcxx
llbuild
Expand Down
2 changes: 1 addition & 1 deletion utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ def create_argument_parser():
help='enable building llvm using modules')

option('--llvm-targets-to-build', store,
default='X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly',
default='X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly;AVR',
help='LLVM target generators to build')

option('--llvm-ninja-targets', append,
Expand Down
3 changes: 2 additions & 1 deletion utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@
'llvm_ninja_targets_for_cross_compile_hosts': [],
'llvm_max_parallel_lto_link_jobs':
defaults.LLVM_MAX_PARALLEL_LTO_LINK_JOBS,
'llvm_targets_to_build': 'X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly',
'llvm_targets_to_build':
'X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly;AVR',
'tsan_libdispatch_test': False,
'long_test': False,
'lto_type': None,
Expand Down