zigembeddedgroup / microzig Goto Github PK
View Code? Open in Web Editor NEWUnified abstraction layer and HAL for several microcontrollers
License: zlib License
Unified abstraction layer and HAL for several microcontrollers
License: zlib License
We had a nice support matrix on the ZEG Front Page, but it was hand-maintained. This didn't really scale well, so the idea is that the tools/bundle.py
also creates a file https://downloads.microzig.tech/.data/bsp-overview.svg that shows a table of all board support packages and their current status
Revert the #153 workaround for ziglang/zig#17882, once we switch to Zig 0.12.0 (or 0.11.1), assuming that newer version fixes the issue.
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
The new build interface can support several different output files, but DFU is missing
New build interface can handle several formats, but the ESP image format is missing:
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.
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.
Expose common functions like install()
and setBuildMode()
, also installRaw()
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?
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:
For AVR, it must be in RAM to be efficiently accessed, for ARM devices, it is less important
The field exists in TransferConfig
but in trigger_transfer
the .DATA_SIZE
register is always set to .SIZE_BYTE
Hey all,
What's the procedure for porting Microzig to MCUs that are neither Microchip/Atmel or ARM? Do we need to create our own SVD/ATDF? Is there documentation on those protocols?
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.
I am having troubles getting examples building with the monorepo. Reporting my issues as requested.
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--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
.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.
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
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.
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.
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")
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.
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.
Bugs:
Features:
Nice-to-have:
It should just assert/panic if an error happens, and probably give some reason why.
STM32F103 sad file did not define which cortex-m core it had so it wasn't able to output a vector table. The resulting code causes a compiler error where it should succeed. BUT if the user tries to specify interrupt handlers they should get a compiler error with an explanation.
I found the packages
options that I need to pass to addEmbeddedExecutable
.
Is there a way to either make it work or make calling addPackagePath
afterward an error? If not, maybe add a bigger note in the documentation.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.