Skip to content

Commit 1ab40e8

Browse files
committed
Try to read and send the requested data in chunks
1 parent 9cfb62c commit 1ab40e8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

main.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static void wait_for_write(void)
110110
static inline void sendbytes_blocking(const void *b, uint32_t len)
111111
{
112112
while (len) {
113-
wait_for_write();
113+
// wait_for_write();
114114
uint32_t w = tud_cdc_n_write(CDC_ITF, b, len);
115115
b += w;
116116
len -= w;
@@ -228,13 +228,15 @@ static void command_loop(void)
228228
sendbyte_blocking(S_ACK);
229229

230230
// Handle receive operation in chunks for large rlen
231-
cs_select(SPI_CS);
232-
while (rlen > 0) {
233-
uint32_t chunk_size = (rlen < MAX_BUFFER_SIZE) ? rlen : MAX_BUFFER_SIZE;
231+
uint32_t chunk;
232+
char buf[128];
234233

235-
spi_read_blocking(SPI_IF, 0, rx_buffer, chunk_size);
236-
sendbytes_blocking(rx_buffer, chunk_size);
237-
rlen -= chunk_size;
234+
cs_select(SPI_CS);
235+
for(uint32_t i = 0; i < rlen; i += chunk) {
236+
chunk = MIN(rlen - i, sizeof(buf));
237+
pio_spi_read8_blocking(spi, buf, chunk);
238+
fwrite(buf, 1, chunk, stdout);
239+
fflush(stdout);
238240
}
239241
cs_deselect(SPI_CS);
240242
break;

0 commit comments

Comments
 (0)