GithubHelp home page GithubHelp logo

avr-arduino-zig's People

Contributors

firefox317 avatar mattnite avatar rekihyt avatar thatoneruffian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avr-arduino-zig's Issues

Use ravedude instead of avrdude

I suggest changing the use of avrdude for build upload to ravedude, avoiding the need to manually find and pass the device where the arduino is located.

About ravedude: It's an avrdude wrapper first made for use with Rust and cargo run, automatically selecting the port the arduino is connected to as well as board and programmer arguments depending on the board name passed to ravedude.

While this would add another dependency in ravedude, it would also remove the requirement to manually specify avrdude arguments, including the correct tty device the arduino is connected to.

The changes to build.zig would be:

  • Remove the `flash_command' constant
  • change the definition of the avrdude constant with
const avrdude = b.addSystemCommand(&.{
        "ravedude",
        "uno",
        bin_path,
    })

Update to v0.10 (stage3)

I have made some modifications (nothing conclusive to the point of sending MR).
However, I could not solve the last error involving the linker (ld) not recognizing memcpy.

Output:

error: ld.lld: undefined symbol: memcpy
    note: referenced by main.zig:25
    note:               /home/kassane/Documentos/Projetos/avr-arduino-zig/zig-cache/o/0ab5a5c493c713136f428c7e79480d08/avr-arduino-zig.o:(_start)
error: avr-arduino-zig...
error: The following command exited with error code 1:
/home/kassane/.local/bin/zig build-exe -freference-trace=256 /home/kassane/Documentos/Projetos/avr-arduino-zig/src/start.zig -OReleaseSafe --cache-dir /home/kassane/Documentos/Projetos/avr-arduino-zig/zig-cache --global-cache-dir /home/kassane/.cache/zig --name avr-arduino-zig -fno-compiler-rt -target avr-freestanding-none -mcpu atmega328p --script /home/kassane/Documentos/Projetos/avr-arduino-zig/src/linker.ld --enable-cache

Changes:

diff --git a/build.zig b/build.zig
index 09ec19d..f492a75 100644
--- a/build.zig
+++ b/build.zig
@@ -29,11 +29,11 @@ pub fn build(b: *Builder) !void {
         try tmp.appendSlice("-Uflash:w:");
         try tmp.appendSlice(bin_path);
         try tmp.appendSlice(":e");
-        break :blk tmp.toOwnedSlice();
+        break :blk tmp.toOwnedSlice() catch unreachable;
     };
 
     const upload = b.step("upload", "Upload the code to an Arduino device using avrdude");
-    const avrdude = b.addSystemCommand(&.{
+    const avrdude = b.addSystemCommand(&[_][]const u8{
         "avrdude",
         "-carduino",
         "-patmega328p",
@@ -46,7 +46,7 @@ pub fn build(b: *Builder) !void {
     avrdude.step.dependOn(&exe.install_step.?.step);
 
     const objdump = b.step("objdump", "Show dissassembly of the code using avr-objdump");
-    const avr_objdump = b.addSystemCommand(&.{
+    const avr_objdump = b.addSystemCommand(&[_][]const u8{
         "avr-objdump",
         "-dh",
         bin_path,
@@ -55,7 +55,7 @@ pub fn build(b: *Builder) !void {
     avr_objdump.step.dependOn(&exe.install_step.?.step);
 
     const monitor = b.step("monitor", "Opens a monitor to the serial output");
-    const screen = b.addSystemCommand(&.{
+    const screen = b.addSystemCommand(&[_][]const u8{
         "screen",
         tty,
         "115200",
diff --git a/src/atmega328p.zig b/src/atmega328p.zig
index 06d4880..35b21bb 100644
--- a/src/atmega328p.zig
+++ b/src/atmega328p.zig
@@ -1313,8 +1313,8 @@ pub fn mmioInt(addr: usize, comptime size: usize, comptime T: type) *volatile Mm
 }
 
 const InterruptVector = extern union {
-    C: fn () callconv(.C) void,
-    Naked: fn () callconv(.Naked) void,
+    C: *const fn () callconv(.C) void,
+    Naked: *const fn () callconv(.Naked) void,
     // Interrupt is not supported on arm
 };
 
diff --git a/src/start.zig b/src/start.zig
index 596febc..e60f677 100644
--- a/src/start.zig
+++ b/src/start.zig
@@ -4,8 +4,12 @@ const uart = @import("uart.zig");
 const std = @import("std");
 const builtin = std.builtin;
 
-export const vector_table linksection(".vectors") = blk: {
-    std.debug.assert(std.mem.eql(u8, "RESET", std.meta.fields(atmega328p.VectorTable)[0].name));
+comptime {
+    @export(vector_table, .{ .name = "vector_table", .linkage = .Strong });
+}
+
+const vector_table linksection(".vectors") = blk: {
+    // std.debug.assert(std.mem.eql(u8, "RESET", std.meta.fields(atmega328p.VectorTable)[0].name));
     var asm_str: []const u8 = "jmp _start\n";
 
     const has_interrupts = @hasDecl(main, "interrupts");
@@ -57,7 +61,13 @@ export const vector_table linksection(".vectors") = blk: {
         asm_str = asm_str ++ new_insn ++ "\n";
     }
 
-    break :blk asm (asm_str);
+    const T = struct {
+        fn _start() callconv(.Naked) void {
+            asm volatile (asm_str);
+        }
+    };
+
+    break :blk T._start;
 };
 
 export fn _unhandled_vector() void {
@@ -122,7 +132,7 @@ fn clear_bss() void {
     // Probably a good idea to add clobbers here, but compiler doesn't seem to care
 }
 
-pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
+pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace, _: ?usize) noreturn {
     // Currently assumes that the uart is initialized in main().
     uart.write("PANIC: ");
     uart.write(msg);

Update for Zig 0.8.0

zig build won't compile due to update in 0.8.0 release:

@import("builtin") no longer re-exports std.builtin

StackTrace struct is now accessed via @import("std").builtin.StackTrace

Updating start.zig panic function to:
error_return_trace: ?*@import("std").builtin.StackTrace solves the issue.

Update to zig 0.11.0

I am trying to build this project using zig 0.11.0. After fixing some syntax in build.zig to get the compiler happy:

const std = @import("std");

pub fn build(b: *std.Build) !void {
    const uno = std.zig.CrossTarget{
        .cpu_arch = .avr,
        .cpu_model = .{ .explicit = &std.Target.avr.cpu.atmega328p },
        .os_tag = .freestanding,
        .abi = .none,
    };

    const target = uno;

    const exe = b.addExecutable(.{
        .name = "avr-arduino-zig",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = .ReleaseSafe, // workaround LLVM limitation
    });
    exe.setLinkerScriptPath(std.build.FileSource{ .path = "src/linker.ld" });

    b.installArtifact(exe);

    // I simply commented the rest out
}

it now fails with the following error:

zig build-exe avr-arduino-zig ReleaseSafe avr-freestanding-none: error: LLVM ERROR: Expected a constant shift amount!

zig build-exe avr-arduino-zig ReleaseSafe avr-freestanding-none: error: the following command terminated unexpectedly:
...
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install avr-arduino-zig transitive failure
   └─ zig build-exe avr-arduino-zig ReleaseSafe avr-freestanding-none failure
error: the following build command failed with exit code 1:
...

Do you have any idea what I can do to debug this further?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.