diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-17 00:33:30 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-17 00:33:30 +0200 |
| commit | 13c88a9ca3e4a192677a184baa7e6ac12646797d (patch) | |
| tree | d66efdeb07bfb41e17d6343b78a260820463d941 /src | |
| parent | 4205eef3ec46840fff77eb45cdadcbd51938b798 (diff) | |
Obtain the firmware blobs from the user instead of hardcoding magic flash addrs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs index e42bae687..0e4a862c5 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -235,11 +235,9 @@ pub struct Control<'a> { | |||
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | impl<'a> Control<'a> { | 237 | impl<'a> Control<'a> { |
| 238 | pub async fn init(&mut self) -> NetDevice<'a> { | 238 | pub async fn init(&mut self, clm: &[u8]) -> NetDevice<'a> { |
| 239 | const CHUNK_SIZE: usize = 1024; | 239 | const CHUNK_SIZE: usize = 1024; |
| 240 | 240 | ||
| 241 | let clm = unsafe { slice::from_raw_parts(0x10140000 as *const u8, 4752) }; | ||
| 242 | |||
| 243 | info!("Downloading CLM..."); | 241 | info!("Downloading CLM..."); |
| 244 | 242 | ||
| 245 | let mut offs = 0; | 243 | let mut offs = 0; |
| @@ -528,7 +526,12 @@ pub struct Runner<'a, PWR, SPI> { | |||
| 528 | backplane_window: u32, | 526 | backplane_window: u32, |
| 529 | } | 527 | } |
| 530 | 528 | ||
| 531 | pub async fn new<'a, PWR, SPI>(state: &'a State, pwr: PWR, spi: SPI) -> (Control<'a>, Runner<'a, PWR, SPI>) | 529 | pub async fn new<'a, PWR, SPI>( |
| 530 | state: &'a State, | ||
| 531 | pwr: PWR, | ||
| 532 | spi: SPI, | ||
| 533 | firmware: &[u8], | ||
| 534 | ) -> (Control<'a>, Runner<'a, PWR, SPI>) | ||
| 532 | where | 535 | where |
| 533 | PWR: OutputPin, | 536 | PWR: OutputPin, |
| 534 | SPI: SpiDevice, | 537 | SPI: SpiDevice, |
| @@ -543,7 +546,7 @@ where | |||
| 543 | backplane_window: 0xAAAA_AAAA, | 546 | backplane_window: 0xAAAA_AAAA, |
| 544 | }; | 547 | }; |
| 545 | 548 | ||
| 546 | runner.init().await; | 549 | runner.init(firmware).await; |
| 547 | 550 | ||
| 548 | (Control { state }, runner) | 551 | (Control { state }, runner) |
| 549 | } | 552 | } |
| @@ -554,7 +557,7 @@ where | |||
| 554 | SPI: SpiDevice, | 557 | SPI: SpiDevice, |
| 555 | SPI::Bus: SpiBusRead<u32> + SpiBusWrite<u32>, | 558 | SPI::Bus: SpiBusRead<u32> + SpiBusWrite<u32>, |
| 556 | { | 559 | { |
| 557 | async fn init(&mut self) { | 560 | async fn init(&mut self, firmware: &[u8]) { |
| 558 | // Reset | 561 | // Reset |
| 559 | self.pwr.set_low().unwrap(); | 562 | self.pwr.set_low().unwrap(); |
| 560 | Timer::after(Duration::from_millis(20)).await; | 563 | Timer::after(Duration::from_millis(20)).await; |
| @@ -598,17 +601,8 @@ where | |||
| 598 | 601 | ||
| 599 | let ram_addr = CHIP.atcm_ram_base_address; | 602 | let ram_addr = CHIP.atcm_ram_base_address; |
| 600 | 603 | ||
| 601 | // I'm flashing the firmwares independently at hardcoded addresses, instead of baking them | ||
| 602 | // into the program with `include_bytes!` or similar, so that flashing the program stays fast. | ||
| 603 | // | ||
| 604 | // Flash them like this, also don't forget to update the lengths below if you change them!. | ||
| 605 | // | ||
| 606 | // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 | ||
| 607 | // probe-rs-cli download 43439A0.clm_blob --format bin --chip RP2040 --base-address 0x10140000 | ||
| 608 | let fw = unsafe { slice::from_raw_parts(0x10100000 as *const u8, 224190) }; | ||
| 609 | |||
| 610 | info!("loading fw"); | 604 | info!("loading fw"); |
| 611 | self.bp_write(ram_addr, fw).await; | 605 | self.bp_write(ram_addr, firmware).await; |
| 612 | 606 | ||
| 613 | info!("loading nvram"); | 607 | info!("loading nvram"); |
| 614 | // Round up to 4 bytes. | 608 | // Round up to 4 bytes. |
