summaryrefslogtreecommitdiff
path: root/docs/troubleshooting.rst
blob: 613c7fceff1bc5c9f39ae68065cea273e0c7c2d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
***************
Troubleshooting
***************

This guide helps you diagnose and fix common issues when developing with TinyUSB.

Build Issues
============

Toolchain Problems
------------------

**"arm-none-eabi-gcc: command not found"**

The ARM GCC toolchain is not installed or not in PATH.

*Solution*:

.. code-block:: bash

   # Ubuntu/Debian
   $ sudo apt-get update && sudo apt-get install gcc-arm-none-eabi

   # macOS with Homebrew
   $ brew install --cask gcc-arm-embedded

   # Windows: Download from ARM website and add to PATH

**"make: command not found" or CMake errors**

Build tools are missing.

*Solution*:

.. code-block:: bash

   # Ubuntu/Debian
   $ sudo apt-get install build-essential cmake

   # macOS
   $ xcode-select --install
   $ brew install cmake

Dependency Issues
-----------------

**"No rule to make target" or missing header files**

Dependencies for your MCU family are not downloaded.

*Solution*:

.. code-block:: bash

   # Download dependencies for specific board or family
   $ python tools/get_deps.py -b stm32h743eval  # Replace with your board
   $ python tools/get_deps.py stm32f4           # Replace with your family

   # Or from example directory
   cd examples/device/cdc_msc
   make BOARD=your_board get-deps

**Board Not Found**

Invalid board name in build command.

*Diagnosis*:

.. code-block:: bash

   # List available boards for a family
   ls hw/bsp/stm32f4/boards/

*Solution*: Use exact board name from the listing.

Runtime Issues
==============

Check :doc:`reference/device_issues` for known hardware-specific issues that may affect USB functionality on your device.

Device Mode Problems
--------------------

**Device not recognized by host**

The most common issue - host doesn't see your USB device.

*Diagnosis steps*:

1. Check USB cable (must support data, not just power)
2. Enable logging: build with ``LOG=2``
3. Use different USB ports/hosts
4. Check device manager (Windows) or ``dmesg`` (Linux)

*Common causes and solutions*:

- **Invalid descriptors**: Review ``usb_descriptors.c`` carefully
- **``tud_task()`` not called**: Ensure regular calls in main loop (< 1ms interval)
- **Wrong USB configuration**: Check ``tusb_config.h`` settings
- **Hardware issues**: Verify USB pins, crystal/clock configuration

**Enumeration starts but fails**

Device is detected but configuration fails.

*Diagnosis*:

.. code-block:: bash

   # Build with logging enabled
   make BOARD=your_board LOG=2 all

*Look for*:

- Setup request handling errors
- Endpoint configuration problems
- String descriptor issues

*Solutions*:

- Implement all required descriptors
- Check endpoint sizes match descriptors
- Ensure control endpoint (EP0) handling is correct

**Data transfer issues**

Device enumerates but data doesn't transfer correctly.

*Common causes*:

- Buffer overruns in class callbacks
- Incorrect endpoint usage (IN vs OUT)
- Flow control issues in CDC class

*Solutions*:

- Check buffer sizes in callbacks
- Verify endpoint directions in descriptors
- Implement proper flow control

Host Mode Problems
------------------

**No devices detected**

Host application doesn't see connected devices.

*Hardware checks*:

- Power supply adequate for host mode
- USB-A connector for host (not micro-USB)
- Board supports host mode on selected port

*Software checks*:

- ``tuh_task()`` called regularly
- Host stack enabled in ``tusb_config.h``
- Correct root hub port configuration

**Device enumeration fails**

Devices connect but enumeration fails.

*Diagnosis*:

.. code-block:: bash

   # Enable host logging
   make BOARD=your_board LOG=2 RHPORT_HOST=1 all

*Common issues*:

- Power supply insufficient during enumeration
- Timing issues with slow devices
- USB hub compatibility problems

**Class driver issues**

Device enumerates but class-specific communication fails.

*Troubleshooting*:

- Check device descriptors match expected class
- Verify interface/endpoint assignments
- Some devices need device-specific handling

Performance Issues
==================

Slow Transfer Speeds
--------------------

**Symptoms**: Lower than expected USB transfer rates

*Causes and solutions*: Improve **task scheduling** by calling ``tud_task()``/``tuh_task()`` more frequently to ensure timely USB event processing. Consider increasing **endpoint buffer sizes** for bulk transfers to reduce the frequency of small transfers. Enable **DMA usage** for USB transfers if your hardware supports it to offload CPU processing. Finally, use **High Speed** (480 Mbps) instead of Full Speed (12 Mbps) when possible to achieve better throughput.

High CPU Usage
--------------

**Symptoms**: MCU spending too much time in USB handling

*Solutions*:

- Use efficient logging (RTT/SWO instead of UART)
- Reduce log level in production builds
- Optimize descriptor parsing
- Use DMA for data transfers

Hardware-Specific Issues
========================

STM32 Issues
------------

**Clock configuration problems**:

- USB requires precise 48MHz clock
- HSE crystal must be configured correctly
- PLL settings affect USB timing

**Pin configuration**:

- USB pins need specific alternate function settings
- VBUS sensing configuration
- ID pin for OTG applications

RP2040 Issues
-------------

**PIO-USB for host mode**:

- Requires specific pin assignments
- CPU overclocking may be needed for reliable operation
- Timing-sensitive - avoid long interrupt disable periods

ESP32 Issues
------------

**USB peripheral differences**:

- ESP32-S2/S3/P4 have different USB capabilities
- DMA configuration varies between models

Advanced Debugging
==================

Using USB Analyzers
-------------------

For complex issues, hardware USB analyzers provide detailed protocol traces:

- **Wireshark** with USBPcap (Windows) or usbmon (Linux)
- **Hardware analyzers**: Total Phase Beagle, LeCroy USB analyzers
- **Logic analyzers**: For timing analysis of USB signals

Debugging with GDB
------------------

Debugging with traditional debuggers is limited due to the real time nature of USB.
However, especially for diagnosis of crashes, it can still be useful.

.. code-block:: bash

   # Build with debug info
   make BOARD=your_board DEBUG=1 all

   # Use with debugger
   arm-none-eabi-gdb build/your_app.elf

*Useful breakpoints*:

- ``dcd_int_handler()`` - USB interrupt entry
- ``tud_task()`` - Main device task
- Class-specific callbacks

Custom Logging
--------------

For production debugging, implement custom logging:

.. code-block:: c

   // In tusb_config.h
   #define CFG_TUSB_DEBUG_PRINTF   my_printf

   // Your implementation
   void my_printf(const char* format, ...) {
     // Send to RTT, SWO, or custom interface
   }

Getting Help
============

When reporting issues:

1. **Minimal reproducible example**: Simplify to bare minimum
2. **Build information**: Board, toolchain version, build flags
3. **Logs**: Include output with ``LOG=2`` enabled
4. **Hardware details**: Board revision, USB connections, power supply
5. **Host environment**: OS version, USB port type

**Resources**:

- GitHub Discussions: https://github.com/hathach/tinyusb/discussions
- Issue Tracker: https://github.com/hathach/tinyusb/issues
- Documentation: https://docs.tinyusb.org