diff --git a/cyw43/src/bluetooth.rs b/cyw43/src/bluetooth.rs index 2c2be069..95ec513b 100644 --- a/cyw43/src/bluetooth.rs +++ b/cyw43/src/bluetooth.rs @@ -18,21 +18,23 @@ pub(crate) async fn upload_bluetooth_firmware( firmware_offsets: &[(u32, usize)], firmware: &[u8], ) { + assert!(firmware.len() == 5952); // read version let version_length = firmware[0]; let _version = &firmware[1..=version_length as usize]; // skip version + 1 extra byte as per cybt_shared_bus_driver.c let firmware = &firmware[version_length as usize + 2..]; // buffer - let mut data_buffer: [u8; 0x100] = [0; 0x100]; let mut aligned_data_buffer: [u8; 0x100] = [0; 0x100]; // structs let mut pointer = 0; for (index, &(dest_addr, num_fw_bytes)) in firmware_offsets.iter().enumerate() { + Timer::after(Duration::from_millis(100)).await; let fw_bytes = &firmware[(pointer)..(pointer + num_fw_bytes)]; assert!(fw_bytes.len() == num_fw_bytes); - pointer += num_fw_bytes; - debug!("index = {}/{} dest_addr = {:08x} num_fw_bytes = {} fw_bytes = {:02x}", index, firmware_offsets.len(), dest_addr, num_fw_bytes, fw_bytes); + //debug!("index = {}/{} dest_addr = {:08x} num_fw_bytes = {} fw_bytes = {:02x}", index, firmware_offsets.len(), dest_addr, num_fw_bytes, fw_bytes); + debug!("index = {}/{} dest_addr = {:08x} num_fw_bytes = {} pointer = {}", index, firmware_offsets.len(), dest_addr, num_fw_bytes, pointer); + assert!(firmware.len() == 5952); let mut dest_start_addr = dest_addr; let mut aligned_data_buffer_index: usize = 0; // pad start @@ -41,7 +43,7 @@ pub(crate) async fn upload_bluetooth_firmware( let padded_dest_start_addr = round_down(dest_start_addr, 4); let mut memory_value_bytes = [0; 4]; bus.bp_read(padded_dest_start_addr, &mut memory_value_bytes).await; - debug!("pad start padded_dest_start_addr = {:08x} memory_value_bytes = {:02x}", padded_dest_start_addr, memory_value_bytes); + //debug!("pad start padded_dest_start_addr = {:08x} memory_value_bytes = {:02x}", padded_dest_start_addr, memory_value_bytes); // Copy the previous memory value's bytes to the start for i in 0..num_pad_bytes as usize { aligned_data_buffer[aligned_data_buffer_index] = memory_value_bytes[i]; @@ -68,7 +70,7 @@ pub(crate) async fn upload_bluetooth_firmware( let padded_dest_end_addr = round_down(dest_end_addr, 4); let mut memory_value_bytes = [0; 4]; bus.bp_read(padded_dest_end_addr, &mut memory_value_bytes).await; - debug!("pad end padded_dest_end_addr = {:08x} memory_value_bytes = {:02x}", padded_dest_end_addr, memory_value_bytes); + //debug!("pad end padded_dest_end_addr = {:08x} memory_value_bytes = {:02x}", padded_dest_end_addr, memory_value_bytes); // Append the necessary memory bytes to pad the end of aligned_data_buffer for i in offset..4 { aligned_data_buffer[aligned_data_buffer_index] = memory_value_bytes[i as usize]; @@ -79,11 +81,13 @@ pub(crate) async fn upload_bluetooth_firmware( // pad end alignment not needed } let buffer_to_write = &aligned_data_buffer[0..aligned_data_buffer_index as usize]; - debug!("upload_bluetooth_firmware: dest_start_addr = {:x} dest_end_addr = {:x} aligned_data_buffer_index = {} buffer_to_write = {:02x}", dest_start_addr, dest_end_addr, aligned_data_buffer_index, buffer_to_write); + //debug!("upload_bluetooth_firmware: dest_start_addr = {:x} dest_end_addr = {:x} aligned_data_buffer_index = {} buffer_to_write = {:02x}", dest_start_addr, dest_end_addr, aligned_data_buffer_index, buffer_to_write); assert!(dest_start_addr % 4 == 0); assert!(dest_end_addr % 4 == 0); assert!(aligned_data_buffer_index % 4 == 0); bus.bp_write(dest_start_addr, buffer_to_write).await; + // increment pointer + pointer += num_fw_bytes; } } @@ -154,6 +158,7 @@ pub(crate) async fn bt_set_intr(bus: &mut Bus< } pub(crate) async fn init_bluetooth(bus: &mut Bus, firmware_offsets: &[(u32, usize)], firmware: &[u8]) { + assert!(firmware.len() == 5952); bus.bp_write32(CHIP.bluetooth_base_address + BT2WLAN_PWRUP_ADDR, BT2WLAN_PWRUP_WAKE) .await; upload_bluetooth_firmware(bus, firmware_offsets, firmware).await; diff --git a/cyw43/src/lib.rs b/cyw43/src/lib.rs index 94f63982..3ce602fc 100644 --- a/cyw43/src/lib.rs +++ b/cyw43/src/lib.rs @@ -226,6 +226,7 @@ where let mut runner = Runner::new(ch_runner, Bus::new(pwr, spi), &state.ioctl_state, &state.events); + assert!(bluetooth_firmware.len() == 5952); runner.init(firmware, bluetooth_firmware_offsets, bluetooth_firmware).await; ( diff --git a/cyw43/src/runner.rs b/cyw43/src/runner.rs index 05ef1294..43d6f497 100644 --- a/cyw43/src/runner.rs +++ b/cyw43/src/runner.rs @@ -74,6 +74,8 @@ where } pub(crate) async fn init(&mut self, firmware: &[u8], bluetooth_firmware_offsets: &[(u32, usize)], bluetooth_firmware: &[u8]) { + assert!(bluetooth_firmware.len() == 5952); + self.bus.init().await; // Init ALP (Active Low Power) clock @@ -116,9 +118,6 @@ where debug!("loading fw"); self.bus.bp_write(ram_addr, firmware).await; - debug!("loading bluetooth fw"); - bluetooth::init_bluetooth(&mut self.bus, bluetooth_firmware_offsets, bluetooth_firmware).await; - debug!("loading nvram"); // Round up to 4 bytes. let nvram_len = (NVRAM.len() + 3) / 4 * 4; @@ -198,6 +197,10 @@ where while self.bus.read8(FUNC_BACKPLANE, REG_BACKPLANE_CHIP_CLOCK_CSR).await & 0x80 == 0 {} debug!("clock ok"); + debug!("loading bluetooth fw"); + assert!(bluetooth_firmware.len() == 5952); + bluetooth::init_bluetooth(&mut self.bus, bluetooth_firmware_offsets, bluetooth_firmware).await; + #[cfg(feature = "firmware-logs")] self.log_init().await; diff --git a/examples/rp/memory.x b/examples/rp/memory.x index aba861aa..4077aab2 100644 --- a/examples/rp/memory.x +++ b/examples/rp/memory.x @@ -2,4 +2,14 @@ MEMORY { BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 RAM : ORIGIN = 0x20000000, LENGTH = 256K -} \ No newline at end of file +} + +EXTERN(BOOT2_FIRMWARE) + +SECTIONS { + /* ### Boot loader */ + .boot2 ORIGIN(BOOT2) : + { + KEEP(*(.boot2)); + } > BOOT2 +} INSERT BEFORE .text; diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs index 5203f6e3..fa44bc66 100644 --- a/examples/rp/src/bin/wifi_blinky.rs +++ b/examples/rp/src/bin/wifi_blinky.rs @@ -33,6 +33,7 @@ async fn main(spawner: Spawner) { let p = embassy_rp::init(Default::default()); let bluetooth_firmware_offsets = &cyw43_firmware::BLUETOOTH_FIRMWARE_OFFSETS; let bluetooth_firmware = &cyw43_firmware::BLUETOOTH_FIRMWARE; + defmt::assert!(bluetooth_firmware.len() == 5952); let fw = include_bytes!("../../../../cyw43-firmware/43439A0.bin"); let clm = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin");