Library 24- Virtual COM Port (VCP) for STM32F4

This library provides Virtual COM port on USB OTG. This means, that you don’t need external USB->UART converter (like FTDI) to communicate with computer. STM32F4xx will be seen to computer like COM port.

Library can be used on all STM32F4xx devices. It has also features to support STM32F4- and STM32F429 Discovery boards.

To use USB with HAL, check my HAL USB library.

Library

Features

  • Enables USB VCP
  • Works in USB FS mode
    • Default for STM32F4-Discovery board
  • Works in USB HS in FS mode
    • Default for STM32F429-Discovery board
  • Version 1.2 – March 08, 2015
    • Added options to detect if user has changed parameters in terminal (baudrate, stop bits, data bits, parity) in case you are doing USB<->UART converter

Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx EXTI
    • MISC
  • TM
    • defines.h
  • USB
    • USB CDC device stack provided by STMicroelectronics (included in library)





Pinout

As 2 options can be used, there are 2 pinouts:

USB FS Mode HS in FS Mode Description
Data + PA12 PB15 USB Data+ line
Data – PA11 PB14 USB Data- line
ID PA10 PB12 USB ID pin
VBUS PA9 PB13 USB activate

Notes:

  • STM32F4-Discovery has micro USB connected to USB FS mode
  • STM32F429-Discovery has micro USB connected to USB HS in FS mode
  • If you have USB->4 wires cable, you can connect both boards in both ways, but then you don’t have fancy connected.
  • Clock for STM32F429 was set down to 168MHz, because you can not get 48MHz for USB with 180MHz core clock

By default, library is set in FS mode, so pins PA11 and PA12 are in use. If you are working with STM32F429 Discovery board and you want to use microUSB connector instead of wires on pinheaders, then open your defines.h file and activate USB HS in FS mode:

You are now working in HS mode.

Default internal buffer size for received data is 128bytes. If you need more, you can set more in defines.h file using specific define:

When you connect board to USB to computer, there will be new COMx seen. For that, you also need USB VCP drivers provided by STMicroelectronics.

Note: In your terminal are options to set baudrate, stop bits, etc. Leave that at it is, these settings don’t care, because everything is configured by USB.

Precompiled versions

Some users has issues with setting project (example below) correctly (don’t know why) and I have precompile long time ago 2 versions of example for F4-Disco and F429-Discovery boards. This is now available here for download.

These examples has positive feedbacks as they work ok.

Download here.

Functions and enumerations

I have written some basic functions to work with data.

Example

USB VCP on STM32F4xx

USB VCP on STM32F4xx

I have used STM32F4-Discovery for this example with default settings, because STM32F4-Discovery has micro USB connected to FS mode (default mode).

View project on Github, download library below.

Icon
TM STM32F4 USB VCP Library

 

tilz0R

Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • oki handinata

    hi, I want to change the data received from the VCP into a numerical value that can be processed. I use itoa, but did not work. this my sample code

    if (TM_USB_VCP_Getc (& c) == TM_USB_VCP_DATA_OK) {

    x = itoa (c);
    }…

    can you help?

    • First, what is not working?

      Emm, so x is char?

      itoa basically returns pointer to character.

      Try to use sprintf instead

      http://www.cplusplus.com/reference/cstdlib/itoa/

      • oki handinata

        i send value 100 from pc to stm32f4, and use function TM_USB_VCP_Getc (& c) to receive data.x is char,then i convert value c use function atoi and put it into the variable x. when i compared value of variable x with integer 100 for blink led, it’s not working.this my code

        int main(void) {

        uint8_t c;

        __IO uint32_t i = 0;

        char a,x;

        unsigned char x1;

        unsigned int nilai,a1;

        /* System Init */

        SystemInit();

        LED_init ();

        /* Initialize LED’s. Make sure to check settings for your board in tm_stm32f4_disco.h file */

        TM_DISCO_LedInit();

        /* Initialize USB VCP */

        TM_USB_VCP_Init();

        while (1) {

        /* USB configured OK, drivers OK */

        if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {

        /* Turn on GREEN led */

        TM_DISCO_LedOn(LED_GREEN);

        //TM_DISCO_LedOff(LED_RED);

        /* If something arrived at VCP */

        if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) {

        /* Return data back */

        x = atoi (c);

        TM_USB_VCP_Putc(c);

        }

        }

        if (x==100)

        {for(a1=0;a1<100;a1++) {

        LED_On (LED_E);

        wait();

        LED_Off (LED_E);

        LED_On (LED_F);

        wait();

        LED_Off (LED_F);

        LED_On (LED_G);

        wait();

        LED_Off (LED_G);

        LED_On (LED_H);

        wait();

        LED_Off (LED_H);

        }

        }

        }

        • TM_USB_VCP_Getc() returns only 1 (one) byte of data, but “100” are 3 bytes.
          0x49, 0x48, 0x48.

          You have to handle 3 bytes, then convert data.

          Also, you can use TM_USB_VCP_Gets() to handle string, then convert it to integer.
          If you use this, send “n” after your string, so somethling like that: “100n”

          • oki handinata

            i still don’t understand.can you give me some example?please. i not success to use function TM_USB_VCP_Gets().

          • http://pastebin.com/CxSg13qe

            Example was tested on STM32F429-Discovery board.

            If you send “100” string from terminal, RED led will turn on.

  • Тетяна Марусенкова

    Could you explain, how to use your project with stm32f4discovery, please?

    • You have everything provided. Where you get stuck?

  • Тетяна Марусенкова

    I just open Options for Target, choose Device and STM32F407VG and that’s all, right?

  • liyuting123

    Where could I get the tm_stm32f4_disco.h ?

    • Here. Under project example you have link, download usb vcp library.

  • Dejan

    Hello,

    thank you for this library, but I have a problem… When I connect to PC it says device descriptor request failed. How can this be solved?

    • I have no idea what are you doing. It works for all abd should for you too.

      Which USB mode you use?

      • Dejan

        I just included your library to the project. I deleted defines.h and removed includes of it since it was actually empty (I use stm32f407 discovery board). I use it in default FS mode and micro usb connection.

        • contact me via email or add me to skype and i will help you figure it out.

          PS: did you install ST’s drivers?

  • Muhammad Azzam

    Dude u r a star :)) i’ve tried your accelerometer through spi project and it worked flawlessly and i’m going to try this vcp usb project :)) thanks a lot

  • Andres

    hello majerle, your web page is excelent, is what i find a lot. this works for me. Keep working! can a suggest a project whith mpu6050 gyro? thanks a lot.

    • Thanks.
      About gyro, it is on the move to my place, lib will be as soon as I get it.

  • Andres

    one question How to handle interrupts for cdc data incoming?

    • STM32F4 have interrupt lines for usb communication.

  • Greg

    hi, this all looks like very useful code but I’m a little confused.

    The link above for defines.h actually delivers defines.rar. unrar says this is not a rar archive. Linux ‘file’ command says it’s a zip ( first four byte identifier ) and unzip will read it but produces garbage.

    If I copy from github there’s no defines.h so I get compiler errors.

  • Greg

    The files provided in the final download link at the bottom of the article to not compile. There are loads of undefined symbols. Clearly there are missing includes and missing library files.

    Perhaps this depends upon of -I directives that are set up in Keil or something.

    It really would save a lot of time wasting if it was clearly explained in the readme what the file structure and what command line directives need to be added or if the files had complete #includes needed to make it compile.

    AFAICT this also needs files from your git hub account but those do not compile either because they are missing files contained here.

    • at the bottom of the article says “Download library”, not entire project.
      If you download defines.h example from dependencies section, you should be able to open it.

      It works just fine for me.
      Also, clone entire from Github works just ok. I don’t know what -l directive means.

      defines.h file must be there, but it can be empty. You can create a new file, leave it empty and add it to project. It will work.

      • Greg

        Thanks for the reply.
        I tried a blank defines.h as my first step, not a prob. Have you checked the download for that file here. Something seems wrong as I detailed in my message below.

        You say github ‘works’ but I just cloned the whole thing and still can not buld the vcp thing form anywhere I have found. There seem to be lots of interdependant code and I’m wasting time grep-ing the tree to find out where all the bits are to include them.

        I’m not working in Keil and I suspect the necessary includes are not there to build from command line compiler command. I’m using arm-none-eabi-gcc

        Is there one place in the git tree where I can issue a compiler command to build the vcp lib that can be used with the code above?

        thanks.

        • defines.h file works like it should.
          If you clone from github, then you also need to use keil to compile. In project there is no CMSIS functions for STM32F4 because Keil has these in program, so I don’t need to include them.

          It looks this is problem for you. You need STM32F4xx DSP and CMSIS standard peripheral libraries to successfully build. I have tested code on GCC, works great, so it is problem somewhere in your side.

          Again. Defines.h download works just great.

          • Greg

            Digging around in the config files ‘project’ files:

            .TM;.User;..0-STM32F429_LIBRARIES;..0-STM32F429_LIBRARIESusb_cdc_device

            Maybe that a clue…

            Those either need a #include or a command line -I ./TM …. etc

            I have compiled other code that uses the CMSIS libs, that is not a “problem” for me. What it is wasting a lot of time is that there are bunches of code here that are interdependant and nothing I can find that tells me what I need to bring together to get it to build.

            When you say it works with gcc , do you mean using gcc from within Keil ??

            I’ve copied code from the rar file download here in ./TM , that is presumably where it has to go.

          • Greg

            Well it seems that you have an incomplete copy of CMSIS library bode in your tree. I added include directives to get to some header files but then had to link to an external copy ( 4 levels up and out of the git clone ) to get the rest. That fixes all the missing symbols from the ST code.

            Presumably Keil also links into this somewhere else on your system automatically and you made an incomplete copy.

            That’s the problem with working with IDEs, lots of button pressing and no one is really sure what they are doing anymore.

            arm-none-eabi-gcc -g -O2 -Wall -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16
            -I. -I../STM32F4-Discovery_FW_V1.1.0/Utilities/STM32F4-Discovery
            -I ../TM
            -I ../../01-STM32F4xx_Keil_CMSIS_Default_Project/CMSIS
            -I ../../00-STM32F429_LIBRARIES
            -I ../../00-STM32F429_LIBRARIES/usb_cdc_device
            -I ../../01-STM32F4xx_Keil_CMSIS_Default_Project/CMSIS/Include
            -I ../../STM32F4xx_StdPeriph_Driver/inc
            -I ../../../../STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include
            -I ../../../../STM32F4-Discovery_FW_V1.1.0/Libraries/ST/STM32F4xx/CMSIS/Include
            -I ../../../../STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc
            -I ../../..
            main.c

            That almost compiles, it just can’t find `TM_USB_VCP_Putc’ and friends which are declared external ….

            No time left to mess with this now but it looks like it may at least compile once I’ve wasted some more time.

          • Greg

            One missing file in the github tree is core_cm4_simd.h referenced from core_cm4.h
            There may be others.

  • lk

    Hi, I have a question. Did anybody try to connect the STM32F4Discovery board running VCP to Windows 8? I was able to compile the code but when I connect the board to PC I get Windows error “A request for the USB device descriptor failed.” and I’m not able to create the COM port. I would be greatful for any help.

    • Currently I don’t have Windows 8 installed, but I will make some research about that.

      • lk

        Will be very greatful, I’m struggling with it for some time and cannot find the solution.

      • lk

        I managed to verify it also on Windows 7 and I’m receiving the same error… It looks like there is something wrong with the uC code… The TM_USB_VCP_GetStatus() always returns an error…

        • It looks like you have problems on your side. For me, result is as expected.
          Also I know for at least 10 people that worked for them.

          Screen from terminal. From Windows 7
          http://screencloud.net/v/E7wb

          • lk

            Will try it in a minute, but I have a question, might be a silly one, but I cannot figure this out by myself. How does the TM_USB_VCP_INT_Status gets updated to TM_USB_VCP_CONNECTED ? I see the

            void USBD_USR_DeviceConfigured (void) {
            TM_USB_VCP_INT_Status = TM_USB_VCP_CONNECTED;
            }

            function, but I cannot find where it is called to update the status?

          • Magic 😉

            Well, you set this variable TM_USB_VCP_INT_Status in some file, and then my status function just return this value. search for status function.

          • lk

            Hi again. I’ve verified and the hex file you’ve sent me works. So it has something to do with the project code. Is there a possibility that you would send me the project that was used to build the hex file you’ve provided

          • It’s on my Github.

          • lk

            Right, I’m apparently blind 😉

  • sahar

    Hi

    I want to run a project that works in two usb modes, first it works in USB VCP mode and with a simple event it switches to USB MSC mode for read and write on a micro SD Card.I used this library: STM32_USB_Host-Device_Lib.V1.2.0 from http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257882#

    when it works in VCP mode, it uses USBD_Init() function and there is another USBD_Init() function for MSC mode. is it necessary to make it disconnect when I want to switch from VCP to MSC mode? or the second initial function does it?

    • Use vcp on one usb port and msc on another.

      In this package you have, are also examples for your needs.

      • sahar

        yes in this package there some dual core examples but I have stm32f4-discovery board, and it has one usb port,another is for programming…

        • Not true exactly, programming usb is not directly connected to f407.
          Usb micro is connected to usb fs mode, but on pins PB 14,15 you have usb hs, but pins are not connected on any connector. You can use wires to connect there.

          • sahar

            as I know usb hs needs an external IC too, right?

            it is ISP1705AET in stm3240G-EVAL boards.

            and what about VBUS and ID pins?

          • Only data+ and data- are need for usb.
            You can use internal phy too.

          • sahar

            how can I do this? can explain more please?

          • Contact me privatelly for 12hours and i will try to explain you.

          • sahar

            forgive me for questioning but how can I contact you privately?

          • Email.

          • sahar

            and what’s your email?

          • Greg

            it is written in each library header file from Majerle 🙂 just check any header file and you’ll find it. I do not want to post it direclty because of bots and so on 🙂

          • Thanks Greg 🙂

  • Hi,
    It is a very good exampe, I tried it and it is working fine on my stm32f429 discovery board. Now I have few questions, how will I increase the speed of data communication? Right now it seems like I am reading byte by byte using

    57 TM_USB_VCP_Result TM_USB_VCP_Getc(uint8_t* c) {
    58 /* Any data in buffer */
    59 if (tm_int_usb_vcp_buf_num > 0) {
    60 /* Check overflow */
    61 if (tm_int_usb_vcp_buf_out >= USB_VCP_RECEIVE_BUFFER_LENGTH) {
    62 tm_int_usb_vcp_buf_out = 0;
    63 }
    64 *c = TM_INT_USB_VCP_ReceiveBuffer[tm_int_usb_vcp_buf_out];
    65 TM_INT_USB_VCP_ReceiveBuffer[tm_int_usb_vcp_buf_out] = 0;
    66
    67 /* Set counters */
    68 tm_int_usb_vcp_buf_out++;
    69 tm_int_usb_vcp_buf_num–;
    70
    71 /* Data OK */
    72 return TM_USB_VCP_DATA_OK;
    73 }
    74 *c = 0;
    75 /* Data not ready */
    76 return TM_USB_VCP_DATA_EMPTY;
    77 }

    • Hi.
      Speed depends on USB mode, HS or FS.
      Every character that arrives on USB to STM, interrupt occured and this char is stored in internal cyclic buffer. You can then read him out with my functions.
      After you read it, char is deleted from buffer.

      • Thanks for quick reply 🙂
        Where exactly the tm_int_usb_vcp_buf_num is incremented?

  • Guest

    In this case, how

    will I increase the speed of data reception? No interrupt is used for USB? Where the tm_int_usb_vcp_buf_num is incremented outside this function? I couldn’t find tm_int_usb_vcp_buf_num anywhere other than this function. So it is a bit confusing 🙂 Also any way to receive a bulk of data say for example 64 bytes instead of 1 byte at a time so that I can increase the throughput ?

    • Interrupts are for USB, you will not increase speed, use external phy and usb HS then.

      • What is external phy? Can I use usb HS on stm32f429 micro usb port?

        • STM32F429 has internal “embedded phy” for USB HS, but not real HS speed. It’s configuration is “USB HS in FS” mode.
          If you want real HS speed, then you need external phy. External phy is external chip (PHY = Physical Layer) who converts USB data into high speed.

          • Oh so the stm32f429 doesn’t have an efficient phy compared to dedicated USB chips right? So does it means that if we are using USB 2.0 pendrive etc, we will not get real speed compared to that we are getting on a computer?
            Also I have a question, if (tm_int_usb_vcp_buf_num > 0) { ….
            How the tm_int_usb_vcp_buf_num is incremented? Where it is incrementing?

          • If you have external PHY chip,you can get speed as on computer.

            I will not describe how is my library been done. It is incremented somewhere in the files for USB CDC. Make a search.

  • Alirio Filho

    Mr. Tilen!
    Congratulations, again I do me board work, now with usb ^^ using your exemple. Marvelous!!! very easy.
    Thankfull again!

  • Dennis W

    Dear Mr Tilen

    Again, I congratulate you on your work. Using your libraries, I have made an door unlock control panel (touch screen, graphics, led, delay, usb_vcp). The stm32f429-discovery is a front end for a raspberry pi, interacting over USB_VCP.

    The code variously
    1) polls the touch screen,
    2) sends touch screen data to the Raspberry Pi, and
    3) receives data back from the PI.

    1 and 2 work ok, but I intermittently lose data transmitted from the Pi to the STM.

    I get data using the following code:

    if (TM_USB_VCP_Gets(inbuf, BUFFSIZE) == TM_USB_VCP_DATA_OK) {

    }

    I have a couple questions.
    – does the routine that reads the serial data work in the background, ie, is it interrupt driven?
    – do you have any idea how I could go about debugging this error?

    Thanks
    Dennis

    • Hi Dennis.

      You are using Gets function, which receives string.
      Gets will detect string, when n is received at the end of string. If there is no “n”, then you will stuck in a while loop and loose your data.

  • Dennis W

    Door unlocker next to the door.

  • Alex

    Hi,
    What is the maximum traffic capacity this VCP?
    I need 25-30 kb/s. My test showed about 1 kb, and more possible?
    Sorry my English!

    • Hi.
      Depends on USB mode. But about 12Mb/s for sure.
      You are doing something really wrong, if you have just 1kb.
      With USART at 115200 you get more then you.

      • Alex

        May be a program on Windows?
        I use Terminal 1.9 (Цin 7)
        I’ll check.

        • Alex

          Yes, the problem in Terminal. I use Hterm – very good – fast speed!
          Thans
          Alex

  • Hi,

    I’m trying to get this solution running. Unfortunately my first attempt failed. I’m using the STM32F4-Discovery board, and added the source files of this solution to CooCox’s CoIDE. The solution builds seamlessly, but when I try to connect the board to the computer I get the “A request for the USB device descriptor failed.” message, as the others before.
    Do you have any hints where should I look for the problem in my solution?

    Thank you,
    Zoltan

    • Hi.

      First, make sure you have correct PLL settings.
      Second, you can send me project on mail and I will take a look for you.

      • Hi,

        You were absolutely right. The xtal frequency was set to 25MHz instead of 8.

        Thank you,
        Zoltan

  • bobby

    After two weeks test, I made some new result for this library. It works very excellent in some situation.
    1.STM32 429 send 512 byte to PC every 1 ms. That means the throughput of it is as below:
    512*1000=512KB=512*8=4096 kbps. It can suit for the my ADC sample requirement.
    2.I still use PyUSB to receive the data from PC.

    • So, you can’t go faster than 512B per second?
      Not believe you this.

      You are doing something wrong then.

      • bobby

        Dear Tilen, You can see my another comment for this. I think 512K byte/s is very good than RS232. But for usb, maybe I can improve the speed. But I have not find the key reason for it.

        • bobby

          By the way, I should say “thanks your library”. It is excellent.

        • A, sorry, I didn’t see K (for filo).
          Yes, it is good but still not as much as possible I think for USB speed.

  • bobby

    This is key point for it.If anyone has advice, I am very happy.
    1.#define USE_USB_OTG_HS
    2.call the function direction to send 512 byte data to PC.
    VCP_DataTx(strBuff, 512);

    • And this takes 1second?
      How fast you call this function?

      • bobby

        Every 1 ms, I call this function. So that means I call the function 1000 times in on second.

  • Šimon Marko

    Hello, I’am trying make work this library but i still have some warnings. The project will build anyway but when i connect Discovery board to PC windows didn’t recognize it. I have installed all drivers and device manager still telling “Device description request failed”.

    • You should tell us your Windows.

      Make sure you have correct clock set for your device.
      USB HS/FS?
      Discovery? Which?

      • Šimon Marko

        I’m using windows 8.1, I have STM32f407VG discovery board and I write nothing into define.h.

        • https://www.dropbox.com/s/mp9m6wxjiby7pwp/project.zip?dl=0

          Try this project. Upload it to discovery via ST-Link and report if it works.
          It’s USB VCP.

          • Šimon Marko

            Now it works fine. Communication through serial port works.

          • Ok then make sure in your project that it runs with fully speed, 168MHz!

          • Šimon Marko

            I think it is running 168MHz. I make new project and didn’t change clock speed or something like that.

          • Well, you will have to tell me more than just “New project”.
            In which IDE? How you did new project?
            In coocox? Keil? IAR, etc? With default settings, 25MHz crystal is expected for proper clock, you have 8MHz!

          • Šimon Marko

            i’m using coocox. And how i can set 25MHz? In stm32f4xx.h i have HSE value 25000000.

          • Yes, and crystal is 8MHz connected to your board.
            Change this value to 8000000

            Also open system_stm32f4xx.c and set PLL_M from 25 to 8.

          • Šimon Marko

            Thanks, now it works. I dont know why but thanks 😀

    • Check if your clock on stm is ok.

  • Mengu Ucok

    How can I active ST-Link debugger and VCP drivers at the same time ? I installed STSW-STM32102 STM32 Virtual COM Port Driver but no luck.

    • Hi,

      you can’t directly. Use separate USB connector on board for this.

  • oattao

    Dear Majerle Tilen,
    Thank you very much for your useful libraries.

    How can I active an interrupt when there data arrived from the PC?

    • Hi,
      no problem at all 🙂

      Interrupt is already used when data arrived.
      Instead of user function, data are transmitted to internal cyclic buffer in my lib.

  • Onur Akgün

    Hi Majerle,

    I want stm32f4 to communicate pc via bluetooth module -hc05- which uses virtual com port. How can I convert this library to which I can use?

    • Never heard that chinese bluetooth module has VCP.

      You need USART to communicate via AT commands.

  • Matija Vukovic

    Hi,

    I’m trying to use this library in combination with I2C3 (I use the Discovery board). I’m having some trouble making it work – separately, both the I2C and the VCP work. When both are used in the same project, the VCP is functional but the slave on I2C stops returning ack signal. The configuration of I2C is correct, and I’ve tried using other two I2C interfaces.
    Do you have any advice? Is there maybe some overlapping between VCP and I2C that causes the I2C to stop functioning? (For example, is it possible to change which usart is used by the vcp?)
    Thanks!
    Matija

    • Hm, USART is not used for VCP, VCP is USB device, USART is USART.
      So you are saying, that your slave I2C device stop sending ACK.

      That’s strange.Slave has nothing to do with STM.
      I will have to take a look.

  • Pingback: Chibi/OS | David Albert()

  • Peter Mather

    Hi Majerle

    This just works superbly like all the libraries I have used – many thanks

    Quick question, is there anyway I can detect when a terminal application on the PC (e.g. Teraterm) has connected to the virtual comm port? I want to display a startup logo, but obviously that needs to be once a terminal has connected so the user can see it.

    Thanks

    Peter

    • I was searching for that but didn’t get any useful informations about that. Sorry

  • Peter Mather

    I believe Teraterm send a DTR-on message when it connects but where it gets handled is the question 🙂

    • You are right about that :)) must discover again 😀

  • Peter Mather
    • I’m now working on this.
      I get function call on “Open” and close, but commands are almost the same and it is hard to detect if it was open or close 😀

  • Iron Kang

    Hi Majerle:
    How could i get the virtual COM in my ubuntu OS?

    When i burn this code to stm32f429-discovery, TM_USB_VCP_GetStatus() not equal to TM_USB_VCP_CONNECTED.

    May i mistake?

    • At least for windows you need special driver from ST.
      I would say for linux is the same.

  • baymax

    hello! this is really good library,
    but I tried to use this library on STM32F4 discovery for USB FS, I run into 2 problems;

    i) when stm constantly send the data into PC (18 bytes per ms), but in my PC the port is not open, after a while, I cant send anymore, STM get stuck..

    ii) when i am sending 18 bytes of data every 1ms to PC and my PC do a loopback, after sending a few seconds, the connection stop.. any reason how to solve them?

    • That’s interesting problem. Can you test on USB HS port too?

      • baymax

        sorry i cant, my STM32F4 discovery kit (http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF252419) only comes with USB FS..you have no problem with that situation?

        • You can.
          Connect wires to pins PB14 and PB15 and connect to computer via USB HS.

          • Onur Akgün

            Thanks for explanation but I wrote there “USE_STDPERIPH_DRIVER” before, If I delete it and write “STM32F407VG” I get “assert_param” error

          • Use stdperiph driver define must be there 🙂

          • baymax

            sorry, do you mean connecting the USB wire to PB14 and PB15 and then connect it to the PC?
            http://i.imgur.com/wt6ha.png (the wire is shown in this link? so data+ to PB14 and data- to PB15?

          • Exactly like this 😉
            Check pinout above in my table.

          • baymax

            hello! i have connected the USB cable to pin GPIOB14 and 15, and I have uncommented the #define USE_USB_OTG_HS in define.h, and i build and run the firmware into the discovery board but my PC detects the USB as unknown USB device (device descriptor request failed), any idea why?

          • In most cases, that’s because your STM clock is not correctly set.
            I mean, system means that have some clock, but real clock is different.

          • baymax

            thanks for quick reply! 😉

            i have no problem using USB FS, my PC could detect it as COMport but not USB HS
            i have checked the clock settings, and it is correctly configured…
            anywhere am i missing?

          • That sounds really, really crazy.
            As I see, you did everything OK.

            Did you correct connect data+ and data- pins?

          • baymax

            yup, D+ (white cable to PB15) and D-(green cable to PB14)… if nothing is wrong, in the firmware, then most likely my USB cable is broken?

          • D+ is green 🙂
            Swap and report 🙂
            Also, try to twist it as far as possible.

          • baymax

            i swap them alraedy but same problem… i will change the USB cable and try again!

          • baymax

            finally! i found the problem!! the USB cable i used is quite long, i need to ground the cable to prevent the interference! and now my PC could detect the COM port! ;)))

            i did a speed test, and the max speed i could get using HS is about ~ 3Mbit/s and for FS is same too ~ 3Mbit/s, and this is strange!, i dint get any speed different despite usingUSB HS…what going wrong here…and I have changed the usbd_conf.h file

            I am sending data of size 512 bytes per transfer

            #define CDC_DATA_MAX_PACKET_SIZE 512
            #define CDC_CMD_PACKET_SZE 8
            #define CDC_IN_FRAME_INTERVAL 1

            and for USB FS to

            #define CDC_DATA_MAX_PACKET_SIZE 64

            this cant be right, USB HS should be faster.

          • Thats correct. Real USB HS works faster with external PHY for USB.
            Your interface is “USB HS in FS” mode. Basically the same as FS but on HS port, which also allows you to connect external phy 🙂

          • baymax

            brilliant! get it! 😉

            may I know what did you change from the original USB CDC stack provided from STM? (which part did u add or modified from their stack?) I try to use the STM32 CubeMX and generate the code for USB CDC using HAL driver, I found many issues with it like connection will stop when i do a loopback of 1ms, and also if i keep sending data to PC without the port open, it will get stuck after a while, but your implementation works perfect with no problem! 😉

          • Amm, I didn’t change a lot of stuff.
            I added some methods to make easier to use 🙂

          • baymax

            Cool! your library and tutorial is awesome! 😉 , have you tried the new HAL driver for USB CDC device??? I have so many problems using it for high speed communication, not sure my implementation or the stack got problem..

          • No, i didn’t try that :I
            I’m not planning yet 🙂

          • baymax

            okie, will checkout if you do release them!
            i have so many issues using HAL driver for other peripheral like UART, USB, it is just not reliable as StdPeriphal! it would be nice in the future if you could list the pros and cons of using HAL and their bad bad things! 😉

          • If there will be a chance not to used them, I won’t use them 🙂

  • Onur Akgün

    Hi Majerle,

    STM32F4 Discovery: (STM32F407VG)
    * Open project options and add “STM32F407VG” define (without quotes)
    * – Leds:
    * – LED_GREEN on PD12
    * – LED_ORANGE on PD13
    * – LED_RED on PD14
    * – LED_BLUE on PD15
    * – Button: (HIGH when pressed)
    * – Blue button on PA0

    Could you tell me where should I do these settings? Can you give me simple example?

    • Do this define inside your compiler. Every compiler has an option to add global defines.

      • Onur Akgün

        Could you tell me where it is in Keil?

        • Options for target, then tab C/C++ and there will be Defines box.

          • Onur Akgün

            Thanks for explanation
            I wrote there “USE_STDPERIPH_DRIVER” before, If I delete it and write “STM32F407VG” I get “assert_param” error

            Edit: I handled that by uncommenting the line which is /*define USE_STDPERIPH_DRIVER*/ in stm32f4xx.h

            Thank you so much

  • Jacky

    Majerle,

    Where can we adjust the baudrate and the other settings?

    • Communication between PC an STM works on max USB speed. Dont need for that.

  • Onur Akgün

    Hi Majerle,

    I’m developing an application and I need to use timer but when I use timer 7, I can’t communicate via VCP. The virtual port doesn’t appear. Why is so that? Is it about particularly timer 7 or all timers?

    • VCP appears if tim7 is disabled?

      • Onur Akgün

        Yes. If there is no use of timer 7, VCP appears and works well

        • Timer use interrupts? Tell me nore how you setup your thing!

          • Onur Akgün

            This is my TimerInit function

            void Init_Tim7(void){

            TIM_TimeBaseInitTypeDef TIM_TBInitStruct;
            NVIC_InitTypeDef NVIC_InitStructure;
            RCC_APB1PeriphClockCmd(RCC_APB1ENR_TIM7EN,ENABLE);
            TIM_TBInitStruct.TIM_Prescaler = 41999;
            TIM_TBInitStruct.TIM_Period =19;
            TIM_TimeBaseInit(TIM7,&TIM_TBInitStruct);
            TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);
            NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
            TIM_Cmd(TIM7, ENABLE);
            //10 ms
            }

            This is the timer function

            void TIM7_IRQHandler(void)
            {
            TIM7->SR=0;
            }

          • Change nvic priorities for test. Now you have them set to 0.

          • Onur Akgün

            void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
            {
            assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));

            //I added this code. Is it true?
            NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

            SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
            }

          • On TIM nvic initialization structure add subprioritry and preemptionpriority settings with bot values for example 5.
            If you look at my USART lib POST, you will see how to set nvic. There is explained.

            Or take a look for my NVIC post.
            Use search on site 🙂

          • Onur Akgün

            Majerle,

            I looked both Usart and NVIC topics. In tm_stm32f4_usart.c file there are NVIC settings

            NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
            NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = TM_USART_NVIC_PRIORITY;
            NVIC_InitStruct.NVIC_IRQChannelSubPriority = TM_USART_INT_GetSubPriority(USARTx);
            NVIC_Init(&NVIC_InitStruct);

            Should I make similar settings in vcp file in order that I can make it to be first prior?

          • This is done in vcp already, but not in your timer. Befire you call nvic init for your timer, fill settings for preeimption/sub priority! Set both values to 5 fir example.

          • Onur Akgün

            I see. I changed the NVIC function in misc.c file but it is still same

            void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
            {
            NVIC_InitTypeDef NVIC_InitStructure;

            /* Check the parameters */
            assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));

            NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;

            /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
            SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;

            }

          • Onur Akgün

            Why could it be? Is there any way to solve it?

          • You dobt need to change STs libs. Your configuration must be changed.

            If you dont init nvic, VCP works?

          • Onur Akgün

            If there is no function in timer 7 function, it works otherwise the vcp doesn’t seem available for communication. I will use other timers and I will tell the result

          • Huum, do you trying to use TIM7 on device that don’t have TIM7 inside?

          • Onur Akgün

            STM32F4 Discovery doesn’t have Timer7?

          • It should have it 🙂

          • Onur Akgün

            VCP works fine with Timer 2. The problem is likely about Timer 7. Thanks Majerle for your great help

  • Nemo

    Hi Majerle,

    Does your USB_VCP project works on stm32f407vg boards??? If not how can I make it compatible??

    It compiles and flashes without error but i still can detect the serial/usb port on my pc…

    Many thanks in advance!!

    • Works.
      Make sure, your clock is correct on your board.

      • Nemo

        The Core Clock is set at 10.000000Mhz on Keil….. what should i put for stm32f407vg??

        PS : Sorry im actually a web developper debugging a landslide detection project for my team.

        • This has nothing to do with real clock 😀
          Well, if you have Keil, then downoad my Github repository, open VCP project from there, rebuild and upload to your board.

          Test if it worked. It should 🙂
          To get my Github repo, search on web here.

          • Nemo

            Yeah i opened the Keil project from your github master folder.. The compilation and upload does not give any errors but plugging my board to both Ubuntu 14.04 and Windows 10 is not detecting any serial port on usb T_T

          • You are using some special OS.
            You need VCP driver from ST to get it working, like I told in POST above.
            Download VCP driver and install to your win10 an try again.

          • Nemo

            Yeah i’ve already installed the VCP driver from ST… maybe there are some compatibility issues with windows 10 :(…. I’ll test with a Win 8 tomorrow and keep u updated…

            Anyway thanks for the late night tech support!!

          • Benjamin

            Hi,

            I have the same problem. I opened your Keil project: “24-STM32F429_USB_VCP”
            Set the target to STM32F4-Discovery

            Rebuild and download.
            No errors or warnings but the VCOM does not show.

            In the included image it is shown the device is shown as “Unknown device” in devices and printers. In device manager it is shown as ST Link Dongle.

            I downloaded the test VCP drivers and STlink drivers from STM but nothing works.

          • Windows 8?

          • Benjamin

            No, Windows 7.

            I found the problem. I didn’t have the micro usb connected, only the mini usb.

            Now it shows up as com1. But terminal programs don’t see the com port. So I cannot connect.

            I have the latest stm32 vcp driver.

          • You said, that it’s seen as COM1.
            This means that terminal see it.

            Try other terminal. There are plenty.

          • Benjamin

            Hi,

            Yes, Device Manager see’s it as COM1.
            But four different terminals don’t see the COM port.
            I tried:
            HyperTerminal
            Putty
            Tera Term
            Terminal in Atmel Studio

            I wanted to test something on a arduino so I installed the software and now
            the STM is seen by the terminals. So I don’t know what solved it but It works.

  • hareesha

    Hi Majerle,
    I have STM32F429ZI Discovery board. I want to configure the USB port into “Device mode”, so that I can connect to my laptop’s USB 2.0 host ports. I mainly want to send and receive some communication data at 12mbps between laptop and STM32 board. Does this COM port configuration method be used for my application too, or is there a different way available to configure the USB port. I have additional questions too:
    1. for high data transfer, is ISOCHRONOUS transfer mode to be configured?
    2. is any hardware changes required on the board to change USB FS host to USB FS device mode?
    Regards,
    Hareesha

    • This library will show to computer as VCP port. Configured as device.
      12Mbit rate you can get easily with “USB FS” or “USB HS in FS” mode.
      STM32F429 supports both USB ports.
      Discovery board uses HS in FS mode, so if you want to use my lib, you need to add define as mentioned in post above.

      For real HS mode (480Mbit) you need external PHY.

  • ranjith

    I’m using a STM32F429I discovery board,
    which has a usb otg configured to host mode, i tried configuring usb otg
    to device mode in FS mode, but was not possible ,even the usb is not
    detected, i tried using the stmcubeMX and went through user manual but
    was not possible , is there any setting to make it as device mode?

    • First I have to correct you.
      It’s not HOST mode, it’s any mode 🙂

      connected is to “HS in FS mode”. To run my library on this board, you need to add define
      #define USE_USB_OTG_HS
      Like it says above in post about lib.
      You can add define in your project defines.h file or inside global compilers settings to set global define.
      Effect will be the same.

      Also, make sure your clock is correct.
      You can download my Github repository and run example direct from there. Will work for sure.
      And, you need VCP drivers from ST, link in post.

  • Peter Mather

    Hi Marjele

    Is there anyway of throttling the line or getting flow control? I’m transferring data to the STM32 ram using xmodem format. I’ve set the buffer length to 4096 but if the data is bigger than this I’m getting buffer overrun which of course kills the xmodem checking. The data is being sent from Teraterm using File/transfer/xmodem/send

    Thanks

    Peter

    • Hi Peter,

      well, for xmodem you can also use a smaller package size as far I know this. Try this.
      Another option, try to increase VCP internal buffer if this is a problem maybe?

      #define USB_VCP_RECEIVE_BUFFER_LENGTH 128

      • Peter Mather

        I’ve already set the buffer size to 4096, can’t really go higher. Teraterm doesn’t give control over xmodem packet size

  • baymax

    I tried your library using STM32F4xx for USB FS implementation, and i send data from STM32F4 to PC, I found that the data I received in my PC is about 2ms, instead of 1ms> I use USBLyzer to do the measurement (http://www.usblyzer.com/), any idea how can I reduce the latency to below 1ms? i have changed the #define CDC_IN_FRAME_INTERVAL to 1 in usbd_conf.h?

  • Василий Спасов

    Hi Majerle,

    How to use printf with TM_USB_VCP_Puts?
    Regards,
    Vasiliy

  • Arkaqius

    Hi Hi Majerle,

    I am use Your library, its quite good 🙂 I have some question. I am send ADC value through USB to PC where i catch them in my Java program, but i have problem with end of packet. Is it special marked, like /0 in the string? I have to know where packet is ended, in other ways my data are shifted in array 🙁 And i don’t know what was first character. Any ideas how to do it?
    Arakqius

  • mike

    is there any way to send USB chars or string without being in the while(1){} loop?

    If I use the TM_USB_VCP_Puts() in the while(1) loop it works. Otherwise nothing is ouput to my VCOM terminal.

    • Huh, nice question. I will try this like you asked and report.

      • Guest

        @majerletilen:disqus hey bro. Its first time i am writing to ur blog, so be nice to me :P. Is there any way to recieve data via interrupt or DMA because i want to recieve data all the time as i made my serial port application in QT environment. and when there is a signal changed the controller should detect the change. And sorry for my bad english as i am asian.

        • Hello,

          My USB VCP lib uses interrupt for input data so you can do that continously if you need.

  • hamza

    @majerletilen:disqus hey bro. Its first time i am writing to ur blog, so be nice to me :P. Is there any way to recieve data via interrupt or DMA because i want to recieve data all the time as i made my serial port application in QT environment. and when there is a signal changed the controller should detect the change. And sorry for my bad english as i am asian..

  • ryan

    Can this lib be used similar to termios in posix where I can just open up a serial port and pend on a read waiting for data to arrive?

    • Yes, you can 🙂

      • ryan

        OK great. Is this essentially what the example you provided is doing, or would it require additional code on my part? I have used your example and can communicate with my STM32F4 via a PC, but I’m trying to interface an autopilot using USB. The autopilot outputs packets over usb. I noticed that when I connect the autopilot to my board via USB, the code never acknowledges a connection like it does when I plug USB into a PC. Do you have any idea why this might be? I’m a noob to USB and don’t understand what causes the board to acknowledge it has a connection and why this works with the PC and not the autopilot. Thanks for any help

        • Ok, your autopilot is probably not a computer.
          It is again, USB device.
          STM is USB device, and autopilot it USB device.

          You can’t connect 2 USB devices together, especially not in VCP mode.

  • John Mavericks

    Hey again! A few questions if that’s alright:

    What would be the best way of finding out what the value of c is? This would be useful to do something like if an incoming string matches a string you define, execute a certain function. (Or would TM_USB_VPC_Gets be better for this? If so do you have a test case for using gets?)

    When using TM_USB_VCP_Puts(“Hello world”); the COM port reader receives the value 14 times instead of just once. Is that supposed to happen?

  • Zack

    Hey!

    your library is really nice but every time i connected the board with PC shows “Device descriptor request failed”

    I have installed the latest vcp driver but it still not works. So what’s the real problem

    • Sounds like wrong PLL settings.

      • Zack

        My MCU is stm32f407zg the external crystal is 12MHz

        the current PLLsetting:

        #define PLL_M 8

        #define PLL_Q 7

        #define PLL_N 224

        #define PLL_P 2

        #define HSE_VALUE ((uint32_t)12000000)

        Is this setting right?

        • Math looks OK. Maybe you can try this:

          M = 12
          N = 336
          Q = 7
          P = 2

          But yeah, HSE/M * N will be the same as in your case.

          • Zack

            Still not working 🙁

            Is that because my main function too simple because i don’t add led or something else on it.

            int main(void)

            {

            SystemInit();

            TM_USB_VCP_Init();

            }

          • Where is while loop?

          • Zack

            It works now!
            I just wanna set the usb as one COM for exchanging data between PC and the board by specific COM software. So i just need to write the codes in the while loop right?
            Anyway thank you very much!

          • Balmung

            Could you tell us how did you get it to work in the end? It might be helpful for people experiencing the same problem.

          • Zack

            My problem is i didn’t add the while loop Majerle showed in the example, so the VCP never starts.
            you can just try Mejerle’s example

          • He changes PLL and aded while loop! 😉

          • Zack

            I got another question.
            Do you have the function of sending lots of data in array form? or can this do printf?

          • It can also printf do the job.

          • Zack

            In which function ? can you tell more details about this
            Thanks a lot

  • Zack

    Hey!

    again for some questions

    I wanna send some data like an array to the computer com software? which function should I use?

    There is a function called USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf,uint16_t len))

    what exactly is the ‘USB_OTG_CORE_HANDLE *pdev’?

    Please give me some help and thank you!

    • Really?
      You have putc function, you can do it like I do.

      for (i = 0; i <array_size; i++) {
      TM_USB_VCP_Putc(arr[i]);
      }

      • Zack

        My main function :

        int main(void)

        {

        uint8_t i;
        u8 a[5] = {1, 2, 3, 4, 5};
        SystemInit();
        TM_USB_VCP_Init();
        while (1) {
        if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED)
        {
        for(i=0;i<4;i++)
        {
        TM_USB_VCP_Putc(a[i]);
        }

        }
        }

        }

        but when i connected it with com software continuously shows the number(need to be save as decimal). So what need to change to show the numbers only one time?

        • Did you look your code?

          You have while loop, which NEVER stops.
          Then, each time you send 4 numbers. It can’t work if it want to.

          • Zack

            I know I have the while loop bu when I delete the while loop, VCP can’t be read by my computer again

          • Learn programming please.
            You can use flags too, you know 😉

            while (1) {
            if (!send) {
            send = 1;
            //send here with for loop
            }
            }

          • Zack

            it‘s quite a long time for last programming project 🙁

            I add the flag on but this time there is no output showed on the software

            while (1) {

            static int flag=0;

            if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED)
            {
            if(!flag)
            {
            for(i=0;i<=4;i++)
            {
            TM_USB_VCP_Putc(a[i]);
            }
            flag=1;
            }
            }
            }

            I tried to place flag inside the for loop but still nothing as output. what's wrong?

  • Mohammad Kamel

    hi i have a very important question haw i can send data from my pc and then get that data using TM_USB_VCP_Puts and TM_USB_VCP_gets

      • Mohammad Kamel

        thank you but i cant use it correctly could you help me to get a string then showing it thank you

        • Send “Test stringn” from your terminal. “n” is the same as 0x0D in hex.
          Then, in your while loop, use:

          if (TM_USB_VCP_Gets(str_pointer, sizeof(str_pointer))) {
          TM_USB_VCP_Puts(str_pointer);
          }

          That’s all.

          • Mohammad Kamel

            thank you but i dont khow why it dosent work i did what you done please help me:

            my sample is :
            char a[100];
            SystemInit();
            TM_USB_VCP_Init();
            while (1) {
            if (TM_USB_VCP_Gets(a, 100)) {
            TM_USB_VCP_Puts(a);
            }
            }

  • Paul

    Hey Majerle, thanks for putting this together. For all of today I’ve been struggling with why my program seems to hang if my screen / console / minicom closes and then resumes when my console program restarts. I finally realized I just had a misunderstanding of USB, not realizing all communication must be initiated by host, so I couldn’t just do PutC calls wherever I pleased. My question to you is this: is the common practice to buffer outgoing data from the uC and then do batch transfers of this data whenever the communication is initiated by the host?

    Additionally and unrelated, have you noticed that the STM32F4 takes a long time (about 20 seconds) to enumerate on Linux (Ubuntu 14.04)? It enumerates in less than a second on my mac.

    Thanks in advance!

    • If it enumerates long time on linux only, then you know where to search for problems.

      I’ve been trying to add feature to library when port is open and when not.
      The problem is, that every terminal sends different “commands” and I was not able to properly detect “OPEN” or “CLOSE”.

  • Andre

    Hey, Majerle Tilen! Great work with this library! You have some serious computing skills.
    I´ve been trying to understand it. I´m no expert, so i have some doubts.
    Can you tell me if there is a way to use your library to make a usb bulk program?
    I want to use the full speed of the USB to transfer data from the uC to the computer.
    The speed of the VCP isn´t enough.

    If not, can you point me to some simple example?
    Thanks.

    • Hello,

      thanks for that.

      Before I suggest you, tell me, what is the speed you need?
      12-Mbit is the speed you can get with USB VCP using FS mode.

      For higher speed, you will need external PHY.

      • Andre

        Well, the speed would be “the faster the better”. The point is to pass a sequence of bits present on 8bits of one port to the computer as fast as possible.
        By external PHY you mean to place additional electronics to speed up communication? I think this uC (stm32f407vg) is suppose to get up to 2.0 full speed (12mbps), and that speed is ok. So, no external PHY, for now.

        I have some difficulty understanding where is the difference between using the USB for BULK and for VCP. Is VCP in a higher layer than BULK? Or am I completely wrong about everything?

        BTW, how did you learn so much about programming at this level?

        • To be honest, I have no idea what BULK is in USB. 12mbit is ok witf F407, that is 1.5MBytes. If I understand you ok, then you want to send one byte in eight bytes. Each byte has a value if bit in checked byte is set or not? Useless 😀

          I started with AVR and wanted something better, cheaper. And here we are 🙂

          I don’t have any special site or similar to give you for studying.
          Learn C is not something difficult, abd then reading datasheet for specific MCU.

          • Andre

            Yes, that´s kind of what i want to do. I´ll try to explain it better;
            With a special ADC for CCD readout i´ll have 8 bits as an output per pixel. This byte then goes in the uC and should be sent in bulk to the PC, like 64bytes per packet or something. The PC then reassembles the stream into an image. I know i´m a long way for that, but i have to start somewhere :P…
            115200bps is just too slow.

            I have to handle it to you. your learning skills are amazing. I can´t stare at a datasheet for to long with my head start spinning until i loose conscious.xP
            I have yet to learn how to properly use the registers on a uC.

          • Why dont you use conputer to reassemble those bits? Just send one byte for 8bits.
            Computer is faster with that and also you can have 8x slower speed.

            Btw, with 921600 baudrate in usart is quite fast. Also, usart on f4 can go up to 5.xx Mbits. Think about your needs.

          • Andre

            Hum..i didn´t even knew there was a possibility to run a usart at those speeds.
            Well, you´ve helped me already with those hints.
            I don´t really understand what you mean with 1byte for 8bits, but that´s ok.
            I´ll study your library some more and try to get up to 1.5mbps.
            If any development arises, i´ll write you about it.
            Thanks a lot for your help.

  • Zack

    Hey! thanks to your lib

    • Zack

      I wanna know how can I apply printf function with VCP?

      • Hi,

        inside your fputc function handler for printf, use TM_USB_VCP_Putc(character_to_send);
        You will be able to find some examples using printf in my examples for different libraries, expecially if you take a look at newer libs and its examples.

        • Zack

          Ok thank you! I will take a try
          by the way , your lib process verrry well!

          • Nice to hear, I hope you got it useful.

            Have a nice programming time 😉

  • Muhammad kamran

    can u please tell me how to change PLL to fix usb interfacing problem

      • Muhammad kamran

        thanks dear , problem solved
        now i have ADC converted data with 12 bit resolution.i want to print it on hyper terminal , how can i do so , what is the format of that 12 bit data , as we can send characters to hyperlink , how can we send proper data

        • Convert number to string using sprintf.
          No offense but if you dont onow how to do it, then USB peripheral is not for you right now 😉

          • Muhammad kamran

            dear i am new to this kindly help me out , i have analogue data as an input and i have to display it on pc , Without USB how can i do so ?

          • Then start with learning process before starting with USB.

          • Muhammad kamran

            i have configured ADC and USB as VCP , data is displaying on hyperterminal , i want to know to read out ADC converted data on hyperterminal

          • Use sprintf to convert. Check google how sprintf function works. It’s one of basic C functions available!

          • Muhammad kamran

            thanks dear

  • Amai

    Hey, where’s the “tm_stm32f4_disco.h” file? I can’t find it neither in the included here library nor on GitHub.
    And by the way, my STM32F4 has microUSB connector by default. So does this mean that I can activate USB HS in FS mode as shown here on my board and use the connector instead of the wires?

    • It is on github and on site here 🙂

      Please read post. F4 discovery has v nnect microusb to fs port.

  • Nova

    Hi guys,

    I’m trying to develop a serial communication bridge prototype using the stm32f4, its purpose is to mediate the communication between an Android device and any other gadget or peripheral that uses serial communication (For prototyping purposes, im using a second stm32f4 board). I’m trying to send a char string through the first board into the second one, and depending on the string, the board should light up one of its LEDs (if I send “red” it lights up the red led), but using the CoIDE debugger i can see that the string is not arriving as it should. The second board receives a great amount of trash data between the characters (i.e. i send “red” and the debugger gets “r�������e������” and obviously the comparation on the code doesnt work. Me and my coleagues are at a loss here, can you imagine what we should do?

    • if you send 3 bytes “RED” and you receive 15 bytes of trash, then I assume that baudrate on board which sends “RED” is 5 times lower than baudrate on receive side.

      Check input clocks.

  • CitizenTen

    AWESOME code, saved me a ton of time. Thanks!

  • quentin

    Nice job

  • grifo

    Hi, I’m really a newcomer for SW development so sorry for any my silly questions;

    I’m interested to this VCP project so I’m trying to compile it with Em::blocks but I get the following errors:

    C:progettivcpsrcmain.c:23||undefined reference to TM_DISCO_LedInit'|
    C:progettivcpsrcmain.c:26||undefined reference to
    TM_USB_VCP_Init’|
    C:progettivcpsrcmain.c:30||undefined reference to TM_USB_VCP_GetStatus'|
    C:progettivcpsrcmain.c:35||undefined reference to
    TM_USB_VCP_Getc’|
    C:progettivcpsrcmain.c:37||undefined reference to `TM_USB_VCP_Putc’|
    ||=== Build finished: 5 errors, 0 warnings (0 minutes, 1 seconds) ===|

    So it seems that such functions are declared as prototype but do not exist in my workspace; where I can find them?

    thanks

    • Include tm_stm32f4_vcp.c file into project and you are done.

      • grifo

        Thanks but I cannot find such file anyware; I look inside tm_stm32fusb_vcp-4.rar, in git and I also try to google but nothing….
        For sure I’m doing something wrong but what?

        • My mistake.filename is tm_stm32f4_usb_vcp.c

          • grifo

            Thanks, you are right! it was missing; now I’ve many warning, I’ll do some verifications on these…….

  • hosweetim
  • grifo

    Hi, I’m back again…I did good steps ahead but I’m now stopped in the following situation:

    Windows recognize the STm32 board but is unable to install the drivers; of course I had previusly downloaded from and installed them.

    Another strange thinghs is that it detect the board 2 times (why 2?) and as “STm32 VirtualCom Port in FS mode” despite the fact that I (should) have configured it as HS_mode because I’m using a simple microUSB cable connected to the STM32F429 discovery board.

    thanks in advance for any suggestions

    • If you have win8,those drivers from ST dont work properly.

      For real HS Usb you need external phy. You have usb hs in fs enabled on your board which is the same as fs port for windows detection.

      • grifo

        Hi Majerle; I’ve win7 but I’d just fixed!

        I was due to the misleading driver installation program provided by ST; if you launch it works and after ia while apparently complete succesfully but

        in reality it is needed another step going inside the installation directory and relaunching a specific driver for x86 or AMD64……..no comment.

        now all seems alive, let’s go on, thanks again.

  • Damir Zainullin

    Hi, thank you for your project. Can you help me?
    I use STM32F4-discovery, downloaded the code to its flash, ok.
    But I got red led is on all the time (with and without USB-cable connected).
    I tried to find out the returned value of ‘TM_USB_VCP_GetStatus()’ and it was ‘TM_USB_VCP_NOT_CONNECTED’
    The listing:
    ==========================

    /**
    * USB VCP for STM32F4xx example.
    *
    * @author Tilen Majerle
    * @email tilen@majerle.eu
    * @website http://stm32f4-discovery.com
    * @ide Keil uVision
    *
    * Add line below to use this example with F429 Discovery board (in defines.h file)
    *
    * #define USE_USB_OTG_HS
    */
    #include
    #include
    #include
    #include “stm32f4xx_conf.h”
    #include “tm_stm32f4_usb_vcp.h”
    #include “tm_stm32f4_disco.h”
    #include “.defines.h”
    /* Activate USB HS in FS mode */
    #define USE_USB_OTG_HS

    // Init system clock
    void SystemInit(void)
    {
    // …
    }

    int main(void) {
    uint8_t c;
    /* System Init */
    SystemInit();

    /* Initialize LED’s. Make sure to check settings for your board in tm_stm32f4_disco.h file */
    TM_DISCO_LedInit();
    TM_DISCO_LedOn(LED_GREEN); // The IO system was loaded OK

    /* Initialize USB VCP */
    TM_USB_VCP_Init();

    while (1) {
    if (TM_USB_VCP_GetStatus() == TM_USB_VCP_NOT_CONNECTED) {
    TM_DISCO_LedOn(LED_BLUE);
    } else {
    TM_DISCO_LedOff(LED_BLUE);
    }

    /* USB configured OK, drivers OK */
    if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {
    /* Turn on GREEN led */
    TM_DISCO_LedOn(LED_GREEN);
    TM_DISCO_LedOff(LED_RED);
    /* If something arrived at VCP */
    if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) {
    /* Return data back */
    TM_USB_VCP_Putc(c);
    }
    } else {
    /* USB not OK */
    TM_DISCO_LedOff(LED_GREEN);
    TM_DISCO_LedOn(LED_RED);
    }
    }
    }
    =============================
    My Blue LED is ON all the time (with and without cable connection to PC).
    I have read other comments but I did not found the answer. Can you help me?

    • When you will read rules before commenting!

      • Damir Zainullin

        I’ve read the rules and tried to use the pastebin. Sorry if something is wrong. Now can you help me with my question?

      • Damir Zainullin

        Hi, what about solvation of my problem? Please, can you help me with it?

        • You are…
          …really annoying!

          Install ST USB VCP drivers and check PLL settings for correct clock!

          • Damir Zainullin

            Do you think, that i have not installed the driver and i have’not checked PLL? May be I’m annoying, and you are very irritable and you are not obversant in reading my comments. I found better solvation. I took another library of other people and it it working without problems. Good day. Be kind next time.

          • You didn’t pay for this library so I’m not obligated to answer you in 5 minutes. You post 4 comments this time asking when will be your answer! You are not the only person in this world!

            And yea, if you would set clock correctly and install drivers, eveerything would work!

  • Damir Zainullin

    Hi, thank you for your project. Can you help me?
    I use STM32F4-discovery, downloaded the code to its flash, ok.
    But I got red led is on all the time (with and without USB-cable connected).
    I tried to find out the returned value of ‘TM_USB_VCP_GetStatus()’ and it was ‘TM_USB_VCP_NOT_CONNECTED’
    http://pastebin.com/embed_js.php?i=wpD82cnF

  • grf

    Hi Majerle, I used both your libraries (VCP & il9341) to build a USB terminal by the STM32F429 discovery but unfortunately the VCP tx side doesn’t work as expected and hangs the uP.

    More in details, from RX side (PC–>STM32) I can transfer any amount of data without any problem but when I try to trasmit (STM32–>PC) STM32 system always hangs after a number of chars that can vary from a few ones to some hundred;

    This happen to me also using your Main() example, simply filling repetetively some chars to the Hterm buffer and sending them to the STM32; again, I did’nt find yet the rule but for a while I receive the echo as expected but always, at a certain point, STM32 CPU crash……..

    I also triyed to send a single char at time very very slowly (about every second); in such condition TX seems stable but not usable for my application.

    Do you have any suggestion?

    • Hello,
      I see a big problem here from your side.

      Tell me please, what do you mean by “CPU CRASH”. Is this Hard-Fault error or something?
      I didn’t noticed any of these problems till now.
      Will definetelly take a look about that problem.

      • grf

        CPU crash means that program stop to run; all seems freezed included a toggling signal inserted in the main loop and monitored by an oscilloscope.

        How can I provide more detail to you?

        • grf

          I’ve disabled all, LCD, touch screen etc and to my eyes I’m running exactly the example above but the problem is still quite evident;
          If I trasmit character very slowly (1..2 per second) the system run for tens of minutes (and thousands of characters) but at the end stop; if I increase the TX rate it collaps well before.

          A part my possible mistakes in theory this behaviur should be easly reproducible by you.

          Can you kindly confirm me that, in your enviroment, you can trasmit towards the PC hundred or even thousands of characters per second without any problem?

          • I’ve tested this. After I uploaded program to MCU, I sent 620-bytes of random data from my terminal and I always received them all back. Also worked if I sent it multiple times in one second. Always everything returned and never CPU hangs.

            And on link, you have .hex file which I used for testing (save as and download):

            http://stm32f4-discovery.com/wp-content/uploads/TM_STM32F4_USB_VCP_F429_WORKING.hex

          • grf

            OK, thanks! I confirm your exe works great also on my HW; I’ve definetevely to look inside my local SW enviroment to discover what is going wrong…..

          • What’s your compiler? ARM or GCC based?

          • grf

            It’s GCC used whithin EM::blocks enviroment; I’ve cleaned all compiled and tested VCP alone and it work; the problem start when I try to set up a more complex enviroment with graphics, touch etc…..

  • sar

    hi
    i used this library and it worked fine for a while but now i have a problem with my stm32f4 . when i plug it to pc using usb to flash it ide tells unable to connect to device and then the card goes off as if there is voltage drop. I don’t understand whether it’s a hardware or software problem !

    • I didnt change lib for a while so it must be something else.

  • Roman Zavyalov

    Hi,

    Is it possible to adapt this library to STM32F37x?

    Regards,
    Roman

    • Sure it is.

      • Roman Zavyalov

        I made a modifications, but the program goes into an infinite loop in the initialization procedure TM_USB_VCP_Init().

        My modifications here –> http://pastebin.com/x1pSCFAa

      • Roman Zavyalov

        Compiler in debug mode is stopped on line 179 in file startup_stm32f37x.s.
        please, help

      • Roman Zavyalov

        can I have your help?

        • To be honest, I don’t know what is happening here.
          I’m not using F37x series.

  • John Doe

    Hi, stupid question – Does this go through the same USB port as STlink on the stm32f429-disco board, or on the OTG us connector? Thanks!

  • Hi Majerle and peaple @ stm32f4-discovery.com,

    I’m quite interested in this project and surely I will try to experiment with, since I have proper STM32F4 DISCOVERY BOARD. Talking about my foreseen future, how will it cost to port from STM32F407VGT6 of STM32F4 DISCOVERY to STM32F401VCT6U of STM32F401C Discovery ?
    Last of this batch of lousy questions: it seems project .rar sources archive being toolchain agnostic? Itn’t it? Do GCC_ARM and/or KEIL work for me?
    Thank You very much!
    gz

    • Hi,

      I’m not sure I understand your point here.
      Please make more clear 🙂

      • Hi,
        first question: which toolchain can I use sources with?
        second question: is target board STM32F4 DISCOVERY ? Isn’t it ?

        third question: how can I have this code work with another target board, that is STM32F401C Discovery? it has similar micro but not exactly the same micro.
        Thank You for Your fast reply. You’re smart.
        gz

  • ali

    Why give this error.please help me

    • This is nothing related with my lib as I see. Means that external function/variable is not found.

  • Muhammad Kamran

    i have configured ADC and m sending sampled data to Hyperterminal by configuring USB port as VCP, but there is a problem i am facing . in while loop , first discovery board is sampling and then sending data to pc , thus results in the loss of data , how i can configure these two fuctions to work in parallel ((sampling,conversion) and sending data to pc)

    • Use DMA for ADC, USB uses TX buffer so you maybe fill up buffers.

      • Muhammad Kamran

        dear how can i count receiving data in hyper terminal

        • Thats funny, didnt you say that it works but not everything? Now it does nothing?

          • Muhammad Kamran

            the receiving data limit in hyper terminal is also limited , kindly tell me some software to receive data from COM port , which can receive data up to 60 Mbits per sec

          • Usb allows you 12Mbit

          • Muhammad Kamran

            then how can i recieve data of 60 Mbits per sec ?

          • Muhammad Kamran

            as i am using ADC of 5 Msps with 12 bit resolution , so needed 60 Mbits per sec data to be received

          • Hmm, funny again, how can you use ADC in 5Mbps mode, if max mode supported is 2.4 Mbps?

          • Muhammad Kamran

            in DMA mode it will be 4.8

          • Muhammad Kamran

            ok if it is 2.4M again we need (28.8 Mbps receiving data )

          • http://screencloud.net/v/mk65

            if you don’t believe me, then I’m not able to help anymore here.

          • Muhammad Kamran

            dear i believe you , call me under develop but need to do it , kindly help me

          • Muhammad Kamran

            tell me some software which can count the data receiving at
            COM port

          • Without external PHY chip for USB you are not able to get your speed.

  • kais

    i am trying the same exemple but using buffer
    i need to send and receive string (10 chars max)
    code is not working is there any solution i think i am using the string’s functions wrongly

    • Hello, USB communication works?
      If so, then yes, you are using gets wrong.

      Gets needs n in your buffer, so the idea here is:
      Send 10 bytes of your data (string), then send n (0x0A) at the end to terminate string.
      For all that, you will need to call function like that:
      a = TM_USB_VCP_Gets(s, 12);

      12 is because you need 10 useful bytes, 11 is 0x0A and last is zero terminator.

      • kais

        i tried with 8 chars string and n but not working

        the functions are used correctly ?
        if (a>0) …

        • aa I see now. Do not send “n”, because these are 2 characters.
          In your terminal, write “azertyui” and before press enter, select option “Send on enter”: “LF”, then press enter 🙂

          • kais

            now i don’t get the string in the transmited data in hterm

          • kais

            now OK thank you
            it was just because i am using Asend buttom not enter

          • Glad to hear that 🙂

          • kais

            but i am not receiving back the string

            i think there is something wrong with
            TM_USB_VCP_Puts

          • What are you receiveing then?
            Go to debug your application to see what happens.

          • kais

            nothing on hterm !

          • Like I said, go to debug window and check what you actually receive and if string is really received.

  • cruuz

    Hello,

    I have also problems with receiving data. Transmiting works well, Board is a stm32f4-discovery.

    int main(void) {
    int i;
    char text[] = “Hallon”;
    TM_RCC_InitSystem();
    HAL_Init();
    TM_DISCO_LedInit();
    TM_DELAY_Init();
    TM_USB_Init();
    TM_USBD_CDC_Init(TM_USB_FS);
    TM_USBD_Start(TM_USB_FS);
    while (1) {

    if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) {
    TM_DISCO_LedOn(LED_GREEN);
    } else {
    TM_DISCO_LedOff(LED_GREEN);
    }
    TM_USBD_CDC_GetSettings(TM_USB_FS, &USB_FS_Settings);
    if (USB_FS_Settings.Updated) {
    TM_USBD_CDC_Puts(TM_USB_FS, “USB FS settings changed!n”);
    }

    if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) {

    TM_USBD_CDC_Putc(TM_USB_FS, ch);

    }

    HAL_Delay(1000);
    TM_USBD_CDC_Puts(TM_USB_FS, text);
    TM_USBD_CDC_Gets(TM_USB_FS, text, sizeof(text)-1);

    }
    }

    with HTerm I am reading only “Hallo” 🙁
    What could it be?

    • 1. you didn’t read rules
      2. you didn’t post this to related library
      3. Did you even read manual as posted in library?

      If so, what have you done so far!

      PS: Post this to related lib from now, or I will ignore it and delete it!

  • Kiran Kadam

    hi TM,on windows 7 x64 usb showing “unknown device”…what would be root cause for this ??vcp drivers from st are installed correclty.any other things that needs to be figure out?

    • Hi, as mentioned in “read before commenting” section, make sure PLL is set correct.

  • John Condon

    Hey, just a heads up. When trying to compile this code in C++ (in my case C++11), there are a couple of fixes that need to be done before it will run. There are a couple places where extern C should be extern “C”. Also the ST library headers and interrupt functions need to wrapped with extern “C”. I believe there is also one structure that was multiply defined. Just comment that out.

    • Funny, because only havs problems with multiple defined structures.
      If you dont use C++ then I dont see a need for extern C wrapper.

  • Lucas Eluani

    Hi, im asking about your experience with this communication mode. Which is the max speed that you could reach using the virtual COM?. It’s the standard 115k?, or you could go more than that?, like 250k?. I know that the max data rate is 12mbs, but i dont know if the ST driver allows using other speed. Sorry the inconvenience. Im using the STM32F4 discovery board. And i want to use it to read some SPI data, and later transmit it by USB-VCP. I will send 500 values of 32bits, about 2kbytes and i’ll need some speed, because i need do send the 2kbytes in less than 100ms. tops. Thanks

    • You will transmit this without problems.
      Usb speed has nothing with uart speeds you are asking. Stack works with 12mbit or 1.5mbytes easily.

  • Hokus Pokus

    Hi, how can i get 12mbs speed ?. When i test this, sending simple text i get:
    pv /dev/ttyACM0 > /dev/null
    84KiB 0:00:04 [ 122KiB/s] [

    and don’t more than 130 Kib/s ?

    • Hi,

      Try to send one big arr at a time.

      • Hokus Pokus

        I’m sending 2048 byte buffer in loop and it doesn’t change speed

        • which board, which USB mode and so on? You could describe it more 😉

          • Hokus Pokus

            I have STM32F4 Discovery board and i have defined
            speed in defines.h by #define USE_USB_OTG_FS, so i’m using micro USB connector on board.

            BTW do you know any program on linux to test this speed

          • Hokus Pokus

            I changed
            CDC_DATA_MAX_PACKET_SIZE 128
            and
            CDC_CMD_PACKET_SZE 16
            but result are still the same. Even using USART i get about 240 KiB/s. My clock setting are correctly.
            What can be wrong ?

          • Hmm, i’m sure it works faster!

            Can I see your project? Or at least main file or where you call function to send data and so on.

          • Hokus Pokus

            Its nothing fancy there, but you lib i Eclipse:
            http://speedy.sh/rsU8x/usb2.tar.gz

          • Check file usbd_conf.h and increase define APP_RX_DATA_SIZE to something like 10000 for test or even more.

          • Hokus Pokus

            using 10000 its speed up to 489KiB/s, great 😉
            But if i must using usb to send ADC values to computer, setting up to bigger buffer its ok ?

          • Without problem.

          • Hokus Pokus

            I tested that the max speed is about 827 KiB/s with buffer 100000 still very slow for USB but much better than 130, thx for help 😉

  • Aleksandr Shponko

    I have STM32F4Discovery. Windows
    7 (64 bit) sees two STMicroelectronics STLink Virtual COM Port. COM ports do
    not work. How to solve the problem?

  • Gary

    Hi,

    I’m now trying this example.
    When the USB port of the STM32F4 is connected to the USB port of my PC, and I run the program, it doesn’t execute the code from (below) this call:
    TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED

    so it appears that the PC doesn’t connect.

    But it’s not clear: do I need to set up the STM32F4 with specific com port settings, if the STM32F4 is to appear to the PC as a COM PORT?

    Thanks.

    • Just install drivers from ST for VCP.

      By the way. Why you don’t download my github repository and open example there directly?

  • Gary

    Hi TM:

    I checked out the github, but your projects are in Keil, I use the poor man’s version (Atollic) 😉
    But I have the same code as your main, and I have compiled in the file “tm_stm32f4_usb_vcp.c” and included the header file “tm_stm32f4_usb_vcp.h”, so everything compiles OK.

    I also installed the VCP driver from ST’s website. After installing, I went to the install directory and ran the file:
    C:Program Files (x86)STMicroelectronicsSoftwareVirtual comport driverWin7dpinst_amd64.exe

    It says it installs OK, and has the checkmark. When I look in the windows panel, I do not see anything running under COM ports that a driver from ST is installed (I have 64 bit)

    However, under USB controllers, I get a “Unknown device”, and a message after plugging in from Windows saying “Device not recognized”

    The running code still returns a message “Not connected” from the call to “TM_USB_VCP_GetStatus() ”

    Thanks for your help!

    • Like I said in another topic, clock is wrong in STM.
      Use search how to set it properly and read “read before commenting” section next time.

  • Gary

    Hi,

    Help me out here. If the clock is wrong in STM for the USB, where is it set? Is it in one of the files from your library?

    Searching for set clock on STM32F4 returns a lot of results. How about sending a link to the specific page where this info might be?

    Thanks!

  • Gary

    Hi,

    The clock is set for this in system file:

    /* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
    #define PLL_Q 7

    Is this not correct?

    Thanks.

  • Gary

    Clock appears to be set OK:

    #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) ||
    defined(STM32F410xx) || defined(STM32F411xE) || defined(STM32F469_479xx)
    #if !defined (HSE_VALUE)
    #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
    #endif /* HSE_VALUE */
    #elif defined(STM32F446xx)
    #if !defined (HSE_VALUE)
    #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
    #endif /* HSE_VALUE */
    #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F411xE || STM32F469_479xx */

    With the STM32F405, I have an 8MHz external crystal.

    So does the clock appear to be wrong?

    • Can you read ebtire clocking post for one time? Next time, I will ignore rules violations.

  • Gary

    Also, if the ST software VCP installed a driver, and it doesn’t appear in the computer system panel, what does that have to do with the ST’s HSE value?

    Also, the build environment in Atollic has been set for HSE_VALUE of 8 Mhz.

    Thanks…

  • Gary

    I have read the entire post, and my clocks are all set up the way the post shows. What did I miss?

  • Aleksandr Shponko

    Hello,

    Bits of system clocking STM32F407VGT6 are exposed correctly (HSE_VALUE=8000000, PLL_M=8, PLL_N=336, PLL_P=2, PLL_Q=7).

    But Windows 7 (64 bits) sees two Virtual COM Port, which don’t work.

    Please help.

    • Hi,

      drivers are installed?

      • Aleksandr Shponko

        Hi,

        Installed drivers:
        Virtual Com port driver Vl.4.0, Windows Driver Package – STMicroelectronics (WinUSB) STLinkWinUSB, Windows Driver Package – STMicroelectronics (usbser) Ports.

        On the PC with
        OS Windows 7 64 bit Ultimate Virtual Com port works.

        On the PC with OS Windows 7 64 bit Professional two Virtual COM Port, which do
        not work. Tested on PCs with different motherboards.

        What is the reason?

        • Aleksandr Shponko

          Hi,

          The problem was solved by setting the driver STMicroelectronics version 1.3.1 for Windows 64 bit instead of version 1.4.0.

          • Mark

            Where I can find this version of drivers? There is 1.4.0 on the STM web sight only. May you send me on my e-mail this driver? mark7cedrick@gmail.com

  • Sterling Archer

    Hello Majerle. I have STM32F407-VG Sorry to bother you with this annoying question, but I’ve downloaded your library from Github, tried two sets of PLL:
    M : 8 / 12
    N : 224 / 336
    Q : 7 / 7
    P : 2 / 2
    I’ve also tried FS & HS mode and i have downloaded drivers from ST (version 1.4.0) and I’m using Windows 7, 64 bit. So, my problem is that my PC cannot recognize my board connected via micro-USB. I’ve connected it via mini and micro USB and LED 7, near the micro USB port is shining. I’ve been struggling with this for a few days now and i cannot find a solution.

    • PLL must be set: M: 8; N: 336; Q: 7 and P: 2.

      If still does not work, then download not just library, but examples also. Open example 24, select board in keil uvision (select target), hit compile and download. MUST WORK!

      If not, try another cable, try another discovery.

      • Sterling Archer

        Thanks for the quick answer!

        I’ve tried that config also, still doesn’t work. I’ve downloaded your master from Github, set target as STM32F4-Discovery, built target and it still doesn’t work. I’ve also tried another cable, doesn’t work. I only didn’t try another Discovery but I think this should work because other projects work.

        • Somehow I don’t believe that it does not work, so I have a hex file for you here.

          http://stm32f4-discovery.com/wp-content/uploads/TM_STM32F4_DISCOVERY_USB_VCP_WORKING.hex

          Click save as and download .hex file from web then patch to board.
          For me, it worked OK. If not other, at least unknown device must be shown in device manager and sound from windows that board is not correct detected should be heard.

          If it does not work, then you have hardware problems, nothing else!

          • Sterling Archer

            Could you please tell me how to patch .hex file to the board? I’ve been googling it but haven’t find any useful data.

          • You have to search properly.

            Download stlink utility.

          • Sterling Archer

            Finally it worked!
            Thanks a lot! If I ever meet you, I owe you a beer 😀

          • Just for the record. The same project as you download on github was compiled like you did.

  • Piotr

    Hi,
    I using your library in my own project with stm32f405. I tested VCP also on discovery board with stm32f407 . In both case communication work fine with PC, but I have two problems:
    1. Second problem is with supply voltage, when I use voltage in my own
    board from discovery 3.0 V, I can send data from uC to PC. But when I
    use supply voltage 3.3 V from my board, the communication didn’t work. I
    see in computer properly recognized COM port, but nothing is sending.

    2. I can’t send more than 64 data in one packet. I must send eg 48 wait 1-2 milliseconds and send last 16. I have enove buffer size with settings:

    #define CDC_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */
    #define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */

    #define CDC_IN_FRAME_INTERVAL 5 /* Number of frames between IN transfers */
    #define APP_RX_DATA_SIZE 4096 /* Total size of IN buffer:

    Data are sent when I call sending function 5 times, but the data are buffered.

    What can be issues?

  • Abhinav Kumar

    hi ,how can we do the same program using the newer hal driver..This program is done using the older version of peripheral drivers.
    is it possible to port the same program using the recent hal drivers.

    • Sure it is. Check for my page with a list of all HAL libraries.

      • Abhinav Kumar

        if i use cube to do the very same functionality, then are the library files present in TM group really required?

        • Please ask further questions regarding hal lib in corresponding post.

  • Jan Folfas

    Hi, thanks you for those examples

    I have problem with VCP. After flash I connect board via USB OTG, and in device manager under windows there are two VCP devices. One marked as working, and second marked as not working with code 10. However this is not problem at all. Problem is data is not returned after sending. As you, I am using HTerm to communicate. Do you have any idea what might be wrong?

    Regards, Jan

    • Hi,

      actually I don’t know. But your PLL is set OK?

      • Jan Folfas

        Thanks for reply,
        my disco seems to be broken. I found hex file below, and I flashed it through ST_Link Utility. Same issues occur.

    • Ann

      Hi! I have the same problem with drivers. It’s not working with code 10. Have you solved this problem?

      • There exists 2 versions of those drivers. one are for win8 and newest. Maybe you are using wrong drivers.

        • Anna Malysheva

          Unfortunately the version is ok. Anyway thanks for help.

          • How exactly you know that?

          • Anna Malysheva

            I’m using Win7 and drivers from official site STM. (32F429IDISCOVERY if it matters)

        • Anna Malysheva

          Hi! I solved this problem increasing size of heap from 0x00200 to 0x00400. (But your project works without this change.) May be it will be helpfull.

      • Jan Folfas

        Hello, unfortunately I was not able to solve the problem

  • Kyaw Kyaw Aung

    Hi, TM. Can I use the CN5 USB Connector on STM32F4 Discovery to connect directly to my computer? Do I need the additional drivers for the computer to detect the discovery kit as a Serial Com Device?
    As always, your libraries have been of much help to me significantly. Thank you for your work.
    Regards,
    Kyaw Kyaw

  • marcin

    Hi,

    I’m using USB VCP (Full Speed) on STM32F407… uC and got problem with “de-initialization”. Somewhere in my code after VCP_Init and some transfer via USB I am jumping to the bootloader(disabling RCC and SysTick, setting MSP to 0x2000100 and jumping SystemMemory location) to be able to upgrade flash using DFU procedure. Unfortunately STM Virtual COM port is still hanging in Device Manager in Windows 10. The only workaround is to reconnect USB cable while powering MCU from other source. Could this be related to hardware (ID pin not connected/ VBUS connected)? Or is it any software method to DeInit VCP? I saw that there is such method but it doesn’t do any logic, only returning some enum.
    I have also observed that after VCP initialization and than issuing reset signal by STLink Utility USB VCP is not recognizable by any application in Windows such as COM terminal anymore. It needs USB cable reconnection.

    It will be very helpful if you can spend a few minutes to answer my questions.
    Here I also want to thank you for great work you are doing.

    Best regards, Marcin

    • Why don’t you reinit USB in your bootloader?

      • marcin

        Thanks for answer! 🙂

        I am not using custom bootloader but the original one. I need MCU to
        be recognized as STM Device in DFU mode. It is normally happening after
        running bootloader code but does not after VCP initialization.

        BR, Marcin

        • Ok, so you jump to native USB bootloader with software?

          • marcin

            That’s right. And I would be happy that STM Virtual COM disappeared from device manager and STM Device in DFU mode will appear. But it is not happening until I reconnect the USB cable.

            BR, Marcin

          • That’s quite logical I would say. Before you jump, STOP USB, totally disable peripheral. And then bootloader will start with new USB.

          • marcin

            Before jump I am using method: RCC_DeInit(), is it not enough to STOP USB? Or should I manually deinit pins used for VCP (or set them to particular logic states?). I have problem with stopping USB VCP, even software reset does not cause USB VCP to disappear from device manager.

            BR, Marcin

  • Kyaw Kyaw Aung

    Hi TM. I’ve already installed VCP drivers from STM but my STM32F4 discovery still doesn’t show up in my device manager. Did I leave out anything?

    • Is there even sound on PC when you attach/detach USB cable?
      You have both USB cables attached to PC? If not, you should have.

      • Kyaw Kyaw Aung

        I have connected both USB cables. only when I plug/unplug the STLink USB, the device manager shows changes. the USB OTG (CN5) however, does not make a sound when I plug in. I’ve attached my device manager window and there’s a code-10 error on the VCPs.

        • So device is there! Check VCP clock. As I see you use Win8, which requires different drivers for VCP.

          • Kyaw Kyaw Aung

            I’ve installed windows 8 drivers from STM website that you mentioned. I don’t know why these COM Ports are still flagged with code 10 (device cannot start) error. And may I know how to check VCP Clock?

          • Did you check VCP clock? PLL clock. Run my example precompiled files. They are somewhere in comments below.

          • Kyaw Kyaw Aung

            Umm. Your program’s already running on my discovery board. Red LED’s on indicating that the VCP status is not OK.

          • Moulay Hassan EL ALAOUI

            Hello.
            I’m thinking if we can emulate two VCPs with an STM32F407VGTx discovery board ?
            Thank you

          • With this lib no. With my HAL lib this is possible but then you need 2 USB ports. You can’t use one port for 2 VCP modules.

          • Moulay Hassan EL ALAOUI

            Can you just tell me how can we do it with tha HAL Library ? I generated a CDC Code with CubeMX but it emulates only one Virual COM Port. Do you know what variables or what Macros that can allow me to have two com ports ?

          • I think I was clear. With MY HAL USB LIB you can do it. So check my HAL USB LIB for more info.

          • Moulay Hassan EL ALAOUI

            Thank you. I checked it. So we can control the the number of VCP’s Interfaces in usb_device_cdc ?that’s right ?

          • Short: no
            Long: ask in related topic.

  • Moulay Hassan EL ALAOUI

    Hi TM. I have emulated one VCP using CDC Library on STM32F4 Discovery Board. Also I’ve emulated two VCPs with two different USB Connectors on the same board but I want (if possible) to emulate 2 Virtual COM Ports with only CN5 connector, exactly like FTDI does ? Thanks TM.

    • You will have to modify stack and build descriptor to match that. Also, new drivers will be required.

      • Moulay Hassan EL ALAOUI

        Can you direct me to what should I modify exactly ? Do I have to add another Descriptor in the USBD_HandleTypeDef in order to let the host read two descriptors for the same device ? or is there another modification to do ?

        • And update driver which I suppose you don’t have source to do it.

          • Moulay Hassan EL ALAOUI

            But I can have access to all libraries and middlewares. I can Modify them to have two VCPs ?

          • You can. But wont be able to run on pc since you dont have driver for pc to run double vcp.

          • Moulay Hassan EL ALAOUI

            Ah I see. the double vcp driver isn’t free to download ? can you just guide me to know what modifications should I do in USB libraries and middlewares ?

          • You don’t get it.Exe file is available, but for 1 (ONE) VCP at the same port.
            And you don’t have source code to modify driver code for your PC.

          • Moulay Hassan EL ALAOUI

            Hi again TM,

            I have emulated two VCPs with only one USB Device. I can send data in one VCP that has the following Endpoint Address.

            #define CDC_IN_EP 0x81 /* EP1 for data IN */

            #define CDC_OUT_EP 0x01 /* EP1 for data OUT */

            #define CDC_CMD_EP 0x82 /* EP2 for CDC commands */

            I would like to know if it’s possible to send data in the other VCP with other Endpoint Address like :

            #define CDC_IN_EP3 0x83 /* EP3 for data IN */

            #define CDC_OUT_EP3 0x03 /* EP3 for data OUT */

            #define CDC_CMD_EP4 0x84 /* EP4 for CDC commands */

            My problem is that addresses others than 0x81 don’t allow me to send data over the second VCP. I’m using two CDC interfaces Full-Speed. Normally we can use 7 endpoints with CDC_FS and that’s what I’m trying to do.. I have 6 Endpoints: 3 for each VCP and the seventh is Endpoint 0 for configuration.

            Have I missed something in the Endpoints Configuration or in the Composite Device Descriptors ?

            Thank you.

  • Андрей

    Hi. I’m using STM32F4x particularly STM32F405 and STM32F407 as slave and I’m using your library for USB connection with master. Everything works OK except I have following problem. Sometimes master gets answer not for current request but for the previous. For example:
    request1 – answer1
    request2 – answer1
    request3 – answer2
    request4 – answer3
    request1 – answer1
    request2 – answer1
    request3 – answer2
    request4 – answer3

    This may happen at any moment. It’s not connected to the command or iteration. Do you think this problem can occur because of your library? Or what else may be the cause? How can I clear the buffer of the slave for sure? Thanks.

    • It could be problem in my lib. What are those requests and answers?

      • Андрей

        While I was describing the problem in details I figured out that there were a mistake in my code on master device. Sorry for disturbing you. Thanks for the great library.

  • Hassan

    Hi TM,

    I have emulated two VCPs with only one USB Device. I can send data in one VCP that has the following Endpoint Address.

    #define CDC_IN_EP 0x81 /* EP1 for data IN */

    #define CDC_OUT_EP 0x01 /* EP1 for data OUT */

    #define CDC_CMD_EP 0x82 /* EP2 for CDC commands */

    I would like to know if it’s possible to send data in the other VCP with other Endpoint Address like :

    #define CDC_IN_EP3 0x83 /* EP3 for data IN */

    #define CDC_OUT_EP3 0x03 /* EP3 for data OUT */

    #define CDC_CMD_EP4 0x84 /* EP4 for CDC commands */

    My problem is that addresses others than 0x81 don’t allow me to send data over the second VCP. I’m using two CDC interfaces Full-Speed. Normally we can use 7 endpoints with CDC_FS and that’s what I’m trying to do.. I have 6 Endpoints: 3 for each VCP and the seventh is Endpoint 0 for configuration.

    Have I missed something in the Endpoints Configuration or in the Composite Device Descriptors ?

    Thank you.

  • Mohammed-Ismail Ben Salah

    Hello TM,first of all thank you very much for your library,i succesfully ported it to another hardware but i still have a question.

    Actually when i use the fonction TM_USB_VCP_Send to send more than 2048 bytes it happens a default handler/hardware error,but i don’t understand why i changed the size of the buffer with the definition APP_RX_DATA_SIZE to 4096 but it still bug.

    Did i miss something in the stack implementation or in the hardware ?

    PS : I’ve send to you donation for your awesome website.

    • This is something I have to investigate. If possible, use my HAL version of USB CDC. It has some features and works really stable. This lib is not so stable because of bugs in ST stack I didn’t resolve.

      • Mohammed-Ismail Ben Salah

        Okey.
        I will try to port it.

      • Mohammed-Ismail Ben Salah

        Hello,i found the problem and it wasn’t with the stack.
        However i have another question : Do you have implemented the support of ULPI for the USB High-Speed ?
        Thanks a lot for the answer,Ismail

        • This lib does not support it. At least not my implementation. Some additional GPIOs and some other things are required.

          So, do you mind to share problem solution with us?

          • Mohammed-Ismail Ben Salah

            Sure.
            P : Send buffer with number of data > than ~2048 with the USB_Send function
            S : Declare the buffer volatile and declare it global(C1)

            C1 : Depends on the targert,needed when using a RTOS

          • Mohammed-Ismail Ben Salah

            Hello TM,
            I used the function TM_USB_VCP_Send(&aTxBuffer[0],(uint32_t)TX_BUFFER_SIZE) but it don’t work,i always have a NAK on the USB in IN transaction.

            I used on the Hal version PutArray but it didn’t work either

            My board i use is the Discovery F429

            Any idea where’s the problem ?

  • leonard_lee

    Hi, majerle

    First, your libs are so good, good job.

    I think I have a problem about vcp project which I have use 3 days debug it.

    I code a project with HAL library to implement vcp function on my mac.

    I using stm32f429discovry to develop vcp.

    so, my build and debug environment is arm-none-eabi-gcc + openocd

    What I have done:

    (1)I have read all comments about vcp on your site
    (2)I have check register level different between your project and mine.

    but it never device enumeration on my windows PC, even display “unknown device”(if it that, is a driver problem)

    Please, Could you help me check my code? Sorry I notice dont paste code on here but I dont know how to give you.

    Thx

    • Hi,

      1. check PLL if it is running OK and if USB has 48MHz clock.
      2. This lib is for STD drivers, not HAL
      3. Use pastebin.net (as mentioned) to copy code and give link here.

      • leonard_lee

        1.external clock 8M, M=8,N=336,P=2,Q=7, I think it`s right
        2.Yes I see. but I need to make it work with HAL lib
        3. http://pastebin.com/DLavZr3k link is here Thx

        • If you need HAL then check my HAL version for USB

          • leonard_lee

            Yes. I have read 24-STM32F429_USB_VCP, but can not found where I wrong…

          • No, again. If you want HAL (HAL HAL HAL) then use my USB library for HAL. This one is not for HAL. Last time.

  • Abhinav Kumar

    Hi, Majerle

    I am using Docklight application to transfer the data between the board and PC.
    But its taking 45 mins to transfer 194kb of data.
    What could be the possible reason?
    I tried using baud rate as 9600,115200, but no change in transfer time was observed.The VCP is configured in FS mode.

    • Whoot? You have delays in code?

      • Abhinav Kumar

        No, I haven’t kept any delay. I have kept a dummy structure which is of 128 bytes and I am just sending this 1552 times.This takes 45 mins to complete.

  • Shuo

    Hi, Majerle

    I am using stm32f429-discovery board to transfer data by using this “USB CDC Device” STD library,
    it worked great and I got about 1100KByte/s of transfering speed(I didn’t use the uart),
    it’s about maxmum of usb full speed(19 frame*64byte in 1 ms).

    But I want higher speed ,so
    (1) Is the “USB HS in FS mode” working in usb full speed?
    (2) Is there any possible that the transfer speed up to “usb high speed”(usb2.0)?
    Thanks.

    • 1. Yes. USB HS in FS means that HS port (High Speed) is working in Full Speed only mode.
      2. You need additional hardware to achieve that. External USB-PHY device is required.

  • joristip

    Hello Majerle,
    Thank you for doing a great great job to share these libraries!
    I have a problem with this one in combination with the STM32F407VG discovery board.
    I tried your example project for the Keil compiler, compiled it and it worked like a charm.
    When I ported this project to CoIDE with the gcc compiler it stopped working and I get the “unknown device” error.
    I didn’t change anything in the code and I triple checked the clock settings. I have no idea what i’m doing wrong. Can you help me?
    Thanks in advance

    • Can you verify your PLL works at the same frequency as in Keil example?
      Check system_stm32f4xx.c file for PLL defines and check HSE_VALUE define if it matches to 8MHz.

      • joristip

        I does work now, thank you very much!

  • Ramya

    hi
    I’m using STM32F4 discovery board to drive some LED matrix hub, i have attached all the VCP and USB libraries required for the project , after building the program i get linker error saying
    Error[Li005]: no definition for “TM_DISCO_LedInit” [referenced from C:UsersTraineeDesktopled matrixDebugObjmain.o]
    Error[Li005]: no definition for “TM_DISCO_ButtonInit” [referenced from C:UsersTraineeDesktopled matrixDebugObjmain.o]
    Error[Li005]: no definition for “TM_USB_VCP_Init” [referenced from C:UsersTraineeDesktopled matrixDebugObjmain.o]
    Error[Li005]: no definition for “TM_USB_VCP_GetStatus” [referenced from C:UsersTraineeDesktopled matrixDebugObjmain.o]
    Error[Li005]: no definition for “TM_USB_VCP_Getc” [referenced from C:UsersTraineeDesktopled matrixDebugObjmain.o]
    Error[Li005]: no definition for “TM_Time” [referenced from C:UsersTraineeDesktopled matrixDebugObjmain.o]
    Error while running Linker

    I couldn’t find whats missing, i have given the correct path in pre-processor .can you please help me out to solve this problem

  • ehsan

    Hi, majerle….
    THANK U FOR SUCH AN AWESOME LIBRARIES…
    I am using stm32f4 discovery as an VCP….
    but when i load above program red led is on….
    i have checked every thing plz help

  • Mihai

    Hi!
    I am using your library to send data to usb. I just want to transfer some data from my gyroscope on the stm32f429 board to pc.
    I am allowing it to send data only when a char was sent.Ok.
    But after like 60-70 messages the program gets stucked in the ISR functions of the USB Lib.

    Anyone got this or know what is the problem here?
    Thank you.

    while (1) {
    /* USB configured OK, drivers OK */
    if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {
    /* Turn on GREEN led */
    TM_DISCO_LedOn(LED_GREEN);
    TM_DISCO_LedOff(LED_RED);
    /* If something arrived at VCP */

    TM_L3GD20_Read(&L3GD20_Data_l);
    if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) {
    /* Return data back */
    sprintf(buff,”%d”,L3GD20_Data_l.X);
    TM_USB_VCP_Puts(buff);
    }
    } else {
    /* USB not OK */
    TM_DISCO_LedOff(LED_GREEN);
    TM_DISCO_LedOn(LED_RED);
    }
    }

  • Jerry

    Going crazy. Your code works, my code works on the 429 discovery but not on the 407 discovery. I'[ve checked HSE_VALUE a dozen times as well as the PLL variables and though they must be wrong, I can’t find anything that would indicate it other than the USB won’t connect. Since your HEX file loads and runs correctly, clearly the problem is in my code.

    I get these warnings on compile: http://pastebin.com/JeY27gcJ I don’t remember getting them on the 429 but that board is 800 miles away right now.

    Your code works fine with windows 10 and my macbook. My code just keeps the red light on. I’ve tried every option in the defines.h that would be applicable.

    I’m pretty sure my clock is right as I am using your DAC code and the wave forms are at the correct frequency where when I started the conversion from the 429 to the 407, I had a problem with PLL_M being set to 25 instead of 8 which caused the output to be 8/25 off.

    Any other pointers? By the way, I’ve said it before, you have great code!

    • I would say you use F429-Disco and F4-Disco. One uses HS port, second FS port. You can’t use the same hex for both.

      • jerry

        That’s what I am trying to do. I have recompiled and can’t get it to work with my code. I’ve checked the HSE_VALUE and PLL variable settings a dozens times. I’ve stared at your projects on github, etc. there is something wrong with my specific compile for the 407 discovery that I just can’t find. The 429 compile came right up without any trouble but he 407 discovery board just won’t connect. I guess I will just use the 429 for this project.

        • Jerry

          This morning I took everything out of defines.h which I tried before. I compiled and ran. I am now walking back my changes trying to get it to fail and I can’t. Go figure. This makes absolutely no sense. But it is working and I’m not one to argue with success. Thanks again.

  • Jerry

    Tilen, I’m able to now draw some conclusions.

    1) I am using an older version (1.5) of the std periph libraries on an older version of Eclipse with a 429 Disco board and the USB VCP works as well as all your other code (DAC, ADC, USB, Touch and LCD, etc).

    2) Using the new integrated workbench from AC6 and the std periph 1.6.1, I can get the 407 discovery board working with USB VCP but can’t get the 429 board working for nothing. It turns out my problems with the 407 board were cable related. The 407 discovery comes right up. I build a project, copy in your code and off it goes.

    3) I’ve tried everything with the 429 board using the 1.6.1 std periph library and it just sits there. I get errors on the attached PC about an unknown device. I looked at system_stm32f4xx.c and changed it to match the code that is working on the older version of the std periph library and in that code I modified PLL_M to 8, N to 336, p to 2 and q to 7. Also, on the working code, I had to change SystemCoreClock = 180000000 to 168000000. I don’t know where this change came from as I did it a year ago. I’ve tried all this with the new level of the periph drivers without luck.

    I am trying to get to the point where I can compile and run on two machines one using the new AC6 workbench and the older Eclipse build using the latest libraries and I’ve been stumped. I do this because I travel a lot and want to bring the Ac6 workbench with me as the debug seems to work better than my older version.

    Any idea what can be causing the problem with the 1.6.1 std periph library and the 429 board?

    Thanks again.

  • Jerry

    Tilen, This morning I took the time to make a project using the 1.5 std periph libraries and as far as I can tell, the old Eclipse project and the Ac6 project are now nearly identical with the exception of the Ac6 uses a startup_stm32.s file. I went thru line by line in the compiler and linker defs, etc. and it still doesn’t run. I get the same error which if I read all the posts, would lead me to believe the clock is wrong. I’ve checked the files countless times and I know (at least they look) are correct. I wonder what is going on?

    So I can compile a project using Ac6 for the 407 board and it works fine; I can compile a project using my old Eclipse toolchain using the 429 board and that works fine. I can’t get the 429 board working with the Ac6 toolchain for nothing, even now with the same std periph libraries.

    Is there a way once the board starts, to check the clock speeds thru debug, etc? A scope? I have every piece of test equipment known to man.

    Thanks, I still have a lot of confidence in your code. I’ll keep comparing the builds. By the way to be clear, your code runs on my 429 board. My code using the old toolchain runs as well. Something about Ac6….

    • Hope you know, that F429 (I assume you have discovery) uses HS port for USB and not FS as used on F407-Discovery board.

      • Jerry

        yes, I know. There is something wrong in either the compiler options or linker that I can’t find. I think the files are now nearly identical. I really would like to get the Ac6 toolchain working with this board. There is obviously a clock issue I can’t resolve.

        • It is funny that you don’t think compiler is a problem (which can easily be true). PLL should be set to 168MHz (M = 8, N = 336, P = 2, Q = 7) and HSE_VALUE set to 8000000. Then clock is done.

          • Jerry

            Compiler could be the problem but the fact that it works with the 407 board confuses me. I have everything set as you teach (SystemCoreClock = 168000000; M = 8, N = 336, P = 2, Q = 7) and HSE_VALUE set to 8000000). I’m running the Ac6 update procedure. I’ll be a little upset with myself if that fixes the problem.

          • Jerry

            Updated Ac6 toolchain and same error with the 429 board. I have an F7 board coming and plan to port to that one so I am going to use my old toolchain on this board until that arrives. There is something hosed-up in the clock I assume but I can’t find it.

          • Jerry

            Anybody know the difference between the 429Disco and 429Disc1? Could that be the issue with the Ac6 compiled projects? I tried reconfiguring the project with Disco v disc1 defines without luck. I guess I just can’t give up on this problem. I’m going to try to scope the lines today to see if it is a timing problem.

          • Jerry

            I put a scope on the USB pins today and it isn’t a timing problem from what I can tell. The pulses look as expected.