Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge the RP2350 and the RP2040 base MCU platform libraries into a common library #467

Merged
merged 27 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6f69dfb
Attempting to get ZuluSCSI to work with a Pico 2
morio Sep 24, 2024
4964108
Update firmware_build.yml
aperezbios Sep 24, 2024
e4da635
change default_envs
aperezbios Sep 24, 2024
cb82a3f
Update platformio.ini
aperezbios Sep 24, 2024
ea86d04
Change build settings
morio Sep 27, 2024
7d95079
Disable bootloader
morio Sep 28, 2024
a546b15
Actually disable bootloader
morio Sep 28, 2024
c7be85a
Remove LED on test
morio Sep 28, 2024
c8e1066
Update ZuluSCSI_config.h
aperezbios Sep 28, 2024
52ed86a
Get bootloader working
morio Oct 9, 2024
4a7843b
Merge branch 'main' into feature/pico2-support
morio Oct 10, 2024
22834f1
Apply SD speed class warning support
morio Oct 10, 2024
12f8030
Adjusted delays for Pico clock of 150 MHz
mglazzari-qinmotion Oct 10, 2024
c381965
Adjust SCSI REQ assertion timing
aperezbios Oct 11, 2024
6d1164b
Added comments, changed min syncperiod to 20 (to support 12.5 MB/s)
mglazzari-qinmotion Oct 17, 2024
c6962f8
Changed PLATFORM_MAX_SCSI_SPEED to Turbo (from 10 MB/s)
mglazzari-qinmotion Oct 17, 2024
396348f
Added delay calculations for speeds above 10 MB/s
mglazzari-qinmotion Oct 17, 2024
16246b3
Update ZuluSCSI_config.h
aperezbios Oct 17, 2024
b1605ae
Update ZuluSCSI_config.h
aperezbios Oct 17, 2024
c4f0479
Move to latest arduino pico framework and pico-sdk
morio Oct 26, 2024
382e2c3
This is a merge of RP2040 and RP2350 libraries
morio Oct 28, 2024
d8665a5
Merge branch 'main' into feature/merge-rp2xxx-libs
morio Oct 28, 2024
8f7de2a
Merge branch 'main' of github.com:ZuluSCSI/ZuluSCSI-firmware
morio Nov 1, 2024
ec7e7b1
Merge branch 'main' into feature/merge-rp2xxx-libs
morio Nov 1, 2024
b3262fe
Merge branch 'main' of github.com:ZuluSCSI/ZuluSCSI-firmware
morio Nov 1, 2024
eeb2cc0
Merge branch 'main' into feature/merge-rp2xxx-libs
morio Nov 1, 2024
6fdb664
Merge branch 'main' into feature/merge-rp2xxx-libs
morio Nov 2, 2024
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
Prev Previous commit
Next Next commit
Apply SD speed class warning support
morio committed Oct 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 22834f1523d81953fb9da3493d8b80cbb3f013da
18 changes: 18 additions & 0 deletions lib/ZuluSCSI_platform_RP2350/sd_card_sdio.cpp
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ static uint32_t g_sdio_ocr; // Operating condition register from card
static uint32_t g_sdio_rca; // Relative card address
static cid_t g_sdio_cid;
static csd_t g_sdio_csd;
static sds_t __attribute__((aligned(4))) g_sdio_sds;
static int g_sdio_error_line;
static sdio_status_t g_sdio_error;
static uint32_t g_sdio_dma_buf[128];
@@ -170,6 +171,17 @@ bool SdioCard::begin(SdioConfig sdioConfig)
return false;
}

// Read SD Status field
memset(&g_sdio_sds, 0, sizeof(sds_t));
uint8_t* stat_pointer = (uint8_t*) &g_sdio_sds;
if (!checkReturnOk(rp2040_sdio_command_R1(CMD55, g_sdio_rca, &reply)) ||
!checkReturnOk(rp2040_sdio_command_R1(ACMD13, 0, &reply)) ||
!checkReturnOk(receive_status_register(stat_pointer)))
{
dbgmsg("SDIO failed to get SD Status");
return false;
}

// Increase to 25 MHz clock rate
rp2040_sdio_init(1);

@@ -213,6 +225,12 @@ bool SdioCard::readCSD(csd_t* csd)
return true;
}

bool SdioCard::readSDS(sds_t* sds)
{
*sds = g_sdio_sds;
return true;
}

bool SdioCard::readOCR(uint32_t* ocr)
{
// SDIO mode does not have CMD58, but main program uses this to
39 changes: 34 additions & 5 deletions lib/ZuluSCSI_platform_RP2350/sdio.cpp
Original file line number Diff line number Diff line change
@@ -157,6 +157,35 @@ uint64_t sdio_crc16_4bit_checksum(uint32_t *data, uint32_t num_words)
return crc;
}

/*******************************************************
* Status Register Receiver
*******************************************************/
sdio_status_t receive_status_register(uint8_t* sds) {
rp2040_sdio_rx_start(sds, 1, 64);
// Wait for the DMA operation to complete, or fail if it took too long
waitagain:
while (dma_channel_is_busy(SDIO_DMA_CHB) || dma_channel_is_busy(SDIO_DMA_CH))
{
if ((uint32_t)(millis() - g_sdio.transfer_start_time) > 2)
{
// Reset the state machine program
dma_channel_abort(SDIO_DMA_CHB);
pio_sm_set_enabled(SDIO_PIO, SDIO_CMD_SM, false);
pio_sm_clear_fifos(SDIO_PIO, SDIO_CMD_SM);
return SDIO_ERR_RESPONSE_TIMEOUT;
}
}
// Assert that both DMA channels are complete
if(dma_channel_is_busy(SDIO_DMA_CHB) || dma_channel_is_busy(SDIO_DMA_CH)) {
// Wait failure, go back.
goto waitagain;
}
pio_sm_set_enabled(SDIO_PIO, SDIO_DATA_SM, false);
g_sdio.transfer_state = SDIO_IDLE;
return SDIO_OK;
}


/*******************************************************
* Basic SDIO command execution
*******************************************************/
@@ -377,7 +406,7 @@ sdio_status_t rp2040_sdio_command_R3(uint8_t command, uint32_t arg, uint32_t *re
* Data reception from SD card
*******************************************************/

sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks)
sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks, uint32_t block_size)
{
// Buffer must be aligned
assert(((uint32_t)buffer & 3) == 0 && num_blocks <= SDIO_MAX_BLOCKS);
@@ -390,12 +419,12 @@ sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks)
g_sdio.blocks_checksumed = 0;
g_sdio.checksum_errors = 0;

// Create DMA block descriptors to store each block of 512 bytes of data to buffer
// Create DMA block descriptors to store each block of block_size bytes of data to buffer
// and then 8 bytes to g_sdio.received_checksums.
for (int i = 0; i < num_blocks; i++)
{
g_sdio.dma_blocks[i * 2].write_addr = buffer + i * SDIO_BLOCK_SIZE;
g_sdio.dma_blocks[i * 2].transfer_count = SDIO_BLOCK_SIZE / sizeof(uint32_t);
g_sdio.dma_blocks[i * 2].write_addr = buffer + i * block_size;
g_sdio.dma_blocks[i * 2].transfer_count = block_size / sizeof(uint32_t);

g_sdio.dma_blocks[i * 2 + 1].write_addr = &g_sdio.received_checksums[i];
g_sdio.dma_blocks[i * 2 + 1].transfer_count = 2;
@@ -427,7 +456,7 @@ sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks)
pio_sm_set_consecutive_pindirs(SDIO_PIO, SDIO_DATA_SM, SDIO_D0, 4, false);

// Write number of nibbles to receive to Y register
pio_sm_put(SDIO_PIO, SDIO_DATA_SM, SDIO_BLOCK_SIZE * 2 + 16 - 1);
pio_sm_put(SDIO_PIO, SDIO_DATA_SM, block_size * 2 + 16 - 1);
pio_sm_exec(SDIO_PIO, SDIO_DATA_SM, pio_encode_out(pio_y, 32));

// Enable RX FIFO join because we don't need the TX FIFO during transfer.
7 changes: 5 additions & 2 deletions lib/ZuluSCSI_platform_RP2350/sdio.h
Original file line number Diff line number Diff line change
@@ -53,8 +53,8 @@ sdio_status_t rp2040_sdio_command_R2(uint8_t command, uint32_t arg, uint8_t *res
sdio_status_t rp2040_sdio_command_R3(uint8_t command, uint32_t arg, uint32_t *response);

// Start transferring data from SD card to memory buffer
// Transfer block size is always 512 bytes.
sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks);
// Transfer block size is always 512 bytes except for certain special commands
sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks, uint32_t num_size = SDIO_BLOCK_SIZE);

// Check if reception is complete
// Returns SDIO_BUSY while transferring, SDIO_OK when done and error on failure.
@@ -69,5 +69,8 @@ sdio_status_t rp2040_sdio_tx_poll(uint32_t *bytes_complete = nullptr);
// Force everything to idle state
sdio_status_t rp2040_sdio_stop();

// Receives the SD Status register. Does not return until the register has been received.
sdio_status_t receive_status_register(uint8_t* sds);

// (Re)initialize the SDIO interface
void rp2040_sdio_init(int clock_divider = 1);
4 changes: 3 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -320,7 +320,7 @@ extra_scripts =
board_build.ldscript = ${BUILD_DIR}/rp2350.ld
ldscript_bootloader = lib/ZuluSCSI_platform_RP2350/rp2350_btldr.ld
lib_deps =
SdFat=https://github.com/rabbitholecomputing/SdFat#2.2.0-gpt
SdFat=https://github.com/rabbitholecomputing/SdFat#2.2.3-gpt
minIni
ZuluSCSI_platform_RP2350
SCSI2SD
@@ -341,6 +341,8 @@ build_flags =
-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