diff --git a/drivers/i2s/i2s_nrf_tdm.c b/drivers/i2s/i2s_nrf_tdm.c index 07c561b77503..2e9e94c07023 100644 --- a/drivers/i2s/i2s_nrf_tdm.c +++ b/drivers/i2s/i2s_nrf_tdm.c @@ -32,6 +32,11 @@ LOG_MODULE_REGISTER(tdm_nrf, CONFIG_I2S_LOG_LEVEL); */ #define NRFX_TDM_STATUS_TRANSFER_STOPPED BIT(1) +/* Due to hardware limitations, the TDM peripheral requires the rx/tx size + * to be greater than 8 bytes. + */ +#define NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED 8 + /* Maximum clock divider value. Corresponds to CKDIV2. */ #define NRFX_TDM_MAX_SCK_DIV_VALUE TDM_CONFIG_SCK_DIV_SCKDIV_Max #define NRFX_TDM_MAX_MCK_DIV_VALUE TDM_CONFIG_MCK_DIV_DIV_Max @@ -475,9 +480,11 @@ static int tdm_nrf_configure(const struct device *dev, enum i2s_dir dir, __ASSERT_NO_MSG(tdm_cfg->mem_slab != NULL && tdm_cfg->block_size != 0); - if ((tdm_cfg->block_size % sizeof(uint32_t)) != 0) { - LOG_ERR("This device can transfer only full 32-bit words"); - return -EINVAL; + if ((tdm_cfg->block_size % sizeof(uint32_t)) != 0 || + tdm_cfg->block_size <= NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED) { + LOG_ERR("This device can only transmit full 32-bit words greater than %u bytes.", + NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED); + return -EIO; } switch (tdm_cfg->word_size) { @@ -673,11 +680,18 @@ static int tdm_nrf_write(const struct device *dev, void *mem_block, size_t size) return -EIO; } - if (size > drv_data->tx.cfg.block_size || size < sizeof(uint32_t)) { + if (size > drv_data->tx.cfg.block_size) { LOG_ERR("This device can only write blocks up to %u bytes", drv_data->tx.cfg.block_size); return -EIO; } + + if ((size % sizeof(uint32_t)) != 0 || size <= NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED) { + LOG_ERR("This device can only write full 32-bit words greater than %u bytes.", + NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED); + return -EIO; + } + ret = dmm_buffer_out_prepare(drv_cfg->mem_reg, buf.mem_block, buf.size, (void **)&buf.dmm_buf); ret = k_msgq_put(&drv_data->tx_queue, &buf, SYS_TIMEOUT_MS(drv_data->tx.cfg.timeout));