Coder Social home page Coder Social logo

zigembeddedgroup / microzig Goto Github PK

View Code? Open in Web Editor NEW
1.0K 28.0 72.0 12.04 MB

Unified abstraction layer and HAL for several microcontrollers

License: zlib License

Zig 78.94% Shell 0.02% RobotFramework 0.04% Assembly 4.08% C 15.35% Nix 0.36% HTML 0.89% CSS 0.32%
ziglang zig-package zig embedded hal

microzig's People

Contributors

ardelean-calin avatar binarycraft007 avatar burgrp avatar fmaggi avatar freiguy1 avatar grazfather avatar hollmmax avatar jacobly0 avatar jinnosukekato avatar kassane avatar kodesoul avatar kuon avatar l1ucas avatar leap0x7b avatar marnix avatar masterq32 avatar matevzmihalic avatar mattnite avatar mattyhall avatar nancyjlau avatar obenjamint avatar paul-vandell avatar philippwendel avatar psnszsn avatar r4gus avatar rbino avatar sreehax avatar tobiaskohlbau avatar vesim987 avatar yerlaser 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microzig's Issues

Implement compiler_rt for AVR

This work requires upstreaming to https://github.com/ziglang/zig

As a repro compile this program with the following build command:

export fn foo(a: i32, b: i32) i32 {
    return a * b;
}
zig build-exe -target avr-freestanding -mcpu=avr5 test.zig -O ReleaseSmall

and you'll see the following output:

LLVM ERROR: Not supported instr: <MCInst 312 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:53>>

note: doing this in a basic program that is being built by the microzig build function, it does not bundle compiler_rt, so you'll see a missing definition:

ld.lld: error: undefined symbol: __mulsi3

documentation not clear and failre when using example

I'm attempting to use microzig, and I'm also very new to zig and the instructions in README.adoc assume that you have a lot of knowledge about zig and how microzig works.

I attempted to use the sample and despite inferring how to make it work, even with modifications, it fails to compile.

run: zig init-exe

undocumented commands (implied via the vague statement: add the hardware support package as a submodule, this is also the "simple way" as zig init-exe doesn't do a git init, so can't do some git submodule command to add it):

mkdir deps
cd deps
git clone --recursive https://github.com/ZigEmbeddedGroup/microchip-atmega
cd ..

replace build.zig (undocumented what file, and need to replace hardware_support_package with microchip-atmega and replace root_source_file with source_file) w/:

const std = @import("std");
const atmega = @import("deps/microchip-atmega/build.zig");

// the hardware support package should have microzig as a dependency
const microzig = @import("deps/microchip-atmega/deps/microzig/build.zig");

pub fn build(b: *std.build.Builder) !void {
    const optimize = b.standardOptimizeOption(.{});
    var exe = microzig.addEmbeddedExecutable( b, .{
        .name = "my-executable",
        .source_file = .{
            .path = "src/main.zig",
        },
        .backing = .{
            .board = atmega.boards.arduino_nano,

            // instead of a board, you can use the raw chip as well
            // .chip = atmega.chips.atmega328p,
        },
        .optimize = optimize,
    });
    exe.install();
}

replace src/main.zig with the next block (undocumented what file to put it in).

run zig build and see the following failure:

$ zig build
zig build-exe my-executable Debug avr-freestanding-eabi: error: the following command terminated unexpectedly:
[xxx]/github/zig/build/zig2 build-exe /private/tmp/mcre/deps/microchip-atmega/deps/microzig/src/start.zig -fno-strip --cache-dir /private/tmp/mcre/zig-cache --global-cache-dir [xxx]/.cache/zig --name my-executable -fno-compiler-rt -fsingle-threaded -target avr-freestanding-eabi -mcpu avr5 --script /private/tmp/mcre/zig-cache/microzig/bad2341405a5fe8c06f6286f91ea1100/ATmega328P_AVR5.ld --mod microzig:config,chip,cpu,hal,board:/private/tmp/mcre/deps/microchip-atmega/deps/microzig/src/microzig.zig --mod chip:microzig:/private/tmp/mcre/deps/microchip-atmega/src/chips/ATmega328P.zig --mod board:microzig:/private/tmp/mcre/deps/microchip-atmega/src/boards/arduino_nano.zig --mod hal:microzig:/private/tmp/mcre/deps/microchip-atmega/src/hals/ATmega328P.zig --mod app:microzig:/private/tmp/mcre/src/main.zig --mod cpu:microzig:/private/tmp/mcre/deps/microchip-atmega/deps/microzig/src/modules/cpus/avr5.zig --mod config::/private/tmp/mcre/zig-cache/microzig/config-6df6165a62f30831cad66fa94379f8d3.zig --deps app,microzig --enable-cache --listen=- 
Build Summary: 1/4 steps succeeded; 1 failed (disable with -fno-summary)
install transitive failure
└─ install my-executable transitive failure
   └─ zig build-exe my-executable Debug avr-freestanding-eabi failure
      └─ linkerscript success
error: the following build command failed with exit code 1:
/private/tmp/mcre/zig-cache/o/b840765e239219fa1562b810d024cd97/build [xxx]/github/zig/build/zig2 /private/tmp/mcre /private/tmp/mcre/zig-cache [xxx]/.cache/zig

environment: MacOS Ventura 13.2

zig version: 0.11.0-dev.2249+dcdb87836

I'm unsure what to do now to make the necessary executable.

Improve customization of linker scripts

Right now in raspberrypi-rp2040 we've had to hardcode the linker script to allow a boot2 section, time_critical section, and have all of sram executable so that some of it may be executed by the processor. Linker scripts can be pretty complex, but maybe we can reduce the feature to only what's typically required in embedded systems. If users are already at the point where they need very specific features or linker script layouts then it's already easy enough for them to write their own.

Compile error on Raspberry Pi

Building a microzig project on a Raspberry Pi 2 fails with this error:

/home/pi/.cache/zig/p/1220af58bdaa721b8189f3a7adfda660517dd354463463388e96d69fe4ceccf80b92/build.zig:161:55: error: expected type 'usize', found 'u64'
                .elf, .bin, .hex, .dfu, .esp => |val| {
                                                      ^
/home/pi/.cache/zig/p/1220af58bdaa721b8189f3a7adfda660517dd354463463388e96d69fe4ceccf80b92/build.zig:161:55: note: unsigned 32-bit int cannot represent all possible unsigned 64-bit values

What could be the reason for this? Maybe because the Pi's CPU is 32 bit, and u64 is hardcoded somewhere?

[Tracking issue] Platform support/wishlist

Currently, the number of supported platforms is rather minimal. If the owners are alright with it, I'd like to designate this issue as a tracking issue for boards/chips which are not yet implemented in here with the aim of getting a good selection supported.

To start off the list, here's a few chips I have come across:

  • ATMega644/A (chip)
  • ATTiny25/45/85 (chip)

Add Support for SparkFun RED-V RISCV Board

I am currently revisiting computer architecture and design for my personal project of building an operating system. In an attempt to tap into my dormant knowledge of the hardware-software concepts, I would like to contribute and add support for the SparkFun RED-V board. It has a RISC-V chip from SiFive, FE310.

Various issues

I am having troubles getting examples building with the monorepo. Reporting my issues as requested.

  1. No mention of need to install requirements.
  2. bundle.py uses pathspec with the negate kwarg in match_tree, but requirements.txt doesn't pin a version. This used 0.11.0 on my machine, but negate shows up in 0.12.0
  3. bundle.py uses the --hard-deference option from tar, which is not a valid option for OSX tar. I suggest using tarlib. I got around this, however, by installing gnutar with brew and symlinking it to tar on my PATH.
  4. No .zon files with the build.zig files for the example. I don't know how to write these to have it point to the server.

Please help: with format a string with numbers or allocator instance in microzig.

Hello!
Thank you for your work on that project.

I start to use it in development. I want to write some simple apps to understand if it works.

I want to be able to format a string with numbers.

I need help with the allocator issue. I need help finding a way to use the standard library functions that require an allocator instance.

Example:

  const allocator = os.heap.page_allocator;

   const string1 = try std.fmt.allocPrint(allocator, "{d}", .{count()});
   defer allocator.free(string1);
   microzig.hal.uart.write(0, string1);

Gives me the error:

 error: root struct of file 'start' has no member named 'os'
 root.os.heap.page_allocator

Is there a way to get the allocator in the Microzig? or ESP32C2 environment? Can I resolve those issues without the allocator usage?
Thank you in advance.

STM32F4XX does not support SysTick register

I think this may be a bug in regz, not microzig, or maybe whatever svd file that was used to generate the register definitions. afaik All Cortex devices have the same definition of this register. I coppied a samd one and it worked without issue

No output files generated

If I clone the repository and run zig build, zig-out folder isn't generated. Only zig-cache is. Tried with this compiler zig-linux-x86_64-0.11.0-dev.2317+46b2f1f70.

I would expect for test programs to compile.

Support serial over USB (CEC ADC)

I'd like to have a log.zig logFn that I could use to emit debug logs over USB, rather than UART.

Currently Microzig has support for acting as a USB HID device. I believe emitting debug logs over USB would require support for acting as a "serial device", which uses USB CDC/ADC.

Suggestions re: STM32 from a Rust Embedded dev

Hey! Chiming in as someone doing embedded Rust things:

Just wanted to share particularly with respect to STM32 chips, which have an insane number of variants, SVD files that are often wrong, and a lot of challenging details, it might be worth looking at https://github.com/embassy-rs/stm32-data, which https://embassy.rs uses for the unified stm32 HAL. It is typically more actively patched and maintained for correctness than the upstream STM32 SVD data sources.

In general, SVD files often require patching and continued maintenance, https://github.com/embassy-rs/chiptool might be a good inspiration, which uses YAML files to apply patches and groupings, rather than hand-editing SVD files.

Feel free to close, or let me know if y'all would like to share notes on anything. Excited to see what you all build!

(edited title to make it more clear this is just my opinion, not like an "offical embedded rust position")

Getting Started

How do I get started ? The instructions on setting up a new project seem out of date.
I would like to develop for raspberry pi pico.

AVR: Support C backend

Right now, the AVR support is degraded. With using avr-gcc, we can make it work quite well though.

This requires updating the AVR code to use a different logic in the start code, and just implement a extern fn main() c_int, that jumps into the microzig code and is happy about .bss, .data being already set up.

As-is, we cannot implement the whole startup logic ourselves via C backend, as some features are still missing.

Add "hal" packages to microzig

Similar to how an app can have it's own packages, create another option to the build function that adds a "hal" package. This is a package that only depends on microzig and would be used to write drivers for chips with similar peripherals, Eg. an nrf52 hal.

An application would be able to access the hal via microzig.hal, and with it's access to other microzig namespaces it would be able to do conditional compilation for different chips if the need arose.

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.