Browse Source

RP2350: Ensure that code flash is in 4-bit mode after boot.

Interaction between RP2350 bootrom and flash_do_cmd() may leave
flash in 1-bit mode if rom_chain_image() is used by a bootloader:
https://github.com/raspberrypi/pico-bootrom-rp2350/issues/10

Having the flash in 4-bit mode reduces latency for code that is not
running from RAM.
Petteri Aimonen 3 tháng trước cách đây
mục cha
commit
4d2469471d
1 tập tin đã thay đổi với 23 bổ sung0 xóa
  1. 23 0
      lib/BlueSCSI_platform_RP2MCU/BlueSCSI_platform.cpp

+ 23 - 0
lib/BlueSCSI_platform_RP2MCU/BlueSCSI_platform.cpp

@@ -359,6 +359,24 @@ void platform_setup_sd() {
     gpio_conf(SDIO_D2,        GPIO_FUNC_SIO, true, false, false, true, true);
 }
 
+#ifdef BLUESCSI_MCU_RP23XX
+static void __no_inline_not_in_flash_func(set_flash_clock)()
+{
+    // Ensure that high performance 4-bit flash mode is used for code fetches.
+    // This is normally the default but if coming through rom_chain_image() the
+    // flash may be in 1-bit mode after flash_do_cmd() call.
+    // See https://github.com/raspberrypi/pico-bootrom-rp2350/issues/10
+    //
+    // Flash clock divider 3 gives 50 MHz clock for 150 MHz, and 83 for 250 MHz.
+    // The W25Q16JV maximum is 133 MHz.
+    //
+    // In practice most of the code is in cache or RAM, so the performance effect
+    // of higher clocks is not huge.
+    rom_flash_exit_xip();
+    rom_flash_select_xip_read_mode(BOOTROM_XIP_MODE_EBH_QUAD, 3);
+}
+#endif
+
 void platform_init()
 {
 #ifndef PICO_RP2040
@@ -487,6 +505,11 @@ void platform_init()
     g_flash_chip_size = (1 << response_jedec[3]);
     logmsg("Flash chip size: ", (int)(g_flash_chip_size / 1024), " kB");
     platform_setup_sd();
+
+#ifdef BLUESCSI_MCU_RP23XX
+    set_flash_clock();
+#endif
+
     // LED pin
     if (!rp2040.isPicoW())
         gpio_conf(LED_PIN,    GPIO_FUNC_SIO, false,false, true,  false, false);