0

I am trying to create a very simple i2c test program to run on my STM32L0 (discovery kit). I have modified the miniblink program in libopencm3-examples/examples/stm32/l0/stm32l0538-disco.

But if I just include the i2c header file:

#include <libopencm3/stm32/i2c.h>

And run make I get the error:

 ../../../../../libopencm3//include/libopencm3/stm32/i2c.h:36:9: error: #error "stm32 family not defined."

Upon investigating this file it appears that there are rules defined for each of the other models but not for the l0, why is this? Does libopencm3 not support i2c on the STM32L0 series?

#if defined(STM32F0)
#       include <libopencm3/stm32/f0/i2c.h>
#elif defined(STM32F1)
#       include <libopencm3/stm32/f1/i2c.h>
#elif defined(STM32F2)
#       include <libopencm3/stm32/f2/i2c.h>
#elif defined(STM32F3)
#       include <libopencm3/stm32/f3/i2c.h>
#elif defined(STM32F4)
#       include <libopencm3/stm32/f4/i2c.h>
#elif defined(STM32L1)
#       include <libopencm3/stm32/l1/i2c.h>
#else
#       error "stm32 family not defined."
#endif

I had a look at libopencm3/stm32/l1/i2c.h and all it seems to do is import the common i2c library anyway. Is there any way I can just use the i2c library for the l1?

Thanks

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
k212
  • 88
  • 7
  • Perhaps it has not been implemented yet? – leppie Jun 29 '15 at 06:22
  • This is what I suspect... but I wasn't sure – k212 Jun 29 '15 at 08:06
  • The docs seem to imply that it has been though... http://libopencm3.github.io/docs/latest/stm32l0/html/group__i2c__defines.html – k212 Jun 29 '15 at 08:07
  • Seems you need to include `i2c_common_all.h`, but looking at timestamps in the headers, it seems `i2c.h` is newer interface. Perhaps this has not been ported? – leppie Jun 29 '15 at 08:22
  • I would but I looked at it and I saw the line `#warning "i2c_common_all.h should not be included explicitly, only via i2c.h"`, so I don't think I can do that – k212 Jun 29 '15 at 08:32
  • It does seem that someone forgot to implement something. You could probably just create it yourself. OR report an issue, or submit a PR :D – leppie Jun 29 '15 at 08:41
  • I tried creating it myself but I couldn't get it to work, it kept saying I had undefined references to the functions, even though I could access the macros in the same file. – k212 Jun 29 '15 at 08:57
  • If you look at https://github.com/libopencm3/libopencm3/tree/master/lib/stm32/l0, there seems to only be rcc and gpio, unlike others. Not sure why the docs look so much different. Seems they incorrect claim support... EEEK... – leppie Jun 29 '15 at 09:09
  • just bit bang the gpio, you could have written that several times over by now instead of trying to get some library patched in... – old_timer Jun 30 '15 at 21:04
  • I'd rather not roll my own everything if I can avoid it... – k212 Jul 01 '15 at 06:30
  • And also, for my application it is vastly preferable to use hardware i2c rather than by doing it in software bit banging. Your comment is unhelpful – k212 Jul 01 '15 at 06:33

1 Answers1

0

STM32L0 specific header need to be added.
though (i2c common header file can probebly be used).
the common header's are not intended to be directly included (for safty and less headache). (it has includer check)

solution:
you should check "i2c_common_all.h" if it is has correct register defination for l0 (probebly yes), then copy stm32/l1/i2c.h to stm32/l0/i2c.h and added (the last two lines) to stm32/i2c.h

#elif defined(STM32L1)
#       include <libopencm3/stm32/l1/i2c.h>
#elif defined(STM32L0)
#       include <libopencm3/stm32/l0/i2c.h>

and make modification to lib/stm32/l0/Makefile OBJS += i2c_common_all.o

if you want, send a pull request

hack: (not recommended)

#include <libopencm3/cm3/common.h>
#include <libopencm3/stm32/memorymap.h>
#define LIBOPENCM3_I2C_H
#include <libopencm3/stm32/i2c_common_all.h>

and include the source file lib/stm32/common/i2c_common_all.c manually.

Kuldeep Dhaka
  • 533
  • 5
  • 22