From 2a4b82e3e12b68705f394bf8d800c64ab81ab1c0 Mon Sep 17 00:00:00 2001 From: Siddharth Chandrasekaran Date: Sun, 8 Mar 2026 00:08:40 +0100 Subject: tinyusb: fix hwfifo PMA pointer advance on ring buffer wrap In hwff_push_n() and hwff_pull_n(), the HWFIFO_ADDR_NEXT_N call after processing the linear part of a wrap-around read/write used the data byte count (lin_even) as the address stride increment. On STM32 FSDEV PMA, data_stride=2 and addr_stride=4, so the pointer must advance by (lin_even / data_stride) * addr_stride bytes, not lin_even bytes. Fixes: 74e59e433 ("fix hwfifo pull/push n with address stride > 0") Signed-off-by: Siddharth Chandrasekaran --- src/common/tusb_fifo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c index 8bd79e56d..991ee18ff 100644 --- a/src/common/tusb_fifo.c +++ b/src/common/tusb_fifo.c @@ -280,7 +280,7 @@ static void hwff_push_n(const tu_fifo_t *f, const void *app_buf, uint16_t n, uin const uint32_t odd_mask = data_stride - 1; uint16_t lin_even = lin_bytes & ~odd_mask; tu_hwfifo_read(hwfifo, ff_buf, lin_even, access_mode); - HWFIFO_ADDR_NEXT_N(hwfifo, const, lin_even); + HWFIFO_ADDR_NEXT_N(hwfifo, const, (lin_even / data_stride) * CFG_TUSB_FIFO_HWFIFO_ADDR_STRIDE); ff_buf += lin_even; // There could be odd 1 byte (16bit) or 1-3 bytes (32bit) before the wrap-around boundary @@ -337,7 +337,7 @@ static void hwff_pull_n(const tu_fifo_t *f, void *app_buf, uint16_t n, uint16_t const uint32_t odd_mask = data_stride - 1; uint16_t lin_even = lin_bytes & ~odd_mask; tu_hwfifo_write(hwfifo, ff_buf, lin_even, access_mode); - HWFIFO_ADDR_NEXT_N(hwfifo, , lin_even); + HWFIFO_ADDR_NEXT_N(hwfifo, , (lin_even / data_stride) * CFG_TUSB_FIFO_HWFIFO_ADDR_STRIDE); ff_buf += lin_even; // There could be odd 1 byte (16bit) or 1-3 bytes (32bit) before the wrap-around boundary -- cgit v1.3.1