嗨,这是我第一次尝试在一个微控制器上实现/使用USB,这是一个相当大的挑战。我使用的是PIC32 MM000 64 GPM028,它应该作为USB主机来连接到一个连接的三星平板电脑,但是我不能让它工作。我需要做一个主机,因为我也想能够为平板电脑提供
电源。我目前使用的软件是:μMPLAB X IDE V4.10μC MCC V3.45.1(核心V4.35)×XC32 V2.10μBug框架Lite,由Microchip技术库版本1.25.5从核心V4.15构建。错误UBSCANNONTRONETRATE和USB S
timeMaCin进入保持状态。在许多其他关于USB主机问题的帖子中常见的问题是错误的USB时钟设置或内部振荡器的使用。我有一个外部石英晶体。它是一个+50ppm的12MHz石英晶体,它应该给我一个48 MHz的USB时钟速度,只有2400赫兹的偏差(0.00005%)。在“MCC系统模块”中,我选择了一个频率为12MHz的“外部时钟”,PLL分频器是1:4,乘法器是8:1。MCC中产生的频率为SysCLK/PBCK 24MHz,USB时钟为48 MHz。(MCC没有显示任何关于一个错误的USB时钟的警告/错误)。在“MCC的MLA USB主机Lite”中,我用“HID供应商”标示了最多1个HID设备和8的数据大小。堆的4096字节。最小的堆栈大小是64字节。我也定期调用我的.c.while循环中的USB主机任务。下面的输出显示了通过UART2(460800的BurdRead)打印到终端的USB总线主机调试输出。(注:我从它中删除了‘一’毫秒定时器ISR],而我只是。打印U1EIR每一行[除非它改变]……U1EIR中的10h的误差值是:BtoEF=总线周转时间错误标志BIT这一类型的错误发生在超过数据包(EOP)的前一个结束的空闲时间超过16比特时。我的5V电源来自平板的230V交流充电器。这也是与VBUS连接的,是我的PIC的3.3V电压调节器。这也是连接到VUSB 3V3的。我的USB连接到平板电脑:UBS55V从充电器USB连接到5V -连接到D的PIC USB连接+连接到D+的PIC USB接口没有连接GND连接到Grundif我没有错,VBUS被配置为输入和仅监测总线的电压,并且主要使用USB作为设备。如果支持OTG,只使用VBUSON/UBSID。但是,关于我的时钟的一个问题可能是错误的基频,但是MCC没有抱怨。在第27节中。“USB ON GO(OTG)”(DS61126)“第3页上的注释5是说:USB PLL UFIN要求:4 MHz & lt=UFL& lt=5兆赫,将购买一个4MHz +50ppm的新石英晶体来解决我的问题吗?或者可以选择3的PLL分频器吗?我的振荡器是不是错了?如果不是,什么会引起我的问题?我遗漏了一些函数调用吗?USB是错误的吗?谢谢你,我明天早上七点之前不能回答。
以上来自于百度翻译
以下为原文
Hi,
this is my first time trying to implement/use USB on a Microcontroller and it's a pretty big challange.
I'm using a PIC32MM0064GPM028 which should act as a USB-Host to communicate to a connected Samsung Tablet, but i can't get it working. I need to act as a host because i want also be able to supply the tablet with power.
The software i'm currently using is:
# MPLAB X IDE v4.10
# MCC v3.45.1 (Core v4.35)
# XC32 v2.10
# USB Framework Lite by Microchip Technology Library version 1.25.5 built from core v4.15
The problem that i get is the error USB_CANNOT_ENUMERATE and the USB statemachine enters into the holding state.
A common problem in many other posts regarding USB-Host problems was a wrong USB Clock setup or the use of the internal oscillator. I do have an external quartz crystal. It's a 12MHz quartz crystal with +-50ppm, which should give me a USB clock speed of 48MHz with a deviation of only 2400Hz (0.00005%).
In "MCC#System Module" i selected "External Clock" with a frequency of 12MHz.My PLL divider is 1:4 and my multiplier is 8:1. The resulting frequencies shown in MCC are 24MHz for SYSCLK/PBCLK, and 48MHz for USB Clock. (MCC does not show any warnings/errors regarding a wrong USB-Clock.)
In "MCC# MLA USB Host Lite" i've ticked "HID Vendor" with a maximum of 1 HID devices and a data size of 8.
I'm initializing the TPL with the following Vendor- and ProductId which i've read via the Windows Device Manager.
I did allocate 4096 Bytes for the heap. The minimum stack size is 64 Bytes.
-------- u***_host_config.h --------
#define USB_SUPPORT_HOST
#define NUM_TPL_ENTRIES 1
...
-------- u***_host_config.c --------
...
USB_TPL u***TPL[] = {
// INIT_VID_PID(VendorId, ProductId), Configuration, ClientDriver, {flags}
// INIT_CL_SC_P(Class, SubClass, Protocol), Configuration, ClientDriver, {flags}
{INIT_VID_PID(0x04E8, 0x6860), 0, 0, {0}}
};
I'm also calling USBHostTasks in my main.c while-loop on a regular basis.
-------- main.c --------
int main(void) {
SYSTEM_Initialize();
// When using interrupts, you need to set the Global Interrupt Enable bits.
// Enable the Global Interrupts
INTERRUPT_GlobalEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalDisable();
...
while (StateMachine_isActive()) {
StateMachine_action();
...
USBHostTasks();
...
}
}
The following output shows the u***_host.c debug output which is printed to a terminal via UART2 (Baudrate of 460800).
(Note: I removed the '~' [One Millisecond Timer ISR] from it and i'm only printing the U1EIR once each line [unless it changes]...)
Error value of 10h in U1EIR is:
BTOEF = Bus Turnaround Time-out Error Flag bit
This type of error occurs when more than 16-bit times of Idle from the previous End-of-Packet (EOP) has elapsed.
-------- USB-host debug output --------
***** System Initialized *****
HOST: Initializing DETACHED state.
***** EVENT_VBUS_REQUEST_POWER *****
[>
HOST: Starting settling delay.
HOST: Resetting the device.
HOST: Reset recovery.
HOST: Reset complete.
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Resetting the device.
HOST: Reset recovery.
HOST: Reset complete.
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Resetting the device.
HOST: Reset recovery.
HOST: Reset complete.
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Getting Device Descriptor size. #10h( BTOEF )!#!#!#!#!#!#!#!#!#!=
HOST: Holding.
***** EVENT_CANNOT_ENUMERATE *****
The attached schematic shows my wiring:
# CHARGER is my 5V power supply which comes from the 230V AC-Charger of the tablet. This is also connected to VBUS.
# LDO is my 3.3V voltage regulator for the PIC. This is also connected to VUSB3V3.
# TABLET is my USB-Connection to the tablet:
USB_5V is connected to 5V from CHARGER
USB_D- is connected to D- of the PIC
USB_D+ is connected to D+ of the PIC
USB_ID is not connected
GND is connected to Ground
If i'm not mistaken, VBUS is configured as input and only monitors the voltage of the bus and is mainly used if USB is used as a device. VBUSON/USB_ID would only be used if OTG is supported.
One problem regarding my clock might be a wrong base frequency though, but MCC doesn't complain about it.
In "Section 27. “USB OnThe-Go(OTG)” (DS61126)" note 5 on page 3 is saying:
USB PLL UFIN requirements: 4 MHz <= UFIN <= 5 MHz
# Would buying a new quartz crystal with 4MHz +-50ppm fix my problem? Or is it possible to select a PLL-Divider of 3?
# Is my type of oscillator wrong?
# If not what could cause my problems?
# Am i missing some function calls?
# Is the USB-Setup wrong?
Thank you in advance
EDIT Note: I'll not be able to answer before tomorrow morning 7 o'clock.
Attached Image(s)