diff options
| author | Ha Thach <[email protected]> | 2025-12-13 09:03:34 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-13 09:03:34 +0700 |
| commit | 3a4d02ba9f150b74df08384d16fac124a7c27485 (patch) | |
| tree | c65f69de4f4f44db6c9b8720c52c2a49dd97bf76 | |
| parent | 09f71727d53d4e70803d7460c3e5cdfb7f2bcb06 (diff) | |
| parent | fa74d1a6e10b8a3d05f94ca876a5cccf515b5c34 (diff) | |
Merge pull request #3407 from hathach/rusb2_fifo_fix
dcd/rusb2: fix fifo write
| -rw-r--r-- | src/portable/renesas/rusb2/dcd_rusb2.c | 27 | ||||
| -rw-r--r-- | src/tusb_option.h | 2 |
2 files changed, 19 insertions, 10 deletions
diff --git a/src/portable/renesas/rusb2/dcd_rusb2.c b/src/portable/renesas/rusb2/dcd_rusb2.c index 786b8d980..779c7bc3d 100644 --- a/src/portable/renesas/rusb2/dcd_rusb2.c +++ b/src/portable/renesas/rusb2/dcd_rusb2.c @@ -213,17 +213,26 @@ static void pipe_write_packet_ff(rusb2_reg_t * rusb, tu_fifo_t *f, volatile void tu_fifo_buffer_info_t info; tu_fifo_get_read_info(f, &info); - uint16_t count = tu_min16(total_len, info.linear.len); - pipe_write_packet(rusb, info.linear.ptr, fifo, count); + uint16_t cnt_lin = tu_min16(total_len, info.linear.len); + uint16_t cnt_wrap = tu_min16(total_len - cnt_lin, info.wrapped.len); + uint16_t const cnt_written = cnt_lin + cnt_wrap; - uint16_t rem = total_len - count; - if (rem) { - rem = tu_min16(rem, info.wrapped.len); - pipe_write_packet(rusb, info.wrapped.ptr, fifo, rem); - count += rem; - } + // Ensure only the last write is odd if total_len is odd + if (cnt_wrap == 0) { + pipe_write_packet(rusb, info.linear.ptr, fifo, cnt_lin); + } else { + pipe_write_packet(rusb, info.linear.ptr, fifo, cnt_lin & ~1); - tu_fifo_advance_read_pointer(f, count); + if (cnt_lin & 1) { + uint8_t glue[2] = {info.linear.ptr[cnt_lin & ~1], info.wrapped.ptr[0]}; + pipe_write_packet(rusb, glue, fifo, 2); + cnt_wrap--; + info.wrapped.ptr++; + } + + pipe_write_packet(rusb, info.wrapped.ptr, fifo, cnt_wrap); + } + tu_fifo_advance_read_pointer(f, cnt_written); } // Read data sw fifo <-- hw fifo diff --git a/src/tusb_option.h b/src/tusb_option.h index a70d7a97e..1dc920d84 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -361,7 +361,7 @@ //------------ RUSB2 --------------// #if defined(TUP_USBIP_RUSB2) - #define CFG_TUD_EDPT_DEDICATED_HWFIFO 0 // need testing to enable + #define CFG_TUD_EDPT_DEDICATED_HWFIFO 1 #endif //-------------------------------------------------------------------- |
