cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 I2S HAL bugs

Klang.Martin
Associate III
Posted on June 22, 2018 at 15:58

There seem to be some bugs in the H7 HAL library.

Firstly HAL_I2S_Receive_IT() causes a HardFault because, as far as I can see:

1) OVR flag is not cleared

2) in `HAL_I2S_IRQHandler()` there is an attempt to call ` hi2s->TxISR(hi2s);` when 

TxISR is set to NULL.

void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s)

{

uint32_t itsource = hi2s->Instance->IER;

uint32_t i2ssr = hi2s->Instance->SR;

/* I2S in mode Receiver ------------------------------------------------*/

if(((i2ssr & I2S_FLAG_OVR) != I2S_FLAG_OVR) &&

((i2ssr & I2S_FLAG_RXNE) == I2S_FLAG_RXNE) && ((itsource & I2S_IT_RXNE) !=

RESET))

{

hi2s->RxISR(hi2s); // not called because OVR not cleared

return;

}

/* I2S in mode Transmitter ---------------------------------------------*/

if(((i2ssr & I2S_FLAG_TXE) == I2S_FLAG_TXE) && ((itsource & I2S_IT_RXNE) != RE

SET))

{

hi2s->TxISR(hi2s); // HardFaults when TxISR == NULL

return;

}

Secondly in the polling function, HAL_I2S_Receive(), the destination data pointer is incremented 4x too fast.

In 32-bit and 24-bit data transfer mode, `hi2s->RxXferCount` is set to twice the Size, which is correct since Size is the number of half words to transfer.

Then, in the data transfer loop, the destination pointer is incremented like this:

hi2s->pRxBuffPtr += sizeof(uint32_t);

Since `hi2s->pRxBuffPtr` is of type `uint16_t*` this increments the pointer by 8 bytes with each half word transfer.

Note that the loop is still counting half-words, with `hi2s->RxXferCount--;`

So unless you've allocated an extra 4x buffer space then not only will you get the wrong results, you will also overflow badly and quite likely HardFault again.

I've not had any luck with HAL_I2S_Receive_DMA() so far (using RAM_D1), will report back when I've investigated some more.

This is using STM32CubeMX Version 4.26.0 and STM32Cube_FW_H7_V1.2.0 - latest versions.

#i2s #hal #stm32h7
11 REPLIES 11
TChat
Associate II

Yes I am already allocating the buffer to D2 (0x30000000), which I think should be right. (and I haven't enabled the cache yet)

Out of frustration I hacked my board to give SAI a try and indeed there's life... Too bad I can't really use it.

Thanks for your help anyway!

Yes, we measure our products in time to working with the suppliers we have. 

STM32 has been an absolute nightmare compared to ESP32. Just line after line doesn't work as expected and we need to go low level into a HAL libraries to figure out what's actually going. Really disappointed in our first STM32 project.

I've been working on a trivial I2S loopback, only to find out DMA doesn't even work property on the H7 and the first solution from ST is to "Disable the entire DCACHE".