Revision 22be62dc

View differences:

kernel/patches/I2C-without-DMA.patch
1
diff --git a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
2
index 6ade226..96c9da0 100644
3
--- a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
4
+++ b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
5
@@ -34,6 +34,7 @@
6
 /* Driver local definitions.                                                 */
7
 /*===========================================================================*/
8
 
9
+#if STM32_I2C_I2C1_USE_DMA
10
 #define I2C1_RX_DMA_CHANNEL                                                 \
11
   STM32_DMA_GETCHANNEL(STM32_I2C_I2C1_RX_DMA_STREAM,                        \
12
                        STM32_I2C1_RX_DMA_CHN)
13
@@ -41,7 +42,9 @@
14
 #define I2C1_TX_DMA_CHANNEL                                                 \
15
   STM32_DMA_GETCHANNEL(STM32_I2C_I2C1_TX_DMA_STREAM,                        \
16
                        STM32_I2C1_TX_DMA_CHN)
17
+#endif
18
 
19
+#if STM32_I2C_I2C2_USE_DMA
20
 #define I2C2_RX_DMA_CHANNEL                                                 \
21
   STM32_DMA_GETCHANNEL(STM32_I2C_I2C2_RX_DMA_STREAM,                        \
22
                        STM32_I2C2_RX_DMA_CHN)
23
@@ -49,7 +52,9 @@
24
 #define I2C2_TX_DMA_CHANNEL                                                 \
25
   STM32_DMA_GETCHANNEL(STM32_I2C_I2C2_TX_DMA_STREAM,                        \
26
                        STM32_I2C2_TX_DMA_CHN)
27
+#endif
28
 
29
+#if STM32_I2C_I2C3_USE_DMA
30
 #define I2C3_RX_DMA_CHANNEL                                                 \
31
   STM32_DMA_GETCHANNEL(STM32_I2C_I2C3_RX_DMA_STREAM,                        \
32
                        STM32_I2C3_RX_DMA_CHN)
33
@@ -57,6 +62,7 @@
34
 #define I2C3_TX_DMA_CHANNEL                                                 \
35
   STM32_DMA_GETCHANNEL(STM32_I2C_I2C3_TX_DMA_STREAM,                        \
36
                        STM32_I2C3_TX_DMA_CHN)
37
+#endif
38
 
39
 /*===========================================================================*/
40
 /* Driver constants.                                                         */
41
@@ -72,6 +78,20 @@
42
 #define I2C_EV6_MASTER_REC_MODE_SELECTED                                    \
43
   ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) | I2C_SR1_ADDR))
44
 
45
+#define I2C_EV7_MASTER_REC_BYTE_RECEIVED                                    \
46
+  ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) | I2C_SR1_RXNE))
47
+
48
+#define I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP                               \
49
+  ((uint32_t)(I2C_SR1_RXNE))
50
+
51
+#define I2C_EV7_2_EV7_3_MASTER_REC_BYTE_QUEUED                              \
52
+  ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) |                         \
53
+              I2C_SR1_BTF | I2C_SR1_RXNE))
54
+
55
+#define I2C_EV8_MASTER_BYTE_TRANSMITTING                                    \
56
+  ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY | I2C_SR2_TRA)<< 16) |           \
57
+              I2C_SR1_TXE))
58
+
59
 #define I2C_EV8_2_MASTER_BYTE_TRANSMITTED                                   \
60
   ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY | I2C_SR2_TRA) << 16) |          \
61
               I2C_SR1_BTF | I2C_SR1_TXE))
62
@@ -129,8 +149,24 @@ static void i2c_lld_abort_operation(I2CDriver *i2cp) {
63
   dp->SR1 = 0;
64
 
65
   /* Stops the associated DMA streams.*/
66
-  dmaStreamDisable(i2cp->dmatx);
67
-  dmaStreamDisable(i2cp->dmarx);
68
+#if STM32_I2C_USE_I2C1 && STM32_I2C_I2C1_USE_DMA
69
+  if (&I2CD1 == i2cp) {
70
+    dmaStreamDisable(i2cp->dmatx);
71
+    dmaStreamDisable(i2cp->dmarx);
72
+  }
73
+#endif
74
+#if STM32_I2C_USE_I2C2 && STM32_I2C_I2C2_USE_DMA
75
+  if (&I2CD2 == i2cp) {
76
+    dmaStreamDisable(i2cp->dmatx);
77
+    dmaStreamDisable(i2cp->dmarx);
78
+  }
79
+#endif
80
+#if STM32_I2C_USE_I2C3 && STM32_I2C_I2C3_USE_DMA
81
+  if (&I2CD3 == i2cp) {
82
+    dmaStreamDisable(i2cp->dmatx);
83
+    dmaStreamDisable(i2cp->dmarx);
84
+  }
85
+#endif
86
 }
87
 
88
 /**
89
@@ -236,13 +272,17 @@ static void i2c_lld_set_opmode(I2CDriver *i2cp) {
90
 }
91
 
92
 /**
93
- * @brief   I2C shared ISR code.
94
+ * @brief   I2C shared ISR code for DMA access.
95
  *
96
  * @param[in] i2cp      pointer to the @p I2CDriver object
97
  *
98
  * @notapi
99
  */
100
-static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
101
+#if (STM32_I2C_USE_I2C1 && STM32_I2C_I2C1_USE_DMA) ||                       \
102
+    (STM32_I2C_USE_I2C2 && STM32_I2C_I2C2_USE_DMA) ||                       \
103
+    (STM32_I2C_USE_I2C3 && STM32_I2C_I2C3_USE_DMA) ||                       \
104
+    defined(__DOXYGEN__)
105
+static void i2c_lld_serve_event_interrupt_dma(I2CDriver *i2cp) {
106
   I2C_TypeDef *dp = i2cp->i2c;
107
   uint32_t regSR2 = dp->SR2;
108
   uint32_t event = dp->SR1;
109
@@ -252,7 +292,7 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
110
      done by the DMA.*/
111
   switch (I2C_EV_MASK & (event | (regSR2 << 16))) {
112
   case I2C_EV5_MASTER_MODE_SELECT:
113
-    if ((i2cp->addr >> 8) > 0) { 
114
+    if ((i2cp->addr >> 8) > 0) {
115
       /* 10-bit address: 1 1 1 1 0 X X R/W */
116
       dp->DR = 0xF0 | (0x6 & (i2cp->addr >> 8)) | (0x1 & i2cp->addr);
117
     } else {
118
@@ -293,6 +333,140 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
119
   if (event & (I2C_SR1_ADDR | I2C_SR1_ADD10))
120
     (void)dp->SR2;
121
 }
122
+#endif /* any I2CDx uses DMA mode */
123
+
124
+/**
125
+ * @brief   I2C shared ISR code for non-DMA access.
126
+ *
127
+ * @param[in] i2cp      pointer to the @p I2CDriver object
128
+ *
129
+ * @notapi
130
+ */
131
+#if (STM32_I2C_USE_I2C1 && !STM32_I2C_I2C1_USE_DMA) ||                      \
132
+    (STM32_I2C_USE_I2C2 && !STM32_I2C_I2C2_USE_DMA) ||                      \
133
+    (STM32_I2C_USE_I2C3 && !STM32_I2C_I2C3_USE_DMA) ||                      \
134
+    defined(__DOXYGEN__)
135
+static void i2c_lld_serve_event_interrupt_isr(I2CDriver *i2cp) {
136
+  I2C_TypeDef *dp = i2cp->i2c;
137
+  uint32_t regSR2 = dp->SR2;
138
+  uint32_t event = dp->SR1;
139
+
140
+  switch (I2C_EV_MASK & (event | (regSR2 << 16))) {
141
+  case I2C_EV5_MASTER_MODE_SELECT:
142
+    dp->CR2 |= I2C_CR2_ITBUFEN;
143
+    dp->DR = i2cp->addr;
144
+    break;
145
+  case I2C_EV6_MASTER_TRA_MODE_SELECTED:
146
+    (void)dp->SR2; // clear ADDR flag
147
+    /* EV8_1 */
148
+    dp->DR = *(i2cp->txbuf);
149
+
150
+    ++i2cp->txbuf;
151
+    --i2cp->txbytes;
152
+
153
+    /* if N == 1, skip the I2C_EV8_MASTER_BYTE_TRANSMITTING event
154
+     * but enter I2C_EV8_2_MASTER_BYTE_TRANSMITTED next */
155
+    if (i2cp->txbytes == 0) {
156
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
157
+    }
158
+    break;
159
+  case I2C_EV6_MASTER_REC_MODE_SELECTED:
160
+    switch (i2cp->rxbytes) {
161
+    case 1:
162
+      dp->CR1 &= ~I2C_CR1_ACK;
163
+      (void)dp->SR2; // clear ADDR flag
164
+      dp->CR1 |= I2C_CR1_STOP;
165
+      break;
166
+    case 2:
167
+      (void)dp->SR2; // clear ADDR flag
168
+      /* EV6_1 */
169
+      dp->CR1 |= I2C_CR1_POS;
170
+      dp->CR1 &= ~I2C_CR1_ACK;
171
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
172
+      break;
173
+    case 3: /* N == 3 is a very special case, since EV7 is completely skipped */
174
+      (void)dp->SR2; // clear ADDR flag
175
+      /* Disable the I2C_EV7_MASTER_REC_BYTE_RECEIVED event
176
+       * but enter I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP next */
177
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
178
+      break;
179
+    default: /* N > 2 */
180
+      (void)dp->SR2; // clear ADDR flag
181
+      break;
182
+    }
183
+    break;
184
+  case I2C_EV7_MASTER_REC_BYTE_RECEIVED:
185
+    if (i2cp->rxbytes > 3) {
186
+      *(i2cp->rxbuf) = dp->DR;
187
+      ++i2cp->rxbuf;
188
+      --i2cp->rxbytes;
189
+    }
190
+    if (i2cp->rxbytes == 3) {
191
+      /* Disable this event for DataN-2, but force into event
192
+       * I2C_EV7_2_EV7_3_MASTER_REC_BYTE_RECEIVED_QUEUED by not reading dp->DR. */
193
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
194
+    }
195
+    break;
196
+  case I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP:
197
+    osalDbgAssert(i2cp->rxbytes == 1, "more than 1 byte to be received");
198
+    *(i2cp->rxbuf) = dp->DR;
199
+    --i2cp->rxbytes;
200
+    dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
201
+    _i2c_wakeup_isr(i2cp);
202
+    break;
203
+  case I2C_EV7_2_EV7_3_MASTER_REC_BYTE_QUEUED:
204
+    if (i2cp->rxbytes == 3) {
205
+      /* EV7_2 (N > 2) */
206
+      dp->CR1 &= ~I2C_CR1_ACK;
207
+      *(i2cp->rxbuf) = dp->DR;
208
+      ++i2cp->rxbuf;
209
+      dp->CR1 |= I2C_CR1_STOP;
210
+      *(i2cp->rxbuf) = dp->DR;
211
+      ++i2cp->rxbuf;
212
+      i2cp->rxbytes -= 2;
213
+      /* enable I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP event */
214
+      dp->CR2 |= I2C_CR2_ITBUFEN;
215
+    } else {
216
+      /* EV7_3 (N == 2) */
217
+      dp->CR1 |= I2C_CR1_STOP;
218
+      *(i2cp->rxbuf) = dp->DR;
219
+      ++i2cp->rxbuf;
220
+      *(i2cp->rxbuf) = dp->DR;
221
+      i2cp->rxbytes -= 2;
222
+
223
+      dp->CR1 &= ~I2C_CR1_POS;
224
+      dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
225
+
226
+      _i2c_wakeup_isr(i2cp);
227
+    }
228
+    break;
229
+  case I2C_EV8_MASTER_BYTE_TRANSMITTING:
230
+    dp->DR = *(i2cp->txbuf);
231
+    ++i2cp->txbuf;
232
+    --i2cp->txbytes;
233
+
234
+    /* if this was the last byte, ensure that this event is not entered again */
235
+    if (i2cp->txbytes == 0) {
236
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
237
+    }
238
+    break;
239
+  case I2C_EV8_2_MASTER_BYTE_TRANSMITTED:
240
+    if (i2cp->rxbytes > 0) {
241
+      /* start "read after write" operation (LSB of address = 1 => read) */
242
+      i2cp->addr |= 0x01;
243
+      dp->CR1 |= I2C_CR1_START | I2C_CR1_ACK;
244
+    } else {
245
+      dp->CR1 |= I2C_CR1_STOP;
246
+      dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
247
+      _i2c_wakeup_isr(i2cp);
248
+    }
249
+    break;
250
+  default:
251
+    osalDbgAssert(i2cp->rxbytes != 1, "more than 1 byte to be received");
252
+    break;
253
+  }
254
+}
255
+#endif /* any I2CDx uses non-DMA mode */
256
 
257
 /**
258
  * @brief   DMA RX end IRQ handler.
259
@@ -302,6 +476,10 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
260
  *
261
  * @notapi
262
  */
263
+#if (STM32_I2C_USE_I2C1 && STM32_I2C_I2C1_USE_DMA) ||                      \
264
+    (STM32_I2C_USE_I2C2 && STM32_I2C_I2C2_USE_DMA) ||                      \
265
+    (STM32_I2C_USE_I2C3 && STM32_I2C_I2C3_USE_DMA) ||                      \
266
+    defined(__DOXYGEN__)
267
 static void i2c_lld_serve_rx_end_irq(I2CDriver *i2cp, uint32_t flags) {
268
   I2C_TypeDef *dp = i2cp->i2c;
269
 
270
@@ -347,6 +525,7 @@ static void i2c_lld_serve_tx_end_irq(I2CDriver *i2cp, uint32_t flags) {
271
      of R/W transaction itself.*/
272
   dp->CR2 |= I2C_CR2_ITEVTEN;
273
 }
274
+#endif /* any I2CDx uses DMA mode */
275
 
276
 /**
277
  * @brief   I2C error handler.
278
@@ -359,8 +538,24 @@ static void i2c_lld_serve_tx_end_irq(I2CDriver *i2cp, uint32_t flags) {
279
 static void i2c_lld_serve_error_interrupt(I2CDriver *i2cp, uint16_t sr) {
280
 
281
   /* Clears interrupt flags just to be safe.*/
282
-  dmaStreamDisable(i2cp->dmatx);
283
-  dmaStreamDisable(i2cp->dmarx);
284
+#if STM32_I2C_USE_I2C1 && STM32_I2C_I2C1_USE_DMA
285
+  if (&I2CD1 == i2cp) {
286
+    dmaStreamDisable(i2cp->dmatx);
287
+    dmaStreamDisable(i2cp->dmarx);
288
+  }
289
+#endif
290
+#if STM32_I2C_USE_I2C2 && STM32_I2C_I2C2_USE_DMA
291
+  if (&I2CD2 == i2cp) {
292
+    dmaStreamDisable(i2cp->dmatx);
293
+    dmaStreamDisable(i2cp->dmarx);
294
+  }
295
+#endif
296
+#if STM32_I2C_USE_I2C3 && STM32_I2C_I2C3_USE_DMA
297
+  if (&I2CD3 == i2cp) {
298
+    dmaStreamDisable(i2cp->dmatx);
299
+    dmaStreamDisable(i2cp->dmarx);
300
+  }
301
+#endif
302
 
303
   i2cp->errors = I2C_NO_ERROR;
304
 
305
@@ -407,7 +602,11 @@ OSAL_IRQ_HANDLER(STM32_I2C1_EVENT_HANDLER) {
306
 
307
   OSAL_IRQ_PROLOGUE();
308
 
309
-  i2c_lld_serve_event_interrupt(&I2CD1);
310
+#if STM32_I2C_I2C1_USE_DMA
311
+  i2c_lld_serve_event_interrupt_dma(&I2CD1);
312
+#else
313
+  i2c_lld_serve_event_interrupt_isr(&I2CD1);
314
+#endif
315
 
316
   OSAL_IRQ_EPILOGUE();
317
 }
318
@@ -437,7 +636,11 @@ OSAL_IRQ_HANDLER(STM32_I2C2_EVENT_HANDLER) {
319
 
320
   OSAL_IRQ_PROLOGUE();
321
 
322
-  i2c_lld_serve_event_interrupt(&I2CD2);
323
+#if STM32_I2C_I2C2_USE_DMA
324
+  i2c_lld_serve_event_interrupt_dma(&I2CD2);
325
+#else
326
+  i2c_lld_serve_event_interrupt_isr(&I2CD2);
327
+#endif
328
 
329
   OSAL_IRQ_EPILOGUE();
330
 }
331
@@ -469,7 +672,11 @@ OSAL_IRQ_HANDLER(STM32_I2C3_EVENT_HANDLER) {
332
 
333
   OSAL_IRQ_PROLOGUE();
334
 
335
-  i2c_lld_serve_event_interrupt(&I2CD3);
336
+#if STM32_I2C_I2C3_USE_DMA
337
+  i2c_lld_serve_event_interrupt_dma(&I2CD3);
338
+#else
339
+  i2c_lld_serve_event_interrupt_isr(&I2CD3);
340
+#endif
341
 
342
   OSAL_IRQ_EPILOGUE();
343
 }
344
@@ -506,24 +713,30 @@ void i2c_lld_init(void) {
345
   i2cObjectInit(&I2CD1);
346
   I2CD1.thread = NULL;
347
   I2CD1.i2c    = I2C1;
348
+#if STM32_I2C_I2C1_USE_DMA
349
   I2CD1.dmarx  = STM32_DMA_STREAM(STM32_I2C_I2C1_RX_DMA_STREAM);
350
   I2CD1.dmatx  = STM32_DMA_STREAM(STM32_I2C_I2C1_TX_DMA_STREAM);
351
+#endif
352
 #endif /* STM32_I2C_USE_I2C1 */
353
 
354
 #if STM32_I2C_USE_I2C2
355
   i2cObjectInit(&I2CD2);
356
   I2CD2.thread = NULL;
357
   I2CD2.i2c    = I2C2;
358
+#if STM32_I2C_I2C2_USE_DMA
359
   I2CD2.dmarx  = STM32_DMA_STREAM(STM32_I2C_I2C2_RX_DMA_STREAM);
360
   I2CD2.dmatx  = STM32_DMA_STREAM(STM32_I2C_I2C2_TX_DMA_STREAM);
361
+#endif
362
 #endif /* STM32_I2C_USE_I2C2 */
363
 
364
 #if STM32_I2C_USE_I2C3
365
   i2cObjectInit(&I2CD3);
366
   I2CD3.thread = NULL;
367
   I2CD3.i2c    = I2C3;
368
+#if STM32_I2C_I2C3_USE_DMA
369
   I2CD3.dmarx  = STM32_DMA_STREAM(STM32_I2C_I2C3_RX_DMA_STREAM);
370
   I2CD3.dmatx  = STM32_DMA_STREAM(STM32_I2C_I2C3_TX_DMA_STREAM);
371
+#endif
372
 #endif /* STM32_I2C_USE_I2C3 */
373
 }
374
 
375
@@ -540,20 +753,24 @@ void i2c_lld_start(I2CDriver *i2cp) {
376
   /* If in stopped state then enables the I2C and DMA clocks.*/
377
   if (i2cp->state == I2C_STOP) {
378
 
379
-    i2cp->txdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
380
-                      STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
381
-                      STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
382
-                      STM32_DMA_CR_DIR_M2P;
383
-    i2cp->rxdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
384
-                      STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
385
-                      STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
386
-                      STM32_DMA_CR_DIR_P2M;
387
-
388
 #if STM32_I2C_USE_I2C1
389
     if (&I2CD1 == i2cp) {
390
+#if STM32_I2C_I2C1_USE_DMA
391
       bool b;
392
 
393
+      i2cp->txdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
394
+                        STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
395
+                        STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
396
+                        STM32_DMA_CR_DIR_M2P;
397
+      i2cp->rxdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
398
+                        STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
399
+                        STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
400
+                        STM32_DMA_CR_DIR_P2M;
401
+#endif
402
+
403
       rccResetI2C1();
404
+
405
+#if STM32_I2C_I2C1_USE_DMA
406
       b = dmaStreamAllocate(i2cp->dmarx,
407
                             STM32_I2C_I2C1_IRQ_PRIORITY,
408
                             (stm32_dmaisr_t)i2c_lld_serve_rx_end_irq,
409
@@ -564,22 +781,52 @@ void i2c_lld_start(I2CDriver *i2cp) {
410
                             (stm32_dmaisr_t)i2c_lld_serve_tx_end_irq,
411
                             (void *)i2cp);
412
       osalDbgAssert(!b, "stream already allocated");
413
+#endif
414
+
415
       rccEnableI2C1(true);
416
       nvicEnableVector(I2C1_EV_IRQn, STM32_I2C_I2C1_IRQ_PRIORITY);
417
       nvicEnableVector(I2C1_ER_IRQn, STM32_I2C_I2C1_IRQ_PRIORITY);
418
 
419
+#if STM32_I2C_I2C1_USE_DMA
420
       i2cp->rxdmamode |= STM32_DMA_CR_CHSEL(I2C1_RX_DMA_CHANNEL) |
421
                        STM32_DMA_CR_PL(STM32_I2C_I2C1_DMA_PRIORITY);
422
       i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C1_TX_DMA_CHANNEL) |
423
                        STM32_DMA_CR_PL(STM32_I2C_I2C1_DMA_PRIORITY);
424
+
425
+      /* I2C registers pointed by the DMA.*/
426
+      dmaStreamSetPeripheral(i2cp->dmarx, &dp->DR);
427
+      dmaStreamSetPeripheral(i2cp->dmatx, &dp->DR);
428
+#endif
429
+
430
+      /* Reset i2c peripheral.*/
431
+      dp->CR1 = I2C_CR1_SWRST;
432
+      dp->CR1 = 0;
433
+#if STM32_I2C_I2C1_USE_DMA
434
+      dp->CR2 = I2C_CR2_ITERREN | I2C_CR2_DMAEN;
435
+#else
436
+      dp->CR2 = I2C_CR2_ITERREN;
437
+#endif
438
     }
439
 #endif /* STM32_I2C_USE_I2C1 */
440
 
441
 #if STM32_I2C_USE_I2C2
442
     if (&I2CD2 == i2cp) {
443
+#if STM32_I2C_I2C2_USE_DMA
444
       bool b;
445
 
446
+      i2cp->txdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
447
+                        STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
448
+                        STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
449
+                        STM32_DMA_CR_DIR_M2P;
450
+      i2cp->rxdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
451
+                        STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
452
+                        STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
453
+                        STM32_DMA_CR_DIR_P2M;
454
+#endif
455
+
456
       rccResetI2C2();
457
+
458
+#if STM32_I2C_I2C2_USE_DMA
459
       b = dmaStreamAllocate(i2cp->dmarx,
460
                             STM32_I2C_I2C2_IRQ_PRIORITY,
461
                             (stm32_dmaisr_t)i2c_lld_serve_rx_end_irq,
462
@@ -590,22 +837,52 @@ void i2c_lld_start(I2CDriver *i2cp) {
463
                             (stm32_dmaisr_t)i2c_lld_serve_tx_end_irq,
464
                             (void *)i2cp);
465
       osalDbgAssert(!b, "stream already allocated");
466
+#endif
467
+
468
       rccEnableI2C2(true);
469
       nvicEnableVector(I2C2_EV_IRQn, STM32_I2C_I2C2_IRQ_PRIORITY);
470
       nvicEnableVector(I2C2_ER_IRQn, STM32_I2C_I2C2_IRQ_PRIORITY);
471
 
472
+#if STM32_I2C_I2C2_USE_DMA
473
       i2cp->rxdmamode |= STM32_DMA_CR_CHSEL(I2C2_RX_DMA_CHANNEL) |
474
                        STM32_DMA_CR_PL(STM32_I2C_I2C2_DMA_PRIORITY);
475
       i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C2_TX_DMA_CHANNEL) |
476
                        STM32_DMA_CR_PL(STM32_I2C_I2C2_DMA_PRIORITY);
477
+
478
+      /* I2C registers pointed by the DMA.*/
479
+      dmaStreamSetPeripheral(i2cp->dmarx, &dp->DR);
480
+      dmaStreamSetPeripheral(i2cp->dmatx, &dp->DR);
481
+#endif
482
+
483
+      /* Reset i2c peripheral.*/
484
+      dp->CR1 = I2C_CR1_SWRST;
485
+      dp->CR1 = 0;
486
+#if STM32_I2C_I2C2_USE_DMA
487
+      dp->CR2 = I2C_CR2_ITERREN | I2C_CR2_DMAEN;
488
+#else
489
+      dp->CR2 = I2C_CR2_ITERREN;
490
+#endif
491
     }
492
 #endif /* STM32_I2C_USE_I2C2 */
493
 
494
 #if STM32_I2C_USE_I2C3
495
     if (&I2CD3 == i2cp) {
496
+#if STM32_I2C_I2C3_USE_DMA
497
       bool b;
498
 
499
+      i2cp->txdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
500
+                        STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
501
+                        STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
502
+                        STM32_DMA_CR_DIR_M2P;
503
+      i2cp->rxdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
504
+                        STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
505
+                        STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
506
+                        STM32_DMA_CR_DIR_P2M;
507
+#endif
508
+
509
       rccResetI2C3();
510
+
511
+#if STM32_I2C_I2C3_USE_DMA
512
       b = dmaStreamAllocate(i2cp->dmarx,
513
                             STM32_I2C_I2C3_IRQ_PRIORITY,
514
                             (stm32_dmaisr_t)i2c_lld_serve_rx_end_irq,
515
@@ -616,27 +893,35 @@ void i2c_lld_start(I2CDriver *i2cp) {
516
                             (stm32_dmaisr_t)i2c_lld_serve_tx_end_irq,
517
                             (void *)i2cp);
518
       osalDbgAssert(!b, "stream already allocated");
519
+#endif
520
+
521
       rccEnableI2C3(true);
522
       nvicEnableVector(I2C3_EV_IRQn, STM32_I2C_I2C3_IRQ_PRIORITY);
523
       nvicEnableVector(I2C3_ER_IRQn, STM32_I2C_I2C3_IRQ_PRIORITY);
524
 
525
+#if STM32_I2C_I2C3_USE_DMA
526
       i2cp->rxdmamode |= STM32_DMA_CR_CHSEL(I2C3_RX_DMA_CHANNEL) |
527
                        STM32_DMA_CR_PL(STM32_I2C_I2C3_DMA_PRIORITY);
528
       i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C3_TX_DMA_CHANNEL) |
529
                        STM32_DMA_CR_PL(STM32_I2C_I2C3_DMA_PRIORITY);
530
+
531
+      /* I2C registers pointed by the DMA.*/
532
+      dmaStreamSetPeripheral(i2cp->dmarx, &dp->DR);
533
+      dmaStreamSetPeripheral(i2cp->dmatx, &dp->DR);
534
+#endif
535
+
536
+      /* Reset i2c peripheral.*/
537
+      dp->CR1 = I2C_CR1_SWRST;
538
+      dp->CR1 = 0;
539
+#if STM32_I2C_I2C3_USE_DMA
540
+      dp->CR2 = I2C_CR2_ITERREN | I2C_CR2_DMAEN;
541
+#else
542
+      dp->CR2 = I2C_CR2_ITERREN;
543
+#endif
544
     }
545
 #endif /* STM32_I2C_USE_I2C3 */
546
   }
547
 
548
-  /* I2C registers pointed by the DMA.*/
549
-  dmaStreamSetPeripheral(i2cp->dmarx, &dp->DR);
550
-  dmaStreamSetPeripheral(i2cp->dmatx, &dp->DR);
551
-
552
-  /* Reset i2c peripheral.*/
553
-  dp->CR1 = I2C_CR1_SWRST;
554
-  dp->CR1 = 0;
555
-  dp->CR2 = I2C_CR2_ITERREN | I2C_CR2_DMAEN;
556
-
557
   /* Setup I2C parameters.*/
558
   i2c_lld_set_clock(i2cp);
559
   i2c_lld_set_opmode(i2cp);
560
@@ -659,11 +944,13 @@ void i2c_lld_stop(I2CDriver *i2cp) {
561
 
562
     /* I2C disable.*/
563
     i2c_lld_abort_operation(i2cp);
564
-    dmaStreamRelease(i2cp->dmatx);
565
-    dmaStreamRelease(i2cp->dmarx);
566
 
567
 #if STM32_I2C_USE_I2C1
568
     if (&I2CD1 == i2cp) {
569
+#if STM32_I2C_I2C1_USE_DMA
570
+      dmaStreamRelease(i2cp->dmatx);
571
+      dmaStreamRelease(i2cp->dmarx);
572
+ #endif
573
       nvicDisableVector(I2C1_EV_IRQn);
574
       nvicDisableVector(I2C1_ER_IRQn);
575
       rccDisableI2C1();
576
@@ -672,6 +959,10 @@ void i2c_lld_stop(I2CDriver *i2cp) {
577
 
578
 #if STM32_I2C_USE_I2C2
579
     if (&I2CD2 == i2cp) {
580
+#if STM32_I2C_I2C2_USE_DMA
581
+      dmaStreamRelease(i2cp->dmatx);
582
+      dmaStreamRelease(i2cp->dmarx);
583
+ #endif
584
       nvicDisableVector(I2C2_EV_IRQn);
585
       nvicDisableVector(I2C2_ER_IRQn);
586
       rccDisableI2C2();
587
@@ -680,6 +971,10 @@ void i2c_lld_stop(I2CDriver *i2cp) {
588
 
589
 #if STM32_I2C_USE_I2C3
590
     if (&I2CD3 == i2cp) {
591
+#if STM32_I2C_I2C3_USE_DMA
592
+      dmaStreamRelease(i2cp->dmatx);
593
+      dmaStreamRelease(i2cp->dmarx);
594
+ #endif
595
       nvicDisableVector(I2C3_EV_IRQn);
596
       nvicDisableVector(I2C3_ER_IRQn);
597
       rccDisableI2C3();
598
@@ -730,10 +1025,43 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
599
   /* Releases the lock from high level driver.*/
600
   osalSysUnlock();
601
 
602
-  /* RX DMA setup.*/
603
-  dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
604
-  dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
605
-  dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
606
+  /* RX (DMA) setup.*/
607
+#if STM32_I2C_USE_I2C1
608
+  if (&I2CD1 == i2cp) {
609
+#if STM32_I2C_I2C1_USE_DMA
610
+    dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
611
+    dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
612
+    dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
613
+#else
614
+    i2cp->rxbuf = rxbuf;
615
+    i2cp->rxbytes = rxbytes;
616
+#endif
617
+  }
618
+#endif
619
+#if STM32_I2C_USE_I2C2
620
+  if (&I2CD2 == i2cp) {
621
+#if STM32_I2C_I2C2_USE_DMA
622
+    dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
623
+    dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
624
+    dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
625
+#else
626
+    i2cp->rxbuf = rxbuf;
627
+    i2cp->rxbytes = rxbytes;
628
+#endif
629
+  }
630
+#endif
631
+#if STM32_I2C_USE_I2C3
632
+  if (&I2CD3 == i2cp) {
633
+#if STM32_I2C_I2C3_USE_DMA
634
+    dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
635
+    dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
636
+    dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
637
+#else
638
+    i2cp->rxbuf = rxbuf;
639
+    i2cp->rxbytes = rxbytes;
640
+#endif
641
+  }
642
+#endif
643
 
644
   /* Calculating the time window for the timeout on the busy bus condition.*/
645
   start = osalOsGetSystemTimeX();
646
@@ -810,15 +1138,61 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
647
   /* Releases the lock from high level driver.*/
648
   osalSysUnlock();
649
 
650
-  /* TX DMA setup.*/
651
-  dmaStreamSetMode(i2cp->dmatx, i2cp->txdmamode);
652
-  dmaStreamSetMemory0(i2cp->dmatx, txbuf);
653
-  dmaStreamSetTransactionSize(i2cp->dmatx, txbytes);
654
-
655
-  /* RX DMA setup.*/
656
-  dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
657
-  dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
658
-  dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
659
+  /* TX (DMA) and RX (DMA) setup */
660
+#if STM32_I2C_USE_I2C1
661
+  if (&I2CD1 == i2cp) {
662
+#if STM32_I2C_I2C1_USE_DMA
663
+    dmaStreamSetMode(i2cp->dmatx, i2cp->txdmamode);
664
+    dmaStreamSetMemory0(i2cp->dmatx, txbuf);
665
+    dmaStreamSetTransactionSize(i2cp->dmatx, txbytes);
666
+
667
+    dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
668
+    dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
669
+    dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
670
+#else
671
+    i2cp->txbuf = txbuf;
672
+    i2cp->txbytes = txbytes;
673
+    i2cp->rxbuf = rxbuf;
674
+    i2cp->rxbytes = rxbytes;
675
+#endif
676
+  }
677
+#endif
678
+#if STM32_I2C_USE_I2C2
679
+  if (&I2CD2 == i2cp) {
680
+#if STM32_I2C_I2C2_USE_DMA
681
+    dmaStreamSetMode(i2cp->dmatx, i2cp->txdmamode);
682
+    dmaStreamSetMemory0(i2cp->dmatx, txbuf);
683
+    dmaStreamSetTransactionSize(i2cp->dmatx, txbytes);
684
+
685
+    dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
686
+    dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
687
+    dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
688
+#else
689
+    i2cp->txbuf = txbuf;
690
+    i2cp->txbytes = txbytes;
691
+    i2cp->rxbuf = rxbuf;
692
+    i2cp->rxbytes = rxbytes;
693
+#endif
694
+  }
695
+#endif
696
+#if STM32_I2C_USE_I2C3
697
+  if (&I2CD3 == i2cp) {
698
+#if STM32_I2C_I2C3_USE_DMA
699
+    dmaStreamSetMode(i2cp->dmatx, i2cp->txdmamode);
700
+    dmaStreamSetMemory0(i2cp->dmatx, txbuf);
701
+    dmaStreamSetTransactionSize(i2cp->dmatx, txbytes);
702
+
703
+    dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
704
+    dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
705
+    dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
706
+#else
707
+    i2cp->txbuf = txbuf;
708
+    i2cp->txbytes = txbytes;
709
+    i2cp->rxbuf = rxbuf;
710
+    i2cp->rxbytes = rxbytes;
711
+#endif
712
+  }
713
+#endif
714
 
715
   /* Calculating the time window for the timeout on the busy bus condition.*/
716
   start = osalOsGetSystemTimeX();
717
diff --git a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h
718
index 1328d47..68f91e1 100644
719
--- a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h
720
+++ b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h
721
@@ -104,6 +104,33 @@
722
 #endif
723
 
724
 /**
725
+ * @brief   I2C1 DMA enable switch.
726
+ * @details If set to @p TRUE the I2C1 driver will use DMA.
727
+ * @note    The default is @p TRUE.
728
+ */
729
+#if !defined(STM32_I2C_I2C1_USE_DMA) || defined(__DOXYGEN__)
730
+#define STM32_I2C_I2C1_USE_DMA              TRUE
731
+#endif
732
+
733
+/**
734
+ * @brief   I2C2 DMA enable switch.
735
+ * @details If set to @p TRUE the I2C2 driver will use DMA.
736
+ * @note    The default is @p TRUE.
737
+ */
738
+#if !defined(STM32_I2C_I2C2_USE_DMA) || defined(__DOXYGEN__)
739
+#define STM32_I2C_I2C2_USE_DMA              TRUE
740
+#endif
741
+
742
+/**
743
+ * @brief   I2C3 DMA enable switch.
744
+ * @details If set to @p TRUE the I2C3 driver will use DMA.
745
+ * @note    The default is @p TRUE.
746
+ */
747
+#if !defined(STM32_I2C_I2C3_USE_DMA) || defined(__DOXYGEN__)
748
+#define STM32_I2C_I2C3_USE_DMA              TRUE
749
+#endif
750
+
751
+/**
752
 * @brief   I2C1 DMA priority (0..3|lowest..highest).
753
 * @note    The priority level is used for both the TX and RX DMA streams but
754
 *          because of the streams ordering the RX stream has always priority
755
@@ -250,16 +277,19 @@
756
 #endif
757
 
758
 #if STM32_I2C_USE_I2C1 &&                                                   \
759
+    STM32_I2C_I2C1_USE_DMA &&                                               \
760
     !STM32_DMA_IS_VALID_PRIORITY(STM32_I2C_I2C1_DMA_PRIORITY)
761
 #error "Invalid DMA priority assigned to I2C1"
762
 #endif
763
 
764
 #if STM32_I2C_USE_I2C2 &&                                                   \
765
+    STM32_I2C_I2C2_USE_DMA &&                                               \
766
     !STM32_DMA_IS_VALID_PRIORITY(STM32_I2C_I2C2_DMA_PRIORITY)
767
 #error "Invalid DMA priority assigned to I2C2"
768
 #endif
769
 
770
 #if STM32_I2C_USE_I2C3 &&                                                   \
771
+    STM32_I2C_I2C3_USE_DMA &&                                               \
772
     !STM32_DMA_IS_VALID_PRIORITY(STM32_I2C_I2C3_DMA_PRIORITY)
773
 #error "Invalid DMA priority assigned to I2C3"
774
 #endif
775
@@ -316,7 +346,10 @@
776
 #endif
777
 #endif /* STM32_ADVANCED_DMA */
778
 
779
-#if !defined(STM32_DMA_REQUIRED)
780
+#if ((STM32_I2C_USE_I2C1 && STM32_I2C_I2C1_USE_DMA) ||                       \
781
+     (STM32_I2C_USE_I2C2 && STM32_I2C_I2C2_USE_DMA) ||                       \
782
+     (STM32_I2C_USE_I2C3 && STM32_I2C_I2C3_USE_DMA)) &&                      \
783
+    !defined(STM32_DMA_REQUIRED)
784
 #define STM32_DMA_REQUIRED
785
 #endif
786
 
787
@@ -437,21 +470,52 @@ struct I2CDriver {
788
    */
789
   i2caddr_t                 addr;
790
   /**
791
-   * @brief RX DMA mode bit mask.
792
-   */
793
-  uint32_t                  rxdmamode;
794
-  /**
795
-   * @brief TX DMA mode bit mask.
796
-   */
797
-  uint32_t                  txdmamode;
798
-  /**
799
-   * @brief     Receive DMA channel.
800
-   */
801
-  const stm32_dma_stream_t  *dmarx;
802
-  /**
803
-   * @brief     Transmit DMA channel.
804
+   * @brief   Anonymous union to store transmission related data for either DMA or non-DMA mode.
805
    */
806
-  const stm32_dma_stream_t  *dmatx;
807
+  union {
808
+    /**
809
+     * @brief   Anonymous struct to store data for DMA mode.
810
+     */
811
+    struct {
812
+      /**
813
+       * @brief RX DMA mode bit mask.
814
+       */
815
+      uint32_t                  rxdmamode;
816
+      /**
817
+       * @brief TX DMA mode bit mask.
818
+       */
819
+      uint32_t                  txdmamode;
820
+      /**
821
+       * @brief     Receive DMA channel.
822
+       */
823
+      const stm32_dma_stream_t  *dmarx;
824
+      /**
825
+       * @brief     Transmit DMA channel.
826
+       */
827
+      const stm32_dma_stream_t  *dmatx;
828
+    };
829
+    /**
830
+     * @brief   Anonymous struct to store data for non-DMA mode.
831
+     */
832
+    struct {
833
+      /**
834
+       * @brief   Receive buffer.
835
+       */
836
+      uint8_t                   *rxbuf;
837
+      /**
838
+       * @brief   Size of the receive buffer.
839
+       */
840
+      size_t                    rxbytes;
841
+      /**
842
+       * @brief   Transmit buffer.
843
+       */
844
+      const uint8_t             *txbuf;
845
+      /**
846
+       * @brief   Size of the transmit buffer.
847
+       */
848
+      size_t                    txbytes;
849
+    };
850
+  };
851
   /**
852
    * @brief     Pointer to the I2Cx registers block.
853
    */
kernel/patches/Introduced-I2C-without-DMA.patch
1
From 736d3be25b7389b6130e0c372328aa56e2532250 Mon Sep 17 00:00:00 2001
2
From: =?UTF-8?q?Thomas=20Sch=C3=B6pping?= <tschoepp@cit-ec.uni-bielefeld.de>
3
Date: Mon, 12 Jun 2017 17:28:49 +0200
4
Subject: [PATCH] Introduced I2C without DMA (I2Cv1 only).
5

  
6
---
7
 os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c | 181 ++++++++++++++++++++++++++++-
8
 os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h |  30 +++++
9
 2 files changed, 210 insertions(+), 1 deletion(-)
10

  
11
diff --git a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
12
index 20b8cf8..b2cfb59 100644
13
--- a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
14
+++ b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c
15
@@ -34,6 +34,7 @@
16
 /* Driver local definitions.                                                 */
17
 /*===========================================================================*/
18
 
19
+#if STM32_I2C_USE_DMA
20
 #define I2C1_RX_DMA_CHANNEL                                                 \
21
   STM32_DMA_GETCHANNEL(STM32_I2C_I2C1_RX_DMA_STREAM,                        \
22
                        STM32_I2C1_RX_DMA_CHN)
23
@@ -57,6 +58,7 @@
24
 #define I2C3_TX_DMA_CHANNEL                                                 \
25
   STM32_DMA_GETCHANNEL(STM32_I2C_I2C3_TX_DMA_STREAM,                        \
26
                        STM32_I2C3_TX_DMA_CHN)
27
+#endif /* STM32_I2C_USE_DMA */
28
 
29
 /*===========================================================================*/
30
 /* Driver constants.                                                         */
31
@@ -72,6 +74,20 @@
32
 #define I2C_EV6_MASTER_REC_MODE_SELECTED                                    \
33
   ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) | I2C_SR1_ADDR))
34
 
35
+#define I2C_EV7_MASTER_REC_BYTE_RECEIVED                                    \
36
+  ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) | I2C_SR1_RXNE))
37
+
38
+#define I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP                               \
39
+  ((uint32_t)(                                      I2C_SR1_RXNE))
40
+
41
+#define I2C_EV7_2_EV7_3_MASTER_REC_BYTE_QUEUED                              \
42
+  ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY)<< 16) |                         \
43
+              I2C_SR1_BTF | I2C_SR1_RXNE))
44
+
45
+#define I2C_EV8_MASTER_BYTE_TRANSMITTING                                    \
46
+  ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY | I2C_SR2_TRA)<< 16) |           \
47
+              I2C_SR1_TXE))
48
+
49
 #define I2C_EV8_2_MASTER_BYTE_TRANSMITTED                                   \
50
   ((uint32_t)(((I2C_SR2_MSL | I2C_SR2_BUSY | I2C_SR2_TRA) << 16) |          \
51
               I2C_SR1_BTF | I2C_SR1_TXE))
52
@@ -128,9 +144,11 @@ static void i2c_lld_abort_operation(I2CDriver *i2cp) {
53
   dp->CR2 = 0;
54
   dp->SR1 = 0;
55
 
56
+#if STM32_I2C_USE_DMA
57
   /* Stops the associated DMA streams.*/
58
   dmaStreamDisable(i2cp->dmatx);
59
   dmaStreamDisable(i2cp->dmarx);
60
+#endif /* STM32_I2C_USE_DMA */
61
 }
62
 
63
 /**
64
@@ -247,12 +265,13 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
65
   uint32_t regSR2 = dp->SR2;
66
   uint32_t event = dp->SR1;
67
 
68
+#if STM32_I2C_USE_DMA
69
   /* Interrupts are disabled just before dmaStreamEnable() because there
70
      is no need of interrupts until next transaction begin. All the work is
71
      done by the DMA.*/
72
   switch (I2C_EV_MASK & (event | (regSR2 << 16))) {
73
   case I2C_EV5_MASTER_MODE_SELECT:
74
-    if ((i2cp->addr >> 8) > 0) { 
75
+    if ((i2cp->addr >> 8) > 0) {
76
       /* 10-bit address: 1 1 1 1 0 X X R/W */
77
       dp->DR = 0xF0 | (0x6 & (i2cp->addr >> 8)) | (0x1 & i2cp->addr);
78
     } else {
79
@@ -292,8 +311,125 @@ static void i2c_lld_serve_event_interrupt(I2CDriver *i2cp) {
80
   /* Clear ADDR flag. */
81
   if (event & (I2C_SR1_ADDR | I2C_SR1_ADD10))
82
     (void)dp->SR2;
83
+#else
84
+  switch (I2C_EV_MASK & (event | (regSR2 << 16))) {
85
+  case I2C_EV5_MASTER_MODE_SELECT:
86
+    dp->CR2 |= I2C_CR2_ITBUFEN;
87
+    dp->DR = i2cp->addr;
88
+    break;
89
+  case I2C_EV6_MASTER_TRA_MODE_SELECTED:
90
+    (void)dp->SR2; // clear ADDR flag
91
+    /* EV8_1 */
92
+    dp->DR = *(i2cp->txbuf);
93
+
94
+    ++i2cp->txbuf;
95
+    --i2cp->txbytes;
96
+
97
+    /* if N == 1, skip the I2C_EV8_MASTER_BYTE_TRANSMITTING event
98
+     * but enter I2C_EV8_2_MASTER_BYTE_TRANSMITTED next */
99
+    if (i2cp->txbytes == 0) {
100
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
101
+    }
102
+    break;
103
+  case I2C_EV6_MASTER_REC_MODE_SELECTED:
104
+    switch (i2cp->rxbytes) {
105
+    case 1:
106
+      dp->CR1 &= ~I2C_CR1_ACK;
107
+      (void)dp->SR2; // clear ADDR flag
108
+      dp->CR1 |= I2C_CR1_STOP;
109
+      break;
110
+    case 2:
111
+      (void)dp->SR2; // clear ADDR flag
112
+      /* EV6_1 */
113
+      dp->CR1 |= I2C_CR1_POS;
114
+      dp->CR1 &= ~I2C_CR1_ACK;
115
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
116
+      break;
117
+    case 3: /* N == 3 is a very special case, since EV7 is completely skipped */
118
+      (void)dp->SR2; // clear ADDR flag
119
+      /* Disable the I2C_EV7_MASTER_REC_BYTE_RECEIVED event
120
+       * but enter I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP next */
121
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
122
+      break;
123
+    default: /* N > 2 */
124
+      (void)dp->SR2; // clear ADDR flag
125
+      break;
126
+    }
127
+    break;
128
+  case I2C_EV7_MASTER_REC_BYTE_RECEIVED:
129
+    if (i2cp->rxbytes > 3) {
130
+      *(i2cp->rxbuf) = dp->DR;
131
+      ++i2cp->rxbuf;
132
+      --i2cp->rxbytes;
133
+    }
134
+    if (i2cp->rxbytes == 3) {
135
+      /* Disable this event for DataN-2, but force into event
136
+       * I2C_EV7_2_EV7_3_MASTER_REC_BYTE_RECEIVED_QUEUED by not reading dp->DR. */
137
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
138
+    }
139
+    break;
140
+  case I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP:
141
+    osalDbgAssert(i2cp->rxbytes == 1, "more than 1 byte to be received");
142
+    *(i2cp->rxbuf) = dp->DR;
143
+    --i2cp->rxbytes;
144
+    dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
145
+    _i2c_wakeup_isr(i2cp);
146
+    break;
147
+  case I2C_EV7_2_EV7_3_MASTER_REC_BYTE_QUEUED:
148
+    if (i2cp->rxbytes == 3) {
149
+      /* EV7_2 (N > 2) */
150
+      dp->CR1 &= ~I2C_CR1_ACK;
151
+      *(i2cp->rxbuf) = dp->DR;
152
+      ++i2cp->rxbuf;
153
+      dp->CR1 |= I2C_CR1_STOP;
154
+      *(i2cp->rxbuf) = dp->DR;
155
+      ++i2cp->rxbuf;
156
+      i2cp->rxbytes -= 2;
157
+      /* enable I2C_EV7_MASTER_REC_BYTE_RECEIVED_STOP event */
158
+      dp->CR2 |= I2C_CR2_ITBUFEN;
159
+    } else {
160
+      /* EV7_3 (N == 2) */
161
+      dp->CR1 |= I2C_CR1_STOP;
162
+      *(i2cp->rxbuf) = dp->DR;
163
+      ++i2cp->rxbuf;
164
+      *(i2cp->rxbuf) = dp->DR;
165
+      i2cp->rxbytes -= 2;
166
+
167
+      dp->CR1 &= ~I2C_CR1_POS;
168
+      dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
169
+
170
+      _i2c_wakeup_isr(i2cp);
171
+    }
172
+    break;
173
+  case I2C_EV8_MASTER_BYTE_TRANSMITTING:
174
+    dp->DR = *(i2cp->txbuf);
175
+    ++i2cp->txbuf;
176
+    --i2cp->txbytes;
177
+
178
+    /* if this was the last byte, ensure that this event is not entered again */
179
+    if (i2cp->txbytes == 0) {
180
+      dp->CR2 &= ~I2C_CR2_ITBUFEN;
181
+    }
182
+    break;
183
+  case I2C_EV8_2_MASTER_BYTE_TRANSMITTED:
184
+    if (i2cp->rxbytes > 0) {
185
+      /* start "read after write" operation (LSB of address = 1 => read) */
186
+      i2cp->addr |= 0x01;
187
+      dp->CR1 |= I2C_CR1_START | I2C_CR1_ACK;
188
+    } else {
189
+      dp->CR1 |= I2C_CR1_STOP;
190
+      dp->CR2 &= ~(I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN);
191
+      _i2c_wakeup_isr(i2cp);
192
+    }
193
+    break;
194
+  default:
195
+    osalDbgAssert(i2cp->rxbytes != 1, "more than 1 byte to be received");
196
+    break;
197
+  }
198
+#endif /* STM32_I2C_USE_DMA */
199
 }
200
 
201
+#if STM32_I2C_USE_DMA
202
 /**
203
  * @brief   DMA RX end IRQ handler.
204
  *
205
@@ -347,6 +483,7 @@ static void i2c_lld_serve_tx_end_irq(I2CDriver *i2cp, uint32_t flags) {
206
      of R/W transaction itself.*/
207
   dp->CR2 |= I2C_CR2_ITEVTEN;
208
 }
209
+#endif /* STM32_I2C_USE_DMA */
210
 
211
 /**
212
  * @brief   I2C error handler.
213
@@ -358,9 +495,11 @@ static void i2c_lld_serve_tx_end_irq(I2CDriver *i2cp, uint32_t flags) {
214
  */
215
 static void i2c_lld_serve_error_interrupt(I2CDriver *i2cp, uint16_t sr) {
216
 
217
+#if STM32_I2C_USE_DMA
218
   /* Clears interrupt flags just to be safe.*/
219
   dmaStreamDisable(i2cp->dmatx);
220
   dmaStreamDisable(i2cp->dmarx);
221
+#endif /* STM32_I2C_USE_DMA */
222
 
223
   i2cp->errors = I2C_NO_ERROR;
224
 
225
@@ -506,24 +645,30 @@ void i2c_lld_init(void) {
226
   i2cObjectInit(&I2CD1);
227
   I2CD1.thread = NULL;
228
   I2CD1.i2c    = I2C1;
229
+#if STM32_I2C_USE_DMA
230
   I2CD1.dmarx  = STM32_DMA_STREAM(STM32_I2C_I2C1_RX_DMA_STREAM);
231
   I2CD1.dmatx  = STM32_DMA_STREAM(STM32_I2C_I2C1_TX_DMA_STREAM);
232
+#endif /* STM32_I2C_USE_DMA */
233
 #endif /* STM32_I2C_USE_I2C1 */
234
 
235
 #if STM32_I2C_USE_I2C2
236
   i2cObjectInit(&I2CD2);
237
   I2CD2.thread = NULL;
238
   I2CD2.i2c    = I2C2;
239
+#if STM32_I2C_USE_DMA
240
   I2CD2.dmarx  = STM32_DMA_STREAM(STM32_I2C_I2C2_RX_DMA_STREAM);
241
   I2CD2.dmatx  = STM32_DMA_STREAM(STM32_I2C_I2C2_TX_DMA_STREAM);
242
+#endif /* STM32_I2C_USE_DMA */
243
 #endif /* STM32_I2C_USE_I2C2 */
244
 
245
 #if STM32_I2C_USE_I2C3
246
   i2cObjectInit(&I2CD3);
247
   I2CD3.thread = NULL;
248
   I2CD3.i2c    = I2C3;
249
+#if STM32_I2C_USE_DMA
250
   I2CD3.dmarx  = STM32_DMA_STREAM(STM32_I2C_I2C3_RX_DMA_STREAM);
251
   I2CD3.dmatx  = STM32_DMA_STREAM(STM32_I2C_I2C3_TX_DMA_STREAM);
252
+#endif /* STM32_I2C_USE_DMA */
253
 #endif /* STM32_I2C_USE_I2C3 */
254
 }
255
 
256
@@ -540,6 +685,7 @@ void i2c_lld_start(I2CDriver *i2cp) {
257
   /* If in stopped state then enables the I2C and DMA clocks.*/
258
   if (i2cp->state == I2C_STOP) {
259
 
260
+#if STM32_I2C_USE_DMA
261
     i2cp->txdmamode = STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
262
                       STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
263
                       STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
264
@@ -548,9 +694,11 @@ void i2c_lld_start(I2CDriver *i2cp) {
265
                       STM32_DMA_CR_MINC       | STM32_DMA_CR_DMEIE |
266
                       STM32_DMA_CR_TEIE       | STM32_DMA_CR_TCIE |
267
                       STM32_DMA_CR_DIR_P2M;
268
+#endif /* STM32_I2C_USE_DMA */
269
 
270
 #if STM32_I2C_USE_I2C1
271
     if (&I2CD1 == i2cp) {
272
+#if STM32_I2C_USE_DMA
273
       bool b;
274
 
275
       rccResetI2C1();
276
@@ -564,19 +712,23 @@ void i2c_lld_start(I2CDriver *i2cp) {
277
                             (stm32_dmaisr_t)i2c_lld_serve_tx_end_irq,
278
                             (void *)i2cp);
279
       osalDbgAssert(!b, "stream already allocated");
280
+#endif /* STM32_I2C_USE_DMA */
281
       rccEnableI2C1(FALSE);
282
       nvicEnableVector(I2C1_EV_IRQn, STM32_I2C_I2C1_IRQ_PRIORITY);
283
       nvicEnableVector(I2C1_ER_IRQn, STM32_I2C_I2C1_IRQ_PRIORITY);
284
 
285
+#if STM32_I2C_USE_DMA
286
       i2cp->rxdmamode |= STM32_DMA_CR_CHSEL(I2C1_RX_DMA_CHANNEL) |
287
                        STM32_DMA_CR_PL(STM32_I2C_I2C1_DMA_PRIORITY);
288
       i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C1_TX_DMA_CHANNEL) |
289
                        STM32_DMA_CR_PL(STM32_I2C_I2C1_DMA_PRIORITY);
290
+#endif /* STM32_I2C_USE_DMA */
291
     }
292
 #endif /* STM32_I2C_USE_I2C1 */
293
 
294
 #if STM32_I2C_USE_I2C2
295
     if (&I2CD2 == i2cp) {
296
+#if STM32_I2C_USE_DMA
297
       bool b;
298
 
299
       rccResetI2C2();
300
@@ -590,19 +742,23 @@ void i2c_lld_start(I2CDriver *i2cp) {
301
                             (stm32_dmaisr_t)i2c_lld_serve_tx_end_irq,
302
                             (void *)i2cp);
303
       osalDbgAssert(!b, "stream already allocated");
304
+#endif /* STM32_I2C_USE_DMA */
305
       rccEnableI2C2(FALSE);
306
       nvicEnableVector(I2C2_EV_IRQn, STM32_I2C_I2C2_IRQ_PRIORITY);
307
       nvicEnableVector(I2C2_ER_IRQn, STM32_I2C_I2C2_IRQ_PRIORITY);
308
 
309
+#if STM32_I2C_USE_DMA
310
       i2cp->rxdmamode |= STM32_DMA_CR_CHSEL(I2C2_RX_DMA_CHANNEL) |
311
                        STM32_DMA_CR_PL(STM32_I2C_I2C2_DMA_PRIORITY);
312
       i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C2_TX_DMA_CHANNEL) |
313
                        STM32_DMA_CR_PL(STM32_I2C_I2C2_DMA_PRIORITY);
314
+#endif /* STM32_I2C_USE_DMA */
315
     }
316
 #endif /* STM32_I2C_USE_I2C2 */
317
 
318
 #if STM32_I2C_USE_I2C3
319
     if (&I2CD3 == i2cp) {
320
+#if STM32_I2C_USE_DMA
321
       bool b;
322
 
323
       rccResetI2C3();
324
@@ -616,26 +772,35 @@ void i2c_lld_start(I2CDriver *i2cp) {
325
                             (stm32_dmaisr_t)i2c_lld_serve_tx_end_irq,
326
                             (void *)i2cp);
327
       osalDbgAssert(!b, "stream already allocated");
328
+#endif /* STM32_I2C_USE_DMA */
329
       rccEnableI2C3(FALSE);
330
       nvicEnableVector(I2C3_EV_IRQn, STM32_I2C_I2C3_IRQ_PRIORITY);
331
       nvicEnableVector(I2C3_ER_IRQn, STM32_I2C_I2C3_IRQ_PRIORITY);
332
 
333
+#if STM32_I2C_USE_DMA
334
       i2cp->rxdmamode |= STM32_DMA_CR_CHSEL(I2C3_RX_DMA_CHANNEL) |
335
                        STM32_DMA_CR_PL(STM32_I2C_I2C3_DMA_PRIORITY);
336
       i2cp->txdmamode |= STM32_DMA_CR_CHSEL(I2C3_TX_DMA_CHANNEL) |
337
                        STM32_DMA_CR_PL(STM32_I2C_I2C3_DMA_PRIORITY);
338
+#endif /* STM32_I2C_USE_DMA */
339
     }
340
 #endif /* STM32_I2C_USE_I2C3 */
341
   }
342
 
343
+#if STM32_I2C_USE_DMA
344
   /* I2C registers pointed by the DMA.*/
345
   dmaStreamSetPeripheral(i2cp->dmarx, &dp->DR);
346
   dmaStreamSetPeripheral(i2cp->dmatx, &dp->DR);
347
+#endif /* STM32_I2C_USE_DMA */
348
 
349
   /* Reset i2c peripheral.*/
350
   dp->CR1 = I2C_CR1_SWRST;
351
   dp->CR1 = 0;
352
+#if STM32_I2C_USE_DMA
353
   dp->CR2 = I2C_CR2_ITERREN | I2C_CR2_DMAEN;
354
+#else
355
+  dp->CR2 = I2C_CR2_ITERREN;
356
+#endif /* STM32_I2C_USE_DMA */
357
 
358
   /* Setup I2C parameters.*/
359
   i2c_lld_set_clock(i2cp);
360
@@ -659,8 +824,10 @@ void i2c_lld_stop(I2CDriver *i2cp) {
361
 
362
     /* I2C disable.*/
363
     i2c_lld_abort_operation(i2cp);
364
+#if STM32_I2C_USE_DMA
365
     dmaStreamRelease(i2cp->dmatx);
366
     dmaStreamRelease(i2cp->dmarx);
367
+#endif /* STM32_I2C_USE_DMA */
368
 
369
 #if STM32_I2C_USE_I2C1
370
     if (&I2CD1 == i2cp) {
371
@@ -730,10 +897,15 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
372
   /* Releases the lock from high level driver.*/
373
   osalSysUnlock();
374
 
375
+#if STM32_I2C_USE_DMA
376
   /* RX DMA setup.*/
377
   dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
378
   dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
379
   dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
380
+#else
381
+  i2cp->rxbuf = rxbuf;
382
+  i2cp->rxbytes = rxbytes;
383
+#endif /* STM32_I2C_USE_DMA */
384
 
385
   /* Calculating the time window for the timeout on the busy bus condition.*/
386
   start = osalOsGetSystemTimeX();
387
@@ -810,6 +982,7 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
388
   /* Releases the lock from high level driver.*/
389
   osalSysUnlock();
390
 
391
+#if STM32_I2C_USE_DMA
392
   /* TX DMA setup.*/
393
   dmaStreamSetMode(i2cp->dmatx, i2cp->txdmamode);
394
   dmaStreamSetMemory0(i2cp->dmatx, txbuf);
395
@@ -819,6 +992,12 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
396
   dmaStreamSetMode(i2cp->dmarx, i2cp->rxdmamode);
397
   dmaStreamSetMemory0(i2cp->dmarx, rxbuf);
398
   dmaStreamSetTransactionSize(i2cp->dmarx, rxbytes);
399
+#else
400
+  i2cp->txbuf = txbuf;
401
+  i2cp->txbytes = txbytes;
402
+  i2cp->rxbuf = rxbuf;
403
+  i2cp->rxbytes = rxbytes;
404
+#endif /* STM32_I2C_USE_DMA */
405
 
406
   /* Calculating the time window for the timeout on the busy bus condition.*/
407
   start = osalOsGetSystemTimeX();
408
diff --git a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h
409
index a812ceb..127c708 100644
410
--- a/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h
411
+++ b/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.h
412
@@ -76,6 +76,15 @@
413
 #endif
414
 
415
 /**
416
+ * @brief   I2C data transfer use dma switch.
417
+ * @details If set to @p TRUE the support for I2C DMA is included.
418
+ * @note    The default is @p FALSE.
419
+ */
420
+#if !defined(STM32_I2C_USE_DMA) || defined(__DOXYGEN__)
421
+#define STM32_I2C_USE_DMA                   TRUE
422
+#endif
423
+
424
+/**
425
  * @brief   I2C timeout on busy condition in milliseconds.
426
  */
427
 #if !defined(STM32_I2C_BUSY_TIMEOUT) || defined(__DOXYGEN__)
428
@@ -249,6 +258,7 @@
429
 #error "Invalid IRQ priority assigned to I2C3"
430
 #endif
431
 
432
+#if STM32_I2C_USE_DMA
433
 #if STM32_I2C_USE_I2C1 &&                                                   \
434
     !STM32_DMA_IS_VALID_PRIORITY(STM32_I2C_I2C1_DMA_PRIORITY)
435
 #error "Invalid DMA priority assigned to I2C1"
436
@@ -319,6 +329,7 @@
437
 #if !defined(STM32_DMA_REQUIRED)
438
 #define STM32_DMA_REQUIRED
439
 #endif
440
+#endif /* STM32_I2C_USE_DMA */
441
 
442
 /* Check clock range. */
443
 #if defined(STM32F4XX)
444
@@ -436,6 +447,7 @@ struct I2CDriver {
445
    * @brief     Current slave address without R/W bit.
446
    */
447
   i2caddr_t                 addr;
448
+#if STM32_I2C_USE_DMA
449
   /**
450
    * @brief RX DMA mode bit mask.
451
    */
452
@@ -452,6 +464,24 @@ struct I2CDriver {
453
    * @brief     Transmit DMA channel.
454
    */
455
   const stm32_dma_stream_t  *dmatx;
456
+#else
457
+  /**
458
+   * @brief     Receive buffer.
459
+   */
460
+  uint8_t                   *rxbuf;
461
+  /**
462
+   * @brief     Receive buffer size.
463
+   */
464
+  size_t                    rxbytes;
465
+  /**
466
+   * @brief     Transmit buffer.
467
+   */
468
+  const uint8_t             *txbuf;
469
+  /**
470
+   * @brief     Transmit buffer size.
471
+   */
472
+  size_t                    txbytes;
473
+#endif /* STM32_I2C_USE_DMA */
474
   /**
475
    * @brief     Pointer to the I2Cx registers block.
476
    */
477
-- 
478
2.7.4
479

  
modules/DiWheelDrive_1-1/mcuconf.h
110 110
#define STM32_I2C_BUSY_TIMEOUT              50
111 111
#define STM32_I2C_I2C1_IRQ_PRIORITY         5
112 112
#define STM32_I2C_I2C2_IRQ_PRIORITY         5
113
#define STM32_I2C_I2C1_USE_DMA              TRUE
114
#define STM32_I2C_I2C2_USE_DMA              TRUE
113 115
#define STM32_I2C_I2C1_DMA_PRIORITY         3
114 116
#define STM32_I2C_I2C2_DMA_PRIORITY         3
115 117
#define STM32_I2C_DMA_ERROR_HOOK(i2cp)      osalSysHalt("DMA failure")
modules/LightRing_1-0/mcuconf.h
110 110
#define STM32_I2C_BUSY_TIMEOUT              50
111 111
#define STM32_I2C_I2C1_IRQ_PRIORITY         5
112 112
#define STM32_I2C_I2C2_IRQ_PRIORITY         5
113
#define STM32_I2C_I2C1_USE_DMA              TRUE
114
#define STM32_I2C_I2C2_USE_DMA              FALSE
113 115
#define STM32_I2C_I2C1_DMA_PRIORITY         3
114 116
#define STM32_I2C_I2C2_DMA_PRIORITY         3
115 117
#define STM32_I2C_DMA_ERROR_HOOK(i2cp)      osalSysHalt("DMA failure")
modules/LightRing_1-0/module.c
63 63
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
64 64
};
65 65

  
66
SPIConfig moduleHalSpiWlConfig = {
67
  /* circular buffer mode        */ false,
68
  /* callback function pointer   */ NULL,
69
  /* chip select line port       */ GPIOB,
70
  /* chip select line pad number */ GPIOB_WL_SS_N,
71
  /* CR1                         */ SPI_CR1_BR_0,
72
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
73
};
74

  
66 75
/*===========================================================================*/
67 76
/**
68 77
 * @name GPIO definitions
modules/LightRing_1-0/module.h
77 77
extern SPIConfig moduleHalSpiLightConfig;
78 78

  
79 79
/**
80
 * @brief   SPI interface driver for the wireless transceiver.
81
 */
82
#define MODULE_HAL_SPI_WL                       SPID2
83

  
84
/**
85
 * @brief   Configuration for the SPI interface driver to communicate with the wireless transceiver.
86
 */
87
extern SPIConfig moduleHalSpiWlConfig;
88

  
89
/**
80 90
 * @brief   Real-Time Clock driver.
81 91
 */
82 92
#define MODULE_HAL_RTC                          RTCD1
......
220 230
  i2cStart(&MODULE_HAL_I2C_EEPROM, &moduleHalI2cEepromConfig);                \
221 231
  /* SPI */                                                                   \
222 232
  spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig);                  \
233
  spiStart(&MODULE_HAL_SPI_WL, &moduleHalSpiWlConfig);                        \
223 234
}
224 235

  
225 236
/**
......
228 239
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
229 240
  /* SPI */                                                                   \
230 241
  spiStop(&MODULE_HAL_SPI_LIGHT);                                             \
242
  spiStop(&MODULE_HAL_SPI_WL);                                                \
231 243
  /* I2C */                                                                   \
232 244
  i2cStop(&MODULE_HAL_I2C_EEPROM);                                            \
233 245
  /* don't stop the serial driver so messages can still be printed */         \

Also available in: Unified diff