STM32F1 DMA stream already allocated

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Thargon
Posts: 79
Joined: Wed Feb 04, 2015 5:03 pm
Location: CITEC, Bielefeld University, germany
Has thanked: 6 times
Been thanked: 10 times

STM32F1 DMA stream already allocated

Postby Thargon » Thu Sep 13, 2018 12:42 pm

Hi,

I encountered a DMA issue with my STM32F103 after porting my project to ChibiOS 18.2.x. When calling spiStart() on SPID2, I get a kernel panic in the spi_lld_start() function (DMA stream already allocated). The problem seems to be that I also use I2CD2, which allocates the same DMA channels before (if I call spiStart() before i2cStart() I get a similar panic from i2c_lld_start() ).

What confuses me, is that with ChibiOS 17.6.x I could use I2C2 and SPI2 at the same time without issues. I further noticed that the SPIConfig is not fully utilized as the cr2 field is never read. Hence, it makes no difference whether or not I set the SPI_CR1_RXDMAEN and SPI_CR1_TXDMAEN flags.

All in all, my questions are: Should it be possible to "share" the same DMA among multiple peripherals and there is a bug in 18.2.x, or was there a bug in 17.6.x (and all earlier versions) that such configurations were allowed? If its not possible, how can I disable DMA for I2C (I'd rather keep the SPI DMA even if i could disable it via the cr2 field)?

Best regards,
Thomas

User avatar
Giovanni
Site Admin
Posts: 11152
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 391 times
Been thanked: 322 times
Contact:

Re: STM32F1 DMA stream already allocated

Postby Giovanni » Thu Sep 13, 2018 1:51 pm

Hi,

You can share the DMA but you cannot start "sharing" drivers at same time.

Giovanni

Thargon
Posts: 79
Joined: Wed Feb 04, 2015 5:03 pm
Location: CITEC, Bielefeld University, germany
Has thanked: 6 times
Been thanked: 10 times

Re: STM32F1 DMA stream already allocated

Postby Thargon » Thu Sep 13, 2018 3:08 pm

Hi,

solved it!
Long time ago I wrote a patch (STM32/LLD/I2Cv1/) to allow non-DMA I2C communication, which relies on ISRs only. The patch could not be applied anymore with the latest ChibiOS but my script did not complain :oops: I reworked the patch, applied it and everything works like a charm :D

You can have a look at the patch here: https://opensource.cit-ec.de/projects/amiro-os/repository/revisions/master/entry/kernel/patches/I2C-without-DMA.patch
It comes only with a minimal overhead if you want to use some I2CDx with and some other without DMA. Otherwise there is no performance impact and moreover no additional runtime memory requirements in any case.
The patch also introduces new configuration for the I2C part in the mcuconf.h:

Code: Select all

/*
 * I2C driver system settings.
 */
#define STM32_I2C_USE_I2C1                  FALSE
#define STM32_I2C_USE_I2C2                  TRUE
#define STM32_I2C_BUSY_TIMEOUT              50
#define STM32_I2C_I2C1_IRQ_PRIORITY         5
#define STM32_I2C_I2C2_IRQ_PRIORITY         5
#define STM32_I2C_I2C1_USE_DMA              TRUE
#define STM32_I2C_I2C2_USE_DMA              FALSE
#define STM32_I2C_I2C1_DMA_PRIORITY         3
#define STM32_I2C_I2C2_DMA_PRIORITY         3
#define STM32_I2C_DMA_ERROR_HOOK(i2cp)      osalSysHalt("DMA failure")

The new STM32_I2C_I2Cx_USE_DMA macros allow to switch to non-DMA mode for each driver individually. If not set the LLD defaults to TRUE.

Best regards,
Thomas

PS: I actually posted the previous version of the patch some time ago here. In that version, however, it was not possible to set the mode for each I2CDx individually but only for the whole I2C LLD.

EDIT: Anyway, shouldn't the SPI driver react accordingly if I disable the DMA flags in the cr2 configuration? It's not my use case, but it is very confusing that parts of the configuration have no effect but are actually completely ignored.


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 1 guest