7 years ago.

How to use USB Serial for Nuleo-STM32F207ZG?

I am using Nuleo-STM32F207ZG and I want to configure the USB port in "Device-only" mode. Is there any library available to send and receive data serially through micro-USB? Or is there any way to manually configure it?

Followed Tutorials:

https://www.youtube.com/watch?v=Jpul3w10tOU

https://www.youtube.com/watch?v=oDoavXrQdEg

Tried both the above tutorials but not working.

1 Answer

7 years ago.

Hi Krushna. Consider to download STM32Cube for F2 series - it is the last download link on this webpage:

http://www.st.com/en/embedded-software/stm32cubef2.html

and review this document (page 26) (title: STM32Cube firmware examples for STM32F2 Series):

http://www.st.com/content/ccc/resource/technical/document/application_note/e7/c4/71/01/04/94/4f/61/DM00210614.pdf/files/DM00210614.pdf/jcr:content/translations/en.DM00210614.pdf

Source code is supplied for USB DEVICE CDC_Standalone

Update

Krushna, need to make sure we fully understand your question. Would you like your Nucleo board to be the USB Device and act like a CDC function ? So you will connect this Nucleo board to a PC and the PC who will be the host ? Or do you wish to make the Nucleo board act like a host so you can attach a CDC device to this PCB ? Believe you want the first idea.

In a closer review, the -EVAL board schematics appears to be making use of an external USB PHY. The immediate pain now is that you must do the same for your Nucleo board to use the -EVAL example code as-is. The issue is that your Nucleo board does not feature the USB Phy shown in the -EVAL kit so you will not be able to use the -EVAL kit source code as originally noted by my first post. Our past review was with the STM32F072 which does not have this issue. It is possible, with some care, to use -EVAL examples on the Nucleo board for the STM32F072 target.

The better idea now is for you is to use the STM32Cube wizard tool to select your Nucleo board and/or select the same CPU with the same number of pins from this tool -> enable the USB features with the GUI -> allow this tool to create a CDC example -> select the external clock which may be fine as supplied by the factory. We recall that USB will only function if specific clock values and conditions are met. Measure the clock value at MCO (SB149) and report this value to the tool. This value may work as-is. If not, you will have to bypass the MCO feed and stuff in a proper crystal @ X3 and then use the shorting blocks in that region to enable your crystal and disable the MCO clock input. This should work for your case but a another potential issue is the CDC example created by the wizard is skeleton code. The USB CDC function should enumerate ok as noted on a PC but you may not have the ability to select all the full features of a normal CDC serial port (ie. 19200, 57.6k, etc.) - that is why it was nice to borrow this code from the -EVAL example which is usually complete. However, assuming that the -EVAL kit is requiring the use of the external USB PHY so you will need to selectively cut & paste the serial port workings from the -EVAL source code and place into your Nucleo version. Do try the STM32Cube with the F2 support to at least review the Nucleo present itself as a CDC USB device. You will need to apply an external USB connector onto the defined USB port pins - we used Adafruit USB connector breakout board (under $ 5USD from Digikey / Mouser). Summary - once you have the proper clock (we used 8 mhz @ X3 and had to disable the MCO clock from the ST-Link CPU -> use the STM32Cube Wizard to create a CDC example -> define the clock with this tool -> connect an external USB connector onto your Nucleo board and then compile to test with the Keil chain. Attach the external USB connector via USB cable to your PC and you should see a USB CDC device get enumerated. Next, run some terminal program and you should be able to send and receive data to / from the STM32 buffers. If you need to allow for the USB CDC function to frame at specific baud rates then you will need to closely review the -EVAL example details which should offer baud rate and other communication parameter tweaks (ie. 19200,N81, stop bits, etc.).

There is a lot of similar dialog on this topic and posted on the STM32 user forum. You may want to consider to also review and post there for additional assistance. Time permitting, will consider to shadow your experiment but as always, have some mini fires that are ongoing so no promises.

see here:

https://community.st.com/thread/39609-nucelo-f207zg-usb-cdc-example-code

https://forum.mikroe.com/viewtopic.php?f=3&t=54612&start=15

Hey Sanjiv thanks for your reply. I tried to configure the clock same as EVAL board but output frequency for PCLK1 is 30MHz and for EVAL board it is 48MHz max. I tried configure it anyways but it is not working. Do you have any Nucleo specific clock configurations? Thanks in advance.

posted by krushna ratnaparkhi 15 Apr 2017

Hello, I am using STM32f207zg as a host to communicate with stm32f205 ( device ) I configured the host with stm32cubex and every tink is ok but I didn't understand how to use the function USBH_CDC_Transmit I include the CDC in the main code #include "usbh_cdc.h" and I want to transmit data to the device and i do not k know how.

posted by Ghassen Brinis 17 Apr 2018