You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2026/10/01 15:31:58 UTC
(nuttx) 02/02: arch/arm/imxrt: Add support for ARMV8M_DCACHE_LINESIZE in imxrt_usbdev.c
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 437306409e8a553ad82a08e6e8cafa382ee77c15
Author: Jukka Laitinen <ju...@tii.ae>
AuthorDate: Thu Oct 1 09:23:51 2026 +0300
arch/arm/imxrt: Add support for ARMV8M_DCACHE_LINESIZE in imxrt_usbdev.c
Select the cache line size from either ARMV7M_DCACHE_LINESIZE or
ARMV8M_DCACHE_LINESIZE, so the driver can also be used with D-cache
enabled on the i.MX RT1180 Cortex-M33.
Also fix the imxrt1180-evk USB DMA allocator alignment. Pad the header
to the 32-byte DMA alignment, so that the buffer remains aligned.
Signed-off-by: Jukka Laitinen <ju...@tii.ae>
---
arch/arm/src/imxrt/imxrt_usbdev.c | 16 +++++++++++-----
boards/arm/imxrt/imxrt1180-evk/src/imxrt_dma_alloc.c | 6 ++++--
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/arch/arm/src/imxrt/imxrt_usbdev.c b/arch/arm/src/imxrt/imxrt_usbdev.c
index 8036239077c..ee5148ae3bd 100644
--- a/arch/arm/src/imxrt/imxrt_usbdev.c
+++ b/arch/arm/src/imxrt/imxrt_usbdev.c
@@ -207,12 +207,18 @@ const struct trace_msg_t g_usb_trace_strings_intdecode[] =
#endif
#if defined(CONFIG_ARMV7M_DCACHE)
+# define USB_DCACHE_LINESIZE ARMV7M_DCACHE_LINESIZE
+#elif defined(CONFIG_ARMV8M_DCACHE)
+# define USB_DCACHE_LINESIZE ARMV8M_DCACHE_LINESIZE
+#endif
+
+#if defined(CONFIG_ARMV7M_DCACHE) || defined(CONFIG_ARMV8M_DCACHE)
# define cache_aligned_alloc(s) \
- kmm_memalign(ARMV7M_DCACHE_LINESIZE, \
- (((s) + ARMV7M_DCACHE_LINESIZE - 1) & \
- ~(ARMV7M_DCACHE_LINESIZE - 1)))
-# define CACHE_ALIGNED_DATA aligned_data(ARMV7M_DCACHE_LINESIZE)
-# define DCACHE_LINEMASK (ARMV7M_DCACHE_LINESIZE - 1)
+ kmm_memalign(USB_DCACHE_LINESIZE, \
+ (((s) + USB_DCACHE_LINESIZE - 1) & \
+ ~(USB_DCACHE_LINESIZE - 1)))
+# define CACHE_ALIGNED_DATA aligned_data(USB_DCACHE_LINESIZE)
+# define DCACHE_LINEMASK (USB_DCACHE_LINESIZE - 1)
# define DCACHE_ALIGN_UP(a) (((a) + DCACHE_LINEMASK) & ~DCACHE_LINEMASK)
# define IS_CACHE_ALIGNED(x,y) \
(((uintptr_t)(x) & DCACHE_LINEMASK) == 0 && \
diff --git a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_dma_alloc.c b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_dma_alloc.c
index 0b6218201f3..63f6a0e2ec5 100644
--- a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_dma_alloc.c
+++ b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_dma_alloc.c
@@ -61,6 +61,7 @@
* overhead and other endpoints.
*/
+#define IMXRT_DMA_ALIGNMENT 32
#define IMXRT_DMA_POOL_SIZE (6 * 1024)
/****************************************************************************
@@ -105,14 +106,15 @@ int imxrt_dma_alloc_init(void)
*
* gran_free() needs to know the size of the allocation being freed, but
* usbdev_dma_free() is not given a size (see include/nuttx/usb/usbdev.h).
- * We work around this by prepending a small header that records the
- * total granule allocation size.
+ * Reserve one alignment unit before the returned buffer and record the
+ * total allocation size there. This keeps the buffer cache-line aligned.
*
****************************************************************************/
struct usbdma_header_s
{
size_t allocsize;
+ uint8_t padding[IMXRT_DMA_ALIGNMENT - sizeof(size_t)];
};
void *usbdev_dma_alloc(size_t size)