Page 15 of 35
Re: I2C implementation for STM32
Posted: Mon Sep 12, 2011 12:32 pm
by Badger
I'm building a C++ class around the i2c drivers (i2cDevice), and I need some way of accessing the data stored within the classes from the static i2c callback functions. What complicates matters is that I am using several sub-classes of my main i2c class, so I can't just treat everything as an i2cDevice, instead I added pointers to internal structures (one of which is a thread pointer, which is sometimes NULL). I guess I can get around the const problem by adding a const pointer to a non const structure.
Looking back now, I think perhaps my main issue before was that I was extending the slave config structure in the wrong place, so the memory was being allocated in the class header file before it was extended, and I ended up with a horrible overflow

moving the hook definition into chconf.h sorted that one out

.
Re: I2C implementation for STM32
Posted: Mon Sep 12, 2011 2:37 pm
by barthess
Badger,
If I right understand, I must set const qualifier back to satisfy both ChibiOS traditions and your desires?
Re: I2C implementation for STM32
Posted: Mon Sep 12, 2011 3:16 pm
by Badger
barthess wrote:If I right understand, I must set const qualifier back to satisfy both ChibiOS traditions and your desires?
Yes, I think that Giovanni's suggestion of having a const pointer to a non-const struct should do the trick
Re: I2C implementation for STM32
Posted: Mon Sep 12, 2011 4:53 pm
by barthess
Done at rev. 3310
Re: I2C implementation for STM32
Posted: Wed Sep 28, 2011 1:01 am
by drgnz
Howdy? What's the status of the I2C driver? Is it working? Is there an example?
Re: I2C implementation for STM32
Posted: Wed Sep 28, 2011 7:58 am
by barthess
Driver successfully works on my stm32f103. Examples in .\testhal\STM32F1xx\I2C
Re: I2C implementation for STM32
Posted: Sat Oct 01, 2011 9:30 pm
by barthess
Hi Giovanni,
For a moment driver uses hardware timers or software wait loops to capture start or stop conditions on the bus. I have try to use trick with EXTI driver like in
viewtopic.php?f=3&t=165 topic. It does not work because port
must be configured in input mode (I2C bus ports must be configured in open drain mode). So, this software hack needs hardware hack -- connecting SDA line to some port of MCU configured in input mode. Now I am developing new board to replace my Olimex demo board and easily can realize that trick. Is it too dirty to be part of the ChibiOS?
Second thing, I have found very abstract software realization of I2C but not tested it.
http://www.levap.ru/2010/03/rabotaem-s- ... i2c-smbus/Is it possible to use it in ChibiOS due to licensing limitations?
Re: I2C implementation for STM32
Posted: Sat Oct 01, 2011 9:42 pm
by Giovanni
Hi,
It could be added as an option, the problem is that the driver is already very complicated (because the HW limitations).
About a software implementation, the author does not specify a license, I guess it could be used but probably a clean sheet implementation with timings done using a GPT driver would be better.
The other problem with a software implementation is that we would have to make the API synchronous (and may be, leave the asynchronous callbacks optional). A software driver would only implement the synchronous part. Currently it is the other way, the default is asynchronous with optional synchronous calls.
Giovanni
Re: I2C implementation for STM32
Posted: Sat Oct 01, 2011 9:47 pm
by DrunkenDonkey
Code is very pretty I must admit, lacks the ability to send/received more than a single byte, but that can easily be added. It was a long time since I learned russian at school, but there is no restriction of any kind in the message either, so can freely be used. (oh, and long live synchronous communication and threads

)
Re: I2C implementation for STM32
Posted: Sat Oct 01, 2011 10:00 pm
by barthess
One more way to simplify driver is using DMA. But it is not always possible, my current hardware has no free DMA requests for I2C at all. On STM32F1x they are hardwired (sic!) to peripherals and can not be reassigned.