cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 trouble with data transfer after USB reconnection with Android accessory ADK

ADras
Associate II

Currently using STM32F429I-DISC1 Discovery Kit (with LCD) for development of Android accessory ADK project.

Original code was obtained from here.

https://github.com/YuuichiAkagawa/STM32F4_ADK

The current code that I have modified for use with the 429 discovery kit is here.

https://github.com/aldras/stm32f429_helloadk_data

Development platform SytemWorkbench6.

There are issues with both the application side and MCU side, but I am working on the MCU side.

Short summary, when USB is enumerated after the MCU is reset there are no issues.

If USB is disconnected, then reconnected, enumeration happens, however, data is no longer transferred correct. I suspect issues with interrupts not being fired or something not being completely reset.

I am looking to solve the bug in the USB communication after reconnection. Something does not seem to reset correctly... an interrupt or buffer maybe, which I am not able to locate.

This project is based on the following USB library... although dated.

STM32F105/7xx, STM32F2xx and STM32F4xx USB On-The-Go Host and Device Library

author MCD Application Team

version V2.1.0

date  19-March-2012

I have tried to update this to the V2.2.0 version, but, there some things that do not function correctly, like setting the Android device to accessory mode and reenumeration, therefor I am attempting to complete the initial prototype with this library, then update it soon.

To repeat the issue, do the following.

Upload the code to the 429 Discovery PCB.

Install the apk to an Android smart phone that supports accessory add (most recent models do)

The source code for the apk can be found here.

https://github.com/YuuichiAkagawa/HelloADK

Disconnect the OTG cable between the discovery PCB and the smart phone.

Make sure the application is closed on the smart phone.

Reset the discovery PCB, or terminate/restart the debug.

Connect the OTG cable to the discovery PCB and smart phone.

The application, if does not auto load, open it.

Pressing the blue button on the discovery PCB should show some response in the Android application.

Pressing the top OFF/ON button in the Android application should show response on the discovery PCB LCD (change from OFF to ON).

Disconnect the USB cable from the smart phone.

Close the application on the smart phone.

Reconnect the USB cable to the smart phone, application should start again.

Notice, however, there is now to data transfer between the two devices.

There is a bug in the Android application that does not reconnect correctly if not restarted, this is independent of the bug in the STM32 logic.

7 REPLIES 7
ADras
Associate II

I have localized the issue to the file usb_adb_core.c

In the function static USBH_Status USBH_ADK_Handle(USB_OTG_CORE_HANDLE *pdev, void *phost)

Under the switch ADK_GET_DATA

if( URB_Status > URB_DONE){

        xputs("ADK:USBH_ADK_Handle:ADK_GET_DATA:URB_Status > URB_DONE\n");

break;

}

is causing the function to return without retrieving data... therefore the state machine is stuck in this state. Looking at URB_Status, it is URB_ERROR.... how can I clear this state? This happens when the USB is disconnected then reconnected...

ADras
Associate II

It appears that by removing the break and attempting to just send data on the endpoint again will clear this error.

I believe this solves the issue... is this the correct way to handle this?

VK Verma
Senior

Hi Allan!

I was also looking some example for Android open accessory (AoA)​ protocol, which is a host side protocol. Can you please share your rectified code workspace, so that others can be benefitted and upgrade it.

Thanks and best regards,

Vk verma​

ADras
Associate II

Thank you for your interest!

I have made substantial progress, but, I have attempted to rewrite the Android ADK USB logic, and it only transfers data when the buffer is full... if anyone can help me out with this, it would be appreciated a lot! I will be working on this today as well.

I have created a new sample...

I have upgraded the USB drivers to the latest, and many things have been brought up to date.

The new sample code is in a different repository.

https://github.com/aldras/stm32f429_usb_host_device_helloadk

There is support for the LCD screen added along with other things.

There are some issues with the LCD output, which I know, and there are in the macros... %s not being replaced correctly, etc.

I am uploading in this state so others can see the updated logic faster.

There are no build issues, it should fully build and run without problem.

ADras
Associate II

Also note, in this state, I have not kept the logic up to date that works with the above Android application, I will fix this soon... at the moment I am troubleshooting the USB bulk endpoint communication trouble.

ADras
Associate II

Sorry I have some things to clean up, I need to take this down for a bit, let me know if you are in a hurry to get access to this.

VK Verma
Senior

Dear Allan,

It will be the good starting point, if you can share an application which is capable of demonstrating basic functionality which you have mentioned ( preferred with least bugs). Also kindly share its ReadMe file mentioning all pending bugs and issues which we can take it further.

Thanks and Best Regards,

VK verma