Skip to content

Commit 337913b

Browse files
committed
samples: usb: uac2: Avoid DMM buffer bouncing on nRF54H20
Place I2S buffer in memory location that can be used directly by the TDM peripheral without DMM bouncing. Signed-off-by: Tomasz Moń <[email protected]>
1 parent 73ea526 commit 337913b

File tree

2 files changed

+20
-6
lines changed
  • samples/subsys/usb
    • uac2_explicit_feedback/src
    • uac2_implicit_feedback/src

2 files changed

+20
-6
lines changed

samples/subsys/usb/uac2_explicit_feedback/src/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <zephyr/usb/class/usbd_uac2.h>
1616
#include <zephyr/drivers/i2s.h>
1717
#include <zephyr/logging/log.h>
18+
#include <zephyr/linker/devicetree_regions.h>
1819

1920
LOG_MODULE_REGISTER(uac2_sample, LOG_LEVEL_INF);
2021

@@ -29,14 +30,20 @@ LOG_MODULE_REGISTER(uac2_sample, LOG_LEVEL_INF);
2930
#define BLOCK_SIZE (SAMPLES_PER_SOF * BYTES_PER_SLOT)
3031
#define MAX_BLOCK_SIZE ((SAMPLES_PER_SOF + 1) * BYTES_PER_SLOT)
3132

33+
#define I2S_MEMORY_SECTION \
34+
COND_CODE_1(DT_NODE_HAS_PROP(DT_NODELABEL(i2s_tx), memory_regions), \
35+
(Z_GENERIC_SECTION(LINKER_DT_NODE_REGION_NAME_TOKEN( \
36+
DT_PHANDLE(DT_NODELABEL(i2s_tx), memory_regions)))), \
37+
(__noinit))
38+
3239
/* Absolute minimum is 5 buffers (1 actively consumed by I2S, 2nd queued as next
3340
* buffer, 3rd acquired by USB stack to receive data to, and 2 to handle SOF/I2S
3441
* offset errors), but add 2 additional buffers to prevent out of memory errors
3542
* when USB host decides to perform rapid terminal enable/disable cycles.
3643
*/
3744
#define I2S_BUFFERS_COUNT 7
38-
K_MEM_SLAB_DEFINE_STATIC(i2s_tx_slab, ROUND_UP(MAX_BLOCK_SIZE, UDC_BUF_GRANULARITY),
39-
I2S_BUFFERS_COUNT, UDC_BUF_ALIGN);
45+
K_MEM_SLAB_DEFINE_IN_SECT_STATIC(i2s_tx_slab, I2S_MEMORY_SECTION,
46+
ROUND_UP(MAX_BLOCK_SIZE, UDC_BUF_GRANULARITY), I2S_BUFFERS_COUNT, UDC_BUF_ALIGN);
4047

4148
struct usb_i2s_ctx {
4249
const struct device *i2s_dev;

samples/subsys/usb/uac2_implicit_feedback/src/main.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <zephyr/usb/class/usbd_uac2.h>
1616
#include <zephyr/drivers/i2s.h>
1717
#include <zephyr/logging/log.h>
18+
#include <zephyr/linker/devicetree_regions.h>
1819

1920
LOG_MODULE_REGISTER(uac2_sample, LOG_LEVEL_INF);
2021

@@ -31,16 +32,22 @@ LOG_MODULE_REGISTER(uac2_sample, LOG_LEVEL_INF);
3132
#define BLOCK_SIZE (SAMPLES_PER_SOF * BYTES_PER_SLOT)
3233
#define MAX_BLOCK_SIZE ((SAMPLES_PER_SOF + 1) * BYTES_PER_SLOT)
3334

35+
#define I2S_MEMORY_SECTION \
36+
COND_CODE_1(DT_NODE_HAS_PROP(DT_NODELABEL(i2s_rxtx), memory_regions), \
37+
(Z_GENERIC_SECTION(LINKER_DT_NODE_REGION_NAME_TOKEN( \
38+
DT_PHANDLE(DT_NODELABEL(i2s_rxtx), memory_regions)))), \
39+
(__noinit))
40+
3441
/* Absolute minimum is 5 TX buffers (1 actively consumed by I2S, 2nd queued as
3542
* next buffer, 3rd acquired by USB stack to receive data to, and 2 to handle
3643
* SOF/I2S offset errors), but add 2 additional buffers to prevent out of memory
3744
* errors when USB host decides to perform rapid terminal enable/disable cycles.
3845
*/
3946
#define I2S_BLOCKS 7
40-
K_MEM_SLAB_DEFINE_STATIC(i2s_tx_slab, ROUND_UP(MAX_BLOCK_SIZE, UDC_BUF_GRANULARITY),
41-
I2S_BLOCKS, UDC_BUF_ALIGN);
42-
K_MEM_SLAB_DEFINE_STATIC(i2s_rx_slab, ROUND_UP(MAX_BLOCK_SIZE, UDC_BUF_GRANULARITY),
43-
I2S_BLOCKS, UDC_BUF_ALIGN);
47+
K_MEM_SLAB_DEFINE_IN_SECT_STATIC(i2s_tx_slab, I2S_MEMORY_SECTION,
48+
ROUND_UP(MAX_BLOCK_SIZE, UDC_BUF_GRANULARITY), I2S_BLOCKS, UDC_BUF_ALIGN);
49+
K_MEM_SLAB_DEFINE_IN_SECT_STATIC(i2s_rx_slab, I2S_MEMORY_SECTION,
50+
ROUND_UP(MAX_BLOCK_SIZE, UDC_BUF_GRANULARITY), I2S_BLOCKS, UDC_BUF_ALIGN);
4451

4552
struct usb_i2s_ctx {
4653
const struct device *i2s_dev;

0 commit comments

Comments
 (0)