Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions lib/BlueSCSI_platform_RP2MCU/BlueSCSI_platform_msc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,49 @@ extern "C" void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8],
uint8_t product_id[16], uint8_t product_rev[4]) {

MSCScopedLock lock;
if (g_msc_initiator) return init_msc_inquiry_cb(lun, vendor_id, product_id, product_rev);
if (g_msc_initiator) {
init_msc_inquiry_cb(lun, vendor_id, product_id, product_rev);

// Build a temporary inquiry structure to get the device type
uint8_t temp_inquiry[36];
uint32_t result = init_msc_inquiry2_cb(lun, temp_inquiry, sizeof(temp_inquiry));

if (result > 0) {
uint8_t device_type = temp_inquiry[0] & 0x1F;
uint8_t is_removable = temp_inquiry[1] & 0x80;

// The inquiry response buffer starts 8 bytes before vendor_id
// vendor_id is at offset 8 in scsi_inquiry_resp_t
uint8_t *inquiry_resp = vendor_id - 8;

// Safely modify the device type fields
inquiry_resp[0] = (inquiry_resp[0] & 0xE0) | (device_type & 0x1F);
inquiry_resp[1] = (inquiry_resp[1] & 0x7F) | is_removable;
}
return;
}

const char vid[] = "BlueSCSI";
const char pid[] = PLATFORM_PID;
const char pid[] = PLATFORM_PID;
const char rev[] = PLATFORM_REVISION;

memcpy(vendor_id, vid, tu_min32(strlen(vid), 8));
memcpy(product_id, pid, tu_min32(strlen(pid), 16));
memcpy(product_rev, rev, tu_min32(strlen(rev), 4));
}

// TODO: When PicoSDK/Arduino-Pico are updated to include TinyUSB 0.19.0+ we can just use this instead of manually manipulating the buffer.
// extern "C" __attribute__((used)) uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uint32_t bufsize) {
// MSCScopedLock lock;
// logmsg("tud_msc_inquiry2_cb (v2): LUN=", (int)lun, " initiator_mode=", g_msc_initiator ? "YES" : "NO");
//
// if (g_msc_initiator) {
// uint32_t result = init_msc_inquiry2_cb(lun, inquiry_resp, bufsize);
// return result;
// }
// return 0;
// }

// max LUN supported
// we only have the one SD card
extern "C" uint8_t tud_msc_get_maxlun_cb(void)
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build_flags =
[env:BlueSCSI_RP2MCU]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git#6164ed92d83c1241a1d84ad848158d7b0fb486e3
platform_packages =
framework-arduinopico@https://github.com/BlueSCSI/arduino-pico-internal.git#v4.7.0-DaynaPORT
framework-arduinopico@https://github.com/BlueSCSI/arduino-pico-internal.git#tusb-0.19.0-test
extra_scripts =
src/build_bootloader.py
src/process-linker-script.py
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ let
cmake
nodejs
git
git-filter-repo
gh
picotool
];
Expand Down
13 changes: 10 additions & 3 deletions src/BlueSCSI_initiator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This file is originally part of ZuluSCSI adopted for BlueSCSI
*
* BlueSCSI - Copyright (c) 2024 Eric Helgeson, Androda
* BlueSCSI - Copyright (c) 2024-2025 Eric Helgeson, Androda
* ZuluSCSI™ - Copyright (c) 2022-2025 Rabbit Hole Computing™
*
* ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
Expand Down Expand Up @@ -881,8 +881,15 @@ bool scsiTestUnitReady(int target_id)
}
else if (sense_key == NOT_READY)
{
dbgmsg("Target ", target_id, " reports NOT_READY, running STARTSTOPUNIT");
scsiStartStopUnit(target_id, true);
#ifdef PLATFORM_MASS_STORAGE
// For MSC initiator mode, don't automatically send START_STOP_UNIT
// Removable media (Zip, MO, etc.) can eject if START is sent during loading
if (!g_msc_initiator)
#endif
{
dbgmsg("Target ", target_id, " reports NOT_READY, running STARTSTOPUNIT");
scsiStartStopUnit(target_id, true);
}
}
}
else
Expand Down
Loading