Page 1 of 1

Using two I2C buses in parallel fails

Posted: Sat Sep 21, 2019 2:20 pm
by rubenswerk
Hello,

I'd like to use two I2C buses on a STM32F767 Nucleo board.
I took the ChibiOS 19.1.0 demo RT-STM32F767ZI-NUCLEO144 and added some minor changes.

I activate the following in halconf/mcuconf:
HAL_USE_I2C TRUE
STM32_I2C_USE_I2C1 TRUE
STM32_I2C_USE_I2C2 TRUE

In my main function, I added:
i2cStart(&I2CD1, &i2cconfig);
i2cStart(&I2CD2, &i2cconfig);

It works if I call only one of these i2cStart functions, no matter if I call it for I2CD1 or I2CD2.
But the program gets stuck if I call both of them.

Are there any knows restrictions when using several I2C peripherals?

Thanks!

Re: Using two I2C buses in parallel fails

Posted: Sat Sep 21, 2019 2:23 pm
by Giovanni
Hi,

Have you checked DMA channels settings? it is possible there is a conflict.

Make sure to enable assertions and state checker too.

Giovanni

Re: Using two I2C buses in parallel fails

Posted: Sat Sep 21, 2019 8:35 pm
by rubenswerk
Thank you Giovanni for your quick response.

Yes you're right, I2C1_TX and I2C2_TX share the same DMA. It works if I use I2C3 instead of I2C2. Looks like you cannot use more than two I2C in DMA mode (which seems to be standard ChibiOS mode), otherwise there is a conflict.

Is it correct that this restriction is given by the microcontroller design and the user cannot change anything about the DMA assignment?

Things become even worse if I start to use SPI and USART.

There is a define STM32_I2C_USE_DMA. Is it meant to be configured by end user, may I disable it?

Have a nice evening.

Re: Using two I2C buses in parallel fails

Posted: Sat Sep 21, 2019 8:43 pm
by Giovanni
Hi,

DMAs can be reassigned in a limited way, older devices cannot reassign at all. You should look into the DMA section of the RM, there is a table with all possible assignment, you need to base your design on allowed combinations.

More recent STM32s have a DMAMUX that allow to assign any channel to any peripheral, very convenient. On those devices ChibiOS HAL assigns channels dynamically.

On older devices it is possible to "share" DMAs: you need to i2cStart(), do operation, i2cStop(), the two I2Cs must never be started at same time. Channels are "taken" and "released" in i2cStart() and i2cStop(). This allows some more flexibility at cost of extra calls.

Giovanni

Re: Using two I2C buses in parallel fails

Posted: Sat Sep 21, 2019 9:31 pm
by rubenswerk
Good hint.
On the STM32F767 there's for most functions at least one alternative option to map the DMA, that's great.
Using start() and stop() might be an option, but in my case I want to optimize I2C throughput and therefore the I2Cs should work in parallel.
Thanks!

Re: Using two I2C buses in parallel fails

Posted: Mon Sep 23, 2019 6:46 am
by rew
rubenswerk wrote:Good hint.
but in my case I want to optimize I2C throughput and therefore the I2Cs should work in parallel.
In that case... don't use I2C... :)
I2C is very slow and can only be sped up in a limited way. Going to SPI will allow you to go 20x faster without any trouble.