stm32_i2cbus_v2.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * Copyright (C) 2013 Uwe Bonnes(bon@elektron.ikp.physik.tu-darmstadt.de
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file arch/cm3/dev/stm/stm32_i2cbus_v2.c
  36. * \brief I2C bus driver for I2C hardware in STM32F0 and STM32F3.
  37. *
  38. * This driver is in an early stage and has been tested on STM32F3 only.
  39. * It doesn't consider Slave operation yet
  40. *
  41. * It is intended that this driver replaces the current STM TWI driver,
  42. * which doesn't allow to have different types of busses in a single
  43. * application, for example TWI hardware and bit banging interfaces.
  44. * This new I2C driver layout allows to attach any I2C slave driver to
  45. * any I2C bus driver by calling NutRegisterI2cSlave().
  46. *
  47. * \verbatim
  48. * $Id$
  49. * \endverbatim
  50. */
  51. /*!
  52. * \brief I2C bus driver for STM32F0/3 hardware.
  53. *
  54. * This is an interrupt driver, which supports master mode only.
  55. * No support for FM+
  56. * No error handling
  57. */
  58. #include <dev/irqreg.h>
  59. #include <sys/nutdebug.h>
  60. #include <sys/timer.h>
  61. #include <sys/event.h>
  62. #include <stdlib.h>
  63. #include <cfg/arch.h>
  64. #include <arch/cm3.h>
  65. #include <dev/gpio.h>
  66. #include <arch/cm3/stm/stm32_gpio.h>
  67. #include <arch/cm3/stm/stm32_irqreg.h>
  68. #include <dev/i2cbus.h>
  69. #include <cfg/twi.h>
  70. /*!
  71. * \addtogroup xgI2cBusSTM32
  72. */
  73. /*@{*/
  74. /*!
  75. * \brief Local data of the STM32 I2C bus driver.
  76. */
  77. typedef struct _STM32_I2CCB {
  78. /*! \brief Register base. */
  79. uptr_t icb_base;
  80. /*! \brief SDA_PIN. */
  81. uint32_t sda_pin;
  82. /*! \brief SCL_PIN. */
  83. uint32_t scl_pin;
  84. /*! \brief SMBA_PIN. */
  85. uint32_t smba_pin;
  86. /*! \brief System event handler. */
  87. IRQ_HANDLER *icb_sig_ev;
  88. /*! \brief System error handler. */
  89. IRQ_HANDLER *icb_sig_er;
  90. /*! \brief I2C message. */
  91. NUTI2C_MSG *icb_msg;
  92. /*! \brief Thread waiting for completion. */
  93. HANDLE icb_queue;
  94. uint32_t errors;
  95. } STM32_I2CCB;
  96. /*
  97. * STM32V2 I2C Event interrupt function.
  98. */
  99. static void I2cEventBusIrqHandler(void *arg)
  100. {
  101. STM32_I2CCB *icb = (STM32_I2CCB *) arg;
  102. NUTI2C_MSG *msg = icb->icb_msg;
  103. I2C_TypeDef *i2c;
  104. uint32_t cr2;
  105. i2c = (I2C_TypeDef *) icb->icb_base;
  106. cr2 = i2c->CR2;
  107. /* TX parts*/
  108. if ((i2c->ISR & I2C_ISR_TCR) && !(cr2 & I2C_CR2_RD_WRN))
  109. {
  110. uint32_t txbytes_left = msg->msg_wlen - msg->msg_widx;
  111. if (txbytes_left <= 0xff)
  112. {
  113. cr2 &= ~(I2C_CR2_NBYTES | I2C_CR2_RELOAD);
  114. cr2 |= txbytes_left << 16;
  115. }
  116. /* else I2C_CR2_NBYTES and I2C_CR2_RELOAD already set*/
  117. i2c->CR2 = cr2; /* Write to NBYTES clears TCR*/
  118. }
  119. if ((i2c->ISR & I2C_ISR_TC) && !(cr2 & I2C_CR2_RD_WRN))
  120. {
  121. i2c->CR1 &= ~I2C_CR1_TXIE;
  122. cr2 &= ~I2C_CR2_NBYTES;
  123. if (msg->msg_rsiz == 0) /* No read transaction, stop after write*/
  124. {
  125. i2c->CR2 = cr2 | I2C_CR2_STOP ;
  126. }
  127. else
  128. {
  129. i2c->CR1 |= I2C_CR1_RXIE;
  130. cr2 |= I2C_CR2_RD_WRN | msg->msg_rsiz << 16;
  131. i2c->CR2 = cr2 | I2C_CR2_START ;
  132. }
  133. }
  134. if ((i2c->ISR & I2C_ISR_TXIS) && !(cr2 & I2C_CR2_RD_WRN))
  135. {
  136. i2c->TXDR = msg->msg_wdat[msg->msg_widx];
  137. msg->msg_widx++;
  138. }
  139. /* RX parts*/
  140. if ((i2c->ISR & I2C_ISR_TCR) && (cr2 & I2C_CR2_RD_WRN))
  141. {
  142. uint32_t rxbytes_left = msg->msg_rsiz - msg->msg_ridx;
  143. if (rxbytes_left <= 0xff)
  144. {
  145. cr2 &= ~(I2C_CR2_NBYTES | I2C_CR2_RELOAD);
  146. cr2 |= rxbytes_left << 16;
  147. }
  148. /* else I2C_CR2_NBYTES and I2C_CR2_RELOAD already set*/
  149. i2c->CR2 = cr2; /* Write to NBYTES clears TCR*/
  150. }
  151. if ((i2c->ISR & I2C_ISR_TC) && (cr2 & I2C_CR2_RD_WRN))
  152. {
  153. i2c->CR1 &= ~(I2C_CR1_TCIE | I2C_CR1_RXIE);
  154. i2c->CR2 = cr2 | I2C_CR2_STOP ;
  155. }
  156. if ((i2c->ISR & I2C_ISR_RXNE) && (cr2 & I2C_CR2_RD_WRN))
  157. {
  158. msg->msg_rdat[msg->msg_ridx] = i2c->RXDR;
  159. msg->msg_ridx++;
  160. if (msg->msg_ridx == msg->msg_rsiz)
  161. /* No more RX Interrupts*/
  162. i2c->CR1 &= ~I2C_CR1_RXIE;
  163. }
  164. if (i2c->ISR & I2C_ISR_STOPF)
  165. {
  166. i2c->CR1 &= ~I2C_CR1_STOPIE;
  167. i2c->ICR |= I2C_ICR_STOPCF;
  168. NutEventPostFromIrq(&icb->icb_queue);
  169. }
  170. if (i2c->ISR & I2C_ISR_NACKF)
  171. {
  172. /* Save error, but only exit through STOPF */
  173. icb->errors |= I2C_ISR_NACKF;
  174. i2c->CR1 &= ~I2C_CR1_NACKIE;
  175. i2c->ICR |= I2C_ICR_NACKCF;
  176. }
  177. }
  178. /*
  179. * STM32V2 I2C Error interrupt function.
  180. */
  181. static void I2cErrorBusIrqHandler(void *arg)
  182. {
  183. STM32_I2CCB *icb = (STM32_I2CCB *) arg;
  184. I2C_TypeDef *i2c;
  185. uint32_t isr;
  186. /* Fixme: More error handling! */
  187. i2c = (I2C_TypeDef *) icb->icb_base;
  188. isr = i2c->ISR;
  189. if (isr & I2C_ISR_ALERT)
  190. i2c->ICR |= I2C_ICR_ALERTCF;
  191. if (isr & I2C_ISR_PECERR)
  192. i2c->ICR |= I2C_ICR_PECCF;
  193. if (isr & I2C_ISR_OVR)
  194. i2c->ICR |= I2C_ICR_OVRCF;
  195. if (isr & I2C_ISR_ARLO)
  196. i2c->ICR |= I2C_ICR_ARLOCF;
  197. if (isr & I2C_ISR_BERR)
  198. i2c->ICR |= I2C_ICR_BERRCF;
  199. if (isr & I2C_ISR_TIMEOUT)
  200. i2c->ICR |= I2C_ICR_TIMOUTCF;
  201. }
  202. /*!
  203. * \brief I2C bus transfer (STM I2C implementation).
  204. *
  205. * This function is called by the platform independent code via the
  206. * NUTI2C_BUS::bus_tran function pointer.
  207. */
  208. static int I2cBusTran(NUTI2C_SLAVE *slave, NUTI2C_MSG *msg)
  209. {
  210. NUTI2C_BUS *bus;
  211. STM32_I2CCB *icb;
  212. I2C_TypeDef *i2c;
  213. uint32_t cr2;
  214. int rc = 0;
  215. bus = slave->slave_bus;
  216. NUTASSERT(bus != NULL);
  217. NUTASSERT(bus->bus_icb != NULL);
  218. icb = (STM32_I2CCB *) bus->bus_icb;
  219. icb->icb_msg = msg;
  220. icb->errors = 0;
  221. i2c = (I2C_TypeDef *) icb->icb_base;
  222. cr2 = i2c->CR2;
  223. cr2 &= 0xf8000000; /* Clean out */
  224. cr2 |= slave->slave_address << 1;
  225. msg->msg_widx = 0;
  226. msg->msg_ridx = 0;
  227. /* are there bytes to write? */
  228. if (msg->msg_wlen)
  229. {
  230. i2c->CR1 |= I2C_CR1_TXIE | I2C_CR1_TCIE | I2C_CR1_STOPIE | I2C_CR1_NACKIE;
  231. if (msg->msg_wlen > 0xff)
  232. cr2 |= I2C_CR2_NBYTES | I2C_CR2_RELOAD;
  233. else
  234. cr2 |= msg->msg_wlen << 16;
  235. }
  236. else if (msg->msg_rsiz)
  237. {
  238. i2c->CR1 |= I2C_CR1_RXIE | I2C_CR1_STOPIE | I2C_CR1_NACKIE;
  239. if (msg->msg_rsiz > 0xff)
  240. cr2 |= I2C_CR2_RD_WRN | I2C_CR2_NBYTES | I2C_CR2_RELOAD;
  241. else
  242. cr2 |= I2C_CR2_RD_WRN | msg->msg_rsiz << 16;
  243. }
  244. i2c->CR2 = cr2 | I2C_CR2_START;
  245. rc = NutEventWait(&icb->icb_queue, slave->slave_timeout);
  246. if ((icb->errors) || (rc))
  247. msg->msg_ridx = -1;
  248. return msg->msg_ridx;
  249. }
  250. static int checkpin_and_config(STM32_I2CCB *icb)
  251. {
  252. uint32_t sda_port, scl_port;
  253. if (icb->icb_base == I2C1_BASE)
  254. {
  255. if ((icb->sda_pin != 7) && (icb->sda_pin != 9) && (icb->sda_pin != 14))
  256. return -1;
  257. if ((icb->scl_pin != 6) && (icb->scl_pin != 8) && (icb->sda_pin != 15))
  258. return -1;
  259. if ((icb->smba_pin != 5) && (icb->smba_pin != -1))
  260. return -1;
  261. if (icb->sda_pin == 15)
  262. sda_port= NUTGPIO_PORTA;
  263. else
  264. sda_port= NUTGPIO_PORTB;
  265. if (icb->scl_pin == 15)
  266. scl_port= NUTGPIO_PORTA;
  267. else
  268. scl_port= NUTGPIO_PORTB;
  269. GpioPinConfigSet(
  270. sda_port, icb->sda_pin, GPIO_CFG_OUTPUT| GPIO_CFG_PERIPHAL|
  271. GPIO_CFG_MULTIDRIVE| GPIO_CFG_PULLUP | GPIO_CFG_SPEED_FAST);
  272. GpioPinConfigSet(
  273. scl_port ,icb->scl_pin, GPIO_CFG_OUTPUT| GPIO_CFG_PERIPHAL|
  274. GPIO_CFG_MULTIDRIVE| GPIO_CFG_PULLUP | GPIO_CFG_SPEED_FAST);
  275. GPIO_PinAFConfig((GPIO_TypeDef*) sda_port, icb->sda_pin, GPIO_AF_4);
  276. GPIO_PinAFConfig((GPIO_TypeDef*) scl_port, icb->scl_pin, GPIO_AF_4);
  277. if (icb->smba_pin == 5)
  278. {
  279. /* TODO: How should SMBA pin be set?*/
  280. GpioPinConfigSet(
  281. NUTGPIO_PORTA, icb->scl_pin, GPIO_CFG_OUTPUT|
  282. GPIO_CFG_PERIPHAL| GPIO_CFG_MULTIDRIVE| GPIO_CFG_PULLUP |
  283. GPIO_CFG_SPEED_FAST);
  284. GPIO_PinAFConfig(GPIOA, icb->smba_pin, GPIO_AF_4);
  285. }
  286. RCC->APB1ENR &= ~RCC_APB1ENR_I2C1EN;
  287. /* Use HSI clock*/
  288. RCC->CFGR3 &= ~RCC_CFGR3_I2C1SW;
  289. RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;
  290. RCC->APB1RSTR |= RCC_APB1RSTR_I2C1RST;
  291. RCC->APB1RSTR &= ~RCC_APB1RSTR_I2C1RST;
  292. }
  293. else if (icb->icb_base == I2C2_BASE)
  294. {
  295. if ((icb->sda_pin != 0) && (icb->sda_pin != 10)&& (icb->sda_pin != 0))
  296. return -1;
  297. if ((icb->scl_pin != 1) && (icb->scl_pin != 9) && (icb->sda_pin != 6)
  298. && (icb->sda_pin != 1))
  299. return -1;
  300. if ((icb->smba_pin != 12) && (icb->smba_pin != 8)
  301. && (icb->smba_pin != -1))
  302. return -1;
  303. if (icb->sda_pin == 10)
  304. sda_port= NUTGPIO_PORTA;
  305. else
  306. sda_port= NUTGPIO_PORTF;
  307. if (icb->scl_pin == 9)
  308. scl_port= NUTGPIO_PORTA;
  309. else /* Both other alternate pins on PORTF*/
  310. scl_port= NUTGPIO_PORTF;
  311. /* Fixme: Handle SMNa Pin*/
  312. GpioPinConfigSet(
  313. sda_port, icb->sda_pin, GPIO_CFG_OUTPUT| GPIO_CFG_PERIPHAL|
  314. GPIO_CFG_MULTIDRIVE| GPIO_CFG_PULLUP | GPIO_CFG_SPEED_FAST);
  315. GpioPinConfigSet(
  316. scl_port ,icb->scl_pin, GPIO_CFG_OUTPUT| GPIO_CFG_PERIPHAL|
  317. GPIO_CFG_MULTIDRIVE| GPIO_CFG_PULLUP | GPIO_CFG_SPEED_FAST);
  318. GPIO_PinAFConfig((GPIO_TypeDef*) sda_port, icb->sda_pin, GPIO_AF_4);
  319. GPIO_PinAFConfig((GPIO_TypeDef*) scl_port, icb->scl_pin, GPIO_AF_4);
  320. RCC->APB1ENR &= ~RCC_APB1ENR_I2C2EN;
  321. /* Use HSI clock*/
  322. RCC->CFGR3 &= ~RCC_CFGR3_I2C2SW;
  323. RCC->APB1ENR |= RCC_APB1ENR_I2C2EN;
  324. RCC->APB1RSTR |= RCC_APB1RSTR_I2C2RST;
  325. RCC->APB1RSTR &= ~RCC_APB1RSTR_I2C2RST;
  326. }
  327. else
  328. return -1;
  329. return 0;
  330. }
  331. /*!
  332. * \brief Configure the I2C bus controller (STM32V2 I2C implementation).
  333. *
  334. * This function is called by the platform independent code via the
  335. * NUTI2C_BUS::bus_conf function pointer. Most implementations will
  336. * also call this function during initialization to set the
  337. * default configuration.
  338. *
  339. * Right now only the bus clock rate is configurable,
  340. * and only at 10/100/400 kHz
  341. */
  342. static int I2cBusConf(NUTI2C_BUS *bus)
  343. {
  344. STM32_I2CCB *icb;
  345. long rate;
  346. uint32_t timing;
  347. I2C_TypeDef *i2c;
  348. /* Check parameters. */
  349. NUTASSERT(bus != NULL);
  350. NUTASSERT(bus->bus_icb != NULL);
  351. icb = (STM32_I2CCB *) bus->bus_icb;
  352. i2c = (I2C_TypeDef*) icb->icb_base;
  353. /* Get requested rate or use the default. */
  354. rate = bus->bus_rate;
  355. if (rate == 0) {
  356. rate = 100000L;
  357. }
  358. if (rate > 400000) {
  359. /* Speed out of range */
  360. return -1;
  361. }
  362. if(rate == 400000)
  363. timing = 0x0 <<28 |0x3 << 20 | 0x1 << 16| 0x03 << 8 | 0x09 << 0;
  364. else if (rate >= 100000)
  365. timing = 0x1 <<28 |0x4 << 20 | 0x2 << 16| 0x0f << 8 | 0x13 << 0;
  366. else if (rate >= 50000)
  367. timing = 0x1 <<28 |0x4 << 20 | 0x2 << 16| 0x23 << 8 | 0x27 << 0;
  368. else
  369. timing = 0x1 <<28 |0x4 << 20 | 0x2 << 16| 0xc3 << 8 | 0xc7 << 0;
  370. if ((i2c->TIMINGR & 0xf0ffffff) != timing)
  371. {
  372. /* Disable I2C and set new timing */
  373. while(i2c->CR1 & I2C_CR1_PE)
  374. i2c->CR1 &= ~I2C_CR1_PE;
  375. i2c->TIMINGR = timing;
  376. }
  377. return 0;
  378. }
  379. /*!
  380. * \brief Initialize the I2C bus controller (STM32 implementation).
  381. *
  382. * This function is called by the platform independent code via the
  383. * NUTI2C_BUS::bus_init function pointer when the first slave is
  384. * attached to this bus. Note, that NUTI2C_BUS::bus_rate must be zero
  385. * initially. Otherwise no call to this function will take place.
  386. *
  387. * This function must do all required initializations so that the
  388. * driver will be ready to process transfers via NUTI2C_BUS::bus_tran.
  389. *
  390. * This function must return 0 on success or -1 otherwise.
  391. */
  392. static int I2cBusInit(NUTI2C_BUS *bus)
  393. {
  394. I2C_TypeDef *i2c;
  395. STM32_I2CCB *icb;
  396. icb = (STM32_I2CCB *) bus->bus_icb;
  397. if (checkpin_and_config(icb))
  398. return -1;
  399. /* Try to configure the bus*/
  400. if (I2cBusConf(bus)) {
  401. return -1;
  402. }
  403. i2c = (I2C_TypeDef*) icb->icb_base;
  404. i2c->CR1 |= I2C_CR1_PE;
  405. if (NutRegisterIrqHandler(icb->icb_sig_ev, I2cEventBusIrqHandler, icb))
  406. return -1;
  407. if (NutRegisterIrqHandler(icb->icb_sig_er, I2cErrorBusIrqHandler, icb))
  408. return -1;
  409. NutIrqEnable(icb->icb_sig_ev);
  410. NutIrqDisable(icb->icb_sig_er);
  411. return 0;
  412. }
  413. /*!
  414. * \brief Probe the I2C bus for a specified slave address
  415. * (STM32V2 implementation).
  416. *
  417. * This function is called by the platform independent code via the
  418. * NUTI2C_BUS::bus_probe function pointer. This may happen even if no
  419. * slave device had been attached to the bus and thus without any
  420. * previous call to NUTI2C_BUS::bus_init. However, in that case
  421. * NUTI2C_BUS::bus_configure will have been called.
  422. *
  423. *
  424. */
  425. static int I2cBusProbe(NUTI2C_BUS *bus, int sla)
  426. {
  427. STM32_I2CCB *icb;
  428. I2C_TypeDef *i2c;
  429. int ret;
  430. if ((bus->bus_flags & I2C_BF_INITIALIZED) == 0) {
  431. int res;
  432. res = I2cBusInit(bus);
  433. if (res)
  434. return res;
  435. }
  436. icb = (STM32_I2CCB *) bus->bus_icb;
  437. i2c = (I2C_TypeDef*) icb->icb_base;
  438. icb->errors = 0;
  439. i2c->CR1 |= I2C_CR1_NACKIE |I2C_CR1_STOPIE;
  440. i2c->CR2 = I2C_CR2_AUTOEND | 0*I2C_CR2_NBYTES| I2C_CR2_STOP |
  441. I2C_CR2_START| 0*I2C_CR2_ADD10 | 0* I2C_CR2_RD_WRN |sla<<1;
  442. NutEventWait(&icb->icb_queue, 10);
  443. if (icb->errors & I2C_ISR_NACKF)
  444. ret = -1;
  445. else
  446. ret = 0;
  447. return ret;
  448. }
  449. /*
  450. F30: AF4
  451. I2C1 SDA PA14 PB7 PB9
  452. I2C1_SCL PA15 PB6 PB8
  453. I2C1_SMBA PB5
  454. I2C2_SDA PA10 PF0
  455. I2C2_SCL PA9 PF1 PF6
  456. I2C2_SMBA PA8 PB12
  457. F0: AF1
  458. I2C1 SDA PB7 PB9
  459. I2C1_SCL PB6 PB8
  460. I2C1_SMBA PB5 (AF3)
  461. I2C2_SDA PB11
  462. I2C2_SCL PB10
  463. I2C2_SMBA NA
  464. */
  465. static STM32_I2CCB i2c1cb = {
  466. I2C1_BASE, /* Register Base */
  467. #if defined (I2C1_SDA_PIN)
  468. I2C1_SDA_PIN, /* SDA Pin number */
  469. #else
  470. -1, /* SDA Pin number */
  471. #endif
  472. #if defined (I2C1_SCL_PIN)
  473. I2C1_SCL_PIN, /* SDA Pin number */
  474. #else
  475. -1, /* SDA Pin number */
  476. #endif
  477. #if defined (I2C1_SMBA_PIN)
  478. I2C1_SMBA_PIN, /* SDA Pin number */
  479. #else
  480. -1, /* SDA Pin number */
  481. #endif
  482. &sig_TWI1_EV, /* Event signal */
  483. &sig_TWI1_ER, /* Error signal */
  484. NULL, /* icb_msg */
  485. NULL /* icb_queue */
  486. };
  487. static STM32_I2CCB i2c2cb = {
  488. I2C2_BASE, /* Register Base */
  489. #if defined (I2C2_SDA_PIN)
  490. I2C2_SDA_PIN, /* SDA Pin number */
  491. #else
  492. -1, /* SDA Pin number */
  493. #endif
  494. #if defined (I2C2_SCL_PIN)
  495. I2C2_SCL_PIN, /* SDA Pin number */
  496. #else
  497. -1, /* SDA Pin number */
  498. #endif
  499. #if defined (I2C2_SMBA_PIN)
  500. I2C2_SMBA_PIN, /* SDA Pin number */
  501. #else
  502. -1, /* SDA Pin number */
  503. #endif
  504. &sig_TWI2_EV, /* Event signal */
  505. &sig_TWI2_ER, /* Error signal */
  506. NULL, /* icb_msg */
  507. NULL /* icb_queue */
  508. };
  509. NUTI2C_BUS i2cBus1Stm32 = {
  510. &i2c1cb, /* bus_icb */
  511. I2cBusInit, /* bus_init */
  512. I2cBusConf, /* bus_configure */
  513. I2cBusProbe,/* bus_probe */
  514. I2cBusTran, /* bus_transceive */
  515. 100, /* bus_timeout */
  516. 0, /* bus_rate */
  517. 0, /* bus_flags */
  518. NULL /* bus_mutex */
  519. };
  520. NUTI2C_BUS i2cBus2Stm32 = {
  521. &i2c2cb, /* bus_icb */
  522. I2cBusInit, /* bus_init */
  523. I2cBusConf, /* bus_configure */
  524. I2cBusProbe,/* bus_probe */
  525. I2cBusTran, /* bus_transceive */
  526. 100, /* bus_timeout */
  527. 0, /* bus_rate */
  528. 0, /* bus_flags */
  529. NULL /* bus_mutex */
  530. };