Procházet zdrojové kódy

RP2040: reduce boot delay by enabling cache during bootloader.

Petteri Aimonen před 3 roky
rodič
revize
1033cb0a2f

+ 11 - 0
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp

@@ -7,6 +7,7 @@
 #include <hardware/gpio.h>
 #include <hardware/uart.h>
 #include <hardware/spi.h>
+#include <hardware/structs/xip_ctrl.h>
 #include <platform/mbed_error.h>
 
 extern "C" {
@@ -297,7 +298,17 @@ bool azplatform_rewrite_flash_page(uint32_t offset, uint8_t buffer[AZPLATFORM_FL
     assert(offset % AZPLATFORM_FLASH_PAGE_SIZE == 0);
     assert(offset >= AZPLATFORM_BOOTLOADER_SIZE);
 
+    // Avoid any mbed timer interrupts triggering during the flashing.
     __disable_irq();
+
+    // For some reason any code executed after flashing crashes
+    // unless we disable the XIP cache.
+    // Not sure why this happens, as flash_range_program() is flushing
+    // the cache correctly.
+    // The cache is now enabled from bootloader start until it starts
+    // flashing, and again after reset to main firmware.
+    xip_ctrl_hw->ctrl = 0;
+
     flash_range_erase(offset, AZPLATFORM_FLASH_PAGE_SIZE);
     flash_range_program(offset, buffer, AZPLATFORM_FLASH_PAGE_SIZE);
     __enable_irq();

+ 1 - 3
lib/ZuluSCSI_platform_RP2040/rp2040_btldr.ld

@@ -9,10 +9,8 @@
     /* The bootloader is linked to begin at 0x12000100.
      * First 256 bytes are reserved for RP2040 second stage bootloader,
      * which comes as part of the main firmware.elf and is never overwritten.
-     * The bootloader also runs without XIP cache because that seemed to cause
-     * problems when writing flash.
      */
-    FLASH(rx) : ORIGIN = 0x12000100, LENGTH = 128k-256
+    FLASH(rx) : ORIGIN = 0x10000100, LENGTH = 128k-256
     RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 240k  /* Leave space for pico-debug */
     SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
     SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k