Something went wrong. Try again.
Baremetal Zig running on RP2350
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849const hal = @import("hal");const clocks = hal.clocks;
const LED_PIN: u32 = 25;
fn flash_led(max_delay: u32, times: i16) void { var counter: i16 = 0; while (times == -1 or counter < times) : (counter += 1) { hal.gpio.toggle(LED_PIN) catch unreachable; hal.dummy_wait(max_delay); }}
// TODO: Needs to be more robust and we also need a panic handlerexport fn _main_runner() void { _main() catch |e| { hal.Uart.write(.UART0, @errorName(e)); };}
fn _main() !void { hal.gpio.init(LED_PIN, .output) catch unreachable;
flash_led(1_000_000, 10);
clocks.xoscInit(.pico2_default); clocks.switchCLKref(); clocks.PLL.applyConfiguration(.PLL_SYS, .pico2_pll_sys_default); clocks.switchCLKsys(); clocks.enableCLKperi();
hal.Uart.init(.UART0, 150_000_000, 115200);
// TODO: These functions should be part of the GPIO library. // GPIO_0 = UART_TX, GPIO_1 = UART_RX hal.mmio.write(hal.registers.GPIO_CTRL + (0 * 8), 0x2); hal.mmio.write(hal.registers.GPIO_CTRL + (1 * 8), 0x2);
// Clear isolate bit from TX hal.mmio.write_clr(hal.registers.PADS_BANK0_GPIO + (0 * 4), 1 << 8); // Clear isolate bit, enable input, enable pull up, disable pull down hal.mmio.write_xor(hal.registers.PADS_BANK0_GPIO + (1 * 4), 1 << 8 | 1 << 6 | 1 << 3 | 1 << 2);
while (true) { const rx = hal.Uart.UART0.read(); hal.Uart.UART0.write(&.{ rx, '\r', '\n' }); }}