cancel
Showing results for 
Search instead for 
Did you mean: 

connecting STM32F4-discovery with Android through USB

Moamen Ayman
Associate III
Posted on November 29, 2016 at 17:45

Hello, I'm trying to connect stm32f4-discovery with Android phone supporting otg through USB virtual port. The microcontroller should work as device and smart phone will be the host. I used CDC library on stm32f4 side and do I need driver for Android to communicate via USB? because when I connect stm32f4-discovery with phone I cann't send or receive any thing, moblie even doesn't feel that I have connected the kti with it!

Thanks in advance
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on December 09, 2016 at 23:40

You should not need a special driver on the Android device to connect.  You just need a terminal emulator program loaded on your Android device, and the device has to have the ability to act as a bus master (not all do).

I use a Nexus 6P phone, and the UsbTerminal app.  It works flawlessly with the USB port on several flavors of F4 discovery boards running USB CDC code generated by CubeMX.  If this is not working for you, my guess is that the problem is either that your Android device doesn't have the hardware capability to be a bus master, or you have a cabling problem. 

View solution in original post

6 REPLIES 6
Moamen Ayman
Associate III
Posted on November 29, 2016 at 21:46

Could someone help?

Walid FTITI_O
Senior II
Posted on November 30, 2016 at 16:39

Hi

Moamen.Ayman,

Try to program the STM32 as a virtual com port device and I think you should find a driver for the androif host.

Check also this

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/USB%20CDC%20Driver%20for%20Android&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=3499

that may help.

-Hannibal-

Posted on December 05, 2016 at 20:40

You don't say whether the comm port works with any other host, such as a PC.  I would try that first since, if you have the CDC running correctly, you can communicate with it through a terminal emulator on a PC and it 'just works'.  If that doesn't work, the Android situation is understandable.  Once you have it working on the PC, you also need a terminal emulator program on your Droid to do what the PC was doing- emulating a terminal.  There are a number of free programs in the playstore that do this fine.

Finally, you have to ensure that your Android is able to operate as an OTG host ( not all of them do) and that your connections between the two are set up correctly.  An Android device, by default is a Device on a USB network where it expects there to be another device (like a PC) acting as the Host.  This is what happens when you plug your phone into your PC and are able to view the files on the phone from the PC.  The configuration you are setting up expects the phone to be the Host while your board is the Device.  This requires the phone to be able to do this through an OTG port, and the right cable or hub to connect them.

I have this working fine on my Nexus6P and any number of Discovery boards.  It can be done but you need to take it a step at a time and know what is working and what is not.

Good luck.

Moamen Ayman
Associate III
Posted on December 09, 2016 at 20:44

First thanks bauch for you answer.

I had tested Discovery board to act as device with PC using CDC library and it works successfully. the issue is to do that I installed stm32f4 driver for virtual com port in order for the PC to recognize the stm32f4 MC and I want to do so on android side so I'm looking for the driver before I can use any emulator.

Posted on December 09, 2016 at 23:40

You should not need a special driver on the Android device to connect.  You just need a terminal emulator program loaded on your Android device, and the device has to have the ability to act as a bus master (not all do).

I use a Nexus 6P phone, and the UsbTerminal app.  It works flawlessly with the USB port on several flavors of F4 discovery boards running USB CDC code generated by CubeMX.  If this is not working for you, my guess is that the problem is either that your Android device doesn't have the hardware capability to be a bus master, or you have a cabling problem. 

Posted on December 09, 2016 at 23:43

and depending on the version of Android you are running, you probably have to enable the USB port for data transfer.  The default mode is for charging only and you have to override that.