cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_Mem_Read_DMA not working on STM32H723

Simon
Associate II

Hi all,

I have been trying to get I2C DMA working on an STM32H723 for a few days now. It works perfectly when using blocking mode (using HAL_I2C_Mem_Read), but when I try to use HAL_I2C_Mem_Read_DMA it returns success, but doesn't actually do the read part of the transaction. Also using HAL_I2C_Mem_Write_DMA works fine.

Looking at a logic analyzer when I execute

retval = HAL_I2C_Mem_Read(&hi2c1, 0x60, 0x2F, I2C_MEMADD_SIZE_8BIT, data, size, 1000);

I see this

Simon_0-1695019170931.png

But if I use the DMA version

retval = HAL_I2C_Mem_Read_DMA(&hi2c1, 0x60, 0x2F, I2C_MEMADD_SIZE_8BIT, data, size);

I get this

Simon_1-1695019340613.png

This call is failing to issue the restart and do the read. It also leaves SCL low which should not happen.

Is there something I am doing wrong or is the HAL_I2C_Mem_Read_DMA function broken?

Any help would be much appreciated.

Cheers
Simon

7 REPLIES 7
Foued_KH
ST Employee

Hello  ,

Could you please share more information about your configuration?
Try with this configuration and let me know if this is helpful or not :

Foued_KH_0-1695034714303.png

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

TDK
Guru

SCL staying low suggests it ran into an error. Perhaps the data is in a non-DMA accessible location. Debug, pause the program and examine relevant registers and I2C handle state information.

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

Hi Foued,

I tried you suggested config with the same result. My config for the DMA is

Simon_0-1695079318050.png

At the moment I am only using I2C1, but eventually need to use I2C2/3. I am using FreeRTOS and the code to read the I2C in a thread of its own. I will try to create a minimal project that only does the I2C stuff (no RTOS or anything else) and report back.

Hi TDK,

All of the buffers used for the DMA are declared as global variable, so I don't think that is the problem. When I pause after the DMA call the return value from HAL_I2C_Mem_Read_DMA is 0 (HAL_OK).

What's the address of the "data" buffer?

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

What TDK already said twice: make sure that I2C buffers are in a DMA accessible SRAM area, so no DTCM.
Check RM0468, page 106.

With all the domains, busses, memories in the H72xx / H73xx family, it makes sense to take care of that in the linker file, then place some variables by declaring them with attribute / section.

But that's only needed if you need all of the internal RAM, if not, just place heap and stack in DTCM, and use "AXI SRAM" as "standard working RAM" - which might be taken care of in Cube's linker file.
Then only beware the few D3 peripherals (e.g., SAI4).

BTW, somehow irritating that "D3 [edited] domain" contains all the stuff numbered "4": AHB4, APB4, SAI4...

PS: with all that said, this might not be your problem... :D

bbee
Associate III

Try to set hi2c->XferSize = 0 in HAL_I2C_Mem_Write_IT and HAL_I2C_Mem_Read_IT in block 'Prepare transfer parameters' in stm32h7xx_hal_i2c.c
IMHO this is a bug and should be fixed, see See 571705