diff --git a/.gitignore b/.gitignore index ee8e6b4c..1e7caa9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ Cargo.lock target/ -*.bin -notes.txt diff --git a/examples/rpi-pico-w/src/main.rs b/examples/rpi-pico-w/src/main.rs index 475c6906..633c1b2b 100644 --- a/examples/rpi-pico-w/src/main.rs +++ b/examples/rpi-pico-w/src/main.rs @@ -43,6 +43,17 @@ async fn net_task(stack: &'static Stack>) -> ! { async fn main(spawner: Spawner, p: Peripherals) { info!("Hello World!"); + // Include the WiFi firmware and CLM. + let fw = include_bytes!("../../../firmware/43439A0.bin"); + let clm = include_bytes!("../../../firmware/43439A0_clm.bin"); + + // To make flashing faster for development, you may want to flash the firmwares independently + // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: + // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 + // probe-rs-cli download 43439A0.clm_blob --format bin --chip RP2040 --base-address 0x10140000 + //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; + //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; + let pwr = Output::new(p.PIN_23, Level::Low); let cs = Output::new(p.PIN_25, Level::High); let clk = Output::new(p.PIN_29, Level::Low); @@ -54,11 +65,11 @@ async fn main(spawner: Spawner, p: Peripherals) { let spi = ExclusiveDevice::new(bus, cs); let state = forever!(cyw43::State::new()); - let (mut control, runner) = cyw43::new(state, pwr, spi).await; + let (mut control, runner) = cyw43::new(state, pwr, spi, fw).await; spawner.spawn(wifi_task(runner)).unwrap(); - let net_device = control.init().await; + let net_device = control.init(clm).await; //control.join_open("MikroTik-951589").await; control.join_wpa2("DirbaioWifi", "HelloWorld").await; diff --git a/firmware/43439A0.bin b/firmware/43439A0.bin new file mode 100755 index 00000000..b46b3bef Binary files /dev/null and b/firmware/43439A0.bin differ diff --git a/firmware/43439A0_clm.bin b/firmware/43439A0_clm.bin new file mode 100755 index 00000000..6e3ba786 Binary files /dev/null and b/firmware/43439A0_clm.bin differ diff --git a/firmware/LICENSE-permissive-binary-license-1.0.txt b/firmware/LICENSE-permissive-binary-license-1.0.txt new file mode 100644 index 00000000..cbb51f9c --- /dev/null +++ b/firmware/LICENSE-permissive-binary-license-1.0.txt @@ -0,0 +1,49 @@ +Permissive Binary License + +Version 1.0, July 2019 + +Redistribution. Redistribution and use in binary form, without +modification, are permitted provided that the following conditions are +met: + +1) Redistributions must reproduce the above copyright notice and the + following disclaimer in the documentation and/or other materials + provided with the distribution. + +2) Unless to the extent explicitly permitted by law, no reverse + engineering, decompilation, or disassembly of this software is + permitted. + +3) Redistribution as part of a software development kit must include the + accompanying file named �DEPENDENCIES� and any dependencies listed in + that file. + +4) Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +Limited patent license. The copyright holders (and contributors) grant a +worldwide, non-exclusive, no-charge, royalty-free patent license to +make, have made, use, offer to sell, sell, import, and otherwise +transfer this software, where such license applies only to those patent +claims licensable by the copyright holders (and contributors) that are +necessarily infringed by this software. This patent license shall not +apply to any combinations that include this software. No hardware is +licensed hereunder. + +If you institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the software +itself infringes your patent(s), then your rights granted under this +license shall terminate as of the date such litigation is filed. + +DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/firmware/README.md b/firmware/README.md new file mode 100644 index 00000000..7381fdc5 --- /dev/null +++ b/firmware/README.md @@ -0,0 +1,5 @@ +# WiFi firmware + +Firmware obtained from https://github.com/Infineon/wifi-host-driver/tree/master/WiFi_Host_Driver/resources/firmware/COMPONENT_43439 + +Licensed under the [Infineon Permissive Binary License](./LICENSE-permissive-binary-license-1.0.txt) \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index e42bae68..0e4a862c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -235,11 +235,9 @@ pub struct Control<'a> { } impl<'a> Control<'a> { - pub async fn init(&mut self) -> NetDevice<'a> { + pub async fn init(&mut self, clm: &[u8]) -> NetDevice<'a> { const CHUNK_SIZE: usize = 1024; - let clm = unsafe { slice::from_raw_parts(0x10140000 as *const u8, 4752) }; - info!("Downloading CLM..."); let mut offs = 0; @@ -528,7 +526,12 @@ pub struct Runner<'a, PWR, SPI> { backplane_window: u32, } -pub async fn new<'a, PWR, SPI>(state: &'a State, pwr: PWR, spi: SPI) -> (Control<'a>, Runner<'a, PWR, SPI>) +pub async fn new<'a, PWR, SPI>( + state: &'a State, + pwr: PWR, + spi: SPI, + firmware: &[u8], +) -> (Control<'a>, Runner<'a, PWR, SPI>) where PWR: OutputPin, SPI: SpiDevice, @@ -543,7 +546,7 @@ where backplane_window: 0xAAAA_AAAA, }; - runner.init().await; + runner.init(firmware).await; (Control { state }, runner) } @@ -554,7 +557,7 @@ where SPI: SpiDevice, SPI::Bus: SpiBusRead + SpiBusWrite, { - async fn init(&mut self) { + async fn init(&mut self, firmware: &[u8]) { // Reset self.pwr.set_low().unwrap(); Timer::after(Duration::from_millis(20)).await; @@ -598,17 +601,8 @@ where let ram_addr = CHIP.atcm_ram_base_address; - // I'm flashing the firmwares independently at hardcoded addresses, instead of baking them - // into the program with `include_bytes!` or similar, so that flashing the program stays fast. - // - // Flash them like this, also don't forget to update the lengths below if you change them!. - // - // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 - // probe-rs-cli download 43439A0.clm_blob --format bin --chip RP2040 --base-address 0x10140000 - let fw = unsafe { slice::from_raw_parts(0x10100000 as *const u8, 224190) }; - info!("loading fw"); - self.bp_write(ram_addr, fw).await; + self.bp_write(ram_addr, firmware).await; info!("loading nvram"); // Round up to 4 bytes.