How to Manually Use DMA for USB Device
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?
