Skip to content

Commit

Permalink
Fix and test uart_echo for rp2350
Browse files Browse the repository at this point in the history
  • Loading branch information
Grazfather committed Mar 7, 2025
1 parent 4414a67 commit 9caa023
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 42 deletions.
2 changes: 1 addition & 1 deletion examples/raspberrypi/rp2xxx/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub fn build(b: *std.Build) void {
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_pwm", .file = "src/rp2040_only/pwm.zig" },
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_random", .file = "src/rp2040_only/random.zig" },
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_rtc", .file = "src/rp2040_only/rtc.zig" },
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_uart-echo", .file = "src/rp2040_only/uart_echo.zig" },
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_usb-hid", .file = "src/rp2040_only/usb_hid.zig" },
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_multicore", .file = "src/rp2040_only/blinky_core1.zig" },
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_hd44780", .file = "src/rp2040_only/hd44780.zig" },
Expand All @@ -38,6 +37,7 @@ pub fn build(b: *std.Build) void {
};

const chip_agnostic_examples: []const ChipAgnosticExample = &.{
.{ .name = "uart-echo", .file = "src/uart_echo.zig" },
.{ .name = "uart-log", .file = "src/uart_log.zig" },
.{ .name = "spi-master", .file = "src/spi_master.zig" },
.{ .name = "spi-slave", .file = "src/spi_slave.zig" },
Expand Down
41 changes: 0 additions & 41 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/uart_echo.zig

This file was deleted.

45 changes: 45 additions & 0 deletions examples/raspberrypi/rp2xxx/src/uart_echo.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const std = @import("std");
const microzig = @import("microzig");
const time = microzig.drivers.time;

const rp2xxx = microzig.hal;
const gpio = rp2xxx.gpio;
const clocks = rp2xxx.clocks;

const led = gpio.num(25);
const uart = rp2xxx.uart.instance.num(0);
const baud_rate = 115200;
const uart_tx_pin = gpio.num(0);
const uart_rx_pin = gpio.num(1);

pub fn main() !void {
led.set_function(.sio);
led.set_direction(.out);
led.put(1);
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
}

uart.apply(.{
.baud_rate = baud_rate,
.clock_config = rp2xxx.clock_config,
});

var data: [1]u8 = .{0};
while (true) {
// Read one byte, timeout disabled
uart.read_blocking(&data, null) catch {
// You need to clear UART errors before making a new transaction
uart.clear_errors();
continue;
};

//tries to write one byte with 100ms timeout
uart.write_blocking(&data, time.Duration.from_ms(100)) catch {
uart.clear_errors();
};
// Toggle the led every time we think we've received a character so we
// know something is going on.
led.toggle();
}
}

0 comments on commit 9caa023

Please sign in to comment.