Skip to content

Commit

Permalink
drivers: i2s : enable rx path and correct TRIGGER_DRAIN
Browse files Browse the repository at this point in the history
In i2s_stm32_isr, remove the errors from SR register
   i2s_stm32_configure, enable the rx path for H7 I2S compatible IP

Correction of the handling of Tx audio samples via DMA

Signed-off-by: Franck Thebault <franck.thebault@st.com>
Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <marwa.ibenelhadjmessaoud-ext@st.com>
  • Loading branch information
francktheb authored and marwaiehm-st committed May 19, 2024
1 parent 92e9c31 commit 7c63853
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 13 deletions.
75 changes: 62 additions & 13 deletions drivers/i2s/i2s_ll_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ static int i2s_stm32_configure(const struct device *dev, enum i2s_dir dir,
int ret;

if (dir == I2S_DIR_RX) {
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_i2s)
return -ENOSYS;
#endif
stream = &dev_data->rx;
} else if (dir == I2S_DIR_TX) {
stream = &dev_data->tx;
Expand Down Expand Up @@ -349,9 +346,18 @@ static int i2s_stm32_trigger(const struct device *dev, enum i2s_dir dir,
LOG_ERR("DRAIN trigger: invalid state");
return -EIO;
}
stream->stream_disable(stream, dev);
stream->queue_drop(stream);
stream->state = I2S_STATE_READY;
if (dir == I2S_DIR_TX) {
if (stream->state == I2S_STATE_RUNNING) {

Check warning on line 350 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SUSPECT_CODE_INDENT

drivers/i2s/i2s_ll_stm32.c:350 suspect code indent for conditional statements (24, 33)
stream->state = I2S_STATE_STOPPING;
/* indicate that the transition to I2S_STATE_STOPPING*/
/* is triggered by DRAIN command */
stream->sample_tx_stop_drain = true;

Check failure on line 354 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

drivers/i2s/i2s_ll_stm32.c:354 trailing whitespace
} else {

Check warning on line 355 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TABSTOP

drivers/i2s/i2s_ll_stm32.c:355 Statements should start on a tabstop
stream->stream_disable(stream, dev);

Check failure on line 356 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2s/i2s_ll_stm32.c:356 code indent should use tabs where possible

Check warning on line 356 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

drivers/i2s/i2s_ll_stm32.c:356 please, no space before tabs
stream->queue_drop(stream);

Check failure on line 357 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2s/i2s_ll_stm32.c:357 code indent should use tabs where possible

Check warning on line 357 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

drivers/i2s/i2s_ll_stm32.c:357 please, no space before tabs
stream->state = I2S_STATE_READY;

Check failure on line 358 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2s/i2s_ll_stm32.c:358 code indent should use tabs where possible

Check warning on line 358 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

drivers/i2s/i2s_ll_stm32.c:358 please, no space before tabs
}

Check failure on line 359 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

drivers/i2s/i2s_ll_stm32.c:359 code indent should use tabs where possible

Check warning on line 359 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

drivers/i2s/i2s_ll_stm32.c:359 please, no space before tabs
}

Check warning on line 360 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TABSTOP

drivers/i2s/i2s_ll_stm32.c:360 Statements should start on a tabstop
irq_unlock(key);
break;

Expand Down Expand Up @@ -528,6 +534,14 @@ static void dma_rx_callback(const struct device *dma_dev, void *arg,
}

mblk_tmp = stream->mem_block;

Check failure on line 537 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

drivers/i2s/i2s_ll_stm32.c:537 trailing whitespace
if ((stream->state == I2S_STATE_STOPPING) && (status == DMA_STATUS_COMPLETE)) {
if (stream->sample_tx_stop_drain == false) {
/* in case of STOP command, just stop the transmission*/
/*at the current. The transmission can be resumed */
goto rx_handle_block;
}
}

/* Prepare to receive the next data block */
ret = k_mem_slab_alloc(stream->cfg.mem_slab, &stream->mem_block,
Expand All @@ -551,6 +565,7 @@ static void dma_rx_callback(const struct device *dma_dev, void *arg,
goto rx_disable;
}

rx_handle_block:
/* Assure cache coherency after DMA write operation */
sys_cache_data_invd_range(mblk_tmp, stream->cfg.block_size);

Expand Down Expand Up @@ -596,12 +611,35 @@ static void dma_tx_callback(const struct device *dma_dev, void *arg,
/* All block data sent */
k_mem_slab_free(stream->cfg.mem_slab, stream->mem_block);
stream->mem_block = NULL;

Check failure on line 614 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

drivers/i2s/i2s_ll_stm32.c:614 trailing whitespace
/*mark the tx sample completion */
stream->sample_tx_block_dma_sent++;

/* Stop transmission if there was an error */
if (stream->state == I2S_STATE_ERROR) {
LOG_ERR("TX error detected");
goto tx_disable;
}

Check failure on line 623 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

drivers/i2s/i2s_ll_stm32.c:623 trailing whitespace
/* check if the tx stop command can be handled */
/*if True, the tx stop command can be handled */
if ((stream->state == I2S_STATE_STOPPING) && (status == DMA_STATUS_COMPLETE)) {
/* check if all tx samples have been completely handled */
/*As stated in zephyr i2s specification, in case of DRAIN command */
/* Send all data in the transmit queue and stop the transmission. */
if (stream->sample_tx_block_sent == stream->sample_tx_block_dma_sent) {

Check failure on line 630 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

drivers/i2s/i2s_ll_stm32.c:630 trailing whitespace
stream->queue_drop(stream);
stream->state = I2S_STATE_READY;
goto tx_disable;
} else {
if (stream->sample_tx_stop_drain == false) {
/* in case of STOP command, just stop the transmission*/
/*at the current. The transmission can be resumed */
stream->state = I2S_STATE_READY;
goto tx_disable;
}
}
}

Check warning on line 642 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

drivers/i2s/i2s_ll_stm32.c:642 please, no spaces at the start of a line

/* Stop transmission if we were requested */
if (stream->last_block) {
Expand Down Expand Up @@ -652,11 +690,6 @@ static uint32_t i2s_stm32_irq_udr_count;
static void i2s_stm32_isr(const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = dev->config;
struct i2s_stm32_data *const dev_data = dev->data;
struct stream *stream = &dev_data->rx;

LOG_ERR("%s: err=%d", __func__, (int)LL_I2S_ReadReg(cfg->i2s, SR));
stream->state = I2S_STATE_ERROR;

/* OVR error must be explicitly cleared */
if (LL_I2S_IsActiveFlag_OVR(cfg->i2s)) {
Expand All @@ -677,8 +710,14 @@ static int i2s_stm32_initialize(const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = dev->config;
struct i2s_stm32_data *const dev_data = dev->data;
struct stream *stream = &dev_data->tx;
int ret, i;

/* initialize the variables used to handle the TX samples */
stream->sample_tx_block_sent = 0;
stream->sample_tx_block_dma_sent = 0;
stream->sample_tx_stop_drain = false;

Check failure on line 720 in drivers/i2s/i2s_ll_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

drivers/i2s/i2s_ll_stm32.c:720 trailing whitespace
/* Enable I2S clock propagation */
ret = i2s_stm32_enable_clock(dev);
if (ret < 0) {
Expand Down Expand Up @@ -846,7 +885,12 @@ static void rx_stream_disable(struct stream *stream, const struct device *dev)
k_mem_slab_free(stream->cfg.mem_slab, stream->mem_block);
stream->mem_block = NULL;
}

/*Check if the Busy Bit of I2S is still active before disabling IP*/
#ifdef LL_SPI_SR_TXC
while (LL_SPI_IsActiveFlag_TXC(cfg->i2s)) {}
#else
while (LL_SPI_IsActiveFlag_BSY(cfg->i2s)) {}
#endif
LL_I2S_Disable(cfg->i2s);

active_dma_rx_channel[stream->dma_channel] = NULL;
Expand All @@ -870,7 +914,12 @@ static void tx_stream_disable(struct stream *stream, const struct device *dev)
k_mem_slab_free(stream->cfg.mem_slab, stream->mem_block);
stream->mem_block = NULL;
}

/*Check if the Busy Bit of I2S is still active before disabling IP*/
#ifdef LL_SPI_SR_TXC
while (LL_SPI_IsActiveFlag_TXC(cfg->i2s)) {}
#else
while (LL_SPI_IsActiveFlag_BSY(cfg->i2s)) {}
#endif
LL_I2S_Disable(cfg->i2s);

active_dma_tx_channel[stream->dma_channel] = NULL;
Expand Down
3 changes: 3 additions & 0 deletions drivers/i2s/i2s_ll_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct stream {
bool src_addr_increment;
bool dst_addr_increment;
uint8_t fifo_threshold;
uint8_t sample_tx_block_sent;
uint8_t sample_tx_block_dma_sent;
bool sample_tx_stop_drain;

struct i2s_config cfg;
struct ring_buf mem_block_queue;
Expand Down

0 comments on commit 7c63853

Please sign in to comment.