Skip to main content
tony239955
Associate II
Jun 22, 2012 3:47 PM UTC
Question

VCP for STM32F4_Discovery

Posted on June 22, 2012 at 17:47

I have recently downloaded the latest USB libraries which include a virtual comms port project. However all the examples use the ''Eval'' boards which include an LCD etc. rather than the Discovery board which does not. I am trying to edit the configurations and files in IAR to work with the Discovery board but as a relative beginner at this, it is proving difficult. Is there an ST project for a VCP which will run on the Discovery board?

Tony
    This topic has been closed for replies.

    14 replies

    Tesla DeLorean
    Guru
    Nov 19, 2012 1:33 AM UTC
    Posted on November 19, 2012 at 02:33

    Or maybe I wasn't clear first time.

    The first time you didn't provide any code, so it wasn't clear what you had done. I don't see anything here that would change the baud rate on UART4 or 5 I'm not sure I like the way this is structured

    int main(void)
    {
    __IO uint32_t i = 0;
    USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
    RCC_Configuration();
    GPIO_Configuration();
    UART4_Configuration();
    UART5_Configuration();
    Enable_Interrupt();
    USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
    USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
    // GPIO_WriteBit(GPIOD, GPIO_Pin_5, Bit_RESET);
    //
    // while(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == 1);
    // while(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == 0);
    while(1)
    {
    // // while(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == 1);
    // //
    // // GPIO_ToggleBits(GPIOD, GPIO_Pin_5);
    // //
    // // while(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_6) == 0);
    // //
    // // GPIO_ToggleBits(GPIOD, GPIO_Pin_5);
    // //
    Length = VCP_get_char(&Buff[0]);
    if(Length)
    {
    while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET); // Wait for Empty
    USART_SendData(UART4, Buff[0]);
    Delay(0xFFFFFF);
    }
    }
    }

    Hopefully you don't have any while() loops in your routines called under interrupt. Not sure I see that code. I might attack it more like this :

    int main(void)
    {
    __IO uint32_t i = 0;
    RCC_Configuration();
    GPIO_Configuration();
    UART4_Configuration();
    UART5_Configuration();
    Enable_Interrupt();
    USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
    USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
    USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
    while(1)
    {
    if (USART_GetFlagStatus(UART4, USART_FLAG_TXE) == SET)
    {
    Length = VCP_get_char(&Buff[0]);
    if(Length)
    USART_SendData(UART4, Buff[0]);
    }
    } // while
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    taha_najmee
    Associate II
    Nov 19, 2012 1:58 AM UTC
    Posted on November 19, 2012 at 02:58

    I have attached my interrupt code with the previous comment as well. Although, I am not using any while loop in the interrupt.

    Well, I tried one thing. I commented out the USB_OTG and USB_Device code and checked only the UART output which still gives me the incorrect frame size. So I suppose that VCP doesn't have to do anything with it.

    Also I am trying to add your VCP files in my UART project just to see what happens, but the USB device is not recognized when I do that. So I am stuck badly on this problem.

    Ok, now I found what was wrong in my UART code. I didn't put the PLL to 8, it was still 25. But when I change it to 8 (thats what it is suppose to be, right?), then I dont get the right frame size. Currently reading the reference manual for for information.

    So in conclusion, if PLL is 25, UART works and if PLL is 8, VCP works. Is there any way to make it both work for same PLL or other clock settings?

    taha_najmee
    Associate II
    Nov 19, 2012 5:32 PM UTC
    Posted on November 19, 2012 at 18:32

    Clive,

    Will 25MHz external oscillator solve the problem? I am really confused about this situation. I dont want to add external components into my project if it is not necessary.
    Tesla DeLorean
    Guru
    Nov 19, 2012 6:06 PM UTC
    Posted on November 19, 2012 at 19:06

    The Crystal, PLL and HSE_VALUE must have coherent settings/values. Correct functioning is predicated on this.

    The STM32F4-Discovery has an 8 MHz crystal, the STM32xxx-EVAL boards have 25 MHz. The latter probably related to Ethernet. Neither is magically better than the other, but you can't ignore what the software is coded to expect. Fix whatever issues you have within the project.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..