@@ -156,6 +156,39 @@ void cycleSdClock() {
156
156
pio_sm_exec (SDIO_PIO, SDIO_CMD_SM, pio_encode_nop () | pio_encode_sideset_opt (1 , 0 ) | pio_encode_delay (1 ));
157
157
}
158
158
159
+ /* ******************************************************
160
+ * Status Register Receiver
161
+ *******************************************************/
162
+ sdio_status_t receive_status_register (uint8_t * sds) {
163
+ rp2040_sdio_rx_start (sds, 1 , 64 );
164
+
165
+ // Wait for the DMA operation to complete, or fail if it took too long
166
+ waitagain:
167
+ while (dma_channel_is_busy (SDIO_DMA_CHB) || dma_channel_is_busy (SDIO_DMA_CH))
168
+ {
169
+ if ((uint32_t )(millis () - g_sdio.transfer_start_time ) > 2 )
170
+ {
171
+ // Reset the state machine program
172
+ dma_channel_abort (SDIO_DMA_CHB);
173
+ pio_sm_set_enabled (SDIO_PIO, SDIO_CMD_SM, false );
174
+ pio_sm_clear_fifos (SDIO_PIO, SDIO_CMD_SM);
175
+ return SDIO_ERR_RESPONSE_TIMEOUT;
176
+ }
177
+ }
178
+
179
+ // Assert that both DMA channels are complete
180
+ if (dma_channel_is_busy (SDIO_DMA_CHB) || dma_channel_is_busy (SDIO_DMA_CH)) {
181
+ // Wait failure, go back.
182
+ goto waitagain;
183
+ }
184
+
185
+ pio_sm_set_enabled (SDIO_PIO, SDIO_DATA_SM, false );
186
+ g_sdio.transfer_state = SDIO_IDLE;
187
+
188
+ return SDIO_OK;
189
+ }
190
+
191
+
159
192
/* ******************************************************
160
193
* Basic SDIO command execution
161
194
*******************************************************/
@@ -437,7 +470,7 @@ sdio_status_t rp2040_sdio_command_R3(uint8_t command, uint32_t arg, uint32_t *re
437
470
* Data reception from SD card
438
471
*******************************************************/
439
472
440
- sdio_status_t rp2040_sdio_rx_start (uint8_t *buffer, uint32_t num_blocks)
473
+ sdio_status_t rp2040_sdio_rx_start (uint8_t *buffer, uint32_t num_blocks, uint32_t block_size )
441
474
{
442
475
// Buffer must be aligned
443
476
assert (((uint32_t )buffer & 3 ) == 0 && num_blocks <= SDIO_MAX_BLOCKS);
@@ -450,12 +483,12 @@ sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks)
450
483
g_sdio.blocks_checksumed = 0 ;
451
484
g_sdio.checksum_errors = 0 ;
452
485
453
- // Create DMA block descriptors to store each block of 512 bytes of data to buffer
486
+ // Create DMA block descriptors to store each block of block_size bytes of data to buffer
454
487
// and then 8 bytes to g_sdio.received_checksums.
455
488
for (int i = 0 ; i < num_blocks; i++)
456
489
{
457
- g_sdio.dma_blocks [i * 2 ].write_addr = buffer + i * SDIO_BLOCK_SIZE ;
458
- g_sdio.dma_blocks [i * 2 ].transfer_count = SDIO_BLOCK_SIZE / sizeof (uint32_t );
490
+ g_sdio.dma_blocks [i * 2 ].write_addr = buffer + ( i * block_size) ;
491
+ g_sdio.dma_blocks [i * 2 ].transfer_count = block_size / sizeof (uint32_t );
459
492
460
493
g_sdio.dma_blocks [i * 2 + 1 ].write_addr = &g_sdio.received_checksums [i];
461
494
g_sdio.dma_blocks [i * 2 + 1 ].transfer_count = 2 ;
@@ -488,7 +521,7 @@ sdio_status_t rp2040_sdio_rx_start(uint8_t *buffer, uint32_t num_blocks)
488
521
pio_sm_set_consecutive_pindirs (SDIO_PIO, SDIO_DATA_SM, SDIO_D0, 4 , false );
489
522
490
523
// Write number of nibbles to receive to Y register
491
- pio_sm_put (SDIO_PIO, SDIO_DATA_SM, SDIO_BLOCK_SIZE * 2 + 16 - 1 );
524
+ pio_sm_put (SDIO_PIO, SDIO_DATA_SM, (block_size * 2 ) + 16 - 1 );
492
525
pio_sm_exec (SDIO_PIO, SDIO_DATA_SM, pio_encode_out (pio_y, 32 ));
493
526
494
527
// Enable RX FIFO join because we don't need the TX FIFO during transfer.
0 commit comments