Skip to content

Commit

Permalink
rp2xxx: improve RP2350 port (#264)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vesim987 authored Dec 4, 2024
1 parent 80383ae commit e40db55
Show file tree
Hide file tree
Showing 27 changed files with 62,506 additions and 49,351 deletions.
4 changes: 2 additions & 2 deletions examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const Pin = rp2xxx.gpio.Pin;

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

// Use the system() preset helper to change the SYS and REF clock frequencies from default
const system_clock_cfg = clocks.config.preset.system(
// Reduce the system clock by a factor of 4 (different default clock speeds for RP2350/RP2040)
switch (get_cpu()) {
switch (cpu) {
.RP2040 => 125_000_000 / 4,
.RP2350 => 150_000_000 / 4,
},
Expand Down
4 changes: 2 additions & 2 deletions examples/raspberrypi/rp2xxx/src/custom_clock_config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Pin = gpio.Pin;

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

const xosc_freq = microzig.board.xosc_freq;

Expand Down Expand Up @@ -84,7 +84,7 @@ const system_clock_cfg: GlobalConfig = val: {
};

// GlobalConfig has a slight difference between RP2350 (has HSTX) and RP2040 (has RTC)
switch (get_cpu()) {
switch (cpu) {
.RP2040 => {
// Drive RTC off XOSC / 3 for a change of pace!
temp.rtc = .{
Expand Down
10 changes: 8 additions & 2 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/adc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const rp2xxx = microzig.hal;
const gpio = rp2xxx.gpio;
const adc = rp2xxx.adc;
const time = rp2xxx.time;
const cpu = rp2xxx.compatibility.cpu;

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

inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
switch (cpu) {
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
},
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart_second);
},
}

uart.apply(.{
Expand Down
10 changes: 8 additions & 2 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/flash_id.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const rp2xxx = microzig.hal;
const time = rp2xxx.time;
const gpio = rp2xxx.gpio;
const flash = rp2xxx.flash;
const cpu = rp2xxx.compatibility.cpu;

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

pub fn main() !void {
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
switch (cpu) {
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
},
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart_second);
},
}

uart.apply(.{
Expand Down
10 changes: 8 additions & 2 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/flash_program.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const flash = rp2xxx.flash;
const time = rp2xxx.time;
const gpio = rp2xxx.gpio;
const clocks = rp2xxx.clocks;
const cpu = rp2xxx.compatibility.cpu;

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

inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
switch (cpu) {
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
},
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart_second);
},
}

uart.apply(.{
Expand Down
16 changes: 13 additions & 3 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_bus_scan.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,32 @@ const rp2xxx = microzig.hal;
const i2c = rp2xxx.i2c;
const gpio = rp2xxx.gpio;
const peripherals = microzig.chip.peripherals;
const cpu = rp2xxx.compatibility.cpu;

pub const microzig_options = .{
.log_level = .info,
.logFn = rp2xxx.uart.logFn,
};

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);

const i2c0 = i2c.instance.num(0);

pub fn main() !void {
inline for (&.{ gpio.num(0), gpio.num(1) }) |pin| {
pin.set_function(.uart);
switch (cpu) {
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
},
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart_second);
},
}

uart.apply(.{
.baud_rate = 115200,
.baud_rate = baud_rate,
.clock_config = rp2xxx.clock_config,
});
rp2xxx.uart.init_logger(uart);
Expand Down
10 changes: 8 additions & 2 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const time = rp2xxx.time;
const gpio = rp2xxx.gpio;
const clocks = rp2xxx.clocks;
const rand = rp2xxx.rand;
const cpu = rp2xxx.compatibility.cpu;

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

inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
switch (cpu) {
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
},
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart_second);
},
}

uart.apply(.{
Expand Down
10 changes: 8 additions & 2 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/uart_log.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const rp2xxx = microzig.hal;
const time = rp2xxx.time;
const gpio = rp2xxx.gpio;
const clocks = rp2xxx.clocks;
const cpu = rp2xxx.compatibility.cpu;

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

inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
switch (cpu) {
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
},
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart_second);
},
}

uart.apply(.{
Expand Down
10 changes: 8 additions & 2 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/usb_cdc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const time = rp2xxx.time;
const gpio = rp2xxx.gpio;
const clocks = rp2xxx.clocks;
const usb = rp2xxx.usb;
const cpu = rp2xxx.compatibility.cpu;

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

inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
switch (cpu) {
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
},
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart_second);
},
}

uart.apply(.{
Expand Down
10 changes: 8 additions & 2 deletions examples/raspberrypi/rp2xxx/src/rp2040_only/usb_hid.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const time = rp2xxx.time;
const gpio = rp2xxx.gpio;
const clocks = rp2xxx.clocks;
const usb = rp2xxx.usb;
const cpu = rp2xxx.compatibility.cpu;

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

inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
switch (cpu) {
.RP2040 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart);
},
.RP2350 => inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| {
pin.set_function(.uart_second);
},
}

uart.apply(.{
Expand Down
61 changes: 24 additions & 37 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e40db55

Please sign in to comment.