cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Flush USB Buffer

luk
Associate II
Posted on October 12, 2016 at 08:46

Hello all,

I'm using the ST Library for USB Communication via VCP and as CDC Device.Now I'm trying to flush the buffer, when the µC recieves a ''p'' from the PC. I already tried to set APP_Rx_ptr_in and APP_Rx_ptr_outto 0, but this has no effect.How can I flush the buffer properly? Thanks for any advice! Mark Edit: I tried something different, should this do the job?

USB_OTG_CORE_HANDLE USB_OTG_dev;
void FlushFifo(void)
{
USB_OTG_FlushTxFifo(&USB_OTG_dev, 0x10); /* all Tx FIFOs */
USB_OTG_FlushRxFifo(&USB_OTG_dev);
}

5 REPLIES 5
Walid FTITI_O
Senior II
Posted on October 12, 2016 at 13:06

Hiwer.mark,

Use the following function in STM32Fxx_ll_Usb. file:

/* Flush a Tx FIFO */
USB_FlushTxFifo (USB_OTG_GlobalTypeDef *USBx, uint32_t num )
/* Flush Rx FIFO */
USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)

-Hannibal-
luk
Associate II
Posted on October 12, 2016 at 16:37

Hi Hannibal,

unfortunately these functions are not available in the library I use.

Walid FTITI_O
Senior II
Posted on October 12, 2016 at 17:42

Hi wer.mark, 

To get help in the forum , you would give more details: wich device ? which hardware ? application purpuse?  Whcih driver/ library versions? share you code or taget parts .

-Hannibal-

luk
Associate II
Posted on October 13, 2016 at 07:39

Hi Hannibal,

I'm using a STM32F4 Discovery Board to measure the time between two edges. The library is based on the STM32_USB-Host-Device_Lib_V2.2.0 library. The buffer should be cleared when I press ''p'' on the keyboard, because sometimes when I press ''s'' to start the measurement again there are still old values which i recieve.

Thanks in advance

Walid FTITI_O
Senior II
Posted on October 17, 2016 at 15:30

Hi wer.mark, 

Are using DMA/ interrupt or polling for UART receive ?

Try to Clear the UART ORE pending flag before receive data.

Try to get help from the description in the driver on top 

''[..]

 

    In this Mode it is advised to use the following functions:

 

      (+) void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);

 

      (+) ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);

 

      (+) void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);

 

 

 

    *** DMA Mode ***

 

    ================

 

    [..]

 

    In DMA Mode, the USART communication can be managed by 2 DMA Channel requests:

 

      (#) USART_DMAReq_Tx: specifies the Tx buffer DMA transfer request

 

      (#) USART_DMAReq_Rx: specifies the Rx buffer DMA transfer request

 

    [..]

 

    In this Mode it is advised to use the following function:

 

      (+) void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);

-Hannibal-