Selaa lähdekoodia

Move to latest arduino pico framework and pico-sdk

Moved the RP2040 and RP2350 to the same customized arduino pico
framework. That is compatible with both USB mass storage and the
DaynaPORT Pico W SPI pio Wifi interface.

Other changes include a base PlatformIO target that all RP builds
inherit from. This gets rid of a lot of repeated settings.

An unrelated change was the added the ability to set the timeout for USB
enumeration as sometimes RP devices take longer than second to enumerate
when on a USB hub. And adding both `EnableUSBMassStorage` and the new
`USBMassStorageWaitPeriod` to the example `zuluscsi.ini` file.
Morio 1 vuosi sitten
vanhempi
sitoutus
c4f0479cca
40 muutettua tiedostoa jossa 241 lisäystä ja 241 poistoa
  1. 2 2
      boards/zuluscsi_rp2040.json
  2. 2 2
      lib/SCSI2SD/src/firmware/log.h
  3. 1 1
      lib/SCSI2SD/src/firmware/network.c
  4. 13 3
      lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform_msc.cpp
  5. 13 3
      lib/ZuluSCSI_platform_GD32F450/ZuluSCSI_platform_msc.cpp
  6. 16 9
      lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp
  7. 16 1
      lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform_msc.cpp
  8. 11 7
      lib/ZuluSCSI_platform_RP2040/program_flash.cpp
  9. 0 1
      lib/ZuluSCSI_platform_RP2040/rp2040-template.ld
  10. 8 8
      lib/ZuluSCSI_platform_RP2040/scsi_accel_target.cpp
  11. 2 1
      lib/ZuluSCSI_platform_RP2040/sdio.cpp
  12. 6 2
      lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform.cpp
  13. 4 4
      lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform.h
  14. 1 1
      lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform_gpio_Pico_2.h
  15. 0 0
      lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform_gpio_RP2350.h
  16. 22 5
      lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform_msc.cpp
  17. 0 41
      lib/ZuluSCSI_platform_RP2350/process-linker-script.py
  18. 2 2
      lib/ZuluSCSI_platform_RP2350/program_flash.cpp
  19. 6 6
      lib/ZuluSCSI_platform_RP2350/run_pioasm.sh
  20. 3 3
      lib/ZuluSCSI_platform_RP2350/scsi_accel_host.cpp
  21. 0 0
      lib/ZuluSCSI_platform_RP2350/scsi_accel_host_Pico_2.pio
  22. 0 0
      lib/ZuluSCSI_platform_RP2350/scsi_accel_host_Pico_2.pio.h
  23. 0 0
      lib/ZuluSCSI_platform_RP2350/scsi_accel_host_RP2350.pio
  24. 0 0
      lib/ZuluSCSI_platform_RP2350/scsi_accel_host_RP2350.pio.h
  25. 4 4
      lib/ZuluSCSI_platform_RP2350/scsi_accel_target.cpp
  26. 0 0
      lib/ZuluSCSI_platform_RP2350/scsi_accel_target_Pico_2.pio
  27. 0 0
      lib/ZuluSCSI_platform_RP2350/scsi_accel_target_Pico_2.pio.h
  28. 0 0
      lib/ZuluSCSI_platform_RP2350/scsi_accel_target_RP2350.pio
  29. 0 0
      lib/ZuluSCSI_platform_RP2350/scsi_accel_target_RP2350.pio.h
  30. 3 3
      lib/ZuluSCSI_platform_RP2350/sdio.cpp
  31. 0 0
      lib/ZuluSCSI_platform_RP2350/sdio_Pico_2.pio
  32. 0 0
      lib/ZuluSCSI_platform_RP2350/sdio_Pico_2.pio.h
  33. 0 0
      lib/ZuluSCSI_platform_RP2350/sdio_RP2350.pio
  34. 0 0
      lib/ZuluSCSI_platform_RP2350/sdio_RP2350.pio.h
  35. 96 127
      platformio.ini
  36. 0 3
      src/ZuluSCSI_msc.h
  37. 2 0
      src/ZuluSCSI_settings.cpp
  38. 1 0
      src/ZuluSCSI_settings.h
  39. 2 2
      src/process-linker-script.py
  40. 5 0
      zuluscsi.ini

+ 2 - 2
boards/zuluscsi_rp2040.json

@@ -9,7 +9,7 @@
       },
       "core": "earlephilhower",
       "cpu": "cortex-m0plus",
-      "extra_flags": "-D ARDUINO_RHC_ZULUSCSI_RP2040 -DARDUINO_ARCH_RP2040 -DUSBD_MAX_POWER_MA=500",
+      "extra_flags": "-DARDUINO_RHC_ZULUSCSI_RP2040 -DARDUINO_ARCH_RP2040 -DUSBD_MAX_POWER_MA=500",
       "f_cpu": "125000000L",
       "hwids": [
         [
@@ -22,7 +22,7 @@
         ]
       ],
       "mcu": "rp2040",
-      "variant": "zuluscsi_rp2040"
+      "variant": "generic"
     },
     "debug": {
       "jlink_device": "RP2040_M0_0",

+ 2 - 2
lib/SCSI2SD/src/firmware/log.h

@@ -33,9 +33,9 @@ extern void dbgmsg_buf(const unsigned char *buf, unsigned long size);
 extern void dbgmsg_f(const char *format, ...);
 
 #define DBGMSG_BUF(buf, size) dbgmsg_buf(buf, size)
-#define DBGMSG_F(format, ...) dbgmsg_f(format, __VA_ARGS__);
+#define DBGMSG_F(format, ...) dbgmsg_f(format, __VA_ARGS__)
 #define LOGMSG_BUF(buf, size) logmsg_buf(buf, size)
-#define LOGMSG_F(format, ...) logmsg_f(format, __VA_ARGS__);
+#define LOGMSG_F(format, ...) logmsg_f(format, __VA_ARGS__)
 
 #else
 

+ 1 - 1
lib/SCSI2SD/src/firmware/network.c

@@ -375,7 +375,7 @@ int scsiNetworkCommand()
 				int size = sizeof(struct wifi_network_entry) * nets;
 				if (size + 2 > sizeof(scsiDev.data))
 				{
-					LOGMSG_F("WARNING: wifi_network_list is bigger than scsiDev.data, truncating");
+					LOGMSG_F("WARNING: wifi_network_list is bigger than scsiDev.data, truncating", 0);
 					size = sizeof(scsiDev.data) - 2;
 					size -= (size % (sizeof(struct wifi_network_entry)));
 				}

+ 13 - 3
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform_msc.cpp

@@ -25,6 +25,7 @@
 #include "ZuluSCSI_platform.h"
 #include "ZuluSCSI_log.h"
 #include "ZuluSCSI_msc.h"
+#include "ZuluSCSI_config.h"
 #include "ZuluSCSI_settings.h"
 #include "usb_serial.h"
 
@@ -93,12 +94,20 @@ bool platform_sense_msc() {
 
   logmsg("Waiting for USB enumeration to expose SD card as a mass storage device");
 
-  // wait for up to a second to be begin to be enumerated
+  // wait to be begin to be enumerated
   uint32_t start = millis();
-  while ((uint32_t)(millis() - start) < CR_ENUM_TIMEOUT)
+  uint16_t usb_timeout =  g_scsi_settings.getSystem()->usbMassStorageWaitPeriod;
+  while ((uint32_t)(millis() - start) < usb_timeout)
+  {
     if (cdc_acm.dev.cur_status >= USBD_ADDRESSED)
+    {
+      dbgmsg("USB enumeration took ", (int)((uint32_t)(millis() - start)), "ms");
       return true;
+    }
+  }
 
+  logmsg("Waiting for USB enumeration timed out after ", usb_timeout, "ms.");
+  logmsg("-- Try increasing 'USBMassStorageWaitPeriod' in the ", CONFIGFILE);
   //if not, disconnect MSC class...
   usbd_disconnect (&cdc_acm);
 
@@ -114,7 +123,8 @@ void platform_enter_msc() {
 
   // give the host a moment to finish enumerate and "load" media
   uint32_t start = millis();
-  while ((USBD_CONFIGURED != cdc_acm.dev.cur_status) && ((uint32_t)(millis() - start) < CR_ENUM_TIMEOUT) ) 
+  uint16_t usb_timeout =  g_scsi_settings.getSystem()->usbMassStorageWaitPeriod;
+  while ((USBD_CONFIGURED != cdc_acm.dev.cur_status) && ((uint32_t)(millis() - start) < usb_timeout ) ) 
     delay(100);
 }
 

+ 13 - 3
lib/ZuluSCSI_platform_GD32F450/ZuluSCSI_platform_msc.cpp

@@ -25,6 +25,7 @@
 #include "ZuluSCSI_platform.h"
 #include "ZuluSCSI_log.h"
 #include "ZuluSCSI_msc.h"
+#include "ZuluSCSI_config.h"
 #include "ZuluSCSI_settings.h"
 #include "usb_serial.h"
 
@@ -93,12 +94,20 @@ bool platform_sense_msc() {
 
   logmsg("Waiting for USB enumeration to expose SD card as a mass storage device");
 
-  // wait for up to a second to be begin to be enumerated
+  // wait to be begin to be enumerated
   uint32_t start = millis();
-  while ((uint32_t)(millis() - start) < CR_ENUM_TIMEOUT)
+  uint16_t usb_timeout =  g_scsi_settings.getSystem()->usbMassStorageWaitPeriod;
+  while ((uint32_t)(millis() - start) < usb_timeout)
+  {
     if (cdc_acm.dev.cur_status >= USBD_ADDRESSED)
+    {
+      dbgmsg("USB enumeration took ", (int)((uint32_t)(millis() - start)), "ms");
       return true;
+    }
+  }
 
+  logmsg("Waiting for USB enumeration timed out after ", usb_timeout, "ms.");
+  logmsg("-- Try increasing 'USBMassStorageWaitPeriod' in the ", CONFIGFILE);
   //if not, disconnect MSC class...
   usbd_disconnect (&cdc_acm);
 
@@ -114,7 +123,8 @@ void platform_enter_msc() {
 
   // give the host a moment to finish enumerate and "load" media
   uint32_t start = millis();
-  while ((USBD_CONFIGURED != cdc_acm.dev.cur_status) && ((uint32_t)(millis() - start) < CR_ENUM_TIMEOUT) ) 
+  uint16_t usb_timeout =  g_scsi_settings.getSystem()->usbMassStorageWaitPeriod;
+  while ((USBD_CONFIGURED != cdc_acm.dev.cur_status) && ((uint32_t)(millis() - start) < usb_timeout ) ) 
     delay(100);
 }
 

+ 16 - 9
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp

@@ -35,6 +35,7 @@
 #include <hardware/flash.h>
 #include <hardware/structs/xip_ctrl.h>
 #include <hardware/structs/usb.h>
+#include <hardware/sync.h>
 #include "scsi_accel_target.h"
 
 #ifndef PIO_FRAMEWORK_ARDUINO_NO_USB
@@ -68,7 +69,7 @@ static bool g_uart_initialized = false;
 /***************/
 
 // Helper function to configure whole GPIO in one line
-static void gpio_conf(uint gpio, enum gpio_function fn, bool pullup, bool pulldown, bool output, bool initial_state, bool fast_slew)
+static void gpio_conf(uint gpio, gpio_function_t fn, bool pullup, bool pulldown, bool output, bool initial_state, bool fast_slew)
 {
     gpio_put(gpio, initial_state);
     gpio_set_dir(gpio, output);
@@ -77,7 +78,7 @@ static void gpio_conf(uint gpio, enum gpio_function fn, bool pullup, bool pulldo
 
     if (fast_slew)
     {
-        padsbank0_hw->io[gpio] |= PADS_BANK0_GPIO0_SLEWFAST_BITS;
+        pads_bank0_hw->io[gpio] |= PADS_BANK0_GPIO0_SLEWFAST_BITS;
     }
 }
 
@@ -253,9 +254,9 @@ void platform_init()
     // Get flash chip size
     uint8_t cmd_read_jedec_id[4] = {0x9f, 0, 0, 0};
     uint8_t response_jedec[4] = {0};
-    __disable_irq();
+    uint32_t saved_irq = save_and_disable_interrupts();
     flash_do_cmd(cmd_read_jedec_id, response_jedec, 4);
-    __enable_irq();
+    restore_interrupts(saved_irq);
     g_flash_chip_size = (1 << response_jedec[3]);
     logmsg("Flash chip size: ", (int)(g_flash_chip_size / 1024), " kB");
 
@@ -623,7 +624,11 @@ static void watchdog_callback(unsigned alarm_num)
             logmsg("scsiDev.phase: ", (int)scsiDev.phase);
             scsi_accel_log_state();
 
-            uint32_t *p =  (uint32_t*)__get_MSP();
+
+            uint32_t msp;
+            asm volatile ("MRS %0, msp" : "=r" (msp) );
+
+            uint32_t *p =  (uint32_t*)msp;
 
             for (int i = 0; i < 8; i++)
             {
@@ -647,7 +652,9 @@ static void watchdog_callback(unsigned alarm_num)
             logmsg("scsiDev.cdb: ", bytearray(scsiDev.cdb, 12));
             logmsg("scsiDev.phase: ", (int)scsiDev.phase);
 
-            uint32_t *p =  (uint32_t*)__get_MSP();
+            uint32_t msp;
+            asm volatile ("MRS %0, msp" : "=r" (msp) );
+            uint32_t *p =  (uint32_t*)msp;
 
             for (int i = 0; i < 8; i++)
             {
@@ -677,7 +684,7 @@ void platform_reset_watchdog()
     if (!g_watchdog_initialized)
     {
         int alarm_num = -1;
-        for (int i = 0; i < NUM_TIMERS; i++)
+        for (int i = 0; i < NUM_GENERIC_TIMERS; i++)
         {
             if (!hardware_alarm_is_claimed(i))
             {
@@ -805,10 +812,10 @@ bool platform_write_romdrive(const uint8_t *data, uint32_t start, uint32_t count
     assert(start < platform_get_romdrive_maxsize());
     assert((count % PLATFORM_ROMDRIVE_PAGE_SIZE) == 0);
 
-    __disable_irq();
+    uint32_t saved_irq = save_and_disable_interrupts();
     flash_range_erase(start + ROMDRIVE_OFFSET, count);
     flash_range_program(start + ROMDRIVE_OFFSET, data, count);
-    __enable_irq();
+    restore_interrupts(saved_irq);
     return true;
 }
 

+ 16 - 1
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform_msc.cpp

@@ -28,6 +28,8 @@
 #include "ZuluSCSI_platform.h"
 #include "ZuluSCSI_log.h"
 #include "ZuluSCSI_msc.h"
+#include "ZuluSCSI_config.h"
+#include "ZuluSCSI_settings.h"
 
 #include <class/msc/msc.h>
 #include <class/msc/msc_device.h>
@@ -57,8 +59,21 @@ bool platform_sense_msc() {
 
   // wait for up to a second to be enumerated
   uint32_t start = millis();
-  while (!tud_connected() && ((uint32_t)(millis() - start) < CR_ENUM_TIMEOUT)) 
+  bool timed_out = false;
+  uint16_t usb_timeout =  g_scsi_settings.getSystem()->usbMassStorageWaitPeriod;
+  while (!tud_connected())
+  {
+    if ((uint32_t)(millis() - start) > usb_timeout)
+    {
+      logmsg("Waiting for USB enumeration timed out after ", usb_timeout, "ms.");
+      logmsg("-- Try increasing 'USBMassStorageWaitPeriod' in the ", CONFIGFILE);
+      timed_out = true;
+      break;
+    } 
     delay(100);
+  }
+  if (!timed_out)
+    dbgmsg("USB enumeration took ", (int)((uint32_t)(millis() - start)), "ms");
 
   // tud_connected returns True if just got out of Bus Reset and received the very first data from host
   // https://github.com/hathach/tinyusb/blob/master/src/device/usbd.h#L63

+ 11 - 7
lib/ZuluSCSI_platform_RP2040/program_flash.cpp

@@ -29,6 +29,10 @@
 #include <hardware/flash.h>
 #include <hardware/structs/xip_ctrl.h>
 #include <hardware/structs/usb.h>
+#include <hardware/structs/nvic.h>
+#include <hardware/structs/scb.h>
+#include <hardware/sync.h>
+
 #ifndef PIO_FRAMEWORK_ARDUINO_NO_USB
 #include <SerialUSB.h>
 #include <class/cdc/cdc_device.h>
@@ -58,10 +62,10 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
     }
 
 
-    if (NVIC_GetEnableIRQ(USBCTRL_IRQ_IRQn))
+    if (nvic_hw->iser & 1 << 14)
     {
         logmsg("Disabling USB during firmware flashing");
-        NVIC_DisableIRQ(USBCTRL_IRQ_IRQn);
+        nvic_hw->icer = 1 << 14;
         usb_hw->main_ctrl = 0;
     }
 
@@ -70,7 +74,7 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
     assert(offset >= PLATFORM_BOOTLOADER_SIZE);
 
     // Avoid any mbed timer interrupts triggering during the flashing.
-    __disable_irq();
+    uint32_t saved_irq = save_and_disable_interrupts();
 
     // For some reason any code executed after flashing crashes
     // unless we disable the XIP cache.
@@ -93,12 +97,12 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
         if (actual != expected)
         {
             logmsg("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
-            __enable_irq();
+            restore_interrupts(saved_irq);
             return false;
         }
     }
 
-    __enable_irq();
+    restore_interrupts(saved_irq);
 
     return true;
 }
@@ -109,7 +113,7 @@ void platform_boot_to_main_firmware()
     // To ensure that the system state is reset properly, we perform
     // a SYSRESETREQ and jump straight from the reset vector to main application.
     g_bootloader_exit_req = &g_bootloader_exit_req;
-    SCB->AIRCR = 0x05FA0004;
+    scb_hw->aircr = 0x05FA0004;
     while(1);
 }
 
@@ -122,7 +126,7 @@ void btldr_reset_handler()
         application_base = (uint32_t*)(XIP_BASE + PLATFORM_BOOTLOADER_SIZE);
     }
 
-    SCB->VTOR = (uint32_t)application_base;
+    scb_hw->vtor = (uint32_t)application_base;
     __asm__(
         "msr msp, %0\n\t"
         "bx %1" : : "r" (application_base[0]),

+ 0 - 1
lib/ZuluSCSI_platform_RP2040/rp2040-template.ld

@@ -77,7 +77,6 @@ SECTIONS
         .pio/build/$project_name/src/ZuluSCSI_log_trace.cpp.o(.text .text*)
         .pio/build/$project_name/src/ZuluSCSI_settings.cpp.o(.text .text*)
         .pio/build/$project_name/src/QuirksCheck.cpp.o(.text .text*)
-        *libZuluSCSI_platform_RP2040.a:ZuluSCSI_platform.cpp.o(.text .text*)
         *libm*:(.text .text*)
         *libc*:(.text .text*)
         *libgcc*:*df*(.text .text*)

+ 8 - 8
lib/ZuluSCSI_platform_RP2040/scsi_accel_target.cpp

@@ -249,7 +249,7 @@ void scsi_accel_rp2040_startWrite(const uint8_t* data, uint32_t count, volatile
     // Any read requests should be matched with a stopRead()
     assert(g_scsi_dma_state != SCSIDMA_READ && g_scsi_dma_state != SCSIDMA_READ_DONE);
 
-    __disable_irq();
+    uint32_t saved_irq = save_and_disable_interrupts();
     if (g_scsi_dma_state == SCSIDMA_WRITE)
     {
         if (!g_scsi_dma.next_app_buf && data == g_scsi_dma.app_buf + g_scsi_dma.app_bytes)
@@ -272,7 +272,7 @@ void scsi_accel_rp2040_startWrite(const uint8_t* data, uint32_t count, volatile
             count = 0;
         }
     }
-    __enable_irq();
+    restore_interrupts(saved_irq);
 
     // Check if the request was combined
     if (count == 0) return;
@@ -371,7 +371,7 @@ bool scsi_accel_rp2040_isWriteFinished(const uint8_t* data)
     
     // Check if this data item is still in queue.
     bool finished = true;
-    __disable_irq();
+    uint32_t saved_irq = save_and_disable_interrupts();
     if (data >= g_scsi_dma.app_buf &&
         data < g_scsi_dma.app_buf + g_scsi_dma.app_bytes &&
         (uint32_t)data >= dma_hw->ch[SCSI_DMA_CH_A].al1_read_addr)
@@ -383,7 +383,7 @@ bool scsi_accel_rp2040_isWriteFinished(const uint8_t* data)
     {
         finished = false; // In queued transfer
     }
-    __enable_irq();
+    restore_interrupts(saved_irq);
 
     return finished;
 }
@@ -634,7 +634,7 @@ void scsi_accel_rp2040_startRead(uint8_t *data, uint32_t count, int *parityError
     // Any write requests should be matched with a stopWrite()
     assert(g_scsi_dma_state != SCSIDMA_WRITE && g_scsi_dma_state != SCSIDMA_WRITE_DONE);
 
-    __disable_irq();
+    uint32_t saved_irq = save_and_disable_interrupts();
     if (g_scsi_dma_state == SCSIDMA_READ)
     {
         if (!g_scsi_dma.next_app_buf && data == g_scsi_dma.app_buf + g_scsi_dma.app_bytes)
@@ -657,7 +657,7 @@ void scsi_accel_rp2040_startRead(uint8_t *data, uint32_t count, int *parityError
             count = 0;
         }
     }
-    __enable_irq();
+    restore_interrupts(saved_irq);
 
     // Check if the request was combined
     if (count == 0) return;
@@ -703,7 +703,7 @@ bool scsi_accel_rp2040_isReadFinished(const uint8_t* data)
 
     // Check if this data item is still in queue.
     bool finished = true;
-    __disable_irq();
+    uint32_t saved_irq = save_and_disable_interrupts();
     if (data >= g_scsi_dma.app_buf &&
         data < g_scsi_dma.app_buf + g_scsi_dma.app_bytes &&
         (uint32_t)data >= dma_hw->ch[SCSI_DMA_CH_A].write_addr)
@@ -715,7 +715,7 @@ bool scsi_accel_rp2040_isReadFinished(const uint8_t* data)
     {
         finished = false; // In queued transfer
     }
-    __enable_irq();
+    restore_interrupts(saved_irq);
 
     return finished;
 }

+ 2 - 1
lib/ZuluSCSI_platform_RP2040/sdio.cpp

@@ -742,7 +742,8 @@ static void rp2040_sdio_tx_irq()
 // Check if transmission is complete
 sdio_status_t rp2040_sdio_tx_poll(uint32_t *bytes_complete)
 {
-    if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
+    // if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
+    if (scb_hw->icsr & (0x1FFUL))
     {
         // Verify that IRQ handler gets called even if we are in hardfault handler
         rp2040_sdio_tx_irq();

+ 6 - 2
lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform.cpp

@@ -165,7 +165,6 @@ static pin_setup_state_t read_setup_ack_pin()
 
 void platform_init()
 {
-    gpio_conf(LED_PIN,        GPIO_FUNC_SIO, false,false, true,  false, false);
     // Make sure second core is stopped
     multicore_reset_core1();
 
@@ -190,7 +189,7 @@ void platform_init()
     bool working_dip = true;
     bool dbglog = false;
     bool termination = false;
-# ifdef ZULUSCSI_PICO
+# ifdef ZULUSCSI_PICO_2
     // Initiator dip setting works on all rev 2023b, 2023c, and newer rev Pico boards
     g_scsi_initiator = !gpio_get(DIP_INITIATOR);
     
@@ -288,6 +287,11 @@ void platform_init()
     gpio_conf(GPIO_EXP_SPARE, GPIO_FUNC_SIO, true,false, false,  true, false);
     // configuration of corresponding SPI unit occurs in audio_setup()
 #endif  // ENABLE_AUDIO_OUTPUT
+
+#ifdef GPIO_USB_POWER
+    gpio_conf(GPIO_USB_POWER, GPIO_FUNC_SIO, false, false, false,  false, false);
+#endif
+
 }
 
 // late_init() only runs in main application, SCSI not needed in bootloader

+ 4 - 4
lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform.h

@@ -27,15 +27,15 @@
 #include <Arduino.h>
 #include "ZuluSCSI_platform_network.h"
 
-#ifdef ZULUSCSI_PICO
+#ifdef ZULUSCSI_PICO_2
 // ZuluSCSI Pico carrier board variant
-#include "ZuluSCSI_platform_gpio_Pico.h"
+#include "ZuluSCSI_platform_gpio_Pico_2.h"
 #elif defined(ZULUSCSI_BS2)
 // BS2 hardware variant, using Raspberry Pico board on a carrier PCB
 #include "ZuluSCSI_platform_gpio_BS2.h"
 #else
 // Normal RP2040 variant, using RP2040 chip directly
-#include "ZuluSCSI_platform_gpio_RP2040.h"
+#include "ZuluSCSI_platform_gpio_RP2350.h"
 #endif
 
 #include "scsiHostPhy.h"
@@ -48,7 +48,7 @@ extern "C" {
 /* These are used in debug output and default SCSI strings */
 extern const char *g_platform_name;
 
-#ifdef ZULUSCSI_PICO
+#ifdef ZULUSCSI_PICO_2
 # ifdef ZULUSCSI_DAYNAPORT
 #   define PLATFORM_NAME "ZuluSCSI Pico DaynaPORT"
 # else

+ 1 - 1
lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform_gpio_Pico.h → lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform_gpio_Pico_2.h

@@ -110,7 +110,7 @@
 
 // Other pins
 #define SWO_PIN 16
-
+#define GPIO_USB_POWER 24
 // Below are GPIO access definitions that are used from scsiPhy.cpp.
 
 // Write a single SCSI pin.

+ 0 - 0
lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform_gpio_RP2040.h → lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform_gpio_RP2350.h


+ 22 - 5
lib/ZuluSCSI_platform_RP2350/ZuluSCSI_platform_msc.cpp

@@ -28,10 +28,12 @@
 #include "ZuluSCSI_platform.h"
 #include "ZuluSCSI_log.h"
 #include "ZuluSCSI_msc.h"
-
+#include "ZuluSCSI_config.h"
+#include "ZuluSCSI_settings.h"
 #include <class/msc/msc.h>
 #include <class/msc/msc_device.h>
 
+
 #if CFG_TUD_MSC_EP_BUFSIZE < SD_SECTOR_SIZE
   #error "CFG_TUD_MSC_EP_BUFSIZE is too small! It needs to be at least 512 (SD_SECTOR_SIZE)"
 #endif
@@ -43,7 +45,10 @@ static bool unitReady = false;
 /* return true if USB presence detected / eligble to enter CR mode */
 bool platform_sense_msc() {
 
-#ifdef ZULUSCSI_PICO
+#ifdef ZULUSCSI_PICO_2
+  if (!gpio_get(GPIO_USB_POWER))
+    return false;
+#else
   // check if we're USB powered, if not, exit immediately
   // pin on the wireless module, see https://github.com/earlephilhower/arduino-pico/discussions/835
   if (rp2040.isPicoW() && !digitalRead(34))
@@ -57,9 +62,21 @@ bool platform_sense_msc() {
 
   // wait for up to a second to be enumerated
   uint32_t start = millis();
-  while (!tud_connected() && ((uint32_t)(millis() - start) < CR_ENUM_TIMEOUT)) 
+  bool timed_out = false;
+  uint16_t usb_timeout =  g_scsi_settings.getSystem()->usbMassStorageWaitPeriod;
+  while (!tud_connected())
+  {
+    if ((uint32_t)(millis() - start) > usb_timeout)
+    {
+      logmsg("Waiting for USB enumeration timed out after ", usb_timeout, "ms.");
+      logmsg("-- Try increasing 'USBMassStorageWaitPeriod' in the ", CONFIGFILE);
+      timed_out = true;
+      break;
+    } 
     delay(100);
-
+  }
+  if (!timed_out)
+    dbgmsg("USB enumeration took ", (int)((uint32_t)(millis() - start)), "ms");
   // tud_connected returns True if just got out of Bus Reset and received the very first data from host
   // https://github.com/hathach/tinyusb/blob/master/src/device/usbd.h#L63
   return tud_connected();
@@ -95,7 +112,7 @@ extern "C" void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8],
 
   // TODO: We could/should use strings from the platform, but they are too long
   const char vid[] = "ZuluSCSI";
-  const char pid[] = "Pico"; 
+  const char pid[] = "Pico 2"; 
   const char rev[] = "1.0";
 
   memcpy(vendor_id, vid, tu_min32(strlen(vid), 8));

+ 0 - 41
lib/ZuluSCSI_platform_RP2350/process-linker-script.py

@@ -1,41 +0,0 @@
-# ZuluSCSI™ - Copyright (c) 2024 Rabbit Hole Computing™
-#
-# ZuluSCSI™ file is licensed under the GPL version 3 or any later version. 
-#
-# https://www.gnu.org/licenses/gpl-3.0.html
-# ----
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version. 
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details. 
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-from string import Template 
-Import ("env")
-
-template_file = 'lib/ZuluSCSI_platform_RP2350/rp2350-template.ld'
-linker_file = env.subst('$BUILD_DIR') + '/rp2350.ld'
-
-def process_template(source, target, env):
-    values = {
-        'program_size': env.GetProjectOption('program_flash_allocation'),
-        'project_name': env.subst('$PIOENV')
-        }
-    with open(template_file, 'r') as t:
-        src = Template(t.read())
-        result = src.substitute(values)
-
-    with open(linker_file, 'w') as linker_script:
-        linker_script.write(result)
-
-env.AddPreAction("${BUILD_DIR}/${PROGNAME}.elf",
-        env.VerboseAction(process_template, 
-        'Generating linker script: "' + linker_file + '" from : "' + template_file + '"'
-        )
-)

+ 2 - 2
lib/ZuluSCSI_platform_RP2350/program_flash.cpp

@@ -62,11 +62,11 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
     }
 
 
-    //if (NVIC_GetEnableIRQ(USBCTRL_IRQ_IRQn))
+    // if USB NVIC is enabled
     if (nvic_hw->iser[0] & 1 << 14)
     {
         logmsg("Disabling USB during firmware flashing");
-        //NVIC_DisableIRQ(USBCTRL_IRQ_IRQn);
+        // Disabled USB NVIC
         nvic_hw->icer[0] = 1 << 14;
         usb_hw->main_ctrl = 0;
     }

+ 6 - 6
lib/ZuluSCSI_platform_RP2350/run_pioasm.sh

@@ -2,13 +2,13 @@
 
 # This script regenerates the .pio.h files from .pio
 
-pioasm sdio_RP2040.pio sdio_RP2040.pio.h
-pioasm sdio_Pico.pio sdio_Pico.pio.h
+pioasm sdio.RP2350.pio sdio.RP2350.pio.h
+pioasm sdio.Pico_2.pio sdio.Pico_2.h
 pioasm sdio_BS2.pio sdio_BS2.pio.h
 
-pioasm scsi_accel_target_RP2040.pio scsi_accel_target_RP2040.pio.h
+pioasm scsi_accel_target_RP2350.pio scsi_accel_target_RP2350.pio.h
 pioasm scsi_accel_target_BS2.pio scsi_accel_target_BS2.pio.h
-pioasm scsi_accel_target_Pico.pio scsi_accel_target_Pico.pio.h
+pioasm scsi_accel_target_Pico_2.pio scsi_accel_target_Pico_2.pio.h
 
-pioasm scsi_accel_host_RP2040.pio scsi_accel_host_RP2040.pio.h
-pioasm scsi_accel_host_Pico.pio scsi_accel_host_Pico.pio.h
+pioasm scsi_accel_host_RP2350.pio scsi_accel_host_RP2350.pio.h
+pioasm scsi_accel_host_Pico_2.pio scsi_accel_host_Pico_2.pio.h

+ 3 - 3
lib/ZuluSCSI_platform_RP2350/scsi_accel_host.cpp

@@ -31,10 +31,10 @@
 #include <hardware/sync.h>
 
 #ifdef PLATFORM_HAS_INITIATOR_MODE
-#ifdef ZULUSCSI_PICO
-#include "scsi_accel_host_Pico.pio.h"
+#ifdef ZULUSCSI_PICO_2
+#include "scsi_accel_host_Pico_2.pio.h"
 #else
-#include "scsi_accel_host_RP2040.pio.h"
+#include "scsi_accel_host_RP2350.pio.h"
 #endif
 
 #define SCSI_PIO pio0

+ 0 - 0
lib/ZuluSCSI_platform_RP2350/scsi_accel_host_Pico.pio → lib/ZuluSCSI_platform_RP2350/scsi_accel_host_Pico_2.pio


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/scsi_accel_host_Pico.pio.h → lib/ZuluSCSI_platform_RP2350/scsi_accel_host_Pico_2.pio.h


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/scsi_accel_host_RP2040.pio → lib/ZuluSCSI_platform_RP2350/scsi_accel_host_RP2350.pio


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/scsi_accel_host_RP2040.pio.h → lib/ZuluSCSI_platform_RP2350/scsi_accel_host_RP2350.pio.h


+ 4 - 4
lib/ZuluSCSI_platform_RP2350/scsi_accel_target.cpp

@@ -44,11 +44,11 @@
 #include <audio.h>
 #endif // ENABLE_AUDIO_OUTPUT
 
-#if defined(ZULUSCSI_PICO) || defined(ZULUSCSI_BS2)
-#include "scsi_accel_target_Pico.pio.h"
+#if defined(ZULUSCSI_PICO_2) || defined(ZULUSCSI_BS2)
+#include "scsi_accel_target_Pico_2.pio.h"
 #else
-#include "scsi_accel_target_RP2040.pio.h"
-#endif // ZULUSCSI_PICO
+#include "scsi_accel_target_RP2350.pio.h"
+#endif // ZULUSCSI_PICO_2
 
 // SCSI bus write acceleration uses up to 3 PIO state machines:
 // SM0: Convert data bytes to lookup addresses to add parity

+ 0 - 0
lib/ZuluSCSI_platform_RP2350/scsi_accel_target_Pico.pio → lib/ZuluSCSI_platform_RP2350/scsi_accel_target_Pico_2.pio


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/scsi_accel_target_Pico.pio.h → lib/ZuluSCSI_platform_RP2350/scsi_accel_target_Pico_2.pio.h


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/scsi_accel_target_RP2040.pio → lib/ZuluSCSI_platform_RP2350/scsi_accel_target_RP2350.pio


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/scsi_accel_target_RP2040.pio.h → lib/ZuluSCSI_platform_RP2350/scsi_accel_target_RP2350.pio.h


+ 3 - 3
lib/ZuluSCSI_platform_RP2350/sdio.cpp

@@ -39,10 +39,10 @@
 // \todo find a better way
 #include <hardware/structs/scb.h>
 
-#if defined(ZULUSCSI_PICO) || defined(ZULUSCSI_BS2)
-#include "sdio_Pico.pio.h"
+#if defined(ZULUSCSI_PICO_2) || defined(ZULUSCSI_BS2)
+#include "sdio_Pico_2.pio.h"
 #else
-#include "sdio_RP2040.pio.h"
+#include "sdio_RP2350.pio.h"
 #endif
 
 #define SDIO_PIO pio1

+ 0 - 0
lib/ZuluSCSI_platform_RP2350/sdio_Pico.pio → lib/ZuluSCSI_platform_RP2350/sdio_Pico_2.pio


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/sdio_Pico.pio.h → lib/ZuluSCSI_platform_RP2350/sdio_Pico_2.pio.h


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/sdio_RP2040.pio → lib/ZuluSCSI_platform_RP2350/sdio_RP2350.pio


+ 0 - 0
lib/ZuluSCSI_platform_RP2350/sdio_RP2040.pio.h → lib/ZuluSCSI_platform_RP2350/sdio_RP2350.pio.h


+ 96 - 127
platformio.ini

@@ -1,8 +1,7 @@
 ; PlatformIO Project Configuration File https://docs.platformio.org/page/projectconf.html
 
 [platformio]
-;default_envs = ZuluSCSIv1_0, ZuluSCSIv1_0_mini, ZuluSCSIv1_1_plus, ZuluSCSI_RP2040, ZuluSCSI_RP2040_Audio, ZuluSCSI_Pico, ZuluSCSI_Pico_DaynaPORT, ZuluSCSI_BS2, ZuluSCSI_Pico_2
-default_envs = ZuluSCSI_Pico_2
+default_envs = ZuluSCSIv1_0, ZuluSCSIv1_0_mini, ZuluSCSIv1_1_plus, ZuluSCSI_RP2040, ZuluSCSI_RP2040_Audio, ZuluSCSI_Pico, ZuluSCSI_Pico_DaynaPORT, ZuluSCSI_BS2, ZuluSCSI_Pico_2
 
 ; Example platform to serve as a base for porting efforts
 [env:template]
@@ -93,35 +92,26 @@ build_flags =
      -DSDFAT_NOARDUINO
      -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
 
-; ZuluSCSI RP2040 hardware platform, based on the Raspberry Pi foundation RP2040 microcontroller
-[env:ZuluSCSI_RP2040]
-platform = https://github.com/maxgerhardt/platform-raspberrypi.git#5e87ae34ca025274df25b3303e9e9cb6c120123c
+; ZuluSCSI setting shared among Raspberry Pi microcontroller like the RP2040 and RP2350
+[env:ZuluSCSI_RP_BASE]
+platform = https://github.com/maxgerhardt/platform-raspberrypi.git#2d445020acf8b792768a5fa5ba1870ac9607c11c
 platform_packages =
-    framework-arduinopico@https://github.com/rabbitholecomputing/arduino-pico.git#v3.6.0-DaynaPORT
-board_build.core = earlephilhower
-board = zuluscsi_rp2040
-framework = arduino
-; How much flash in bytes the bootloader and main app will be allocated
-; It is used as the starting point for a ROM image saved in flash
-; Changing this will cause issues with boards that already have a ROM drive in flash
-program_flash_allocation = 360448
+    framework-arduinopico@https://github.com/rabbitholecomputing/arduino-pico.git#v4.1.1-DaynaPORT
 extra_scripts =
     src/build_bootloader.py
-    lib/ZuluSCSI_platform_RP2040/process-linker-script.py
-board_build.ldscript = ${BUILD_DIR}/rp2040.ld
-ldscript_bootloader = lib/ZuluSCSI_platform_RP2040/rp2040_btldr.ld
+    src/process-linker-script.py
+board_build.core = earlephilhower
+board_build.ldscript = ${BUILD_DIR}/rp_linker.ld ; created by src/process-linker-script.py
+framework = arduino
 lib_deps =
     SdFat=https://github.com/rabbitholecomputing/SdFat#2.2.3-gpt
     minIni
-    ZuluSCSI_platform_RP2040
     SCSI2SD
     CUEParser
 upload_protocol = cmsis-dap
 debug_tool = cmsis-dap
 debug_build_flags =
     -O2 -ggdb -g3
-; The values can be adjusted down to get a debug build to fit in to SRAM
-    -DLOGBUFSIZE=4096
 build_flags =
     -O2 -Isrc -ggdb -g3
     -Wall -Wno-sign-compare -Wno-ignored-qualifiers
@@ -131,14 +121,36 @@ build_flags =
     -DHAS_SDIO_CLASS
     -DUSE_ARDUINO=1
     -DPICO_FLASH_SPI_CLKDIV=2
-    -DZULUSCSI_V2_0
-    -DROMDRIVE_OFFSET=${env:ZuluSCSI_RP2040.program_flash_allocation}
-; build flags mirroring the framework-arduinopico#v3.6.0-DaynaPORT static library build
+    -DPLATFORM_MASS_STORAGE
+    -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
+; build flags mirroring the framework-arduinopico#v4.1.1-DaynaPORT static library build
     -DPICO_CYW43_ARCH_POLL=1
 	-DCYW43_LWIP=0
 	-DCYW43_USE_OTP_MAC=0
-    -DPLATFORM_MASS_STORAGE
-    -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
+
+
+
+; ZuluSCSI RP2040 hardware platform, based on the Raspberry Pi foundation RP2040 microcontroller
+[env:ZuluSCSI_RP2040]
+extends = env:ZuluSCSI_RP_BASE
+board = zuluscsi_rp2040
+; How much flash in bytes the bootloader and main app will be allocated
+; It is used as the starting point for a ROM image saved in flash
+; Changing this will cause issues with boards that already have a ROM drive in flash
+program_flash_allocation = 360448
+linker_script_template = lib/ZuluSCSI_platform_RP2040/rp2040-template.ld
+ldscript_bootloader = lib/ZuluSCSI_platform_RP2040/rp2040_btldr.ld
+lib_deps =
+    ${env:ZuluSCSI_RP_BASE.lib_deps}
+    ZuluSCSI_platform_RP2040
+debug_build_flags =
+    ${env:ZuluSCSI_RP_BASE.debug_build_flags}
+; The values can be adjusted down to get a debug build to fit in to SRAM
+    -DLOGBUFSIZE=4096
+build_flags =
+    ${env:ZuluSCSI_RP_BASE.build_flags}
+    -DZULUSCSI_V2_0
+    -DROMDRIVE_OFFSET=${env:ZuluSCSI_RP2040.program_flash_allocation}
 
 ; ZuluSCSI RP2040 hardware platform, as above, but with audio output support enabled
 [env:ZuluSCSI_RP2040_Audio]
@@ -151,70 +163,47 @@ build_flags =
 ; Variant of RP2040 platform, based on Raspberry Pico board and a carrier PCB
 ; Part of the ZuluSCSI_RP2040 platform, but with different pins.
 [env:ZuluSCSI_Pico]
-extends = env:ZuluSCSI_RP2040
+extends = env:ZuluSCSI_RP_BASE
+board = rpipico
+lib_deps =
+    ${env:ZuluSCSI_RP_BASE.lib_deps}
+    ZuluSCSI_platform_RP2040
+program_flash_allocation = 360448
+linker_script_template = lib/ZuluSCSI_platform_RP2040/rp2040-template.ld
+ldscript_bootloader = lib/ZuluSCSI_platform_RP2040/rp2040_btldr.ld
 build_flags =
-    -O2 -Isrc -ggdb -g3
-    -Wall -Wno-sign-compare -Wno-ignored-qualifiers
-    -DSPI_DRIVER_SELECT=3
-    -DSD_CHIP_SELECT_MODE=2
-    -DENABLE_DEDICATED_SPI=1
-    -DHAS_SDIO_CLASS
-    -DUSE_ARDUINO=1
+    ${env:ZuluSCSI_RP_BASE.build_flags}
     -DZULUSCSI_PICO
-    -DROMDRIVE_OFFSET=${env:ZuluSCSI_RP2040.program_flash_allocation}
-; build flags mirroring the framework-arduinopico#v3.6.0-DaynaPORT static library build
-    -DPICO_CYW43_ARCH_POLL=1
-	-DCYW43_LWIP=0
-	-DCYW43_USE_OTP_MAC=0
-    -DPLATFORM_MASS_STORAGE
-    -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
+    -DROMDRIVE_OFFSET=${env:ZuluSCSI_Pico.program_flash_allocation}
 
 ; Build for the ZuluSCSI Pico carrier board with a Pico-W
 ; for SCSI DaynaPORT emulation
 [env:ZuluSCSI_Pico_DaynaPORT]
-platform = https://github.com/maxgerhardt/platform-raspberrypi.git#5e87ae34ca025274df25b3303e9e9cb6c120123c
-platform_packages =
-    framework-arduinopico@https://github.com/rabbitholecomputing/arduino-pico.git#v3.6.0-DaynaPORT
-framework = arduino
+extends = env:ZuluSCSI_RP_BASE
 board = rpipicow
-board_build.core = earlephilhower
 ; How much flash in bytes the bootloader and main app will be allocated
 ; It is used as the starting point for a ROM image saved in flash
 program_flash_allocation = 589824
-extra_scripts =
-    src/build_bootloader.py
-    lib/ZuluSCSI_platform_RP2040/process-linker-script.py
+linker_script_template = lib/ZuluSCSI_platform_RP2040/rp2040-template.ld
 ldscript_bootloader = lib/ZuluSCSI_platform_RP2040/rp2040_btldr.ld
-board_build.ldscript = ${BUILD_DIR}/rp2040.ld
-debug_tool = cmsis-dap
+lib_deps =
+    ${env:ZuluSCSI_RP_BASE.lib_deps}
+    ZuluSCSI_platform_RP2040
+
 debug_build_flags =
-    -O2 -ggdb -g3
+    ${env:ZuluSCSI_RP_BASE.debug_build_flags}
     -DLOGBUFSIZE=4096
     -DPREFETCH_BUFFER_SIZE=0
     -DSCSI2SD_BUFFER_SIZE=57344
 ; This controls the depth NETWORK_PACKET_MAX_SIZE (1520 bytes)
 ; For example a queue size of 10 would be 10 x 1520 = 30400 bytes
-    -DNETWORK_PACKET_QUEUE_SIZE=10
+    -DNETWORK_PACKET_QUEUE_SIZE=8
 ; This flag enables verbose logging of TCP/IP traffic and other information
 ; it also takes up a bit of SRAM so it should be disabled with production code
     -DNETWORK_DEBUG_LOGGING
-    -DPLATFORM_MASS_STORAGE
-    -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
 
-lib_deps =
-    SdFat=https://github.com/rabbitholecomputing/SdFat#2.2.3-gpt
-    minIni
-    ZuluSCSI_platform_RP2040
-    SCSI2SD
-    CUEParser
 build_flags =
-    -O2 -Isrc
-    -Wall -Wno-sign-compare -Wno-ignored-qualifiers
-    -DSPI_DRIVER_SELECT=3
-    -DSD_CHIP_SELECT_MODE=2
-    -DENABLE_DEDICATED_SPI=1
-    -DHAS_SDIO_CLASS
-    -DUSE_ARDUINO=1
+    ${env:ZuluSCSI_RP_BASE.build_flags}
     -DZULUSCSI_PICO
     -DZULUSCSI_NETWORK
     -DZULUSCSI_DAYNAPORT
@@ -226,39 +215,46 @@ build_flags =
 ; This controls the depth of NETWORK_PACKET_MAX_SIZE (1520 bytes)
 ; For example a queue size of 10 would be 10 x 1520 = 15200 bytes
     -DNETWORK_PACKET_QUEUE_SIZE=14
-    
 ; This flag enables verbose logging of TCP/IP traffic and other information
 ; it also takes up a bit of SRAM so it should be disabled with production code
-    ;-DNETWORK_DEBUG_LOGGING
+    ; -DNETWORK_DEBUG_LOGGING
 
-; build flags mirroring the framework-arduinopico#v3.6.0-DaynaPORT static library build
-    -DPICO_CYW43_ARCH_POLL=1
-	-DCYW43_LWIP=0
-	-DCYW43_USE_OTP_MAC=0
- ;   -DPIO_FRAMEWORK_ARDUINO_NO_USB
-    -DPLATFORM_MASS_STORAGE
-    -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
 
 ; Variant of RP2040 platform, based on Raspberry Pico board and a carrier PCB
 ; Differs in pinout from ZuluSCSI_RP2040 platform, but shares most of the code.
 [env:ZuluSCSI_BS2]
-extends = env:ZuluSCSI_RP2040
+extends = env:ZuluSCSI_RP_BASE
+board = rpipico
+program_flash_allocation = 360448
+linker_script_template = lib/ZuluSCSI_platform_RP2040/rp2040-template.ld
+ldscript_bootloader = lib/ZuluSCSI_platform_RP2040/rp2040_btldr.ld
+lib_deps =
+    ${env:ZuluSCSI_RP_BASE.lib_deps}
+    ZuluSCSI_platform_RP2040
 build_flags =
-    -O2 -Isrc -ggdb -g3
-    -Wall -Wno-sign-compare -Wno-ignored-qualifiers
-    -DSPI_DRIVER_SELECT=3
-    -DSD_CHIP_SELECT_MODE=2
-    -DENABLE_DEDICATED_SPI=1
-    -DHAS_SDIO_CLASS
-    -DUSE_ARDUINO=1
+    ${env:ZuluSCSI_RP_BASE.build_flags}
     -DZULUSCSI_BS2
-    -DROMDRIVE_OFFSET=${env:ZuluSCSI_RP2040.program_flash_allocation}
-; build flags mirroring the framework-arduinopico#v3.6.0-DaynaPORT static library build
-    -DPICO_CYW43_ARCH_POLL=1
-	-DCYW43_LWIP=0
-	-DCYW43_USE_OTP_MAC=0
-    -DPLATFORM_MASS_STORAGE
-    -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
+    -DROMDRIVE_OFFSET=${env:ZuluSCSI_BS2.program_flash_allocation}
+
+; ZuluSCSI Pico2 hardware platform, based on the Raspberry Pi foundation RP2350A microcontroller
+[env:ZuluSCSI_Pico_2]
+extends = env:ZuluSCSI_RP_BASE
+board = rpipico2
+lib_deps =
+    ${env:ZuluSCSI_RP_BASE.lib_deps}
+    ZuluSCSI_platform_RP2350
+; How much flash in bytes the bootloader and main app will be allocated
+; It is used as the starting point for a ROM image saved in flash
+; Changing this will cause issues with boards that already have a ROM drive in flash
+program_flash_allocation = 360448
+linker_script_template = lib/ZuluSCSI_platform_RP2350/rp2350-template.ld
+ldscript_bootloader = lib/ZuluSCSI_platform_RP2350/rp2350_btldr.ld
+debug_build_flags =
+    ${env:ZuluSCSI_RP_BASE.debug_build_flags}
+build_flags =
+    ${env:ZuluSCSI_RP_BASE.build_flags}
+    -DZULUSCSI_PICO_2
+    -DROMDRIVE_OFFSET=${env:ZuluSCSI_Pico_2.program_flash_allocation}
 
 ; ZuluSCSI VF4 hardware platform with GD32F450ZET6 CPU.
 [env:ZULUSCSIv1_4]
@@ -292,7 +288,7 @@ build_flags =
      -D__SYSTEM_CLOCK_200M_PLL_IRC16M=200000000
      -DSPI_DRIVER_SELECT=3
      -DSD_CHIP_SELECT_MODE=2
-     -DENABLE_DEDICATED_SPI=1
+     -DENABLE_DEDICATED_SPI=1   
      -DHAS_SDIO_CLASS
      -DPIO_USBFS_DEVICE_CDC
      -DZULUSCSI_V1_4
@@ -303,48 +299,21 @@ build_flags =
 
 ;========================================
 ; ZuluSCSI RP2350 hardware platform, based on the Raspberry Pi foundation RP2350 microcontroller
-[env:ZuluSCSI_Pico_2]
-platform = https://github.com/maxgerhardt/platform-raspberrypi.git#5e87ae34ca025274df25b3303e9e9cb6c120123c
-platform_packages =
-    framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#f49d058477ac8dacd802ff65b528cf755b6de191
-board_build.core = earlephilhower
-board = rpipico2
-framework = arduino
+[env:ZuluSCSI_RP2350A]
+extends = env:ZuluSCSI_RP_BASE
+board = zuluscsi_RP2350A
 ; How much flash in bytes the bootloader and main app will be allocated
 ; It is used as the starting point for a ROM image saved in flash
 ; Changing this will cause issues with boards that already have a ROM drive in flash
 program_flash_allocation = 360448
-extra_scripts =
-    src/build_bootloader.py
-    lib/ZuluSCSI_platform_RP2350/process-linker-script.py
-board_build.ldscript = ${BUILD_DIR}/rp2350.ld
+linker_script_template = lib/ZuluSCSI_platform_RP2350/rp2350-template.ld
 ldscript_bootloader = lib/ZuluSCSI_platform_RP2350/rp2350_btldr.ld
 lib_deps =
-    SdFat=https://github.com/rabbitholecomputing/SdFat#2.2.3-gpt
-    minIni
+    ${env:ZuluSCSI_RP_BASE.lib_deps}
     ZuluSCSI_platform_RP2350
-    SCSI2SD
-    CUEParser
-upload_protocol = cmsis-dap
-debug_tool = cmsis-dap
 debug_build_flags =
-    -O2 -ggdb -g3
-; The values can be adjusted down to get a debug build to fit in to SRAM
-    -DLOGBUFSIZE=4096
+    ${env:ZuluSCSI_RP_BASE.debug_build_flags}
 build_flags =
-    -O2 -Isrc -ggdb -g3
-    -Wall -Wno-sign-compare -Wno-ignored-qualifiers
-    -DSPI_DRIVER_SELECT=3
-    -DSD_CHIP_SELECT_MODE=2
-    -DENABLE_DEDICATED_SPI=1
-    -DHAS_SDIO_CLASS
-    -DUSE_ARDUINO=1
-    -DZULUSCSI_PICO
-    -DROMDRIVE_OFFSET=${env:ZuluSCSI_RP2040.program_flash_allocation}
-    -DFILE_COPY_CONSTRUCTOR_SELECT=FILE_COPY_CONSTRUCTOR_PUBLIC
-
-; build flags mirroring the framework-arduinopico#v3.6.0-DaynaPORT static library build
-    ; -DPICO_CYW43_ARCH_POLL=1
-	; -DCYW43_LWIP=0
-	; -DCYW43_USE_OTP_MAC=0
-    ; -DPLATFORM_MASS_STORAGE
+    ${env:ZuluSCSI_RP_BASE.build_flags}
+    -DZULUSCSI_RP2350
+    -DROMDRIVE_OFFSET=${env:ZuluSCSI_RP2350A.program_flash_allocation}

+ 0 - 3
src/ZuluSCSI_msc.h

@@ -25,9 +25,6 @@
 // include platform-specific defines
 #include "ZuluSCSI_platform_msc.h"
 
-// wait up to this long during init sequence for USB enumeration to enter card reader
-#define CR_ENUM_TIMEOUT 1000
-
 enum  MSC_LEDState { LED_SOLIDON = 0, LED_BLINK_FAST, LED_BLINK_SLOW };
 extern volatile enum MSC_LEDState MSC_LEDMode;
 

+ 2 - 0
src/ZuluSCSI_settings.cpp

@@ -297,6 +297,7 @@ scsi_system_settings_t *ZuluSCSISettings::initSystem(const char *presetName)
     cfgSys.useFATAllocSize = false;
     cfgSys.enableCDAudio = false;
     cfgSys.enableUSBMassStorage = false;
+    cfgSys.usbMassStorageWaitPeriod = 1000;
     
     // setting set for all or specific devices
     cfgDev.deviceType = S2S_CFG_NOT_SET;
@@ -392,6 +393,7 @@ scsi_system_settings_t *ZuluSCSISettings::initSystem(const char *presetName)
     cfgSys.enableCDAudio = ini_getbool("SCSI", "EnableCDAudio", cfgSys.enableCDAudio, CONFIGFILE);
 
     cfgSys.enableUSBMassStorage = ini_getbool("SCSI", "EnableUSBMassStorage", cfgSys.enableUSBMassStorage, CONFIGFILE);
+    cfgSys.usbMassStorageWaitPeriod = ini_getl("SCSI", "USBMassStorageWaitPeriod", cfgSys.usbMassStorageWaitPeriod, CONFIGFILE);
     
     return &cfgSys;
 }

+ 1 - 0
src/ZuluSCSI_settings.h

@@ -66,6 +66,7 @@ typedef struct __attribute__((__packed__)) scsi_system_settings_t
     bool useFATAllocSize;
     bool enableCDAudio;
     bool enableUSBMassStorage;
+    uint16_t usbMassStorageWaitPeriod;
 } scsi_system_settings_t;
 
 // This struct should only have new setting added to the end

+ 2 - 2
lib/ZuluSCSI_platform_RP2040/process-linker-script.py → src/process-linker-script.py

@@ -19,8 +19,8 @@
 from string import Template 
 Import ("env")
 
-template_file = 'lib/ZuluSCSI_platform_RP2040/rp2040-template.ld'
-linker_file = env.subst('$BUILD_DIR') + '/rp2040.ld'
+template_file =  env.GetProjectOption('linker_script_template')
+linker_file = env.subst('$BUILD_DIR') + '/rp_linker.ld'
 
 def process_template(source, target, env):
     values = {

+ 5 - 0
zuluscsi.ini

@@ -66,6 +66,11 @@
 #DisableMacSanityCheck = 0 # Disable sanity warnings for Mac disk drives. Default is 0 - enable checks
 #BlockSize = 0 # Set the drive's blocksize, defaults to 2048 for CDs and 512 for all other drives
 
+# Mount SD card as a mass storage device before entering SCSI emulator
+# EnableUSBMassStorage = 1 # setting this to one will mount the SD card if the USB cord is plugged in
+# USBMassStorageWaitPeriod = 1000 # Number of milliseconds the device will wait for the host to mount SD card
+#   May need to be increased if coneneted through a USB hub
+
 # SCSI DaynaPORT settings
 #WiFiSSID = "Wifi SSID string"
 #WiFiPassword = "WiFi Password"