embassy icon indicating copy to clipboard operation
embassy copied to clipboard

RP235x support

Open brandonros opened this issue 1 year ago • 16 comments

Do we know enough yet what we need to do to be able to support RP2350 instead of just RP2040?

brandonros avatar Aug 08 '24 22:08 brandonros

Initial support is coming in #3243, though much work remains.

CBJamo avatar Aug 09 '24 02:08 CBJamo

I've preordered the Raspberry Pi Pico 2 and would be willing to test it on actual hardware and write/verify some examples.

BjornTheProgrammer avatar Aug 12 '24 09:08 BjornTheProgrammer

I've got a couple of Tiny2350 from pimoroni, got blinky to work without much trouble except that elf2uf2 would work because of hard float in the executable.

elf2uf2-rs ./target/thumbv8m.main-none-eabihf/debug/blinky                                                                                                                                                                            
Error: "HARD-FLOAT not supported"

Worked around that by using picotool and this small script: picotool-run.sh

picotool uf2 convert -t elf $1 out.uf2
picotool load out.uf2
picotool reboot

in .cargo/config.toml for the runner

This is a quick workaround until we get support in elf2uf2 for thumbv8m.main-none-eabihf or full probe-rs support.

ionspin avatar Aug 20 '24 11:08 ionspin

JP has a pull request for elf2uf2-rs to allow use with the rp2350. https://github.com/JoNil/elf2uf2-rs/pull/33

CBJamo avatar Aug 20 '24 19:08 CBJamo

However, I recommend switching to picotool because it's faster and doesn't require mounting the disk drive. Binary releases are available from https://github.com/raspberrypi/pico-sdk-tools/releases

thejpster avatar Aug 22 '24 18:08 thejpster

I'm running into a bit of issue, I'm getting different behavior after picotool reboot and resetting the RP2350 (using reset button on Tiny2350, or just unplugging the Pico2). After picotool reboot it works fine every time, but the reset gets it into a partially broken state.

This is more or less the current setup, it's reproducible if I remove the USB part and just leave the blinky loop

#[embassy_executor::main]
async fn main(spawner: Spawner) {
    let peripherals = embassy_rp::init(Default::default());


    let other_side_channel = OTHER_SIDE_CHANNEL.init(Channel::new());

    UsbHandler::new(peripherals.USB, other_side_channel, spawner, true);


    
    let delay = 100;

    let mut counter = 0;
    #[cfg(feature = "tiny2350")]
    {
        let mut red_led = Output::new(peripherals.PIN_18, Level::Low);
        let mut green_led = Output::new(peripherals.PIN_19, Level::Low);
        let mut blue_led = Output::new(peripherals.PIN_20, Level::Low);
        green_led.set_high();
        blue_led.set_high();
        red_led.set_high();
        loop {
            log::info!("Tick {}", counter);
            counter += 1;
            red_led.set_low();
            Timer::after_millis(delay).await;

            red_led.set_high();
            Timer::after_millis(delay).await;

            green_led.set_low();
            Timer::after_millis(delay).await;

            green_led.set_high();
            Timer::after_millis(delay).await;

            blue_led.set_low();
            Timer::after_millis(delay).await;

            blue_led.set_high();
            Timer::after_millis(delay).await;
        }
    }

    #[cfg(feature = "pico2")]
    {
        let mut led =  Output::new(peripherals.PIN_25, Level::Low);
        led.set_low();
        loop {
            log::info!("Tick {}", counter);
            counter += 1;
            led.set_high();
            Timer::after_millis(delay).await;
            led.set_low();
            Timer::after_millis(delay).await;
        }
    }

}

On picotool reboot the blinks and log-over-usb works fine, as expected, but when using reset on Tiny2350 or unplugging and plugging in on Pico2, the blinks are not there, while log-over-usb gets set up most of the time.

Any clues on why this is happening? I'm planning to solder the headers tomorrow so I can try to set up UART and see if I get more info that way.

ionspin avatar Aug 23 '24 20:08 ionspin

I don't think this is correct: https://github.com/embassy-rs/embassy/blob/423e5d7655d038ead9ad7f5f448cabbd0b330660/embassy-rp/src/clocks.rs#L515

image

I suspect picotool reboot initializes ticks, and embassy-rp does not, here's my log collected through defmt-uart



0.037927 INFO  Defmt serial test
0.038167 INFO  USB: config_descriptor used: 94
0.038175 INFO  USB: bos_descriptor used: 12
0.038182 INFO  USB: msos_descriptor used: 0
0.038188 INFO  USB: control_buf size: 256
0.038432 INFO  Defmt tick 0
0.238699 INFO  Defmt tick 1
0.364565 DEBUG SET_CONFIGURATION: configured
0.365786 DEBUG Set line coding to: LineCoding { stop_bits: One, data_bits: 8, parity_type: None, data_rate: 9600 }
0.438751 INFO  Defmt tick 2
0.537203 DEBUG Set dtr true, rts true
0.638785 INFO  Defmt tick 3
0.838805 INFO  Defmt tick 4
1.038821 INFO  Defmt tick 5
1.238837 INFO  Defmt tick 6
1.438854 INFO  Defmt tick 7
1.638870 INFO  Defmt tick 8
1.838886 INFO  Defmt tick 9
2.038903 INFO  Defmt tick 10
2.238919 INFO  Defmt tick 11




0.000000 INFO  Defmt serial test
0.000000 INFO  USB: config_descriptor used: 94
0.000000 INFO  USB: bos_descriptor used: 12
0.000000 INFO  USB: msos_descriptor used: 0
0.000000 INFO  USB: control_buf size: 256
0.000000 INFO  Defmt tick 0
0.000000 DEBUG SET_CONFIGURATION: configured
0.000000 DEBUG Set line coding to: LineCoding { stop_bits: One, data_bits: 8, parity_type: None, data_rate: 9600 }
0.000000 DEBUG Set dtr true, rts true

First part is picotool reboot and second is manual restart, note the timestamps

I'll try to submit a pull request for this today if I'm right and setting ticks up fixes it.

ionspin avatar Aug 24 '24 09:08 ionspin

Nice catch. When doing the initial support I loaded all my firmware using the uf2 method, and so the usb bootloader must've set up timer0 for me. Since the bootrom source is available it'd probably be a good idea to take a look through for anything else it was doing for me.

CBJamo avatar Aug 24 '24 20:08 CBJamo

just calling this out for anybody in case they weren’t aware

https://hackaday.com/2024/09/04/the-worsening-raspberry-pi-rp2350-e9-erratum-situation/

brandonros avatar Sep 08 '24 13:09 brandonros

I'm working on adding TRNG support, hopefully I'll have a draft this weekend.

ionspin avatar Sep 14 '24 09:09 ionspin

It otc 14. Is any progress for the RP2350 Pico2...

sndnvaps avatar Oct 14 '24 14:10 sndnvaps

Embassy doesn't have board specific code, but embassy does support the rp2350, yes. Check out the examples here: https://github.com/embassy-rs/embassy/tree/main/examples/rp23

CBJamo avatar Oct 14 '24 16:10 CBJamo

Embassy doesn't have board specific code, but embassy does support the rp2350, yes. Check out the examples here: https://github.com/embassy-rs/embassy/tree/main/examples/rp23

i known it support, but not publish it to crates.io yet. in

embassy-rp = "0.2.0"

features not support `rp235xa'

sndnvaps avatar Oct 15 '24 10:10 sndnvaps

For now you'll have to use a git dependency. See here: https://embassy.dev/book/index.html#_how_do_i_switch_to_the_main_branch

CBJamo avatar Oct 15 '24 13:10 CBJamo

For now you'll have to use a git dependency. See here: https://embassy.dev/book/index.html#_how_do_i_switch_to_the_main_branch

thanks bro, i have do it now.

sndnvaps avatar Oct 15 '24 14:10 sndnvaps

@ionspin elf2uf2-rs has been updated to fix the HARD-FLOAT error.

You can install the new version with cargo install elf2uf2-rs

BjornTheProgrammer avatar Oct 20 '24 15:10 BjornTheProgrammer

I don't think this is correct:

https://github.com/embassy-rs/embassy/blob/423e5d7655d038ead9ad7f5f448cabbd0b330660/embassy-rp/src/clocks.rs#L515

image

I suspect picotool reboot initializes ticks, and embassy-rp does not, here's my log collected through defmt-uart



0.037927 INFO  Defmt serial test
0.038167 INFO  USB: config_descriptor used: 94
0.038175 INFO  USB: bos_descriptor used: 12
0.038182 INFO  USB: msos_descriptor used: 0
0.038188 INFO  USB: control_buf size: 256
0.038432 INFO  Defmt tick 0
0.238699 INFO  Defmt tick 1
0.364565 DEBUG SET_CONFIGURATION: configured
0.365786 DEBUG Set line coding to: LineCoding { stop_bits: One, data_bits: 8, parity_type: None, data_rate: 9600 }
0.438751 INFO  Defmt tick 2
0.537203 DEBUG Set dtr true, rts true
0.638785 INFO  Defmt tick 3
0.838805 INFO  Defmt tick 4
1.038821 INFO  Defmt tick 5
1.238837 INFO  Defmt tick 6
1.438854 INFO  Defmt tick 7
1.638870 INFO  Defmt tick 8
1.838886 INFO  Defmt tick 9
2.038903 INFO  Defmt tick 10
2.238919 INFO  Defmt tick 11




0.000000 INFO  Defmt serial test
0.000000 INFO  USB: config_descriptor used: 94
0.000000 INFO  USB: bos_descriptor used: 12
0.000000 INFO  USB: msos_descriptor used: 0
0.000000 INFO  USB: control_buf size: 256
0.000000 INFO  Defmt tick 0
0.000000 DEBUG SET_CONFIGURATION: configured
0.000000 DEBUG Set line coding to: LineCoding { stop_bits: One, data_bits: 8, parity_type: None, data_rate: 9600 }
0.000000 DEBUG Set dtr true, rts true

First part is picotool reboot and second is manual restart, note the timestamps

I'll try to submit a pull request for this today if I'm right and setting ticks up fixes it.

Hey, do you think you could expand on what you meant by defmt-uart if you get a chance? Looking at getting some kind of logging working for the Pico 2. Is it a feature for a crate already in embassy or another project like defmt-serial. I I've just been using the rp23 uart example to log over to the debug probe. Would love to just use defmt's info. Any projects or examples you could point me to would be greatly appreciated! Thank you!

fatfingers23 avatar Nov 20 '24 13:11 fatfingers23

@fatfingers23

Hey, do you think you could expand on what you meant by defmt-uart if you get a chance? Looking at getting some kind of logging working for the Pico 2. Is it a feature for a crate already in embassy or another project like defmt-serial. I I've just been using the rp23 uart example to log over to the debug probe. Would love to just use defmt's info. Any projects or examples you could point me to would be greatly appreciated! Thank you!

Yeah, I was mistaken, it was defmt-serial, and I was using debug probe as well. I also have serial over usb set up, but it's not as useful for me at least, as it misses a couple of seconds of logs when rp boots. Here's the usb example, https://github.com/embassy-rs/embassy/blob/main/examples/rp/src/bin/usb_serial_with_logger.rs

ionspin avatar Nov 20 '24 13:11 ionspin