Using two I2C buses in parallel fails

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
rubenswerk
Posts: 104
Joined: Wed Feb 22, 2012 11:39 am

Using two I2C buses in parallel fails

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Using two I2C buses in parallel fails

Post 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
rubenswerk
Posts: 104
Joined: Wed Feb 22, 2012 11:39 am

Re: Using two I2C buses in parallel fails

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Using two I2C buses in parallel fails

Post 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
rubenswerk
Posts: 104
Joined: Wed Feb 22, 2012 11:39 am

Re: Using two I2C buses in parallel fails

Post 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!
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: Using two I2C buses in parallel fails

Post 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.
Post Reply