cancel
Showing results for 
Search instead for 
Did you mean: 

How to Manually Use DMA for USB Device

mcho.19
Associate II

I made a High Speed ​​USB DEVICE using USB PHY with STM32F207.

When delivering data to the HOST, there are small-sized data (less than 512bytes) and large-sized data (more than 1Mbytes).

At this time, I want to transfer small-sized data without using DMA, and I want to transfer large-sized data using DMA.

For this purpose, DMA was set to DISABLE during initialization.

hpcd_USB_OTG_HS.Init.dma_enable = DISABLE;

And the following functions were created by referring to USB_CoreInit and USB_DevInit in stm32f2xx_ll_usb.c.

void SetModeDMA ( uint8_t mode )
{
	USB_OTG_GlobalTypeDef *USBx = hpcd_USB_OTG_HS.Instance;
 
	if ( mode == 1 )
	{
		hpcd_USB_OTG_HS.Init.dma_enable = 1U;
	    USBx->GAHBCFG |= USB_OTG_GAHBCFG_HBSTLEN_2;
	    USBx->GAHBCFG |= USB_OTG_GAHBCFG_DMAEN;
	    USBx->GINTMSK &= ~USB_OTG_GINTMSK_RXFLVLM;
 
	}
	else
	{
		hpcd_USB_OTG_HS.Init.dma_enable = 0U;
	    USBx->GAHBCFG &= ~USB_OTG_GAHBCFG_HBSTLEN_2;
	    USBx->GAHBCFG &= ~USB_OTG_GAHBCFG_DMAEN;
	    USBx->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM;
	}
}

After transferring small-size data, when transferring large-size data, call USB_SetModeDMA(1) before transfer, and then call USB_SetModeDMA(0) when the transfer is complete.

And try to transmit small size data, it will not be transmitted.

After initializing DMA to DISABLE, is it possible to transfer using DMA only when necessary?

And, when transferring with DMA, can data more than 0x80000 be transferred at once?

1 ACCEPTED SOLUTION

Accepted Solutions

> After initializing DMA to DISABLE, is it possible to transfer using DMA only when necessary?

Hard to tell. At first glance it may appear that yes, but the OTG module is picky, and I'd expect at least the Out endpoints (namely EP0) needs to be disabled/enabled. There may be more obstacles ahead.

JW

View solution in original post

4 REPLIES 4

> After initializing DMA to DISABLE, is it possible to transfer using DMA only when necessary?

Hard to tell. At first glance it may appear that yes, but the OTG module is picky, and I'd expect at least the Out endpoints (namely EP0) needs to be disabled/enabled. There may be more obstacles ahead.

JW

Thank you for answer

I can transfer 1 byte data or none multifle of 4 bytes data. In this case, if DMA is ENABLE, wouldn't it be a problem?

Also, can DMA transfers only be transferred up to a maximum of 0x7FFFF at a time?

I don't quite understand your question but again, the

OTG module is very poorly documented so maybe it's good to stick to existing implementations.

JW​

OK. Thank you​