cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WBA65 HAL_SAI_Transmit_DMA not transmitting all data

JFisher-Legato
Visitor

Hello,

I am having trouble with a call to HAL_SAI_Transmit_DMA() to transfer data to our audio codec.

  1. Buffer stored in RAM: unsigned char sweep_tone[80000]. For the sake of this demo, I've filled the buffer with 16-bit samples counting from 0 - 39999.
  2. The SAI interface is configured for 16KHz, 16-bit samples, mono (i.e., data is the same on both channels)
  3. When I call HAL_SAI_Transmit_DMA(&hsai_BlockB1, pBuffer, 500); the first 500 samples are continuously transferred, as expected. I confirmed this by monitoring the I2S signal with a Saleae.
  4. However, when I call HAL_SAI_Transmit_DMA(&hsai_BlockB1, pBuffer, 40000); the I2S only shows the values 0 to 7231 being clocked out.

The number 7231 is interesting to me. The size argument to HAL_SAI_Transmit_DMA() is 16 bits, and UINT16_MAX =65535. If there's a conversion someplace in the HAL calls that converts 40000 samples to 80000 bytes, this would overflow to 14465 bytes, which is 7232.5 samples, truncated to 7232, which corresponds to a max value of 7231 being clocked out.

However, I've not found where this overflow could occur, if this is indeed what is going on!

Any ideas?

Thank you,
Jonathan

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

While debugging, step through the code until the write to the DMA's NDTR register. Should be apparent where the overflow occurs.

Ensure your DMA is set to transfer half-words rather than bytes, as 65535 is the max number of items that can be sent through DMA.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Super User

While debugging, step through the code until the write to the DMA's NDTR register. Should be apparent where the overflow occurs.

Ensure your DMA is set to transfer half-words rather than bytes, as 65535 is the max number of items that can be sent through DMA.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for the response!

On the WBA65, at least, it appears to be the BR1 register that you're referring to, and the BNDT field, which is 16 bits. Interestingly, this is in bytes, not in blocks/item sizes: "BNDT[15:0] is programmed in number of bytes, maximum source block size is 64 Kbytes -1".

So that answers that!