2023-09-17 11:45 PM
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
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
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
2023-09-18 03:45 AM - edited 2023-09-18 03:59 AM
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
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.
2023-09-18 05:41 AM
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.
2023-09-18 04:26 PM
Hi Foued,
I tried you suggested config with the same result. My config for the DMA is
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.
2023-09-18 04:28 PM
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).
2023-09-18 04:47 PM
What's the address of the "data" buffer?
2023-09-18 09:50 PM - edited 2023-09-19 10:55 PM
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
2023-09-19 06:13 AM - edited 2023-09-19 06:19 AM
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