cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any max bytes limitation on function HAL_I2C_Mem_Read_DMA() using STM32F746IG and FW1.17.0 ?

ALORE.1
Associate II

I´m trying read bytes from Adafruit I2C Non-Volatile FRAM Breakout module (ic MB85RC256V from FUJITSU) in my STM32F746IG custom board.

Using FW 1.16.2, I can read 512 bytes using HAL_I2C_Mem_Read_DMA.

Using FW 1.17.0, The I2C stops (clock pin goes down forever) after first attempt using this same command. The problem disappears in FW 1.17.0 if I read only 256 bytes. (code below)

Is it a bug in FW 1.17.0 or only a limitation in library ?

I attached a simple project to show this behavior.

int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MPU Configuration--------------------------------------------------------*/
  MPU_Config();
 
  /* Enable I-Cache---------------------------------------------------------*/
  SCB_EnableICache();
 
  /* Enable D-Cache---------------------------------------------------------*/
  SCB_EnableDCache();
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  memset(_Buffer, 0, 512);
	  HAL_I2C_Mem_Read_DMA(&hi2c1, 0xAE, 0x000, I2C_MEMADD_SIZE_16BIT, _Buffer, 256);
	  HAL_Delay(1000);
 
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

8 REPLIES 8
TDK
Guru

The limit is 255 bytes.

https://github.com/STMicroelectronics/STM32CubeF7/blob/f8bda023e34ce9935cb4efb9d1c299860137b6f3/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_i2c.c#L2991

Monitor the return value of HAL_* functions to determine if they succeed or not. Or step through.

> Is it a bug in FW 1.17.0 or only a limitation in library ?

The limitation is in hardware. See I2C_CR2 in the reference manual.

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

Not a limitation of the library. Documentation does not specify a size limit.

Try to read 510 bytes (255+255) and 511 (255+256). Will it work?

Hi TDK,

I understand the hardware limitation on the I2C_CR2 register and the library's limitation on the hi2c->XferSize.

However, hi2c->XferCount is not limited in the library (same link above but line 2986) being used in the I2C_Mem_ISR_DMA interrupt handler.

In version 1.16.2, the interrupt handler reconfigured the I2C to re-read the missing bytes (in the case of more than 255) using hi2c->XferCount and I can read 512 byte in one command.

So this behavior no longer exists or is it a bug in the library in 1.17.0?

I need to know whether or not I should modify my firmware to be compatible with new versions.

Thanks

Hi pavel,

I also found no limitation in the documentation.

About the recommendation:

1) read 510 bytes: (first read 255 and after more 255):

OK. Success. I can read as many bytes as I want using several 255 bytes read command in sequence.

2) read 511 bytes: (first read 255 and after more 256):

OK: I can read 511 bytes. But If I try read more than 256 bytes in same command, the clock goes low forever and the I2C Stops.

I'm not an expert on HAL Driver but it seems that after reading more than 256 bytes in a command, the interrupt handler is not sending the STOP bit correctly.

this behavior occurs only in version 1.17.0 for F7. In version 1.16.2 it works fine.

I also tested my code for HAL 1.10 for H7 family with success.

Similar theme

https://community.st.com/s/question/0D53W00001wIUJNSA4/what-is-the-i2c-transaction-size-for-the-stm32-hali2cmemread-function-i-know-for-arduino-the-i2c-transaction-size-is-limited-to-32-bytes-but-i-was-unable-to-find-similar-information-about-stm32s-i2c-im-currently-using-the-stm32l010rb-chip

Watch what other slaves expect. Some of these devices are pretty dumb, so seeing long sustained / continuous bursts of data might be miss interpreted.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello,

in my case I am using an I2C FRAM (https://www.fujitsu.com/uk/Images/MB85RC256V-20171207.pdf). This slave has no page boundary.

Furthermore, I have a known pattern written and I can read everything correctly. I believe that the problem is with the master that does not release the clock after the communication when I perform readings of more bytes.

look osciloscope images below (I´m sorry .. I dont have a logic analizer)

OK (Blue is Clock .. it goes high after communication)

0693W00000WIZtUQAX.jpg 

FAIL (Blue is Clock .. it goes low forever and I2C stops)

0693W00000WIZuNQAX.jpg 

I only change the bytes to read using HAL_I2C_Mem_Read_DMA().

@ALORE.1​ Then you've likely found a bug in the new version (aka regression). You can report it here or on github.

following your suggestion and to keep track of the solution here, follow the github link

https://github.com/STMicroelectronics/STM32CubeF7/issues/77