Page 2 of 3

Re: DMA2 support on F091 missing?

Posted: Sat Sep 23, 2017 2:37 pm
by FXCoder
Steve,
I took a closer look at the problem.
It seems to me that the DMA definitions are incorrect for the F091 section of STM32F0xx/stm32_registry.h and mcuconf.h.
Don't have time to verify all the device DMAs now but just check the RM0091 DMA section Table 31 for the assignments.
You'll see I2C1 is on DMA1, Stream 0, ch 1 & 2 (0 numbered) and on DMA1 Steam 2 ch 1 & 2 but definitions do not reflect this.
(Watch out for that channel numbering which is 1 numbered in table 31 but needs 0 numbered in DMA definitions.)
Fixes required in mcuconf.h and also in STM32F0xx/stm32_registry.h so that the xxx_DMA_CHN definitions are correct.
Probably good to review all the DMA definitions in STM32F0xx/stm32_registry.h

e.g. Example fix for I2C1_RX in STM32F0xx/stm32_registry.h...

Code: Select all

#define STM32_HAS_I2C1                      TRUE
#define STM32_I2C1_RX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(1, 0) |\
                                             STM32_DMA_STREAM_ID_MSK(1, 2))
#define STM32_I2C1_RX_DMA_CHN               0x00000202


Bob

Re: DMA2 support on F091 missing?

Posted: Sat Sep 23, 2017 11:55 pm
by FXCoder
I see that DMAV1 macros use +1 for stream IDs versus macros in DMAV2 which use 0 numbered (which is what I was looking at).

So ignore the prior post while I go back to the drawing board.

Re: DMA2 support on F091 missing?

Posted: Wed Sep 27, 2017 8:57 am
by steved
Made a little more progress on this.

There is a definite error in the registry settings for I2C2 port on the F091 - they don't support DMA2, and may be another value error. Starting around line 1879:

Code: Select all

/* I2C attributes.*/
#define STM32_HAS_I2C1                      TRUE
#define STM32_I2C1_RX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(1, 3) |\
                                             STM32_DMA_STREAM_ID_MSK(1, 7))
#define STM32_I2C1_RX_DMA_CHN               0x02000200
#define STM32_I2C1_TX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(1, 2) |\
                                             STM32_DMA_STREAM_ID_MSK(1, 6))
#define STM32_I2C1_TX_DMA_CHN               0x00200002      /* Looks wrong! Should be 0x00200020? */

#define STM32_HAS_I2C2                      TRUE            /*    All values updated */
#define STM32_I2C2_RX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(1, 5) |\
                                             STM32_DMA_STREAM_ID_MSK(2, 2))
#define STM32_I2C2_RX_DMA_CHN               0x00000020
#define STM32_I2C2_TX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(1, 4) |\
                                             STM32_DMA_STREAM_ID_MSK(2, 1))
#define STM32_I2C2_TX_DMA_CHN               0x00000002   

#define STM32_HAS_I2C3                      FALSE
#define STM32_HAS_I2C4                      FALSE

Found this when testing the effect of having both I2C2 and SPI1 using DMA2 (and no other peripherals using DMA). With this configuration (and the registry updated as above) the SPI works. So current hypothesis is that there's something which confuses the issue if both DMA controllers are used.

Re: DMA2 support on F091 missing?

Posted: Wed Sep 27, 2017 9:18 am
by Giovanni
I will commit this fix ASAP.

Giovanni

Re: DMA2 support on F091 missing?

Posted: Thu Sep 28, 2017 11:04 pm
by steved
While you're there, in the same area (i.e. F091/098 registry):
1. ADC1 DMA has an option for (3, 5) - should be (2,5) I think (line 1783)
2. SPI2 Tx should be (1, 5) and (1, 7) (line 1922)

Re: DMA2 support on F091 missing?

Posted: Sun Oct 01, 2017 3:04 pm
by Giovanni
Fixed as bug #889.

Thanks everybody.

Giovanni

Re: DMA2 support on F091 missing?

Posted: Sun Oct 01, 2017 9:30 pm
by steved
Giovanni wrote:Fixed as bug #889.

Unfortunately the fixes I, at least, have highlighted so far are only incidental to my original problem, which is still present.

It is possibly another manifestation of this problem

And the stripped down project I'm now using, posted earlier, is basically 'pure' ChibiOS with a few lines of my code.

Re: DMA2 support on F091 missing?

Posted: Wed Oct 04, 2017 3:38 pm
by steved
steved wrote:Found this when testing the effect of having both I2C2 and SPI1 using DMA2 (and no other peripherals using DMA). With this configuration (and the registry updated as above) the SPI works. So current hypothesis is that there's something which confuses the issue if both DMA controllers are used.

I've realised that this may be a red herring - finally registered that the relevant DMA channels for I2C2 and SPI1 are configured to share the same interrupt vector when the program doesn't work (and different vectors when the program does work). Had a trawl through the code and not found any reason for it, though.


Also, one of the mods to the F0 registry file didn't make it to trunk; around line 1883:

Code: Select all

#define STM32_HAS_I2C2                      TRUE
#define STM32_I2C2_RX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(1, 5) |\
                                             STM32_DMA_STREAM_ID_MSK(2, 2))
#define STM32_I2C2_RX_DMA_CHN               0x00020020
#define STM32_I2C2_TX_DMA_MSK               (STM32_DMA_STREAM_ID_MSK(1, 4) |\
                                             STM32_DMA_STREAM_ID_MSK(2, 1))
#define STM32_I2C2_TX_DMA_CHN               0x00002002   

Re: DMA2 support on F091 missing?

Posted: Wed Oct 04, 2017 3:53 pm
by Giovanni
Fixed thanks.

It is hard to track all the posted changes.

Giovanni

Re: DMA2 support on F091 missing?

Posted: Thu Oct 05, 2017 10:53 am
by steved
I'm now pretty confident that the problem is related to DMA interrupts; quite possibly the same problem as kreyl is encountering.

I've verified that the SPI transfer physically takes place - so the DMA operation itself succeeds.

However the (shared) DMA ISR isn't entered, and the SPI thread is suspended waiting for the transfer complete interrupt.

Looking at DMA2 registers after SPI thread suspended:

Code: Select all

   CCR3 = 0x108b (i.e. Tx complete interrupt enabled)
   CCR4 = 0x1099 (i.e. Rx interrupt disabled)
   DMA2_ISR = 0x7700 (i.e. interrupts pending from DMA channels 3, 4)
   SYSCFG_ITLINE11 = 0 (i.e. no pending interrupts from DMA Controller)

I didn't find the manual clear as to whether the flags in the ISR register are set even if the corresponding interrupt is masked; probably, but uncertain.

Not sure where to look next.

Don't think its changed, but I've reattached the test project in case.