STM32 I2Cv1 driver with interrupts

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

Moderators: RoccoMarco, barthess

king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

STM32 I2Cv1 driver with interrupts

Postby king2 » Tue Mar 28, 2017 1:41 am

Hi, @Giovanni!

I met a problem in my design with STM32F437, I did not looked on DMA streams allocation, so I have now all my alwayw-needed peripherals connected to same DMA channel (UART4, I2S2 and I2C3). I2S2 used to make some type of PWM on external DAC (to increase its accuracy and linearity), so it cannot be changed to any mode except DMA. In UART4 I can use serial driver, so it is not a big problem.

But I2C3 is a problem for me, because I cannot change pcb routing and I cannot stop I2S to periodically use I2C.

I see that I2Cv2 driver can be used without DMA, but I2Cv1 have no such possibility.
I2Cv1 driver was modified such way two years ago by @Thargon (viewtopic.php?t=2604), but it still not included in main repo.

Is there any reasons not to do this?
Sure I can just patch and use it, but may be I have missed some problems that can be seen by professionals only?

And another question. I was met such situations before, I met it now, and this will happen in future. I'm far away of trying to ask to add anything to well-tested main repo (community repo exists for this reason, despite of good quality drivers inside).
Sure I can patch sources in ChibiOS path, but I know that this way is wrong and is a reason for a big pain when updating.

For example, now I can make patched version of I2C2v1 driver (in fact, I will patch it manually to understand how it will work), but will it enough to just place it into different path and correct include paths?

Is there a some type of "best practice" in ChibiOS when I need to 1) add my own driver or 2) replace existing?

Thank you in advance!

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: STM32 I2Cv1 driver with interrupts

Postby Giovanni » Tue Mar 28, 2017 12:59 pm

Hi,

The I2Cv1 driver has always been problematic because "limitations" of the old STM32 I2C hardware, this is why I prefer to not touch it and this is why that code has not been integrated. If you want to try that code and then test it then it could be added to the community repository (this is the best practice for code I can't include in the mainline for whatever reason).

Note that I added a SW I2C implementation to the trunk repository, it is not yet tested, you could give it a try if you want. This driver should be able to run on any platform.

Giovanni

king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: STM32 I2Cv1 driver with interrupts

Postby king2 » Tue Mar 28, 2017 1:06 pm

I have applied the patch and it works as expected (with little cosmetic modifications due to new version of ChibiOS).
Driver works like I2Cv2 version, with DMA or IRQ depending on same STM32_I2C_USE_DMA define.

I do not know how to add something to community right way, so I will attach patched driver here.
Can you add it by yourlself?

If not, please tell me how to add it, because I think its presence can be helpful to other people.
Thanks!
Attachments
i2c_lld_dma_or_irq.zip
(9.57 KiB) Downloaded 212 times

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: STM32 I2Cv1 driver with interrupts

Postby Giovanni » Tue Mar 28, 2017 1:35 pm

Hi,

The community repository is handled by barthess, contact him via PM in case he does not see this post.

Giovanni

User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Location: Minsk, Belarus
Been thanked: 7 times

Re: STM32 I2Cv1 driver with interrupts

Postby barthess » Mon Apr 03, 2017 7:25 pm

Hello.
Sorry for late response. You can submit your driver using pull request on github. Driver must be added with new name to avoid conflicts with existing ones (something like i2c_irq).


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 15 guests