I2C DMA "stream already allocated"

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

Moderator: RoccoMarco

Post Reply
chrismerck
Posts: 21
Joined: Fri Mar 14, 2014 12:35 am
Been thanked: 4 times

I2C DMA "stream already allocated"

Post by chrismerck »

Hi,

I'm trying to bring up I2C on an Olimexino-STM32 (STM32F103-based).

When I step through with gdb, I see that i2cStart is failing with "stream already allocated".

I don't know what it could be that is using the DMA. I do have UARTs and Serial-over-USB enabled. Could that be it?

Code: Select all

 45 static I2CConfig i2c_cfg = {
 46   OPMODE_I2C,
 47   100000,
 48   STD_DUTY_CYCLE,
 49 };
 50
 51 static THD_WORKING_AREA(waTestThd, 128);
 52 static msg_t TestThd(void *arg) {
 53   (void)arg;
 54
 55   i2cStart(&I2CD1, &i2c_cfg);
 56
 57   uint8_t rxbuf[128];
 58   uint8_t txbuf[2];
 59   txbuf[0]=0;
 60   txbuf[1]=0;
 61
 62   // I2C
 63   while(1)
 64   {
 65     i2cAcquireBus(&I2CD1);
 66     i2cMasterTransmitTimeout(&I2CD1,
 67         /*addr*/ 0b1010000,
 68         /*txbuf*/ txbuf,
 69         /*txbytes*/ 2,
 70         /*rxbuf*/ rxbuf,
 71         /*rxbytes*/ 0,
 72         /*timeout(ticks)*/ MS2ST(4));
 73     i2cReleaseBus(&I2CD1);
 74   };
 75
 76   return 0;
 77 }



And in mcuconf.h:

Code: Select all

104 /*
105  * I2C driver system settings.
106  */
107 #define STM32_I2C_USE_I2C1                  TRUE
108 #define STM32_I2C_USE_I2C2                  FALSE
109 #define STM32_I2C_BUSY_TIMEOUT              50
110 #define STM32_I2C_I2C1_IRQ_PRIORITY         5
111 #define STM32_I2C_I2C2_IRQ_PRIORITY         5
112 #define STM32_I2C_I2C1_DMA_PRIORITY         3
113 #define STM32_I2C_I2C2_DMA_PRIORITY         3
114 #define STM32_I2C_DMA_ERROR_HOOK(i2cp)      osalSysHalt("DMA failure")


182 /*
183  * UART driver system settings.
184  */
185 #define STM32_UART_USE_USART1               TRUE
186 #define STM32_UART_USE_USART2               TRUE
187 #define STM32_UART_USE_USART3               FALSE
188 #define STM32_UART_USART1_IRQ_PRIORITY      12
189 #define STM32_UART_USART2_IRQ_PRIORITY      12
190 #define STM32_UART_USART3_IRQ_PRIORITY      12
191 #define STM32_UART_USART1_DMA_PRIORITY      0
192 #define STM32_UART_USART2_DMA_PRIORITY      0
193 #define STM32_UART_USART3_DMA_PRIORITY      0
194 #define STM32_UART_DMA_ERROR_HOOK(uartp)    osalSysHalt("DMA failure")
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C DMA "stream already allocated"

Post by Giovanni »

Hi,

Yes, on the STM32F1 DMA channels are shared among multiple peripherals so if you "start" drivers sharing the same DMAs then you get that error.

You can use both drivers but not at the same time, try start/use/stop....start/use/stop.

Giovanni
chrismerck
Posts: 21
Joined: Fri Mar 14, 2014 12:35 am
Been thanked: 4 times

Re: I2C DMA "stream already allocated"

Post by chrismerck »

It looks possible to run both drivers at once by tweaking the DMA_STREAM definitions in stm32_registry.h, but I don't see a way to override these from mcuconf.h.

I'll try hacking it first and if it works I'll see about making it override-able from the project's mcuconf.h.

So user can do something like this in mcuconf:

Code: Select all

  80 #define STM32_I2C_I2C1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 7)
  81 #define STM32_I2C_I2C1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 6)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C DMA "stream already allocated"

Post by Giovanni »

It is an hardware limitation, not something you can tweak.

Giovanni
chrismerck
Posts: 21
Joined: Fri Mar 14, 2014 12:35 am
Been thanked: 4 times

Re: I2C DMA "stream already allocated"

Post by chrismerck »

Ah, thanks. I read the Reference Manual and now I understand the hardware limitation.

My solution is simply to use the Serial driver rather than Uart.

There is also steved's solution to make the Uart driver run without DMA, but Serial is already written and tested so that works for me.
http://forum.chibios.org/phpbb/viewtopic.php?f=14&t=1002
Post Reply