Skip to content

Commit e40db55

Browse files
authored
rp2xxx: improve RP2350 port (#264)
* flake: update lock * rp2xxx: update rp2350 svd to the latest one from pico-sdk * rp2xxx: update rp2040 svd to the latest one from pico-sdk * rp2xxx: port more HALs to RP2350 and enable examples * rp2xxx: change get_cpu() to comptime known value to avoid calling at runtime
1 parent 80383ae commit e40db55

27 files changed

+62506
-49351
lines changed

examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const Pin = rp2xxx.gpio.Pin;
99

1010
/// The HAL provides a convenvience function for detecting which of the RP2XXX
1111
/// family you're currently compiling for.
12-
const get_cpu = rp2xxx.compatibility.get_cpu;
12+
const cpu = rp2xxx.compatibility.cpu;
1313

1414
// Use the system() preset helper to change the SYS and REF clock frequencies from default
1515
const system_clock_cfg = clocks.config.preset.system(
1616
// Reduce the system clock by a factor of 4 (different default clock speeds for RP2350/RP2040)
17-
switch (get_cpu()) {
17+
switch (cpu) {
1818
.RP2040 => 125_000_000 / 4,
1919
.RP2350 => 150_000_000 / 4,
2020
},

examples/raspberrypi/rp2xxx/src/custom_clock_config.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Pin = gpio.Pin;
1010

1111
/// The HAL provides a convenvience function for detecting which of the RP2XXX
1212
/// family you're currently compiling for.
13-
const get_cpu = rp2xxx.compatibility.get_cpu;
13+
const cpu = rp2xxx.compatibility.cpu;
1414

1515
const xosc_freq = microzig.board.xosc_freq;
1616

@@ -84,7 +84,7 @@ const system_clock_cfg: GlobalConfig = val: {
8484
};
8585

8686
// GlobalConfig has a slight difference between RP2350 (has HSTX) and RP2040 (has RTC)
87-
switch (get_cpu()) {
87+
switch (cpu) {
8888
.RP2040 => {
8989
// Drive RTC off XOSC / 3 for a change of pace!
9090
temp.rtc = .{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const rp2xxx = microzig.hal;
66
const gpio = rp2xxx.gpio;
77
const adc = rp2xxx.adc;
88
const time = rp2xxx.time;
9+
const cpu = rp2xxx.compatibility.cpu;
910

1011
const uart = rp2xxx.uart.instance.num(0);
1112
const baud_rate = 115200;
@@ -21,8 +22,13 @@ pub fn main() void {
2122
.temp_sensor_enabled = true,
2223
});
2324

24-
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
25-
pin.set_function(.uart);
25+
switch (cpu) {
26+
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
27+
pin.set_function(.uart);
28+
},
29+
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
30+
pin.set_function(.uart_second);
31+
},
2632
}
2733

2834
uart.apply(.{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const rp2xxx = microzig.hal;
55
const time = rp2xxx.time;
66
const gpio = rp2xxx.gpio;
77
const flash = rp2xxx.flash;
8+
const cpu = rp2xxx.compatibility.cpu;
89

910
const uart = rp2xxx.uart.instance.num(0);
1011
const baud_rate = 115200;
@@ -23,8 +24,13 @@ pub const std_options = struct {
2324
};
2425

2526
pub fn main() !void {
26-
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
27-
pin.set_function(.uart);
27+
switch (cpu) {
28+
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
29+
pin.set_function(.uart);
30+
},
31+
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
32+
pin.set_function(.uart_second);
33+
},
2834
}
2935

3036
uart.apply(.{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const flash = rp2xxx.flash;
66
const time = rp2xxx.time;
77
const gpio = rp2xxx.gpio;
88
const clocks = rp2xxx.clocks;
9+
const cpu = rp2xxx.compatibility.cpu;
910

1011
const led = gpio.num(25);
1112
const uart = rp2xxx.uart.instance.num(0);
@@ -32,8 +33,13 @@ pub fn main() !void {
3233
led.set_direction(.out);
3334
led.put(1);
3435

35-
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
36-
pin.set_function(.uart);
36+
switch (cpu) {
37+
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
38+
pin.set_function(.uart);
39+
},
40+
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
41+
pin.set_function(.uart_second);
42+
},
3743
}
3844

3945
uart.apply(.{

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,32 @@ const rp2xxx = microzig.hal;
55
const i2c = rp2xxx.i2c;
66
const gpio = rp2xxx.gpio;
77
const peripherals = microzig.chip.peripherals;
8+
const cpu = rp2xxx.compatibility.cpu;
89

910
pub const microzig_options = .{
1011
.log_level = .info,
1112
.logFn = rp2xxx.uart.logFn,
1213
};
1314

1415
const uart = rp2xxx.uart.instance.num(0);
16+
const baud_rate = 115200;
17+
const uart_tx_pin = gpio.num(0);
18+
const uart_rx_pin = gpio.num(1);
19+
1520
const i2c0 = i2c.instance.num(0);
1621

1722
pub fn main() !void {
18-
inline for (&.{ gpio.num(0), gpio.num(1) }) |pin| {
19-
pin.set_function(.uart);
23+
switch (cpu) {
24+
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
25+
pin.set_function(.uart);
26+
},
27+
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
28+
pin.set_function(.uart_second);
29+
},
2030
}
2131

2232
uart.apply(.{
23-
.baud_rate = 115200,
33+
.baud_rate = baud_rate,
2434
.clock_config = rp2xxx.clock_config,
2535
});
2636
rp2xxx.uart.init_logger(uart);

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const time = rp2xxx.time;
99
const gpio = rp2xxx.gpio;
1010
const clocks = rp2xxx.clocks;
1111
const rand = rp2xxx.rand;
12+
const cpu = rp2xxx.compatibility.cpu;
1213

1314
const led = gpio.num(25);
1415
const uart = rp2xxx.uart.instance.num(0);
@@ -32,8 +33,13 @@ pub fn main() !void {
3233
led.set_direction(.out);
3334
led.put(1);
3435

35-
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
36-
pin.set_function(.uart);
36+
switch (cpu) {
37+
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
38+
pin.set_function(.uart);
39+
},
40+
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
41+
pin.set_function(.uart_second);
42+
},
3743
}
3844

3945
uart.apply(.{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const rp2xxx = microzig.hal;
55
const time = rp2xxx.time;
66
const gpio = rp2xxx.gpio;
77
const clocks = rp2xxx.clocks;
8+
const cpu = rp2xxx.compatibility.cpu;
89

910
const led = gpio.num(25);
1011
const uart = rp2xxx.uart.instance.num(0);
@@ -28,8 +29,13 @@ pub fn main() !void {
2829
led.set_direction(.out);
2930
led.put(1);
3031

31-
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
32-
pin.set_function(.uart);
32+
switch (cpu) {
33+
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
34+
pin.set_function(.uart);
35+
},
36+
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
37+
pin.set_function(.uart_second);
38+
},
3339
}
3440

3541
uart.apply(.{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const time = rp2xxx.time;
77
const gpio = rp2xxx.gpio;
88
const clocks = rp2xxx.clocks;
99
const usb = rp2xxx.usb;
10+
const cpu = rp2xxx.compatibility.cpu;
1011

1112
const led = gpio.num(25);
1213
const uart = rp2xxx.uart.instance.num(0);
@@ -68,8 +69,13 @@ pub fn main() !void {
6869
led.set_direction(.out);
6970
led.put(1);
7071

71-
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
72-
pin.set_function(.uart);
72+
switch (cpu) {
73+
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
74+
pin.set_function(.uart);
75+
},
76+
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
77+
pin.set_function(.uart_second);
78+
},
7379
}
7480

7581
uart.apply(.{

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const time = rp2xxx.time;
77
const gpio = rp2xxx.gpio;
88
const clocks = rp2xxx.clocks;
99
const usb = rp2xxx.usb;
10+
const cpu = rp2xxx.compatibility.cpu;
1011

1112
const led = gpio.num(25);
1213
const uart = rp2xxx.uart.instance.num(0);
@@ -70,8 +71,13 @@ pub fn main() !void {
7071
led.set_direction(.out);
7172
led.put(1);
7273

73-
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
74-
pin.set_function(.uart);
74+
switch (cpu) {
75+
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
76+
pin.set_function(.uart);
77+
},
78+
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
79+
pin.set_function(.uart_second);
80+
},
7581
}
7682

7783
uart.apply(.{

0 commit comments

Comments
 (0)