Implements blinky for mbed LPC1768

wch-ch32v003
Felix "xq" Queißner 1 year ago
parent 11b5bef01a
commit 38793077e8

@ -15,10 +15,10 @@ jobs:
- all-platforms - all-platforms
- raspberrypi-rp2040 - raspberrypi-rp2040
- espressif-esp - espressif-esp
- nxp-lpc
# TODO: - gigadevice-gd32 # TODO: - gigadevice-gd32
# TODO: - microchip-atmega # TODO: - microchip-atmega
# TODO: - nordic-nrf5x # TODO: - nordic-nrf5x
# TODO: - nxp-lpc
# TODO: - stmicro-stm32 # TODO: - stmicro-stm32
os: os:
- windows-latest - windows-latest

@ -0,0 +1,4 @@
# Examples for the BSP `nxp-lpc`
- [Blinky](src/blinky.zig) on [mbed LPC1768](https://os.mbed.com/platforms/mbed-LPC1768/)
Performs a really basic round robin blinky on the four LEDs on the development board. Flash by copying `zig-out/firmware/mbed-lpc1768_blinky.hex` to the mass storage of the board, then press the big button in the center.

@ -1,75 +1,25 @@
const std = @import("std"); const std = @import("std");
const rp2040 = @import("rp2040");
const stm32 = @import("stm32");
const lpc = @import("lpc"); const lpc = @import("lpc");
const gd32 = @import("gd32");
const nrf5x = @import("nrf5x"); const available_examples = [_]ExampleDesc{
const esp = @import("esp"); .{ .name = "mbed-lpc1768_blinky", .target = lpc.boards.mbed.lpc1768, .file = "src/blinky.zig" },
const atmega = @import("atmega"); };
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const microzig = @import("microzig").init(b, "microzig"); const microzig = @import("microzig").init(b, "microzig");
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const TargetDesc = struct { for (available_examples) |example| {
target: @import("microzig").Target,
name: []const u8,
};
const available_targets = [_]TargetDesc{
// RP2040
.{ .name = "pico", .target = rp2040.boards.raspberry_pi.pico },
.{ .name = "rp2040-eth", .target = rp2040.boards.waveshare.rp2040_eth },
.{ .name = "rp2040-plus-4m", .target = rp2040.boards.waveshare.rp2040_plus_4m },
.{ .name = "rp2040-plus-16m", .target = rp2040.boards.waveshare.rp2040_plus_16m },
.{ .name = "rp2040-matrix", .target = rp2040.boards.waveshare.rp2040_matrix },
// STM32
.{ .name = "stm32f103x8", .target = stm32.chips.stm32f103x8 },
.{ .name = "stm32f303vc", .target = stm32.chips.stm32f303vc },
.{ .name = "stm32f407vg", .target = stm32.chips.stm32f407vg },
.{ .name = "stm32f429zit6u", .target = stm32.chips.stm32f429zit6u },
.{ .name = "stm32f3discovery", .target = stm32.boards.stm32f3discovery },
.{ .name = "stm32f4discovery", .target = stm32.boards.stm32f4discovery },
.{ .name = "stm3240geval", .target = stm32.boards.stm3240geval },
.{ .name = "stm32f429idiscovery", .target = stm32.boards.stm32f429idiscovery },
// NXP LPC
.{ .name = "lpc176x5x", .target = lpc.chips.lpc176x5x },
.{ .name = "mbed-lpc1768", .target = lpc.boards.mbed.lpc1768 },
// GigaDevice GD32
.{ .name = "gd32vf103xb", .target = gd32.chips.gd32vf103xb },
.{ .name = "gd32vf103x8", .target = gd32.chips.gd32vf103x8 },
.{ .name = "sipeed-longan_nano", .target = gd32.boards.sipeed.longan_nano },
// Nordic Nrf5x
.{ .name = "nrf52832", .target = nrf5x.chips.nrf52832 },
.{ .name = "nrf52840", .target = nrf5x.chips.nrf52840 },
.{ .name = "nrf52840-dongle", .target = nrf5x.boards.nordic.nRF52840_Dongle }, // TODO: Add support for DFU files!
// RISC-V Espressif ESP
.{ .name = "esp32-c3", .target = esp.chips.esp32_c3 }, // TODO: Add support for Espressif Update Binaries
// Microchip ATmega
// TODO: Fix compiler bugs
// - https://github.com/ziglang/zig/issues/17219
// .{ .name = "atmega328p", .target = atmega.chips.atmega328p },
// .{ .name = "arduino-nano", .target = atmega.boards.arduino.nano },
// .{ .name = "arduino-uno-rev3", .target = atmega.boards.arduino.uno_rev3 },
};
for (available_targets) |dest| {
// `addFirmware` basically works like addExecutable, but takes a // `addFirmware` basically works like addExecutable, but takes a
// `microzig.Target` for target instead of a `std.zig.CrossTarget`. // `microzig.Target` for target instead of a `std.zig.CrossTarget`.
// //
// The target will convey all necessary information on the chip, // The target will convey all necessary information on the chip,
// cpu and potentially the board as well. // cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{ const firmware = microzig.addFirmware(b, .{
.name = b.fmt("empty-{s}", .{dest.name}), .name = example.name,
.target = dest.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.source_file = .{ .path = "src/empty.zig" }, .source_file = .{ .path = example.file },
}); });
// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()` // `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
@ -82,3 +32,9 @@ pub fn build(b: *std.Build) void {
microzig.installFirmware(b, firmware, .{ .format = .elf }); microzig.installFirmware(b, firmware, .{ .format = .elf });
} }
} }
const ExampleDesc = struct {
target: @import("microzig").Target,
name: []const u8,
file: []const u8,
};

@ -0,0 +1,56 @@
const std = @import("std");
const microzig = @import("microzig");
const chip = microzig.chip;
// LED-1: P1.18
// LED-2: P1.20
// LED-3: P1.21
// LED-4: P1.23
const conn = chip.peripherals.PINCONNECT;
const gpio: *volatile [5]PatchedGpio = @ptrCast(@alignCast(chip.peripherals.GPIO));
const led_mask = [4]u32{
(1 << 18),
(1 << 20),
(1 << 21),
(1 << 23),
};
const all_mask = led_mask[0] | led_mask[1] | led_mask[2] | led_mask[3];
pub fn main() !void {
conn.PINSEL3.modify(.{
.P1_18 = .{ .value = .GPIO_P1 },
.P1_20 = .{ .value = .GPIO_P1 },
.P1_21 = .{ .value = .GPIO_P1 },
.P1_23 = .{ .value = .GPIO_P1 },
});
const p1 = &gpio[1];
p1.dir = all_mask;
while (true) {
for (led_mask) |mask| {
p1.pin_clr = (all_mask & ~mask);
p1.pin_set = mask;
microzig.core.experimental.debug.busy_sleep(100_000);
}
}
}
const PatchedGpio = extern struct {
dir: u32, // 0x2009 C000
__padding0: u32, // 0x2009 C004
__padding1: u32, // 0x2009 C008
__padding2: u32, // 0x2009 C00C
mask: u32, // 0x2009 C010
pin: u32, // 0x2009 C014
pin_set: u32, // 0x2009 C018
pin_clr: u32, // 0x2009 C01C
comptime {
std.debug.assert(@sizeOf(PatchedGpio) == 0x20);
}
};
Loading…
Cancel
Save