Skip to content

Commit 9caa023

Browse files
committed
Fix and test uart_echo for rp2350
1 parent 4414a67 commit 9caa023

File tree

3 files changed

+46
-42
lines changed

3 files changed

+46
-42
lines changed

examples/raspberrypi/rp2xxx/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub fn build(b: *std.Build) void {
2020
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_pwm", .file = "src/rp2040_only/pwm.zig" },
2121
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_random", .file = "src/rp2040_only/random.zig" },
2222
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_rtc", .file = "src/rp2040_only/rtc.zig" },
23-
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_uart-echo", .file = "src/rp2040_only/uart_echo.zig" },
2423
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_usb-hid", .file = "src/rp2040_only/usb_hid.zig" },
2524
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_multicore", .file = "src/rp2040_only/blinky_core1.zig" },
2625
.{ .target = mb.ports.rp2xxx.boards.raspberrypi.pico, .name = "pico_hd44780", .file = "src/rp2040_only/hd44780.zig" },
@@ -38,6 +37,7 @@ pub fn build(b: *std.Build) void {
3837
};
3938

4039
const chip_agnostic_examples: []const ChipAgnosticExample = &.{
40+
.{ .name = "uart-echo", .file = "src/uart_echo.zig" },
4141
.{ .name = "uart-log", .file = "src/uart_log.zig" },
4242
.{ .name = "spi-master", .file = "src/spi_master.zig" },
4343
.{ .name = "spi-slave", .file = "src/spi_slave.zig" },

examples/raspberrypi/rp2xxx/src/rp2040_only/uart_echo.zig

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const std = @import("std");
2+
const microzig = @import("microzig");
3+
const time = microzig.drivers.time;
4+
5+
const rp2xxx = microzig.hal;
6+
const gpio = rp2xxx.gpio;
7+
const clocks = rp2xxx.clocks;
8+
9+
const led = gpio.num(25);
10+
const uart = rp2xxx.uart.instance.num(0);
11+
const baud_rate = 115200;
12+
const uart_tx_pin = gpio.num(0);
13+
const uart_rx_pin = gpio.num(1);
14+
15+
pub fn main() !void {
16+
led.set_function(.sio);
17+
led.set_direction(.out);
18+
led.put(1);
19+
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
20+
pin.set_function(.uart);
21+
}
22+
23+
uart.apply(.{
24+
.baud_rate = baud_rate,
25+
.clock_config = rp2xxx.clock_config,
26+
});
27+
28+
var data: [1]u8 = .{0};
29+
while (true) {
30+
// Read one byte, timeout disabled
31+
uart.read_blocking(&data, null) catch {
32+
// You need to clear UART errors before making a new transaction
33+
uart.clear_errors();
34+
continue;
35+
};
36+
37+
//tries to write one byte with 100ms timeout
38+
uart.write_blocking(&data, time.Duration.from_ms(100)) catch {
39+
uart.clear_errors();
40+
};
41+
// Toggle the led every time we think we've received a character so we
42+
// know something is going on.
43+
led.toggle();
44+
}
45+
}

0 commit comments

Comments
 (0)