USB disturbing DMA2 transactions

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

Moderator: RoccoMarco

Post Reply
joewa
Posts: 22
Joined: Tue May 13, 2014 10:40 pm

USB disturbing DMA2 transactions

Post by joewa »

Hi!
this thread is related to my previous one about bit-banging some GPIO using DMA2: viewtopic.php?f=16&t=3778

When I am using USB (FS) the DMA2-transactions become disturbed randomly.

This article describes a similar issue: https://vjordan.info/log/fpga/stm32-bar ... speed.html
Please see the last plot on the bottom.

He assumes that this happens because the CPU blocks the DMA when accessing the SRAM.

However, there is a (probably) a solution for that: I moved the buffer into sram2 while everything else remains into sram1. According to "Figure 4. STM32F446xC/E and Multi-AHB matrix" in the STM32F446 datasheet, there should be "no way" for the CPU to disturb DMA2 anymore:

Code: Select all

#define intoSRAM2  __attribute__((section(".ram2")))  __attribute__((aligned(4)))
volatile uint32_t buffer[8] intoSRAM2;

This solved the problem for me.

Now, I added USB to my project and the trouble starts again. This is my USB-config in mcuconf.h:

Code: Select all

#define STM32_USB_USE_OTG1                  TRUE   // USB OTG FS
#define STM32_USB_USE_OTG2                  FALSE   // USB OTG HS
#define STM32_USB_OTG1_IRQ_PRIORITY         14
#define STM32_USB_OTG2_IRQ_PRIORITY         14
#define STM32_USB_OTG1_RX_FIFO_SIZE         512
#define STM32_USB_OTG2_RX_FIFO_SIZE         1024
#define STM32_USB_OTG_THREAD_PRIO           LOWPRIO
#define STM32_USB_OTG_THREAD_STACK_SIZE     128
#define STM32_USB_OTGFIFO_FILL_BASEPRI      0


When I connect to USB, I start writing to the port through:

Code: Select all

void USB_VCP_send_string(unsigned char *ptr)
{
    while (*ptr != 0) {
        streamPut(&SDU1, *ptr);
        ptr++;
    }
}

This is called from a thread. The buffer is never touched after initialization.

Image

The purple signal is generated by DMA2 writing to GPIOA->BSRR.W. When the signal remains high, there is at least the respective byte not been transferred to the BSRR register. This happens almost regardless of the actual DMA2-request-frequency (this was 3.6MHz, but also at a few kHz).

Is it possible, that the USB driver has any effects to DMA2?

I would be happy about any ideas again!

Jörg
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: USB disturbing DMA2 transactions

Post by Giovanni »

Hi,

Is the DMA triggered by a timer?

The USB driver does nothing special, it just copies data from/to USB FIFOs through AHB, the rate is high (fast loops) so it is possible that the CPU introduces jitter on the DMA activity.

You may try putting some nops into the USB data copy routines loops and see if it makes a difference. Hopefully it would make the driver not starve the bus.

Giovanni
Post Reply