mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
62a8e39c9b
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -26,4 +26,4 @@ Steps to reproduce the behavior:
|
||||
If applicable, add screenshots, bus capture to help explain your problem.
|
||||
|
||||
**Log**
|
||||
Please provide the stack's log (uart/rtt/swo) where the issue occurred, best with comments to explain the actual events. To enable logging, add `LOG=2` to to the make command if building with stock examples or set `CFG_TUSB_DEBUG=2` in your tusb_config.h. More information can be found at [example's readme](/examples/readme.md)
|
||||
Please provide the stack's log (uart/rtt/swo) where the issue occurred, best with comments to explain the actual events. To enable logging, add `LOG=2` to to the make command if building with stock examples or set `CFG_TUSB_DEBUG=2` in your tusb_config.h. More information can be found at [example's readme](/docs/getting_started.md)
|
||||
|
27
.github/workflows/build.yml
vendored
27
.github/workflows/build.yml
vendored
@ -26,9 +26,22 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
example: ['board_test', 'cdc_dual_ports', 'cdc_msc', 'cdc_msc_freertos', 'dfu_rt',
|
||||
'hid_composite', 'hid_composite_freertos', 'hid_generic_inout', 'midi_test', 'msc_dual_lun', 'net_lwip_webserver',
|
||||
'usbtmc', 'webusb_serial']
|
||||
example:
|
||||
- 'device/board_test'
|
||||
- 'device/cdc_dual_ports'
|
||||
- 'device/cdc_msc'
|
||||
- 'device/cdc_msc_freertos'
|
||||
- 'device/dfu_rt'
|
||||
- 'device/hid_composite'
|
||||
- 'device/hid_composite_freertos'
|
||||
- 'device/hid_generic_inout'
|
||||
- 'device/midi_test'
|
||||
- 'device/msc_dual_lun'
|
||||
- 'device/net_lwip_webserver'
|
||||
- 'device/usbtmc'
|
||||
- 'device/webusb_serial'
|
||||
- 'host/cdc_msc_hid'
|
||||
|
||||
steps:
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v1
|
||||
@ -41,10 +54,12 @@ jobs:
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: /tmp/dl/
|
||||
# Increment serial number at end when updating downloads
|
||||
key: msp430-${{ runner.os }}-0
|
||||
# Increment gcc version number at end when updating downloads
|
||||
key: msp430-${{ runner.os }}-9.2.0.50
|
||||
|
||||
- name: Install Toolchains
|
||||
env:
|
||||
MSP430GCC_URL: http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2
|
||||
run: |
|
||||
# ARM & RISC-V GCC from xpack
|
||||
npm install --global xpm
|
||||
@ -55,7 +70,7 @@ jobs:
|
||||
|
||||
# TI MSP430 GCC
|
||||
mkdir -p /tmp/dl/
|
||||
[ -f "/tmp/dl/msp430-gcc.tar.bz2" ] || wget --progress=dot:mega http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/8_3_0_0/exports/msp430-gcc-8.3.0.16_linux64.tar.bz2 -O /tmp/dl/msp430-gcc.tar.bz2
|
||||
[ -f "/tmp/dl/msp430-gcc.tar.bz2" ] || wget --progress=dot:mega $MSP430GCC_URL -O /tmp/dl/msp430-gcc.tar.bz2
|
||||
tar -C $HOME -xaf /tmp/dl/msp430-gcc.tar.bz2
|
||||
echo "::add-path::`echo $HOME/msp430-gcc-*_linux64/bin`"
|
||||
|
||||
|
@ -32,7 +32,7 @@ The stack supports the following MCUs:
|
||||
|
||||
- **Espressif:** ESP32-S2
|
||||
- **Dialog:** DA1469x
|
||||
- **MicroChip:** SAMD21, SAMD51, SAME5x (device only)
|
||||
- **MicroChip:** SAMD11, SAMD21, SAMD51, SAME5x, SAMG (device only)
|
||||
- **NordicSemi:** nRF52833, nRF52840
|
||||
- **Nuvoton:** NUC120, NUC121/NUC125, NUC126, NUC505
|
||||
- **NXP:**
|
||||
|
@ -19,7 +19,7 @@ This code base already had supported for a handful of following boards (sorted a
|
||||
- [DA14695 Development Kit – USB](https://www.dialog-semiconductor.com/products/da14695-development-kit-usb)
|
||||
- [DA1469x Development Kit – Pro](https://www.dialog-semiconductor.com/products/da14695-development-kit-pro)
|
||||
|
||||
### MicroChip SAMD
|
||||
### MicroChip SAM
|
||||
|
||||
- [Adafruit Circuit Playground Express](https://www.adafruit.com/product/3333)
|
||||
- [Adafruit Feather M0 Express](https://www.adafruit.com/product/3403)
|
||||
@ -28,8 +28,10 @@ This code base already had supported for a handful of following boards (sorted a
|
||||
- [Adafruit ItsyBitsy M4 Express](https://www.adafruit.com/product/3800)
|
||||
- [Adafruit Metro M0 Express](https://www.adafruit.com/product/3505)
|
||||
- [Adafruit Metro M4 Express](https://www.adafruit.com/product/3382)
|
||||
- [Seeeduino Xiao](https://www.seeedstudio.com/Seeeduino-XIAO-Arduino-Microcontroller-SAMD21-Cortex-M0+-p-4426.html)
|
||||
- [Great Scott Gadgets LUNA](https://greatscottgadgets.com/luna/)
|
||||
- [Microchip SAMD11 Xplained](https://www.microchip.com/developmenttools/ProductDetails/atsamd11-xpro)
|
||||
- [Microchip SAMG55 Xplained Pro Evaluation Kit](https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/ATSAMG55-XPRO)
|
||||
- [Seeeduino Xiao](https://www.seeedstudio.com/Seeeduino-XIAO-Arduino-Microcontroller-SAMD21-Cortex-M0+-p-4426.html)
|
||||
|
||||
### Nordic nRF5x
|
||||
|
||||
@ -37,6 +39,7 @@ This code base already had supported for a handful of following boards (sorted a
|
||||
- [Adafruit CLUE](https://www.adafruit.com/product/4500)
|
||||
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
|
||||
- [Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
|
||||
- [Adafruit ItsyBitsy nRF52840 Express](https://www.adafruit.com/product/4481)
|
||||
- [Arduino Nano 33 BLE](https://store.arduino.cc/usa/nano-33-ble)
|
||||
- [Arduino Nano 33 BLE Sense](https://store.arduino.cc/usa/nano-33-ble-sense)
|
||||
- [Maker Diary nRF52840 MDK Dongle](https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle)
|
||||
|
@ -1,14 +1,6 @@
|
||||
# Getting Started #
|
||||
|
||||
## Get
|
||||
|
||||
```
|
||||
git clone git@github.com:hathach/tinyusb.git tinyusb
|
||||
```
|
||||
|
||||
*examples* is the folder where all the application & project files are located. There are demos for both device and hosts. For each, there are different projects for each of supported RTOS. Click to have more information on how to [build](../examples/readme.md) and run [device](../examples/device/readme.md) demos.
|
||||
|
||||
## Add tinyusb to your project
|
||||
## Add TinyUSB to your project
|
||||
|
||||
It is relatively simple to incorporate tinyusb to your (existing) project
|
||||
|
||||
@ -37,6 +29,104 @@ int main(void)
|
||||
}
|
||||
~~~
|
||||
|
||||
[//]: # "\subpage md_boards_readme"
|
||||
[//]: # "\subpage md_doxygen_started_demo"
|
||||
[//]: # "\subpage md_tools_readme"
|
||||
## Examples
|
||||
|
||||
For your convenience, TinyUSB contains a handful of examples for both host and device with/without RTOS to quickly test the functionality as well as demonstrate how API() should be used. Most examples will work on most of [the supported Boards](boards.md). Firstly we need to `git clone` if not already
|
||||
|
||||
```
|
||||
$ git clone https://github.com/hathach/tinyusb tinyusb
|
||||
$ cd tinyusb
|
||||
```
|
||||
|
||||
TinyUSB examples includes external repos aka submodules to provide low-level MCU peripheral's driver as well as external libraries such as FreeRTOS to compile with. Therefore we will firstly fetch those mcu driver repo by running this command in the top folder repo
|
||||
|
||||
```
|
||||
$ git submodule update --init --recursive
|
||||
```
|
||||
|
||||
It will takes a bit of time due to the number of supported MCUs, luckily we only need to do this once. Or if you only want to test with a specific mcu, you could only fetch its driver submodule.
|
||||
|
||||
### Build
|
||||
|
||||
To build example, first change directory to an example folder.
|
||||
|
||||
```
|
||||
$ cd examples/device/cdc_msc
|
||||
```
|
||||
|
||||
Then compile with `make BOARD=[board_name] all`, for example
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express all
|
||||
```
|
||||
|
||||
#### Port Selection
|
||||
|
||||
If a board has several ports, one port is chosen by default in the individual board.mk file. Use option `PORT=x` To choose another port. For example to select the HS port of a STM32F746Disco board, use:
|
||||
|
||||
```
|
||||
$ make BOARD=stm32f746disco PORT=1 all
|
||||
```
|
||||
|
||||
#### Port Speed
|
||||
|
||||
A MCU can support multiple operational speed. By default, the example build system will use the fastest supported on the board. Use option `SPEED=full/high` e.g To force F723 operate at full instead of default high speed
|
||||
|
||||
```
|
||||
$ make BOARD=stm32f746disco SPEED=full all
|
||||
```
|
||||
|
||||
### Debug
|
||||
|
||||
To compile for debugging add `DEBUG=1`, for example
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express DEBUG=1 all
|
||||
```
|
||||
|
||||
#### Log
|
||||
|
||||
Should you have an issue running example and/or submitting an bug report. You could enable TinyUSB built-in debug logging with optional `LOG=`. LOG=1 will only print out error message, LOG=2 print more information with on-going events. LOG=3 or higher is not used yet.
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 all
|
||||
```
|
||||
|
||||
#### Logger
|
||||
|
||||
By default log message is printed via on-board UART which is slow and take lots of CPU time comparing to USB speed. If your board support on-board/external debugger, it would be more efficient to use it for logging. There are 2 protocols:
|
||||
|
||||
- `LOGGER=rtt`: use [Segger RTT protocol](https://www.segger.com/products/debug-probes/j-link/technology/about-real-time-transfer/)
|
||||
- Cons: requires jlink as the debugger.
|
||||
- Pros: work with most if not all MCUs
|
||||
- Software viewer is JLink RTT Viewer/Client/Logger which is bundled with JLink driver package.
|
||||
- `LOGGER=swo`: Use dedicated SWO pin of ARM Cortex SWD debug header.
|
||||
- Cons: only work with ARM Cortex MCUs minus M0
|
||||
- Pros: should be compatible with more debugger that support SWO.
|
||||
- Software viewer should be provided along with your debugger driver.
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=rtt all
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=swo all
|
||||
```
|
||||
|
||||
### Flash
|
||||
|
||||
`flash` target will use the default on-board debugger (jlink/cmsisdap/stlink/dfu) to flash the binary, please install those support software in advance. Some board use bootloader/DFU via serial which is required to pass to make command
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express flash
|
||||
$ make SERIAL=/dev/ttyACM0 BOARD=feather_nrf52840_express flash
|
||||
```
|
||||
|
||||
Since jlink can be used with most of the boards, there is also `flash-jlink` target for your convenience.
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express flash-jlink
|
||||
```
|
||||
|
||||
Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can be generated with `uf2` target
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express all uf2
|
||||
```
|
||||
|
@ -62,7 +62,7 @@ All of the code for the low-level device API is in `src/portable/<vendor>/<chip
|
||||
##### dcd_init
|
||||
|
||||
Initializes the USB peripheral for device mode and enables it.
|
||||
This function should leave an internal D+/D- pull-up in its default power-on state. `dcd_connect` will be called by the USBD core following `dcd_init`.
|
||||
This function should enable internal D+/D- pull-up for enumeration.
|
||||
|
||||
##### dcd_int_enable / dcd_int_disable
|
||||
|
||||
|
0
examples/device/cdc_msc/.skip.MCU_SAMD11
Normal file
0
examples/device/cdc_msc/.skip.MCU_SAMD11
Normal file
0
examples/device/cdc_msc_freertos/.skip.MCU_SAMD11
Normal file
0
examples/device/cdc_msc_freertos/.skip.MCU_SAMD11
Normal file
0
examples/device/msc_dual_lun/.skip.MCU_SAMD11
Normal file
0
examples/device/msc_dual_lun/.skip.MCU_SAMD11
Normal file
0
examples/device/net_lwip_webserver/.skip.MCU_SAMD11
Normal file
0
examples/device/net_lwip_webserver/.skip.MCU_SAMD11
Normal file
@ -6,9 +6,6 @@ CFLAGS += \
|
||||
-DTCP_WND=2*TCP_MSS \
|
||||
-DHTTPD_USE_CUSTOM_FSDATA=0
|
||||
|
||||
# TODO rndis_reports.c and net_device cause cast algin warnings
|
||||
CFLAGS += -Wno-error=cast-align
|
||||
|
||||
INC += \
|
||||
src \
|
||||
$(TOP)/hw \
|
||||
|
0
examples/host/cdc_msc_hid/.only.MCU_LPC175X_6X
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC175X_6X
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC177X_8X
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC177X_8X
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC18XX
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC18XX
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC40XX
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC40XX
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC43XX
Normal file
0
examples/host/cdc_msc_hid/.only.MCU_LPC43XX
Normal file
26
examples/host/cdc_msc_hid/Makefile
Normal file
26
examples/host/cdc_msc_hid/Makefile
Normal file
@ -0,0 +1,26 @@
|
||||
include ../../../tools/top.mk
|
||||
include ../../make.mk
|
||||
|
||||
INC += \
|
||||
src \
|
||||
$(TOP)/hw \
|
||||
|
||||
# Example source
|
||||
EXAMPLE_SOURCE += $(wildcard src/*.c)
|
||||
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
|
||||
|
||||
CFLAGS += -Wno-error=cast-align
|
||||
|
||||
# TinyUSB Host Stack source
|
||||
SRC_C += \
|
||||
src/class/cdc/cdc_host.c \
|
||||
src/class/hid/hid_host.c \
|
||||
src/class/msc/msc_host.c \
|
||||
src/host/usbh.c \
|
||||
src/host/hub.c \
|
||||
src/host/ehci/ehci.c \
|
||||
src/host/ohci/ohci.c \
|
||||
src/portable/nxp/lpc18_43/hcd_lpc18_43.c \
|
||||
src/portable/nxp/lpc17_40/hcd_lpc17_40.c
|
||||
|
||||
include ../../rules.mk
|
@ -19,8 +19,8 @@
|
||||
arm_target_device_name="LPC1769"
|
||||
arm_target_interface_type="SWD"
|
||||
build_treat_warnings_as_errors="Yes"
|
||||
c_preprocessor_definitions="LPC175x_6x;__LPC1700_FAMILY;__LPC176x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;BOARD_LPCXPRESSO1769;CFG_TUSB_MCU=OPT_MCU_LPC175X_6X"
|
||||
c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)/inc"
|
||||
c_preprocessor_definitions="LPC175x_6x;__LPC1700_FAMILY;__LPC176x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;BOARD_LPCXPRESSO1769;CFG_TUSB_MCU=OPT_MCU_LPC175X_6X;CFG_TUSB_DEBUG=2;LOGGER_RTT"
|
||||
c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)/inc;$(rootDir)/lib/SEGGER_RTT/RTT"
|
||||
debug_register_definition_file="LPC176x5x_Registers.xml"
|
||||
debug_target_connection="J-Link"
|
||||
gcc_enable_all_warnings="Yes"
|
||||
@ -101,12 +101,19 @@
|
||||
<file file_name="LPC176x5x_Vectors.s" />
|
||||
<file file_name="thumb_crt0.s" />
|
||||
</folder>
|
||||
<folder
|
||||
Name="segger_rtt"
|
||||
exclude=""
|
||||
filter="*.c;*.h"
|
||||
path="../../../../../lib/segger_rtt"
|
||||
recurse="No" />
|
||||
<folder Name="lib">
|
||||
<folder Name="SEGGER_RTT">
|
||||
<folder Name="RTT">
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT.c" />
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT.h" />
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT_Conf.h" />
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT_printf.c" />
|
||||
</folder>
|
||||
<folder Name="Syscalls">
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/Syscalls/SEGGER_RTT_Syscalls_SES.c" />
|
||||
</folder>
|
||||
</folder>
|
||||
</folder>
|
||||
</project>
|
||||
<configuration Name="LPCXpresso 1769" />
|
||||
</solution>
|
||||
|
@ -17,8 +17,8 @@
|
||||
arm_target_debug_interface_type="ADIv5"
|
||||
arm_target_device_name="LPC1857"
|
||||
arm_target_interface_type="SWD"
|
||||
c_preprocessor_definitions="LPC18xx;__LPC1800_FAMILY;__LPC185x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;BOARD_MCB1800;CFG_TUSB_MCU=OPT_MCU_LPC18XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")))"
|
||||
c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)//inc;$(lpcDir)//inc/config_18xx"
|
||||
c_preprocessor_definitions="LPC18xx;__LPC1800_FAMILY;__LPC185x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;BOARD_MCB1800;CFG_TUSB_MCU=OPT_MCU_LPC18XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")));CFG_TUSB_DEBUG=2"
|
||||
c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)//inc;$(lpcDir)//inc/config_18xx;$(rootDir)/lib/SEGGER_RTT/RTT"
|
||||
debug_register_definition_file="$(ProjectDir)/LPC18xx_Registers.xml"
|
||||
debug_target_connection="J-Link"
|
||||
gcc_entry_point="Reset_Handler"
|
||||
@ -53,6 +53,7 @@
|
||||
<folder Name="mcb1800">
|
||||
<file file_name="../../../../../hw/bsp/mcb1800/mcb1800.c" />
|
||||
</folder>
|
||||
<file file_name="../../../../../hw/bsp/board.c" />
|
||||
</folder>
|
||||
<folder Name="mcu">
|
||||
<folder Name="nxp">
|
||||
@ -101,12 +102,6 @@
|
||||
</folder>
|
||||
</folder>
|
||||
</folder>
|
||||
<folder
|
||||
Name="segger_rtt"
|
||||
exclude=""
|
||||
filter="*.c;*.h"
|
||||
path="../../../../../lib/segger_rtt"
|
||||
recurse="No" />
|
||||
<folder
|
||||
Name="src"
|
||||
exclude=""
|
||||
@ -119,6 +114,21 @@
|
||||
filter="*.c;*.h"
|
||||
path="../../../../../src"
|
||||
recurse="Yes" />
|
||||
<folder Name="lib">
|
||||
<folder Name="SEGGER_RTT">
|
||||
<folder Name="RTT">
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT.c" />
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT_printf.c" />
|
||||
</folder>
|
||||
<folder Name="Syscalls">
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/Syscalls/SEGGER_RTT_Syscalls_SES.c" />
|
||||
</folder>
|
||||
</folder>
|
||||
</folder>
|
||||
<configuration
|
||||
Name="MCB1800"
|
||||
arm_target_interface_type="JTAG"
|
||||
speed="12000" />
|
||||
</project>
|
||||
<configuration
|
||||
Name="MCB1800"
|
||||
|
@ -18,8 +18,8 @@
|
||||
arm_target_debug_interface_type="ADIv5"
|
||||
arm_target_device_name="LPC4088"
|
||||
arm_target_interface_type="SWD"
|
||||
c_preprocessor_definitions="CORE_M4;__LPC4000_FAMILY;__LPC408x_SUBFAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_EA4088QS;CFG_TUSB_MCU=OPT_MCU_LPC40XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")))"
|
||||
c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)/inc"
|
||||
c_preprocessor_definitions="CORE_M4;__LPC4000_FAMILY;__LPC408x_SUBFAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_EA4088QS;CFG_TUSB_MCU=OPT_MCU_LPC40XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")));CFG_TUSB_DEBUG=2;LOGGER_RTT"
|
||||
c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)/inc;$(rootDir)/lib/SEGGER_RTT/RTT"
|
||||
debug_register_definition_file="$(ProjectDir)/LPC408x_7x_Registers.xml"
|
||||
debug_target_connection="J-Link"
|
||||
gcc_enable_all_warnings="Yes"
|
||||
@ -55,6 +55,7 @@
|
||||
<folder Name="ea4088qs">
|
||||
<file file_name="../../../../../hw/bsp/ea4088qs/ea4088qs.c" />
|
||||
</folder>
|
||||
<file file_name="../../../../../hw/bsp/board.c" />
|
||||
</folder>
|
||||
<folder Name="mcu">
|
||||
<folder Name="nxp">
|
||||
@ -91,12 +92,6 @@
|
||||
</folder>
|
||||
</folder>
|
||||
</folder>
|
||||
<folder
|
||||
Name="segger_rtt"
|
||||
exclude=""
|
||||
filter="*.c;*.h"
|
||||
path="../../../../../lib/segger_rtt"
|
||||
recurse="No" />
|
||||
<folder
|
||||
Name="src"
|
||||
exclude=""
|
||||
@ -109,6 +104,19 @@
|
||||
filter="*.c;*.h"
|
||||
path="../../../../../src"
|
||||
recurse="Yes" />
|
||||
<folder Name="lib">
|
||||
<folder Name="SEGGER_RTT">
|
||||
<folder Name="RTT">
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT.c" />
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT.h" />
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT_Conf.h" />
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT_printf.c" />
|
||||
</folder>
|
||||
<folder Name="Syscalls">
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/Syscalls/SEGGER_RTT_Syscalls_SES.c" />
|
||||
</folder>
|
||||
</folder>
|
||||
</folder>
|
||||
</project>
|
||||
<configuration
|
||||
Name="EA4088 QuickStart"
|
||||
|
@ -20,7 +20,7 @@
|
||||
arm_target_interface_type="SWD"
|
||||
build_treat_warnings_as_errors="No"
|
||||
c_preprocessor_definitions="CORE_M4;__LPC4300_FAMILY;__LPC435x_SUBFAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_EA4357;CFG_TUSB_MCU=OPT_MCU_LPC43XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")))"
|
||||
c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)//inc;$(lpcDir)//inc/config_43xx"
|
||||
c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)//inc;$(rootDir)/lib/SEGGER_RTT/RTT;$(lpcDir)//inc/config_43xx"
|
||||
debug_register_definition_file="LPC43xx_Registers.xml"
|
||||
debug_target_connection="J-Link"
|
||||
gcc_enable_all_warnings="Yes"
|
||||
@ -122,11 +122,16 @@
|
||||
<file file_name="LPC43xx_Vectors.s" />
|
||||
<file file_name="thumb_crt0.s" />
|
||||
</folder>
|
||||
<folder
|
||||
Name="segger_rtt"
|
||||
exclude=""
|
||||
filter="*.c;*.h"
|
||||
path="../../../../../lib/segger_rtt"
|
||||
recurse="No" />
|
||||
<folder Name="lib">
|
||||
<folder Name="SEGGER_RTT">
|
||||
<folder Name="RTT">
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT.c" />
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/RTT/SEGGER_RTT_printf.c" />
|
||||
</folder>
|
||||
<folder Name="Syscalls">
|
||||
<file file_name="../../../../../lib/SEGGER_RTT/Syscalls/SEGGER_RTT_Syscalls_SES.c" />
|
||||
</folder>
|
||||
</folder>
|
||||
</folder>
|
||||
</project>
|
||||
</solution>
|
||||
|
@ -58,7 +58,7 @@ int main(void)
|
||||
cdc_task();
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
#if CFG_TUH_HID_KEYBOARD || CFG_TUH_HID_MOUSE
|
||||
hid_task();
|
||||
#endif
|
||||
}
|
||||
@ -75,7 +75,7 @@ CFG_TUSB_MEM_SECTION static char serial_in_buffer[64] = { 0 };
|
||||
void tuh_mount_cb(uint8_t dev_addr)
|
||||
{
|
||||
// application set-up
|
||||
printf("\na CDC device (address %d) is mounted\n", dev_addr);
|
||||
printf("A device with address %d is mounted\r\n", dev_addr);
|
||||
|
||||
tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // schedule first transfer
|
||||
}
|
||||
@ -83,7 +83,7 @@ void tuh_mount_cb(uint8_t dev_addr)
|
||||
void tuh_umount_cb(uint8_t dev_addr)
|
||||
{
|
||||
// application tear-down
|
||||
printf("\na CDC device (address %d) is unmounted \n", dev_addr);
|
||||
printf("A device with address %d is unmounted \r\n", dev_addr);
|
||||
}
|
||||
|
||||
// invoked ISR context
|
||||
@ -110,27 +110,83 @@ void cdc_task(void)
|
||||
// USB HID
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
|
||||
uint8_t const keycode2ascii[128][2] = { HID_KEYCODE_TO_ASCII };
|
||||
|
||||
// look up new key in previous keys
|
||||
static inline bool find_key_in_report(hid_keyboard_report_t const *p_report, uint8_t keycode)
|
||||
{
|
||||
for(uint8_t i=0; i<6; i++)
|
||||
{
|
||||
if (p_report->keycode[i] == keycode) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void process_kbd_report(hid_keyboard_report_t const *p_new_report)
|
||||
{
|
||||
static hid_keyboard_report_t prev_report = { 0, 0, {0} }; // previous report to check key released
|
||||
|
||||
//------------- example code ignore control (non-printable) key affects -------------//
|
||||
for(uint8_t i=0; i<6; i++)
|
||||
{
|
||||
if ( p_new_report->keycode[i] )
|
||||
{
|
||||
if ( find_key_in_report(&prev_report, p_new_report->keycode[i]) )
|
||||
{
|
||||
// exist in previous report means the current key is holding
|
||||
}else
|
||||
{
|
||||
// not existed in previous report means the current key is pressed
|
||||
bool const is_shift = p_new_report->modifier & (KEYBOARD_MODIFIER_LEFTSHIFT | KEYBOARD_MODIFIER_RIGHTSHIFT);
|
||||
uint8_t ch = keycode2ascii[p_new_report->keycode[i]][is_shift ? 1 : 0];
|
||||
putchar(ch);
|
||||
if ( ch == '\r' ) putchar('\n'); // added new line for enter key
|
||||
|
||||
fflush(stdout); // flush right away, else nanolib will wait for newline
|
||||
}
|
||||
}
|
||||
// TODO example skips key released
|
||||
}
|
||||
|
||||
prev_report = *p_new_report;
|
||||
}
|
||||
|
||||
CFG_TUSB_MEM_SECTION static hid_keyboard_report_t usb_keyboard_report;
|
||||
|
||||
void hid_task(void)
|
||||
{
|
||||
|
||||
uint8_t const addr = 1;
|
||||
if ( tuh_hid_keyboard_is_mounted(addr) )
|
||||
{
|
||||
if ( !tuh_hid_keyboard_is_busy(addr) )
|
||||
{
|
||||
process_kbd_report(&usb_keyboard_report);
|
||||
tuh_hid_keyboard_get_report(addr, &usb_keyboard_report);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tuh_hid_keyboard_mounted_cb(uint8_t dev_addr)
|
||||
{
|
||||
// application set-up
|
||||
printf("\na Keyboard device (address %d) is mounted\n", dev_addr);
|
||||
printf("A Keyboard device (address %d) is mounted\r\n", dev_addr);
|
||||
|
||||
tuh_hid_keyboard_get_report(dev_addr, &usb_keyboard_report);
|
||||
}
|
||||
|
||||
void tuh_hid_keyboard_unmounted_cb(uint8_t dev_addr)
|
||||
{
|
||||
// application tear-down
|
||||
printf("\na Keyboard device (address %d) is unmounted\n", dev_addr);
|
||||
printf("A Keyboard device (address %d) is unmounted\r\n", dev_addr);
|
||||
}
|
||||
|
||||
// invoked ISR context
|
||||
void tuh_hid_keyboard_isr(uint8_t dev_addr, xfer_result_t event)
|
||||
{
|
||||
|
||||
(void) dev_addr;
|
||||
(void) event;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -139,18 +195,20 @@ void tuh_hid_keyboard_isr(uint8_t dev_addr, xfer_result_t event)
|
||||
void tuh_hid_mouse_mounted_cb(uint8_t dev_addr)
|
||||
{
|
||||
// application set-up
|
||||
printf("\na Mouse device (address %d) is mounted\n", dev_addr);
|
||||
printf("A Mouse device (address %d) is mounted\r\n", dev_addr);
|
||||
}
|
||||
|
||||
void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr)
|
||||
{
|
||||
// application tear-down
|
||||
printf("\na Mouse device (address %d) is unmounted\n", dev_addr);
|
||||
printf("A Mouse device (address %d) is unmounted\r\n", dev_addr);
|
||||
}
|
||||
|
||||
// invoked ISR context
|
||||
void tuh_hid_mouse_isr(uint8_t dev_addr, xfer_result_t event)
|
||||
{
|
||||
(void) dev_addr;
|
||||
(void) event;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -187,16 +245,23 @@ void print_greeting(void)
|
||||
[OPT_OS_FREERTOS] = "FreeRTOS",
|
||||
};
|
||||
|
||||
printf("\n--------------------------------------------------------------------\n");
|
||||
printf("- Host example\n");
|
||||
printf("- if you find any bugs or get any questions, feel free to file an\n");
|
||||
printf("- issue at https://github.com/hathach/tinyusb\n");
|
||||
printf("--------------------------------------------------------------------\n\n");
|
||||
printf("--------------------------------------------------------------------\r\n");
|
||||
printf("- Host example\r\n");
|
||||
printf("- if you find any bugs or get any questions, feel free to file an\r\n");
|
||||
printf("- issue at https://github.com/hathach/tinyusb\r\n");
|
||||
printf("--------------------------------------------------------------------\r\n\r\n");
|
||||
|
||||
printf("This Host demo is configured to support:\r\n");
|
||||
printf(" - RTOS = %s\r\n", rtos_name[CFG_TUSB_OS]);
|
||||
|
||||
#if CFG_TUH_CDC
|
||||
printf(" - Communication Device Class\r\n");
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_MSC
|
||||
printf(" - Mass Storage\r\n");
|
||||
#endif
|
||||
|
||||
printf("This Host demo is configured to support:");
|
||||
printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
|
||||
// if (CFG_TUH_CDC ) puts(" - Communication Device Class");
|
||||
// if (CFG_TUH_MSC ) puts(" - Mass Storage");
|
||||
// if (CFG_TUH_HID_KEYBOARD ) puts(" - HID Keyboard");
|
||||
// if (CFG_TUH_HID_MOUSE ) puts(" - HID Mouse");
|
||||
}
|
||||
|
@ -35,23 +35,24 @@
|
||||
//------------- IMPLEMENTATION -------------//
|
||||
void tuh_msc_mounted_cb(uint8_t dev_addr)
|
||||
{
|
||||
puts("\na MassStorage device is mounted");
|
||||
printf("A MassStorage device is mounted\r\n");
|
||||
|
||||
// //------------- Disk Information -------------//
|
||||
// // SCSI VendorID[8] & ProductID[16] from Inquiry Command
|
||||
// uint8_t const* p_vendor = tuh_msc_get_vendor_name(dev_addr);
|
||||
// uint8_t const* p_product = tuh_msc_get_product_name(dev_addr);
|
||||
//
|
||||
// for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]);
|
||||
//
|
||||
// putchar(' ');
|
||||
// for(uint8_t i=0; i<16; i++) putchar(p_product[i]);
|
||||
// putchar('\n');
|
||||
//
|
||||
// uint32_t last_lba, block_size;
|
||||
// tuh_msc_get_capacity(dev_addr, &last_lba, &block_size);
|
||||
// printf("Disk Size: %d MB\n", (last_lba+1)/ ((1024*1024)/block_size) );
|
||||
// printf("LBA 0-0x%X Block Size: %d\n", last_lba, block_size);
|
||||
//------------- Disk Information -------------//
|
||||
// SCSI VendorID[8] & ProductID[16] from Inquiry Command
|
||||
uint8_t const* p_vendor = tuh_msc_get_vendor_name(dev_addr);
|
||||
uint8_t const* p_product = tuh_msc_get_product_name(dev_addr);
|
||||
|
||||
for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]);
|
||||
|
||||
putchar(' ');
|
||||
for(uint8_t i=0; i<16; i++) putchar(p_product[i]);
|
||||
putchar('\n');
|
||||
|
||||
uint32_t last_lba = 0;
|
||||
uint32_t block_size = 0;
|
||||
tuh_msc_get_capacity(dev_addr, &last_lba, &block_size);
|
||||
printf("Disk Size: %ld MB\r\n", (last_lba+1)/ ((1024*1024)/block_size) );
|
||||
printf("LBA 0-0x%lX Block Size: %ld\r\n", last_lba, block_size);
|
||||
//
|
||||
// //------------- file system (only 1 LUN support) -------------//
|
||||
// uint8_t phy_disk = dev_addr-1;
|
||||
@ -81,7 +82,8 @@ void tuh_msc_mounted_cb(uint8_t dev_addr)
|
||||
|
||||
void tuh_msc_unmounted_cb(uint8_t dev_addr)
|
||||
{
|
||||
puts("\na MassStorage device is unmounted");
|
||||
(void) dev_addr;
|
||||
printf("A MassStorage device is unmounted\r\n");
|
||||
|
||||
// uint8_t phy_disk = dev_addr-1;
|
||||
//
|
||||
|
@ -40,9 +40,9 @@
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
|
||||
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
|
||||
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
|
||||
#else
|
||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST
|
||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST
|
||||
#endif
|
||||
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
@ -69,29 +69,16 @@
|
||||
// CONFIGURATION
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
#define CFG_TUH_HUB 1
|
||||
#define CFG_TUH_HUB 0
|
||||
#define CFG_TUH_CDC 1
|
||||
#define CFG_TUH_HID_KEYBOARD 0
|
||||
#define CFG_TUH_HID_MOUSE 0
|
||||
#define CFG_TUH_HID_KEYBOARD 1
|
||||
#define CFG_TUH_HID_MOUSE 1
|
||||
#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported)
|
||||
#define CFG_TUH_MSC 0
|
||||
#define CFG_TUH_MSC 1
|
||||
#define CFG_TUH_VENDOR 0
|
||||
|
||||
#define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define CFG_TUD_CDC 0
|
||||
#define CFG_TUD_MSC 0
|
||||
#define CFG_TUD_HID 0
|
||||
#define CFG_TUD_VENDOR 0
|
||||
|
||||
// CDC FIFO size of TX and RX
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE 64
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE 64
|
||||
|
||||
// MSC Buffer size of Device Mass storage
|
||||
#define CFG_TUD_MSC_BUFSIZE 512
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -84,7 +84,6 @@ ifeq ($(LOGGER),rtt)
|
||||
RTT_SRC = lib/SEGGER_RTT
|
||||
CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
|
||||
INC += $(TOP)/$(RTT_SRC)/RTT
|
||||
SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT_printf.c
|
||||
SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
|
||||
else ifeq ($(LOGGER),swo)
|
||||
CFLAGS += -DLOGGER_SWO
|
||||
|
@ -1,104 +0,0 @@
|
||||
# Examples
|
||||
|
||||
## Clone this repo
|
||||
|
||||
```
|
||||
$ git clone https://github.com/hathach/tinyusb tinyusb
|
||||
$ cd tinyusb
|
||||
```
|
||||
|
||||
## Fetch submodule MCUs drivers
|
||||
|
||||
TinyUSB examples includes external repos aka submodules to provide low-level MCU peripheral's driver to compile with. Therefore we will firstly fetch those mcu driver repo by running this command in the top folder repo
|
||||
|
||||
```
|
||||
$ git submodule update --init --recursive
|
||||
```
|
||||
|
||||
It will takes a bit of time due to the number of supported MCUs, luckily we only need to do this once. Or if you only want to test with a specific mcu, you could only update its driver submodule
|
||||
|
||||
## Build
|
||||
|
||||
[Here is the list of supported Boards](docs/boards.md) that should work out of the box with provided examples (hopefully).
|
||||
To build example, first change directory to example folder.
|
||||
|
||||
```
|
||||
$ cd examples/device/cdc_msc
|
||||
```
|
||||
|
||||
Then compile with `make BOARD=[your_board] all`, for example
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express all
|
||||
```
|
||||
|
||||
**Port Selection**
|
||||
|
||||
If a board has several ports, one port is chosen by default in the individual board.mk file. Use option `PORT=x` To choose another port. For example to select the HS port of a STM32F746Disco board, use:
|
||||
|
||||
```
|
||||
$ make BOARD=stm32f746disco PORT=1 all
|
||||
```
|
||||
|
||||
**Port Speed**
|
||||
|
||||
A MCU can support multiple operational speed. By default, the example build system will use the fastest supported on the board. Use option `SPEED=full/high` e.g To force F723 operate at full instead of default high speed
|
||||
|
||||
```
|
||||
$ make BOARD=stm32f746disco SPEED=full all
|
||||
```
|
||||
|
||||
### Debug
|
||||
|
||||
To compile for debugging with debug symbols add `DEBUG=1`, for example
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express DEBUG=1 all
|
||||
```
|
||||
|
||||
#### Log
|
||||
|
||||
Should you have an issue running example and/or submitting an bug report. You could enable TinyUSB built-in debug logging with optional `LOG=`. LOG=1 will only print out error message, LOG=2 print more information with on-going events. LOG=3 or higher is not used yet.
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 all
|
||||
```
|
||||
|
||||
#### Logger
|
||||
|
||||
By default log message is printed via on-board UART which is slow and take lots of CPU time comparing to USB speed. If your board support on-board/external debugger, it would be more efficient to use it for logging. There are 2 protocols:
|
||||
|
||||
- `LOGGER=rtt`: use [Segger RTT protocol](https://www.segger.com/products/debug-probes/j-link/technology/about-real-time-transfer/)
|
||||
- Cons: requires jlink as the debugger.
|
||||
- Pros: work with most if not all MCUs
|
||||
- Software viewer is JLink RTT Viewer/Client/Logger which is bundled with JLink driver package.
|
||||
- `LOGGER=swo`: Use dedicated SWO pin of ARM Cortex SWD debug header.
|
||||
- Cons: only work with ARM Cortex MCUs minus M0
|
||||
- Pros: should be compatible with more debugger that support SWO.
|
||||
- Software viewer should be provided along with your debugger driver.
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=rtt all
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=swo all
|
||||
```
|
||||
|
||||
## Flash
|
||||
|
||||
`flash` target will use the default on-board debugger (jlink/cmsisdap/stlink/dfu) to flash the binary, please install those support software in advance. Some board use bootloader/DFU via serial which is required to pass to make command
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express flash
|
||||
$ make SERIAL=/dev/ttyACM0 BOARD=feather_nrf52840_express flash
|
||||
```
|
||||
|
||||
Since jlink can be used with most of the boards, there is also `flash-jlink` target for your convenience.
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express flash-jlink
|
||||
```
|
||||
|
||||
Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can be generated with `uf2` target
|
||||
|
||||
```
|
||||
$ make BOARD=feather_nrf52840_express all uf2
|
||||
```
|
@ -40,6 +40,8 @@
|
||||
#if defined(LOGGER_RTT)
|
||||
// Logging with RTT
|
||||
|
||||
// If using SES IDE, use the Syscalls/SEGGER_RTT_Syscalls_SES.c instead
|
||||
#if !(defined __SES_ARM) && !(defined __SES_RISCV) && !(defined __CROSSWORKS_ARM)
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count)
|
||||
@ -54,6 +56,7 @@ TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count)
|
||||
(void) fhdl;
|
||||
return SEGGER_RTT_Read(0, buf, count);
|
||||
}
|
||||
#endif
|
||||
|
||||
#elif defined(LOGGER_SWO)
|
||||
// Logging with SWO for ARM Cortex
|
||||
|
@ -52,7 +52,7 @@
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
|
||||
#include "nrf.h"
|
||||
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_SAMD21 || CFG_TUSB_MCU == OPT_MCU_SAMD51
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_SAMD11 || CFG_TUSB_MCU == OPT_MCU_SAMD21 || CFG_TUSB_MCU == OPT_MCU_SAMD51
|
||||
#include "sam.h"
|
||||
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_SAMG
|
||||
|
@ -3,11 +3,13 @@ CFLAGS += \
|
||||
-mthumb \
|
||||
-mabi=aapcs \
|
||||
-mcpu=cortex-m4 \
|
||||
-mfloat-abi=hard \
|
||||
-mfpu=fpv4-sp-d16 \
|
||||
-nostdlib \
|
||||
-DCORE_M4 \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC40XX \
|
||||
-D__USE_LPCOPEN \
|
||||
-DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM2")))' \
|
||||
-D__USE_LPCOPEN
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC40XX
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=strict-prototypes -Wno-error=unused-parameter
|
||||
@ -25,7 +27,8 @@ SRC_C += \
|
||||
$(MCU_DIR)/src/iocon_17xx_40xx.c \
|
||||
$(MCU_DIR)/src/sysctl_17xx_40xx.c \
|
||||
$(MCU_DIR)/src/sysinit_17xx_40xx.c \
|
||||
$(MCU_DIR)/src/uart_17xx_40xx.c
|
||||
$(MCU_DIR)/src/uart_17xx_40xx.c \
|
||||
$(MCU_DIR)/src/fpu_init.c
|
||||
|
||||
INC += \
|
||||
$(TOP)/$(MCU_DIR)/inc
|
||||
@ -35,7 +38,7 @@ VENDOR = nxp
|
||||
CHIP_FAMILY = lpc17_40
|
||||
|
||||
# For freeRTOS port source
|
||||
FREERTOS_PORT = ARM_CM3
|
||||
FREERTOS_PORT = ARM_CM4F
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = LPC4088
|
||||
|
@ -33,7 +33,7 @@
|
||||
void USB_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -86,6 +86,16 @@ static const PINMUX_GRP_T pin_usb_mux[] =
|
||||
// Invoked by startup code
|
||||
void SystemInit(void)
|
||||
{
|
||||
#ifdef __USE_LPCOPEN
|
||||
extern void (* const g_pfnVectors[])(void);
|
||||
unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08;
|
||||
*pSCB_VTOR = (unsigned int) g_pfnVectors;
|
||||
|
||||
#if __FPU_USED == 1
|
||||
fpuInit();
|
||||
#endif
|
||||
#endif // __USE_LPCOPEN
|
||||
|
||||
Chip_IOCON_Init(LPC_IOCON);
|
||||
Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));
|
||||
Chip_SetupXtalClocking();
|
||||
|
@ -7,8 +7,8 @@ CFLAGS += \
|
||||
-mfpu=fpv4-sp-d16 \
|
||||
-nostdlib \
|
||||
-DCORE_M4 \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC43XX \
|
||||
-D__USE_LPCOPEN
|
||||
-D__USE_LPCOPEN \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC43XX
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter -Wno-error=strict-prototypes
|
||||
@ -26,7 +26,8 @@ SRC_C += \
|
||||
$(MCU_DIR)/src/sysinit_18xx_43xx.c \
|
||||
$(MCU_DIR)/src/i2c_18xx_43xx.c \
|
||||
$(MCU_DIR)/src/i2cm_18xx_43xx.c \
|
||||
$(MCU_DIR)/src/uart_18xx_43xx.c
|
||||
$(MCU_DIR)/src/uart_18xx_43xx.c \
|
||||
$(MCU_DIR)/src/fpu_init.c
|
||||
|
||||
INC += \
|
||||
$(TOP)/$(MCU_DIR)/inc \
|
||||
@ -40,8 +41,8 @@ CHIP_FAMILY = transdimension
|
||||
FREERTOS_PORT = ARM_CM4F
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = LPC4357
|
||||
JLINK_IF = jtag
|
||||
JLINK_DEVICE = LPC4357_M4
|
||||
JLINK_IF = swd
|
||||
|
||||
# flash using jlink
|
||||
flash: flash-jlink
|
||||
|
@ -30,8 +30,8 @@
|
||||
|
||||
#define UART_DEV LPC_USART0
|
||||
#define UART_PORT 0x0f
|
||||
#define UART_PIN_TX 10 // PF.10 : UART0_TXD
|
||||
#define UART_PIN_RX 11 // PF.11 : UART0_RXD
|
||||
#define UART_PIN_TX 10
|
||||
#define UART_PIN_RX 11
|
||||
|
||||
// P9_1 joystick down
|
||||
#define BUTTON_PORT 4
|
||||
@ -63,9 +63,13 @@ const uint32_t ExtRateIn = 0;
|
||||
|
||||
static const PINMUX_GRP_T pinmuxing[] =
|
||||
{
|
||||
// Button
|
||||
// Button ( Joystick down )
|
||||
{0x9, 1, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLUP)},
|
||||
|
||||
// UART
|
||||
{UART_PORT, UART_PIN_TX, SCU_MODE_PULLDOWN | SCU_MODE_FUNC1},
|
||||
{UART_PORT, UART_PIN_RX, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1},
|
||||
|
||||
// USB
|
||||
};
|
||||
|
||||
@ -81,6 +85,16 @@ static const PINMUX_GRP_T pinclockmuxing[] =
|
||||
// Invoked by startup code
|
||||
void SystemInit(void)
|
||||
{
|
||||
#ifdef __USE_LPCOPEN
|
||||
extern void (* const g_pfnVectors[])(void);
|
||||
unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08;
|
||||
*pSCB_VTOR = (unsigned int) g_pfnVectors;
|
||||
|
||||
#if __FPU_USED == 1
|
||||
fpuInit();
|
||||
#endif
|
||||
#endif // __USE_LPCOPEN
|
||||
|
||||
/* Setup system level pin muxing */
|
||||
Chip_SCU_SetPinMuxing(pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));
|
||||
|
||||
@ -119,9 +133,6 @@ void board_init(void)
|
||||
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTON_PORT, BUTTON_PIN);
|
||||
|
||||
//------------- UART -------------//
|
||||
Chip_SCU_PinMuxSet(UART_PORT, UART_PIN_TX, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC1));
|
||||
Chip_SCU_PinMuxSet(UART_PORT, UART_PIN_RX, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1));
|
||||
|
||||
Chip_UART_Init(UART_DEV);
|
||||
Chip_UART_SetBaud(UART_DEV, CFG_BOARD_UART_BAUDRATE);
|
||||
Chip_UART_ConfigData(UART_DEV, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS);
|
||||
@ -138,52 +149,65 @@ void board_init(void)
|
||||
USBMODE_VBUS_HIGH = 1
|
||||
};
|
||||
|
||||
/* USB0
|
||||
* For USB Device operation; insert jumpers in position 1-2 in JP17/JP18/JP19. GPIO28 controls USB
|
||||
* connect functionality and LED32 lights when the USB Device is connected. SJ4 has pads 1-2 shorted
|
||||
* by default. LED33 is controlled by GPIO27 and signals USB-up state. GPIO54 is used for VBUS
|
||||
/* From EA4357 user manual
|
||||
*
|
||||
* USB0 Device operation:
|
||||
* - Insert jumpers in position 1-2 in JP17/JP18/JP19.
|
||||
* - GPIO28 controls USB connect functionality
|
||||
* - LED32 lights when the USB Device is connected. SJ4 has pads 1-2 shorted by default.
|
||||
* - LED33 is controlled by GPIO27 and signals USB-up state. GPIO54 is used for VBUS
|
||||
* sensing.
|
||||
* For USB Host operation; insert jumpers in position 2-3 in JP17/JP18/JP19. USB Host power is
|
||||
* controlled via distribution switch U20 (found in schematic page 11). Signal GPIO26 is active low and
|
||||
* enables +5V on VBUS2. LED35 light whenever +5V is present on VBUS2. GPIO55 is connected to
|
||||
* status feedback from the distribution switch. GPIO54 is used for VBUS sensing. 15Kohm pull-down
|
||||
* resistors are always active
|
||||
*
|
||||
* USB0 Host operation:
|
||||
* - insert jumpers in position 2-3 in JP17/JP18/JP19.
|
||||
* - USB Host power is controlled via distribution switch U20 (found in schematic page 11).
|
||||
* - Signal GPIO26 is active low and enables +5V on VBUS2.
|
||||
* - LED35 light whenever +5V is present on VBUS2.
|
||||
* - GPIO55 is connected to status feedback from the distribution switch.
|
||||
* - GPIO54 is used for VBUS sensing. 15Kohm pull-down resistors are always active
|
||||
*
|
||||
* Note:
|
||||
* - Insert jumpers in position 2-3 in JP17/JP18/JP19
|
||||
* - Insert jumpers in JP31 (OTG)
|
||||
*/
|
||||
#if CFG_TUSB_RHPORT0_MODE
|
||||
Chip_USB0_Init();
|
||||
|
||||
// // Reset controller
|
||||
// LPC_USB0->USBCMD_D |= 0x02;
|
||||
// while( LPC_USB0->USBCMD_D & 0x02 ) {}
|
||||
//
|
||||
// // Set mode
|
||||
// #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
// LPC_USB0->USBMODE_H = USBMODE_HOST | (USBMODE_VBUS_HIGH << 5);
|
||||
//
|
||||
// LPC_USB0->PORTSC1_D |= (1<<24); // FIXME force full speed for debugging
|
||||
// #else // TODO OTG
|
||||
// LPC_USB0->USBMODE_D = USBMODE_DEVICE;
|
||||
// LPC_USB0->OTGSC = (1<<3) | (1<<0) /*| (1<<16)| (1<<24)| (1<<25)| (1<<26)| (1<<27)| (1<<28)| (1<<29)| (1<<30)*/;
|
||||
// #endif
|
||||
// Reset controller
|
||||
LPC_USB0->USBCMD_D |= 0x02;
|
||||
while( LPC_USB0->USBCMD_D & 0x02 ) {}
|
||||
|
||||
// Set mode
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
LPC_USB0->USBMODE_H = USBMODE_HOST | (USBMODE_VBUS_HIGH << 5);
|
||||
|
||||
LPC_USB0->PORTSC1_D |= (1<<24); // FIXME force full speed for debugging
|
||||
#else // TODO OTG
|
||||
LPC_USB0->USBMODE_D = USBMODE_DEVICE;
|
||||
LPC_USB0->OTGSC = (1<<3) | (1<<0) /*| (1<<16)| (1<<24)| (1<<25)| (1<<26)| (1<<27)| (1<<28)| (1<<29)| (1<<30)*/;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* USB1
|
||||
* When USB channel #1 is used as USB Host, 15Kohm pull-down resistors are needed on the USB data
|
||||
* signals. These are activated inside the USB OTG chip (U31), and this has to be done via the I2C
|
||||
* interface of GPIO52/GPIO53.
|
||||
* J20 is the connector to use when USB Host is used. In order to provide +5V to the external USB
|
||||
* device connected to this connector (J20), channel A of U20 must be enabled. It is enabled by default
|
||||
* since SJ5 is normally connected between pin 1-2. LED34 lights green when +5V is available on J20.
|
||||
* JP15 shall not be inserted. JP16 has no effect
|
||||
*
|
||||
* When USB channel #1 is used as USB Device, a 1.5Kohm pull-up resistor is needed on the USB DP
|
||||
* data signal. There are two methods to create this. JP15 is inserted and the pull-up resistor is always
|
||||
* enabled. Alternatively, the pull-up resistor is activated inside the USB OTG chip (U31), and this has to
|
||||
* be done via the I2C interface of GPIO52/GPIO53. In the latter case, JP15 shall not be inserted.
|
||||
* J19 is the connector to use when USB Device is used. Normally it should be a USB-B connector for
|
||||
* For USB Device:
|
||||
* - a 1.5Kohm pull-up resistor is needed on the USB DP data signal. There are two methods to create this.
|
||||
* JP15 is inserted and the pull-up resistor is always enabled. Alternatively, the pull-up resistor is activated
|
||||
* inside the USB OTG chip (U31), and this has to be done via the I2C interface of GPIO52/GPIO53. In the latter case,
|
||||
* JP15 shall not be inserted.
|
||||
* - J19 is the connector to use when USB Device is used. Normally it should be a USB-B connector for
|
||||
* creating a USB Device interface, but the mini-AB connector can also be used in this case. The status
|
||||
* of VBUS can be read via U31.
|
||||
* JP16 shall not be inserted.
|
||||
* - JP16 shall not be inserted.
|
||||
*
|
||||
* For USB Host:
|
||||
* - 15Kohm pull-down resistors are needed on the USB data signals. These are activated inside the USB OTG chip (U31),
|
||||
* and this has to be done via the I2C interface of GPIO52/GPIO53.
|
||||
* - J20 is the connector to use when USB Host is used. In order to provide +5V to the external USB
|
||||
* device connected to this connector (J20), channel A of U20 must be enabled. It is enabled by default
|
||||
* since SJ5 is normally connected between pin 1-2.
|
||||
* - LED34 lights green when +5V is available on J20.
|
||||
* - JP15 shall not be inserted. JP16 has no effect
|
||||
*/
|
||||
#if CFG_TUSB_RHPORT1_MODE
|
||||
Chip_USB1_Init();
|
||||
@ -222,7 +246,7 @@ void board_init(void)
|
||||
void USB0_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -233,7 +257,7 @@ void USB0_IRQHandler(void)
|
||||
void USB1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
|
||||
tuh_isr(1);
|
||||
tuh_int_handler(1);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
|
||||
|
64
hw/bsp/itsybitsy_nrf52840/board.mk
Normal file
64
hw/bsp/itsybitsy_nrf52840/board.mk
Normal file
@ -0,0 +1,64 @@
|
||||
CFLAGS += \
|
||||
-flto \
|
||||
-mthumb \
|
||||
-mabi=aapcs \
|
||||
-mcpu=cortex-m4 \
|
||||
-mfloat-abi=hard \
|
||||
-mfpu=fpv4-sp-d16 \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_NRF5X \
|
||||
-DNRF52840_XXAA \
|
||||
-DCONFIG_GPIO_AS_PINRESET
|
||||
|
||||
# suppress warning caused by vendor mcu driver
|
||||
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align
|
||||
|
||||
# due to tusb_hal_nrf_power_event
|
||||
GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion)))
|
||||
ifeq ($(shell expr $(GCCVERSION) \>= 8), 1)
|
||||
CFLAGS += -Wno-error=cast-function-type
|
||||
endif
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/$(BOARD)/nrf52840_s140_v6.ld
|
||||
|
||||
LDFLAGS += -L$(TOP)/hw/mcu/nordic/nrfx/mdk
|
||||
|
||||
SRC_C += \
|
||||
hw/mcu/nordic/nrfx/drivers/src/nrfx_power.c \
|
||||
hw/mcu/nordic/nrfx/drivers/src/nrfx_uarte.c \
|
||||
hw/mcu/nordic/nrfx/mdk/system_nrf52840.c
|
||||
|
||||
INC += \
|
||||
$(TOP)/lib/CMSIS_4/CMSIS/Include \
|
||||
$(TOP)/hw/mcu/nordic \
|
||||
$(TOP)/hw/mcu/nordic/nrfx \
|
||||
$(TOP)/hw/mcu/nordic/nrfx/mdk \
|
||||
$(TOP)/hw/mcu/nordic/nrfx/hal \
|
||||
$(TOP)/hw/mcu/nordic/nrfx/drivers/include \
|
||||
$(TOP)/hw/mcu/nordic/nrfx/drivers/src \
|
||||
|
||||
SRC_S += hw/mcu/nordic/nrfx/mdk/gcc_startup_nrf52840.S
|
||||
|
||||
ASFLAGS += -D__HEAP_SIZE=0
|
||||
|
||||
# For TinyUSB port source
|
||||
VENDOR = nordic
|
||||
CHIP_FAMILY = nrf5x
|
||||
|
||||
# For freeRTOS port source
|
||||
FREERTOS_PORT = ARM_CM4F
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = nRF52840_xxAA
|
||||
JLINK_IF = swd
|
||||
|
||||
# For uf2 conversion
|
||||
UF2_FAMILY = 0xADA52840
|
||||
|
||||
$(BUILD)/$(BOARD)-firmware.zip: $(BUILD)/$(BOARD)-firmware.hex
|
||||
adafruit-nrfutil dfu genpkg --dev-type 0x0052 --sd-req 0xFFFE --application $^ $@
|
||||
|
||||
# flash using adafruit-nrfutil dfu
|
||||
flash: $(BUILD)/$(BOARD)-firmware.zip
|
||||
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
|
||||
adafruit-nrfutil --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank --touch 1200
|
225
hw/bsp/itsybitsy_nrf52840/itsybitsy_nrf52840.c
Normal file
225
hw/bsp/itsybitsy_nrf52840/itsybitsy_nrf52840.c
Normal file
@ -0,0 +1,225 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include "bsp/board.h"
|
||||
|
||||
#include "nrfx.h"
|
||||
#include "nrfx/hal/nrf_gpio.h"
|
||||
#include "nrfx/drivers/include/nrfx_power.h"
|
||||
#include "nrfx/drivers/include/nrfx_uarte.h"
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_sdm.h"
|
||||
#include "nrf_soc.h"
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Forward USB interrupt events to TinyUSB IRQ Handler
|
||||
//--------------------------------------------------------------------+
|
||||
void USBD_IRQHandler(void)
|
||||
{
|
||||
tud_int_handler(0);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* MACRO TYPEDEF CONSTANT ENUM
|
||||
*------------------------------------------------------------------*/
|
||||
#define _PINNUM(port, pin) ((port)*32 + (pin))
|
||||
|
||||
#define LED_PIN _PINNUM(0, 6)
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BUTTON_PIN _PINNUM(0, 29)
|
||||
|
||||
#define UART_RX_PIN 25
|
||||
#define UART_TX_PIN 24
|
||||
|
||||
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0);
|
||||
|
||||
// tinyusb function that handles power event (detected, ready, removed)
|
||||
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
|
||||
extern void tusb_hal_nrf_power_event(uint32_t event);
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
// stop LF clock just in case we jump from application without reset
|
||||
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
|
||||
|
||||
// Config clock source: XTAL or RC in sdk_config.h
|
||||
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
|
||||
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
|
||||
|
||||
// LED
|
||||
nrf_gpio_cfg_output(LED_PIN);
|
||||
board_led_write(false);
|
||||
|
||||
// Button
|
||||
nrf_gpio_cfg_input(BUTTON_PIN, NRF_GPIO_PIN_PULLUP);
|
||||
|
||||
// 1ms tick timer
|
||||
SysTick_Config(SystemCoreClock/1000);
|
||||
|
||||
// UART
|
||||
nrfx_uarte_config_t uart_cfg =
|
||||
{
|
||||
.pseltxd = UART_TX_PIN,
|
||||
.pselrxd = UART_RX_PIN,
|
||||
.pselcts = NRF_UARTE_PSEL_DISCONNECTED,
|
||||
.pselrts = NRF_UARTE_PSEL_DISCONNECTED,
|
||||
.p_context = NULL,
|
||||
.baudrate = NRF_UARTE_BAUDRATE_115200, // CFG_BOARD_UART_BAUDRATE
|
||||
.interrupt_priority = 7,
|
||||
.hal_cfg = {
|
||||
.hwfc = NRF_UARTE_HWFC_DISABLED,
|
||||
.parity = NRF_UARTE_PARITY_EXCLUDED,
|
||||
}
|
||||
};
|
||||
|
||||
nrfx_uarte_init(&_uart_id, &uart_cfg, NULL); //uart_handler);
|
||||
|
||||
//------------- USB -------------//
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
// Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
|
||||
// 2 is highest for application
|
||||
NVIC_SetPriority(USBD_IRQn, 2);
|
||||
|
||||
// USB power may already be ready at this time -> no event generated
|
||||
// We need to invoke the handler based on the status initially
|
||||
uint32_t usb_reg;
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
uint8_t sd_en = false;
|
||||
sd_softdevice_is_enabled(&sd_en);
|
||||
|
||||
if ( sd_en ) {
|
||||
sd_power_usbdetected_enable(true);
|
||||
sd_power_usbpwrrdy_enable(true);
|
||||
sd_power_usbremoved_enable(true);
|
||||
|
||||
sd_power_usbregstatus_get(&usb_reg);
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
// Power module init
|
||||
const nrfx_power_config_t pwr_cfg = { 0 };
|
||||
nrfx_power_init(&pwr_cfg);
|
||||
|
||||
// Register tusb function as USB power handler
|
||||
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event };
|
||||
nrfx_power_usbevt_init(&config);
|
||||
|
||||
nrfx_power_usbevt_enable();
|
||||
|
||||
usb_reg = NRF_POWER->USBREGSTATUS;
|
||||
}
|
||||
|
||||
if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
|
||||
if ( usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Board porting API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state)
|
||||
{
|
||||
nrf_gpio_pin_write(LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void)
|
||||
{
|
||||
// button is active LOW
|
||||
return (nrf_gpio_pin_read(BUTTON_PIN) ? 0 : 1);
|
||||
}
|
||||
|
||||
int board_uart_read(uint8_t* buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
// return NRFX_SUCCESS == nrfx_uart_rx(&_uart_id, buf, (size_t) len) ? len : 0;
|
||||
}
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
return (NRFX_SUCCESS == nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len)) ? len : 0;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
void SysTick_Handler (void)
|
||||
{
|
||||
system_ticks++;
|
||||
}
|
||||
|
||||
uint32_t board_millis(void)
|
||||
{
|
||||
return system_ticks;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
// process SOC event from SD
|
||||
uint32_t proc_soc(void)
|
||||
{
|
||||
uint32_t soc_evt;
|
||||
uint32_t err = sd_evt_get(&soc_evt);
|
||||
|
||||
if (NRF_SUCCESS == err)
|
||||
{
|
||||
/*------------- usb power event handler -------------*/
|
||||
int32_t usbevt = (soc_evt == NRF_EVT_POWER_USB_DETECTED ) ? NRFX_POWER_USB_EVT_DETECTED:
|
||||
(soc_evt == NRF_EVT_POWER_USB_POWER_READY) ? NRFX_POWER_USB_EVT_READY :
|
||||
(soc_evt == NRF_EVT_POWER_USB_REMOVED ) ? NRFX_POWER_USB_EVT_REMOVED : -1;
|
||||
|
||||
if ( usbevt >= 0) tusb_hal_nrf_power_event(usbevt);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
uint32_t proc_ble(void)
|
||||
{
|
||||
// do nothing with ble
|
||||
return NRF_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
void SD_EVT_IRQHandler(void)
|
||||
{
|
||||
// process BLE and SOC until there is no more events
|
||||
while( (NRF_ERROR_NOT_FOUND != proc_ble()) || (NRF_ERROR_NOT_FOUND != proc_soc()) )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info)
|
||||
{
|
||||
(void) id;
|
||||
(void) pc;
|
||||
(void) info;
|
||||
}
|
||||
#endif
|
38
hw/bsp/itsybitsy_nrf52840/nrf52840_s140_v6.ld
Normal file
38
hw/bsp/itsybitsy_nrf52840/nrf52840_s140_v6.ld
Normal file
@ -0,0 +1,38 @@
|
||||
/* Linker script to configure memory regions. */
|
||||
|
||||
SEARCH_DIR(.)
|
||||
GROUP(-lgcc -lc -lnosys)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0xED000 - 0x26000
|
||||
|
||||
/* SRAM required by S132 depend on
|
||||
* - Attribute Table Size
|
||||
* - Vendor UUID count
|
||||
* - Max ATT MTU
|
||||
* - Concurrent connection peripheral + central + secure links
|
||||
* - Event Len, HVN queue, Write CMD queue
|
||||
*/
|
||||
RAM (rwx) : ORIGIN = 0x20003400, LENGTH = 0x20040000 - 0x20003400
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ALIGN(4);
|
||||
.svc_data :
|
||||
{
|
||||
PROVIDE(__start_svc_data = .);
|
||||
KEEP(*(.svc_data))
|
||||
PROVIDE(__stop_svc_data = .);
|
||||
} > RAM
|
||||
|
||||
.fs_data :
|
||||
{
|
||||
PROVIDE(__start_fs_data = .);
|
||||
KEEP(*(.fs_data))
|
||||
PROVIDE(__stop_fs_data = .);
|
||||
} > RAM
|
||||
} INSERT AFTER .data;
|
||||
|
||||
INCLUDE "nrf52_common.ld"
|
@ -33,7 +33,7 @@
|
||||
void USB_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -78,21 +78,28 @@ static const PINMUX_GRP_T pin_usb_mux[] =
|
||||
{
|
||||
{0, 29, IOCON_MODE_INACT | IOCON_FUNC1}, // D+
|
||||
{0, 30, IOCON_MODE_INACT | IOCON_FUNC1}, // D-
|
||||
{2, 9, IOCON_MODE_INACT | IOCON_FUNC1}, // Connect
|
||||
{2, 9, IOCON_MODE_INACT | IOCON_FUNC1}, // Soft Connect
|
||||
|
||||
{1, 19, IOCON_MODE_INACT | IOCON_FUNC2}, // USB_PPWR
|
||||
{1, 22, IOCON_MODE_INACT | IOCON_FUNC2}, // USB_PWRD
|
||||
{1, 19, IOCON_MODE_INACT | IOCON_FUNC2}, // USB_PPWR (Host mode)
|
||||
|
||||
/* VBUS is not connected on this board, so leave the pin at default setting. */
|
||||
/*Chip_IOCON_PinMux(LPC_IOCON, 1, 30, IOCON_MODE_INACT, IOCON_FUNC2);*/ /* USB VBUS */
|
||||
// VBUS is not connected on this board, so leave the pin at default setting.
|
||||
/// Chip_IOCON_PinMux(LPC_IOCON, 1, 30, IOCON_MODE_INACT, IOCON_FUNC2); // USB VBUS
|
||||
};
|
||||
|
||||
// Invoked by startup code
|
||||
void SystemInit(void)
|
||||
{
|
||||
#ifdef __USE_LPCOPEN
|
||||
extern void (* const g_pfnVectors[])(void);
|
||||
unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08;
|
||||
*pSCB_VTOR = (unsigned int) g_pfnVectors;
|
||||
#endif
|
||||
|
||||
Chip_IOCON_Init(LPC_IOCON);
|
||||
Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));
|
||||
Chip_SetupXtalClocking();
|
||||
|
||||
Chip_SYSCTL_SetFLASHAccess(FLASHTIM_100MHZ_CPU);
|
||||
}
|
||||
|
||||
void board_init(void)
|
||||
|
@ -65,6 +65,12 @@ static const PINMUX_GRP_T pin_usb_mux[] =
|
||||
// Invoked by startup code
|
||||
void SystemInit(void)
|
||||
{
|
||||
#ifdef __USE_LPCOPEN
|
||||
extern void (* const g_pfnVectors[])(void);
|
||||
unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08;
|
||||
*pSCB_VTOR = (unsigned int) g_pfnVectors;
|
||||
#endif
|
||||
|
||||
Chip_IOCON_Init(LPC_IOCON);
|
||||
Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));
|
||||
Chip_SetupXtalClocking();
|
||||
@ -141,7 +147,7 @@ void board_init(void)
|
||||
void USB_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
|
@ -5,8 +5,8 @@ CFLAGS += \
|
||||
-mcpu=cortex-m3 \
|
||||
-nostdlib \
|
||||
-DCORE_M3 \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC18XX \
|
||||
-D__USE_LPCOPEN
|
||||
-D__USE_LPCOPEN \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC18XX
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter -Wno-error=strict-prototypes
|
||||
|
@ -33,7 +33,7 @@
|
||||
void USB0_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -44,7 +44,7 @@ void USB0_IRQHandler(void)
|
||||
void USB1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
|
||||
tuh_isr(1);
|
||||
tuh_int_handler(1);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
|
||||
@ -64,6 +64,11 @@ void USB1_IRQHandler(void)
|
||||
#define BUTTON_PORT 2
|
||||
#define BUTTON_PIN 0
|
||||
|
||||
#define UART_DEV LPC_USART3
|
||||
#define UART_PORT 0x02
|
||||
#define UART_PIN_TX 3
|
||||
#define UART_PIN_RX 4
|
||||
|
||||
|
||||
/* System configuration variables used by chip driver */
|
||||
const uint32_t OscRateIn = 12000000;
|
||||
@ -71,40 +76,48 @@ const uint32_t ExtRateIn = 0;
|
||||
|
||||
static const PINMUX_GRP_T pinmuxing[] =
|
||||
{
|
||||
// LEDs
|
||||
{0xD, 10, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4)},
|
||||
{0xD, 11, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN)},
|
||||
{0xD, 12, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN)},
|
||||
{0xD, 13, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN)},
|
||||
{0xD, 14, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN)},
|
||||
{0x9, 0, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLDOWN)},
|
||||
{0x9, 1, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLDOWN)},
|
||||
{0x9, 2, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLDOWN)},
|
||||
// LEDs
|
||||
{ 0xD, 10, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4) },
|
||||
{ 0xD, 11, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN) },
|
||||
{ 0xD, 12, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN) },
|
||||
{ 0xD, 13, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN) },
|
||||
{ 0xD, 14, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC4 | SCU_MODE_PULLDOWN) },
|
||||
{ 0x9, 0, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLDOWN) },
|
||||
{ 0x9, 1, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLDOWN) },
|
||||
{ 0x9, 2, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLDOWN) },
|
||||
|
||||
// Button
|
||||
{0x4, 0, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLUP)},
|
||||
// Button
|
||||
{ 0x4, 0, (SCU_MODE_INBUFF_EN | SCU_MODE_INACT | SCU_MODE_FUNC0 | SCU_MODE_PULLUP) },
|
||||
|
||||
/* I2S */
|
||||
{0x3, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC2)},
|
||||
{0x6, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC4)},
|
||||
{0x7, 2, (SCU_PINIO_FAST | SCU_MODE_FUNC2)},
|
||||
{0x6, 2, (SCU_PINIO_FAST | SCU_MODE_FUNC3)},
|
||||
{0x7, 1, (SCU_PINIO_FAST | SCU_MODE_FUNC2)},
|
||||
{0x6, 1, (SCU_PINIO_FAST | SCU_MODE_FUNC3)},
|
||||
// UART
|
||||
{ UART_PORT, UART_PIN_TX, SCU_MODE_PULLDOWN | SCU_MODE_FUNC2 },
|
||||
{ UART_PORT, UART_PIN_RX, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2 },
|
||||
|
||||
// USB0
|
||||
{ 0x6, 3, SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC1 }, // P6_3 USB0_PWR_EN, USB0 VBus function
|
||||
|
||||
{ 0x9, 5, SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC2 }, // P9_5 USB1_VBUS_EN, USB1 VBus function
|
||||
{ 0x2, 5, SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2 }, // P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION
|
||||
};
|
||||
|
||||
/* Pin clock mux values, re-used structure, value in first index is meaningless */
|
||||
static const PINMUX_GRP_T pinclockmuxing[] =
|
||||
{
|
||||
{0, 0, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC0)},
|
||||
{0, 1, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC0)},
|
||||
{0, 2, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC0)},
|
||||
{0, 3, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC0)},
|
||||
{ 0, 0, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC0)},
|
||||
{ 0, 1, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC0)},
|
||||
{ 0, 2, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC0)},
|
||||
{ 0, 3, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_FUNC0)},
|
||||
};
|
||||
|
||||
// Invoked by startup code
|
||||
void SystemInit(void)
|
||||
{
|
||||
#ifdef __USE_LPCOPEN
|
||||
extern void (* const g_pfnVectors[])(void);
|
||||
unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08;
|
||||
*pSCB_VTOR = (unsigned int) g_pfnVectors;
|
||||
#endif
|
||||
|
||||
/* Setup system level pin muxing */
|
||||
Chip_SCU_SetPinMuxing(pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));
|
||||
|
||||
@ -137,19 +150,11 @@ void board_init(void)
|
||||
// Button
|
||||
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, BUTTON_PORT, BUTTON_PIN);
|
||||
|
||||
#if 0
|
||||
//------------- UART -------------//
|
||||
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN, FUNC1);
|
||||
scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN | MD_EZI | MD_ZI, FUNC1);
|
||||
|
||||
UART_CFG_Type UARTConfigStruct;
|
||||
UART_ConfigStructInit(&UARTConfigStruct);
|
||||
UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE;
|
||||
UARTConfigStruct.Clock_Speed = 0;
|
||||
|
||||
UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
|
||||
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
|
||||
#endif
|
||||
Chip_UART_Init(UART_DEV);
|
||||
Chip_UART_SetBaud(UART_DEV, CFG_BOARD_UART_BAUDRATE);
|
||||
Chip_UART_ConfigData(UART_DEV, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS);
|
||||
Chip_UART_TXEnable(UART_DEV);
|
||||
|
||||
//------------- USB -------------//
|
||||
enum {
|
||||
@ -166,17 +171,18 @@ void board_init(void)
|
||||
#if CFG_TUSB_RHPORT0_MODE
|
||||
Chip_USB0_Init();
|
||||
|
||||
// // Reset controller
|
||||
// LPC_USB0->USBCMD_D |= 0x02;
|
||||
// while( LPC_USB0->USBCMD_D & 0x02 ) {}
|
||||
//
|
||||
// // Set mode
|
||||
// #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
// LPC_USB0->USBMODE_H = USBMODE_HOST | (USBMODE_VBUS_HIGH << 5);
|
||||
// #else // TODO OTG
|
||||
// LPC_USB0->USBMODE_D = USBMODE_DEVICE;
|
||||
// LPC_USB0->OTGSC = (1<<3) | (1<<0) /*| (1<<16)| (1<<24)| (1<<25)| (1<<26)| (1<<27)| (1<<28)| (1<<29)| (1<<30)*/;
|
||||
// #endif
|
||||
// Host/Device mode can only be set right after controller reset
|
||||
LPC_USB0->USBCMD_D |= 0x02;
|
||||
while( LPC_USB0->USBCMD_D & 0x02 ) {}
|
||||
|
||||
// Set mode
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
LPC_USB0->USBMODE_H = USBMODE_HOST | (USBMODE_VBUS_HIGH << 5);
|
||||
LPC_USB0->PORTSC1_H |= (1<<24); // FIXME force full speed for debugging
|
||||
#else // TODO OTG
|
||||
LPC_USB0->USBMODE_D = USBMODE_DEVICE;
|
||||
LPC_USB0->OTGSC = (1<<3) | (1<<0) /*| (1<<16)| (1<<24)| (1<<25)| (1<<26)| (1<<27)| (1<<28)| (1<<29)| (1<<30)*/;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// USB1
|
||||
@ -223,9 +229,14 @@ int board_uart_read(uint8_t* buf, int len)
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
//UART_Send(BOARD_UART_PORT, &c, 1, BLOCKING);
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
uint8_t const* buf8 = (uint8_t const*) buf;
|
||||
for(int i=0; i<len; i++)
|
||||
{
|
||||
while ((Chip_UART_ReadLineStatus(UART_DEV) & UART_LSR_THRE) == 0) {}
|
||||
Chip_UART_SendByte(UART_DEV, buf8[i]);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
@ -121,7 +121,7 @@ void board_init(void)
|
||||
void USB_OTG1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
|
@ -121,7 +121,7 @@ void board_init(void)
|
||||
void USB_OTG1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
|
@ -120,7 +120,7 @@ void board_init(void)
|
||||
void USB_OTG1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
|
@ -124,7 +124,7 @@ void board_init(void)
|
||||
void USB_OTG1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -135,7 +135,7 @@ void USB_OTG1_IRQHandler(void)
|
||||
void USB_OTG2_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
|
||||
tuh_isr(1);
|
||||
tuh_int_handler(1);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
|
||||
|
@ -124,7 +124,7 @@ void board_init(void)
|
||||
void USB_OTG1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -135,7 +135,7 @@ void USB_OTG1_IRQHandler(void)
|
||||
void USB_OTG2_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
|
||||
tuh_isr(1);
|
||||
tuh_int_handler(1);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
|
||||
|
@ -124,7 +124,7 @@ void board_init(void)
|
||||
void USB_OTG1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -135,7 +135,7 @@ void USB_OTG1_IRQHandler(void)
|
||||
void USB_OTG2_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
|
||||
tuh_isr(1);
|
||||
tuh_int_handler(1);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
|
||||
|
@ -7,8 +7,8 @@ CFLAGS += \
|
||||
-mfpu=fpv4-sp-d16 \
|
||||
-nostdlib \
|
||||
-DCORE_M4 \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC43XX \
|
||||
-D__USE_LPCOPEN
|
||||
-D__USE_LPCOPEN \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC43XX
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=strict-prototypes -Wno-error=unused-parameter
|
||||
@ -24,7 +24,8 @@ SRC_C += \
|
||||
$(MCU_DIR)/src/clock_18xx_43xx.c \
|
||||
$(MCU_DIR)/src/gpio_18xx_43xx.c \
|
||||
$(MCU_DIR)/src/sysinit_18xx_43xx.c \
|
||||
$(MCU_DIR)/src/uart_18xx_43xx.c
|
||||
$(MCU_DIR)/src/uart_18xx_43xx.c \
|
||||
$(MCU_DIR)/src/fpu_init.c
|
||||
|
||||
INC += \
|
||||
$(TOP)/$(MCU_DIR)/inc \
|
||||
|
@ -71,11 +71,17 @@ static const PINMUX_GRP_T pinmuxing[] =
|
||||
};
|
||||
|
||||
// Invoked by startup code
|
||||
extern void (* const g_pfnVectors[])(void);
|
||||
void SystemInit(void)
|
||||
{
|
||||
// Remap isr vector
|
||||
*((uint32_t *) 0xE000ED08) = (uint32_t) &g_pfnVectors;
|
||||
#ifdef __USE_LPCOPEN
|
||||
extern void (* const g_pfnVectors[])(void);
|
||||
unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08;
|
||||
*pSCB_VTOR = (unsigned int) g_pfnVectors;
|
||||
|
||||
#if __FPU_USED == 1
|
||||
fpuInit();
|
||||
#endif
|
||||
#endif // __USE_LPCOPEN
|
||||
|
||||
// Set up pinmux
|
||||
Chip_SCU_SetPinMuxing(pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T));
|
||||
@ -225,7 +231,7 @@ void board_init(void)
|
||||
void USB0_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -236,7 +242,7 @@ void USB0_IRQHandler(void)
|
||||
void USB1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
|
||||
tuh_isr(1);
|
||||
tuh_int_handler(1);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
|
||||
|
53
hw/bsp/samd11_xplained/board.mk
Normal file
53
hw/bsp/samd11_xplained/board.mk
Normal file
@ -0,0 +1,53 @@
|
||||
CFLAGS += \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-Wl,--gc-sections \
|
||||
-mthumb \
|
||||
-mabi=aapcs-linux \
|
||||
-mcpu=cortex-m0plus \
|
||||
-nostdlib -nostartfiles \
|
||||
-D__SAMD11D14AM__ \
|
||||
-DCONF_DFLL_OVERWRITE_CALIBRATION=0 \
|
||||
-DOSC32K_OVERWRITE_CALIBRATION=0 \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_SAMD11 \
|
||||
-fshort-enums \
|
||||
-Os
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/$(BOARD)/samd11d14am_flash.ld
|
||||
|
||||
SRC_C += \
|
||||
hw/mcu/microchip/samd11/gcc/gcc/startup_samd11.c \
|
||||
hw/mcu/microchip/samd11/gcc/system_samd11.c \
|
||||
hw/mcu/microchip/samd11/hpl/gclk/hpl_gclk.c \
|
||||
hw/mcu/microchip/samd11/hpl/pm/hpl_pm.c \
|
||||
hw/mcu/microchip/samd11/hpl/sysctrl/hpl_sysctrl.c \
|
||||
hw/mcu/microchip/samd11/hal/src/hal_atomic.c
|
||||
|
||||
INC += \
|
||||
$(TOP)/hw/mcu/microchip/samd11/ \
|
||||
$(TOP)/hw/mcu/microchip/samd11/config \
|
||||
$(TOP)/hw/mcu/microchip/samd11/include \
|
||||
$(TOP)/hw/mcu/microchip/samd11/hal/include \
|
||||
$(TOP)/hw/mcu/microchip/samd11/hal/utils/include \
|
||||
$(TOP)/hw/mcu/microchip/samd11/hpl/pm/ \
|
||||
$(TOP)/hw/mcu/microchip/samd11/hpl/port \
|
||||
$(TOP)/hw/mcu/microchip/samd11/hri \
|
||||
$(TOP)/hw/mcu/microchip/samd11/CMSIS/Include \
|
||||
$(TOP)/hw/mcu/microchip/samd11/CMSIS/Core/Include
|
||||
|
||||
# For TinyUSB port source
|
||||
VENDOR = microchip
|
||||
CHIP_FAMILY = samd
|
||||
|
||||
# For freeRTOS port source
|
||||
FREERTOS_PORT = ARM_CM0
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = ATSAMD11D14
|
||||
JLINK_IF = swd
|
||||
|
||||
# flash using edbg
|
||||
flash: $(BUILD)/$(BOARD)-firmware.bin
|
||||
edbg -b -t samd11 -e -pv -f $<
|
||||
|
152
hw/bsp/samd11_xplained/samd11_xplained.c
Normal file
152
hw/bsp/samd11_xplained/samd11_xplained.c
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2020 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include "bsp/board.h"
|
||||
|
||||
#include "sam.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
#include "hal/include/hal_init.h"
|
||||
#include "hri/hri_nvmctrl_d11.h"
|
||||
|
||||
#include "hpl/gclk/hpl_gclk_base.h"
|
||||
#include "hpl_pm_config.h"
|
||||
#include "hpl/pm/hpl_pm_base.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Forward USB interrupt events to TinyUSB IRQ Handler
|
||||
//--------------------------------------------------------------------+
|
||||
void USB_Handler(void)
|
||||
{
|
||||
tud_int_handler(0);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
#define LED_PIN PIN_PA16 // pin PA22
|
||||
#define BUTTON_PIN PIN_PA14 // pin PB22
|
||||
|
||||
/* Referenced GCLKs, should be initialized firstly */
|
||||
#define _GCLK_INIT_1ST (1 << 0 | 1 << 1)
|
||||
|
||||
/* Not referenced GCLKs, initialized last */
|
||||
#define _GCLK_INIT_LAST (~_GCLK_INIT_1ST)
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
// Clock init ( follow hpl_init.c )
|
||||
hri_nvmctrl_set_CTRLB_RWS_bf(NVMCTRL, 2);
|
||||
|
||||
_pm_init();
|
||||
_sysctrl_init_sources();
|
||||
#if _GCLK_INIT_1ST
|
||||
_gclk_init_generators_by_fref(_GCLK_INIT_1ST);
|
||||
#endif
|
||||
_sysctrl_init_referenced_generators();
|
||||
_gclk_init_generators_by_fref(_GCLK_INIT_LAST);
|
||||
|
||||
// 1ms tick timer (samd SystemCoreClock may not correct)
|
||||
SystemCoreClock = CONF_CPU_FREQUENCY;
|
||||
SysTick_Config(CONF_CPU_FREQUENCY / 1000);
|
||||
|
||||
// Led init
|
||||
gpio_set_pin_direction(LED_PIN, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(LED_PIN, 0);
|
||||
|
||||
// Button init
|
||||
gpio_set_pin_direction(BUTTON_PIN, GPIO_DIRECTION_IN);
|
||||
gpio_set_pin_pull_mode(BUTTON_PIN, GPIO_PULL_UP);
|
||||
|
||||
/* USB Clock init
|
||||
* The USB module requires a GCLK_USB of 48 MHz ~ 0.25% clock
|
||||
* for low speed and full speed operation. */
|
||||
_pm_enable_bus_clock(PM_BUS_APBB, USB);
|
||||
_pm_enable_bus_clock(PM_BUS_AHB, USB);
|
||||
_gclk_enable_channel(USB_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK0_Val);
|
||||
|
||||
// USB Pin Init
|
||||
gpio_set_pin_direction(PIN_PA24, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(PIN_PA24, false);
|
||||
gpio_set_pin_pull_mode(PIN_PA24, GPIO_PULL_OFF);
|
||||
gpio_set_pin_direction(PIN_PA25, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(PIN_PA25, false);
|
||||
gpio_set_pin_pull_mode(PIN_PA25, GPIO_PULL_OFF);
|
||||
|
||||
gpio_set_pin_function(PIN_PA24, PINMUX_PA24G_USB_DM);
|
||||
gpio_set_pin_function(PIN_PA25, PINMUX_PA25G_USB_DP);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Board porting API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state)
|
||||
{
|
||||
gpio_set_pin_level(LED_PIN, state);
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void)
|
||||
{
|
||||
// button is active low
|
||||
return gpio_get_pin_level(BUTTON_PIN) ? 0 : 1;
|
||||
}
|
||||
|
||||
int board_uart_read(uint8_t* buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
volatile uint32_t system_ticks = 0;
|
||||
|
||||
void SysTick_Handler (void)
|
||||
{
|
||||
system_ticks++;
|
||||
}
|
||||
|
||||
uint32_t board_millis(void)
|
||||
{
|
||||
return system_ticks;
|
||||
}
|
||||
|
||||
void _init(void)
|
||||
{
|
||||
// This _init() standin makes certain GCC environments happier.
|
||||
// They expect the main binary to have a constructor called _init; but don't provide a weak default.
|
||||
// Providing an empty constructor satisfies this odd case, and doesn't harm anything.
|
||||
}
|
||||
|
||||
|
||||
#endif
|
143
hw/bsp/samd11_xplained/samd11d14am_flash.ld
Normal file
143
hw/bsp/samd11_xplained/samd11d14am_flash.ld
Normal file
@ -0,0 +1,143 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Linker script for running in internal FLASH on the SAMD11D14AM
|
||||
*
|
||||
* Copyright (c) 2018 Microchip Technology Inc.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the Licence at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
SEARCH_DIR(.)
|
||||
|
||||
/* Memory Spaces Definitions */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00004000
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00001000
|
||||
}
|
||||
|
||||
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
|
||||
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x400;
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
KEEP(*(.vectors .vectors.*))
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
*(.glue_7t) *(.glue_7)
|
||||
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
|
||||
/* Support C constructors, and C destructors in both user code
|
||||
and the C library. This also provides support for C++ code. */
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.init))
|
||||
. = ALIGN(4);
|
||||
__preinit_array_start = .;
|
||||
KEEP (*(.preinit_array))
|
||||
__preinit_array_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
__init_array_start = .;
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
__init_array_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*crtend.o(.ctors))
|
||||
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
__fini_array_start = .;
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
__fini_array_end = .;
|
||||
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*crtend.o(.dtors))
|
||||
|
||||
. = ALIGN(4);
|
||||
_efixed = .; /* End of text section */
|
||||
} > rom
|
||||
|
||||
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||
PROVIDE_HIDDEN (__exidx_start = .);
|
||||
.ARM.exidx :
|
||||
{
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
} > rom
|
||||
PROVIDE_HIDDEN (__exidx_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
|
||||
.relocate : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.ramfunc .ramfunc.*);
|
||||
*(.data .data.*);
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} > ram
|
||||
|
||||
/* .bss section which is used for uninitialized data */
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sbss = . ;
|
||||
_szero = .;
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = . ;
|
||||
_ezero = .;
|
||||
} > ram
|
||||
|
||||
/* stack section */
|
||||
.stack (NOLOAD):
|
||||
{
|
||||
. = ALIGN(8);
|
||||
_sstack = .;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(8);
|
||||
_estack = .;
|
||||
} > ram
|
||||
|
||||
. = ALIGN(4);
|
||||
_end = . ;
|
||||
}
|
@ -18,8 +18,8 @@ ASF_DIR = hw/mcu/microchip/samg55
|
||||
LD_FILE = hw/bsp/$(BOARD)/samg55j19_flash.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ASF_DIR)/samg55/gcc/gcc/startup_samg55j19.c \
|
||||
$(ASF_DIR)/samg55/gcc/system_samg55j19.c \
|
||||
$(ASF_DIR)/samg55/gcc/gcc/startup_samg55.c \
|
||||
$(ASF_DIR)/samg55/gcc/system_samg55.c \
|
||||
$(ASF_DIR)/hpl/core/hpl_init.c \
|
||||
$(ASF_DIR)/hpl/usart/hpl_usart.c \
|
||||
$(ASF_DIR)/hpl/pmc/hpl_pmc.c \
|
||||
@ -46,7 +46,7 @@ CHIP_FAMILY = samg
|
||||
FREERTOS_PORT = ARM_CM4F
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = ATSAMD51J19
|
||||
JLINK_DEVICE = ATSAMG55J19
|
||||
JLINK_IF = swd
|
||||
|
||||
# flash using edbg from https://github.com/ataradov/edbg
|
||||
|
@ -125,7 +125,7 @@ void board_init(void)
|
||||
void USB_OTG1_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
|
||||
tuh_isr(0);
|
||||
tuh_int_handler(0);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
|
||||
@ -136,7 +136,7 @@ void USB_OTG1_IRQHandler(void)
|
||||
void USB_OTG2_IRQHandler(void)
|
||||
{
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
|
||||
tuh_isr(1);
|
||||
tuh_int_handler(1);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 66b5a11995025426224e0ba6f377322e6e8893b6
|
||||
Subproject commit 168322aa7100f60d6837505f5705fd61454dac27
|
2
lib/lwip
2
lib/lwip
@ -1 +1 @@
|
||||
Subproject commit 0192fe773ec28e11f66ec76f4e827fbb58b7e257
|
||||
Subproject commit 159e31b689577dbf69cf0683bbaffbd71fa5ee10
|
@ -74,7 +74,7 @@ static const uint32_t OIDSupportedList[] =
|
||||
#define OID_LIST_LENGTH TU_ARRAY_SIZE(OIDSupportedList)
|
||||
#define ENC_BUF_SIZE (OID_LIST_LENGTH * 4 + 32)
|
||||
|
||||
static uint8_t *encapsulated_buffer;
|
||||
static void *encapsulated_buffer;
|
||||
|
||||
static void rndis_report(void)
|
||||
{
|
||||
@ -152,7 +152,7 @@ static void rndis_query(void)
|
||||
}
|
||||
}
|
||||
|
||||
#define INFBUF ((uint32_t *)((uint8_t *)&(m->RequestId) + m->InformationBufferOffset))
|
||||
#define INFBUF ((uint8_t *)&(m->RequestId) + m->InformationBufferOffset)
|
||||
|
||||
static void rndis_handle_config_parm(const char *data, int keyoffset, int valoffset, int keylen, int vallen)
|
||||
{
|
||||
@ -191,14 +191,14 @@ static void rndis_handle_set_msg(void)
|
||||
char *ptr = (char *)m;
|
||||
ptr += sizeof(rndis_generic_msg_t);
|
||||
ptr += m->InformationBufferOffset;
|
||||
p = (rndis_config_parameter_t *)ptr;
|
||||
p = (rndis_config_parameter_t *) ((void*) ptr);
|
||||
rndis_handle_config_parm(ptr, p->ParameterNameOffset, p->ParameterValueOffset, p->ParameterNameLength, p->ParameterValueLength);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Mandatory general OIDs */
|
||||
case OID_GEN_CURRENT_PACKET_FILTER:
|
||||
oid_packet_filter = *INFBUF;
|
||||
memcpy(&oid_packet_filter, INFBUF, 4);
|
||||
if (oid_packet_filter)
|
||||
{
|
||||
rndis_packetFilter(oid_packet_filter);
|
||||
@ -239,7 +239,7 @@ void rndis_class_set_handler(uint8_t *data, int size)
|
||||
encapsulated_buffer = data;
|
||||
(void)size;
|
||||
|
||||
switch (((rndis_generic_msg_t *)data)->MessageType)
|
||||
switch (((rndis_generic_msg_t *)encapsulated_buffer)->MessageType)
|
||||
{
|
||||
case REMOTE_NDIS_INITIALIZE_MSG:
|
||||
{
|
||||
|
@ -121,7 +121,7 @@ uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_
|
||||
desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
|
||||
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
|
||||
TU_ASSERT(dcd_edpt_open(rhport, desc_ep), 0);
|
||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
|
||||
_btd_itf.ep_ev = desc_ep->bEndpointAddress;
|
||||
|
||||
// Open endpoint pair
|
||||
|
@ -164,7 +164,7 @@ uint32_t tud_cdc_n_write_flush (uint8_t itf)
|
||||
// skip if previous transfer not complete yet
|
||||
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in), 0 );
|
||||
|
||||
uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epin_buf, sizeof(p_cdc->epin_buf));
|
||||
uint16_t count = tu_fifo_read_n(&p_cdc->tx_ff, p_cdc->epin_buf, sizeof(p_cdc->epin_buf));
|
||||
if ( count )
|
||||
{
|
||||
TU_VERIFY( tud_cdc_n_connected(itf), 0 ); // fifo is empty if not connected
|
||||
@ -376,7 +376,6 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
|
||||
bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) rhport;
|
||||
(void) result;
|
||||
|
||||
uint8_t itf;
|
||||
@ -393,6 +392,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
// Received new data
|
||||
if ( ep_addr == p_cdc->ep_out )
|
||||
{
|
||||
// TODO search for wanted char first for better performance
|
||||
for(uint32_t i=0; i<xferred_bytes; i++)
|
||||
{
|
||||
tu_fifo_write(&p_cdc->rx_ff, &p_cdc->epout_buf[i]);
|
||||
@ -416,13 +416,17 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
// Though maybe the baudrate is not really important !!!
|
||||
if ( ep_addr == p_cdc->ep_in )
|
||||
{
|
||||
// invoke transmit callback to possibly refill tx fifo
|
||||
if ( tud_cdc_tx_complete_cb ) tud_cdc_tx_complete_cb(itf);
|
||||
|
||||
if ( 0 == tud_cdc_n_write_flush(itf) )
|
||||
{
|
||||
// There is no data left, a ZLP should be sent if
|
||||
// xferred_bytes is multiple of EP size and not zero
|
||||
// FIXME CFG_TUD_CDC_EP_BUFSIZE is not Endpoint packet size
|
||||
if ( xferred_bytes && (0 == (xferred_bytes % CFG_TUD_CDC_EP_BUFSIZE)) )
|
||||
{
|
||||
usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, NULL, 0);
|
||||
usbd_edpt_xfer(rhport, p_cdc->ep_in, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,6 @@
|
||||
// CFG_TUD_CDC > 1
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
// Check if terminal is connected to this port
|
||||
bool tud_cdc_n_connected (uint8_t itf);
|
||||
|
||||
@ -133,6 +132,9 @@ TU_ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
|
||||
// Invoked when received `wanted_char`
|
||||
TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
|
||||
|
||||
// Invoked when space becomes available in TX buffer
|
||||
TU_ATTR_WEAK void tud_cdc_tx_complete_cb(uint8_t itf);
|
||||
|
||||
// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
|
||||
TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
|
||||
|
||||
|
@ -86,7 +86,6 @@ bool tuh_cdc_serial_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
// TODO consider all AT Command as serial candidate
|
||||
return tuh_cdc_mounted(dev_addr) &&
|
||||
(CDC_COMM_PROTOCOL_NONE <= cdch_data[dev_addr-1].itf_protocol) &&
|
||||
(cdch_data[dev_addr-1].itf_protocol <= CDC_COMM_PROTOCOL_ATCOMMAND_CDMA);
|
||||
}
|
||||
|
||||
@ -159,7 +158,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
// notification endpoint
|
||||
tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc;
|
||||
|
||||
TU_ASSERT( hcd_edpt_open(rhport, dev_addr, ep_desc) );
|
||||
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, ep_desc) );
|
||||
p_cdc->ep_notif = ep_desc->bEndpointAddress;
|
||||
|
||||
(*p_length) += p_desc[DESC_OFFSET_LEN];
|
||||
@ -180,7 +179,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
|
||||
TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
|
||||
|
||||
TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
|
||||
TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
|
||||
|
||||
if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
|
||||
{
|
||||
|
@ -35,35 +35,43 @@
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
typedef struct {
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
|
||||
uint16_t report_size;
|
||||
}hidh_interface_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HID Interface common functions
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_desc_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid)
|
||||
static inline bool hidh_interface_open(uint8_t rhport, uint8_t dev_addr, uint8_t interface_number, tusb_desc_endpoint_t const *p_endpoint_desc, hidh_interface_t *p_hid)
|
||||
{
|
||||
p_hid->pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
|
||||
p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
|
||||
p_hid->interface_number = interface_number;
|
||||
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, p_endpoint_desc) );
|
||||
|
||||
TU_ASSERT (pipehandle_is_valid(p_hid->pipe_hdl));
|
||||
p_hid->ep_in = p_endpoint_desc->bEndpointAddress;
|
||||
p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
|
||||
p_hid->itf_num = interface_number;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void hidh_interface_close(hidh_interface_info_t *p_hid)
|
||||
static inline void hidh_interface_close(hidh_interface_t *p_hid)
|
||||
{
|
||||
tu_memclr(p_hid, sizeof(hidh_interface_info_t));
|
||||
tu_memclr(p_hid, sizeof(hidh_interface_t));
|
||||
}
|
||||
|
||||
// called from public API need to validate parameters
|
||||
tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_interface_info_t *p_hid)
|
||||
tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_interface_t *p_hid)
|
||||
{
|
||||
//------------- parameters validation -------------//
|
||||
// TODO change to use is configured function
|
||||
TU_ASSERT (TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
TU_VERIFY (report, TUSB_ERROR_INVALID_PARA);
|
||||
TU_ASSERT (!hcd_edpt_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY);
|
||||
TU_ASSERT(TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
TU_VERIFY(report, TUSB_ERROR_INVALID_PARA);
|
||||
TU_ASSERT(!hcd_edpt_busy(dev_addr, p_hid->ep_in), TUSB_ERROR_INTERFACE_IS_BUSY);
|
||||
|
||||
TU_ASSERT_ERR( hcd_pipe_xfer(p_hid->pipe_hdl, report, p_hid->report_size, true) ) ;
|
||||
TU_ASSERT( hcd_pipe_xfer(dev_addr, p_hid->ep_in, report, p_hid->report_size, true) ) ;
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
@ -73,24 +81,12 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
|
||||
#if 0
|
||||
#define EXPAND_KEYCODE_TO_ASCII(keycode, ascii, shift_modified) \
|
||||
[0][keycode] = ascii,\
|
||||
[1][keycode] = shift_modified,\
|
||||
|
||||
// TODO size of table should be a macro for application to check boundary
|
||||
uint8_t const hid_keycode_to_ascii_tbl[2][128] =
|
||||
{
|
||||
HID_KEYCODE_TABLE(EXPAND_KEYCODE_TO_ASCII)
|
||||
};
|
||||
#endif
|
||||
|
||||
static hidh_interface_info_t keyboardh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
static hidh_interface_t keyboardh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
|
||||
//------------- KEYBOARD PUBLIC API (parameter validation required) -------------//
|
||||
bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_device_is_configured(dev_addr) && pipehandle_is_valid(keyboardh_data[dev_addr-1].pipe_hdl);
|
||||
return tuh_device_is_configured(dev_addr) && (keyboardh_data[dev_addr-1].ep_in != 0);
|
||||
}
|
||||
|
||||
tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void* p_report)
|
||||
@ -100,8 +96,7 @@ tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void* p_report)
|
||||
|
||||
bool tuh_hid_keyboard_is_busy(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_hid_keyboard_is_mounted(dev_addr) &&
|
||||
hcd_edpt_busy( keyboardh_data[dev_addr-1].pipe_hdl );
|
||||
return tuh_hid_keyboard_is_mounted(dev_addr) && hcd_edpt_busy(dev_addr, keyboardh_data[dev_addr-1].ep_in);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -111,18 +106,17 @@ bool tuh_hid_keyboard_is_busy(uint8_t dev_addr)
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
|
||||
static hidh_interface_info_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
static hidh_interface_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
|
||||
//------------- Public API -------------//
|
||||
bool tuh_hid_mouse_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_device_is_configured(dev_addr) && pipehandle_is_valid(mouseh_data[dev_addr-1].pipe_hdl);
|
||||
return tuh_device_is_configured(dev_addr) && (mouseh_data[dev_addr-1].ep_in != 0);
|
||||
}
|
||||
|
||||
bool tuh_hid_mouse_is_busy(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_hid_mouse_is_mounted(dev_addr) &&
|
||||
hcd_edpt_busy( mouseh_data[dev_addr-1].pipe_hdl );
|
||||
return tuh_hid_mouse_is_mounted(dev_addr) && hcd_edpt_busy(dev_addr, mouseh_data[dev_addr-1].ep_in);
|
||||
}
|
||||
|
||||
tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void * report)
|
||||
@ -149,11 +143,11 @@ tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void * report)
|
||||
void hidh_init(void)
|
||||
{
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
tu_memclr(&keyboardh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
tu_memclr(&keyboardh_data, sizeof(hidh_interface_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
tu_memclr(&mouseh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
tu_memclr(&mouseh_data, sizeof(hidh_interface_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_GENERIC
|
||||
@ -165,7 +159,7 @@ void hidh_init(void)
|
||||
CFG_TUSB_MEM_SECTION uint8_t report_descriptor[256];
|
||||
#endif
|
||||
|
||||
bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length)
|
||||
bool hidh_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length)
|
||||
{
|
||||
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
|
||||
|
||||
@ -208,7 +202,8 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
if ( HID_PROTOCOL_KEYBOARD == p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
TU_ASSERT( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) );
|
||||
TU_ASSERT( hidh_interface_open(rhport, dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) );
|
||||
TU_LOG2_HEX(keyboardh_data[dev_addr-1].ep_in);
|
||||
tuh_hid_keyboard_mounted_cb(dev_addr);
|
||||
} else
|
||||
#endif
|
||||
@ -216,7 +211,8 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
if ( HID_PROTOCOL_MOUSE == p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
TU_ASSERT ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) );
|
||||
TU_ASSERT ( hidh_interface_open(rhport, dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) );
|
||||
TU_LOG2_HEX(mouseh_data[dev_addr-1].ep_in);
|
||||
tuh_hid_mouse_mounted_cb(dev_addr);
|
||||
} else
|
||||
#endif
|
||||
@ -236,22 +232,22 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
|
||||
return true;
|
||||
}
|
||||
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes)
|
||||
void hidh_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) xferred_bytes; // TODO may need to use this para later
|
||||
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
if ( pipehandle_is_equal(pipe_hdl, keyboardh_data[pipe_hdl.dev_addr-1].pipe_hdl) )
|
||||
if ( ep_addr == keyboardh_data[dev_addr-1].ep_in )
|
||||
{
|
||||
tuh_hid_keyboard_isr(pipe_hdl.dev_addr, event);
|
||||
tuh_hid_keyboard_isr(dev_addr, event);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
if ( pipehandle_is_equal(pipe_hdl, mouseh_data[pipe_hdl.dev_addr-1].pipe_hdl) )
|
||||
if ( ep_addr == mouseh_data[dev_addr-1].ep_in )
|
||||
{
|
||||
tuh_hid_mouse_isr(pipe_hdl.dev_addr, event);
|
||||
tuh_hid_mouse_isr(dev_addr, event);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -264,7 +260,7 @@ void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_byte
|
||||
void hidh_close(uint8_t dev_addr)
|
||||
{
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
if ( pipehandle_is_valid( keyboardh_data[dev_addr-1].pipe_hdl ) )
|
||||
if ( keyboardh_data[dev_addr-1].ep_in != 0 )
|
||||
{
|
||||
hidh_interface_close(&keyboardh_data[dev_addr-1]);
|
||||
tuh_hid_keyboard_unmounted_cb(dev_addr);
|
||||
@ -272,7 +268,7 @@ void hidh_close(uint8_t dev_addr)
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
if( pipehandle_is_valid( mouseh_data[dev_addr-1].pipe_hdl ) )
|
||||
if( mouseh_data[dev_addr-1].ep_in != 0 )
|
||||
{
|
||||
hidh_interface_close(&mouseh_data[dev_addr-1]);
|
||||
tuh_hid_mouse_unmounted_cb( dev_addr );
|
||||
|
@ -195,15 +195,9 @@ void tuh_hid_generic_isr(uint8_t dev_addr, xfer_result_t event);
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
pipe_handle_t pipe_hdl;
|
||||
uint16_t report_size;
|
||||
uint8_t interface_number;
|
||||
}hidh_interface_info_t;
|
||||
|
||||
void hidh_init(void);
|
||||
bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes);
|
||||
bool hidh_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
|
||||
void hidh_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void hidh_close(uint8_t dev_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -101,8 +101,7 @@ uint32_t tud_midi_n_read(uint8_t itf, uint8_t jack_id, void* buffer, uint32_t bu
|
||||
|
||||
// Fill empty buffer
|
||||
if (midi->read_buffer_length == 0) {
|
||||
if (!tud_midi_n_receive(itf, midi->read_buffer))
|
||||
return 0;
|
||||
if (!tud_midi_n_receive(itf, midi->read_buffer)) return 0;
|
||||
|
||||
uint8_t code_index = midi->read_buffer[0] & 0x0f;
|
||||
// We always copy over the first byte.
|
||||
@ -119,8 +118,7 @@ uint32_t tud_midi_n_read(uint8_t itf, uint8_t jack_id, void* buffer, uint32_t bu
|
||||
}
|
||||
|
||||
uint32_t n = midi->read_buffer_length - midi->read_target_length;
|
||||
if (bufsize < n)
|
||||
n = bufsize;
|
||||
if (bufsize < n) n = bufsize;
|
||||
|
||||
// Skip the header in the buffer
|
||||
memcpy(buffer, midi->read_buffer + 1 + midi->read_target_length, n);
|
||||
@ -153,10 +151,8 @@ void midi_rx_done_cb(midid_interface_t* midi, uint8_t const* buffer, uint32_t bu
|
||||
// WRITE API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static bool maybe_transmit(midid_interface_t* midi, uint8_t itf_index)
|
||||
static uint32_t write_flush(midid_interface_t* midi)
|
||||
{
|
||||
(void) itf_index;
|
||||
|
||||
// skip if previous transfer not complete
|
||||
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, midi->ep_in) );
|
||||
|
||||
@ -165,7 +161,7 @@ static bool maybe_transmit(midid_interface_t* midi, uint8_t itf_index)
|
||||
{
|
||||
TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, midi->ep_in, midi->epin_buf, count) );
|
||||
}
|
||||
return true;
|
||||
return count;
|
||||
}
|
||||
|
||||
uint32_t tud_midi_n_write(uint8_t itf, uint8_t jack_id, uint8_t const* buffer, uint32_t bufsize)
|
||||
@ -234,7 +230,8 @@ uint32_t tud_midi_n_write(uint8_t itf, uint8_t jack_id, uint8_t const* buffer, u
|
||||
}
|
||||
i++;
|
||||
}
|
||||
maybe_transmit(midi, itf);
|
||||
|
||||
write_flush(midi);
|
||||
|
||||
return i;
|
||||
}
|
||||
@ -250,7 +247,7 @@ bool tud_midi_n_send (uint8_t itf, uint8_t const packet[4])
|
||||
return false;
|
||||
|
||||
tu_fifo_write_n(&midi->tx_ff, packet, 4);
|
||||
maybe_transmit(midi, itf);
|
||||
write_flush(midi);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -388,28 +385,40 @@ bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32
|
||||
{
|
||||
(void) result;
|
||||
|
||||
uint8_t itf = 0;
|
||||
midid_interface_t* p_midi = _midid_itf;
|
||||
uint8_t itf;
|
||||
midid_interface_t* p_midi;
|
||||
|
||||
for ( ; ; itf++, p_midi++)
|
||||
// Identify which interface to use
|
||||
for (itf = 0; itf < CFG_TUD_MIDI; itf++)
|
||||
{
|
||||
if (itf >= TU_ARRAY_SIZE(_midid_itf)) return false;
|
||||
|
||||
if ( ep_addr == p_midi->ep_out ) break;
|
||||
p_midi = &_midid_itf[itf];
|
||||
if ( ( ep_addr == p_midi->ep_out ) || ( ep_addr == p_midi->ep_in ) ) break;
|
||||
}
|
||||
TU_ASSERT(itf < CFG_TUD_MIDI);
|
||||
|
||||
// receive new data
|
||||
if ( ep_addr == p_midi->ep_out )
|
||||
{
|
||||
midi_rx_done_cb(p_midi, p_midi->epout_buf, xferred_bytes);
|
||||
tu_fifo_write_n(&p_midi->rx_ff, p_midi->epout_buf, xferred_bytes);
|
||||
|
||||
// invoke receive callback if available
|
||||
if (tud_midi_rx_cb) tud_midi_rx_cb(itf);
|
||||
|
||||
// prepare for next
|
||||
TU_ASSERT( usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EP_BUFSIZE), false );
|
||||
} else if ( ep_addr == p_midi->ep_in ) {
|
||||
maybe_transmit(p_midi, itf);
|
||||
TU_ASSERT(usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EP_BUFSIZE), false);
|
||||
}
|
||||
else if ( ep_addr == p_midi->ep_in )
|
||||
{
|
||||
if (0 == write_flush(p_midi))
|
||||
{
|
||||
// There is no data left, a ZLP should be sent if
|
||||
// xferred_bytes is multiple of EP size and not zero
|
||||
if ( xferred_bytes && (0 == (xferred_bytes % CFG_TUD_MIDI_EP_BUFSIZE)) )
|
||||
{
|
||||
usbd_edpt_xfer(rhport, p_midi->ep_in, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nothing to do with in and notif endpoint
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ bool tud_midi_n_receive (uint8_t itf, uint8_t packet[4]);
|
||||
bool tud_midi_n_send (uint8_t itf, uint8_t const packet[4]);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Interface0)
|
||||
// Application API (Single Interface)
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_midi_mounted (void);
|
||||
static inline uint32_t tud_midi_available (void);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "common/tusb_common.h"
|
||||
#include "msc_device.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
#include "device/dcd.h" // for faking dcd_event_xfer_complete
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
@ -105,7 +106,7 @@ static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
|
||||
static lookup_entry_t const _msc_scsi_cmd_lookup[] =
|
||||
static tu_lookup_entry_t const _msc_scsi_cmd_lookup[] =
|
||||
{
|
||||
{ .key = SCSI_CMD_TEST_UNIT_READY , .data = "Test Unit Ready" },
|
||||
{ .key = SCSI_CMD_INQUIRY , .data = "Inquiry" },
|
||||
@ -120,7 +121,7 @@ static lookup_entry_t const _msc_scsi_cmd_lookup[] =
|
||||
{ .key = SCSI_CMD_WRITE_10 , .data = "Write10" }
|
||||
};
|
||||
|
||||
static lookup_table_t const _msc_scsi_cmd_table =
|
||||
static tu_lookup_table_t const _msc_scsi_cmd_table =
|
||||
{
|
||||
.count = TU_ARRAY_SIZE(_msc_scsi_cmd_lookup),
|
||||
.items = _msc_scsi_cmd_lookup
|
||||
@ -418,7 +419,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
TU_ASSERT( event == XFER_RESULT_SUCCESS &&
|
||||
xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE );
|
||||
|
||||
TU_LOG2(" SCSI Command: %s\r\n", lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
|
||||
TU_LOG2(" SCSI Command: %s\r\n", tu_lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
|
||||
// TU_LOG2_MEM(p_cbw, xferred_bytes, 2);
|
||||
|
||||
p_csw->signature = MSC_CSW_SIGNATURE;
|
||||
|
@ -293,7 +293,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
|
||||
TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
|
||||
|
||||
TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
|
||||
TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
|
||||
|
||||
if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
|
||||
{
|
||||
@ -306,15 +306,16 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc);
|
||||
}
|
||||
|
||||
p_msc->itf_numr = itf_desc->bInterfaceNumber;
|
||||
p_msc->itf_num = itf_desc->bInterfaceNumber;
|
||||
(*p_length) += sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
//------------- Get Max Lun -------------//
|
||||
TU_LOG2("MSC Get Max Lun\r\n");
|
||||
tusb_control_request_t request = {
|
||||
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_IN },
|
||||
.bRequest = MSC_REQ_GET_MAX_LUN,
|
||||
.wValue = 0,
|
||||
.wIndex = p_msc->itf_numr,
|
||||
.wIndex = p_msc->itf_num,
|
||||
.wLength = 1
|
||||
};
|
||||
// TODO STALL means zero
|
||||
@ -327,7 +328,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_OUT },
|
||||
.bRequest = MSC_REQ_RESET,
|
||||
.wValue = 0,
|
||||
.wIndex = p_msc->itf_numr,
|
||||
.wIndex = p_msc->itf_num,
|
||||
.wLength = 0
|
||||
};
|
||||
TU_ASSERT( usbh_control_xfer( dev_addr, &request, NULL ) );
|
||||
|
@ -175,7 +175,7 @@ void tuh_msc_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct
|
||||
{
|
||||
uint8_t itf_numr;
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
|
||||
|
@ -326,7 +326,7 @@ bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
{
|
||||
if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
|
||||
{
|
||||
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)notify.rndis_buf;
|
||||
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *) ((void*) notify.rndis_buf);
|
||||
uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
|
||||
TU_ASSERT(msglen <= sizeof(notify.rndis_buf));
|
||||
tud_control_xfer(rhport, request, notify.rndis_buf, msglen);
|
||||
@ -356,7 +356,7 @@ static void handle_incoming_packet(uint32_t len)
|
||||
}
|
||||
else
|
||||
{
|
||||
rndis_data_packet_t *r = (rndis_data_packet_t *)pnt;
|
||||
rndis_data_packet_t *r = (rndis_data_packet_t *) ((void*) pnt);
|
||||
if (len >= sizeof(rndis_data_packet_t))
|
||||
if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
|
||||
if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
|
||||
@ -450,7 +450,7 @@ void tud_network_xmit(struct pbuf *p)
|
||||
|
||||
if (!_netd_itf.ecm_mode)
|
||||
{
|
||||
rndis_data_packet_t *hdr = (rndis_data_packet_t *)transmitted;
|
||||
rndis_data_packet_t *hdr = (rndis_data_packet_t *) ((void*) transmitted);
|
||||
memset(hdr, 0, sizeof(rndis_data_packet_t));
|
||||
hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
|
||||
hdr->MessageLength = len;
|
||||
|
@ -80,7 +80,6 @@
|
||||
#include <string.h>
|
||||
#include "usbtmc.h"
|
||||
#include "usbtmc_device.h"
|
||||
#include "device/dcd.h"
|
||||
#include "device/usbd.h"
|
||||
#include "osal/osal.h"
|
||||
|
||||
|
2
src/class/vendor/vendor_host.c
vendored
2
src/class/vendor/vendor_host.c
vendored
@ -107,7 +107,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_
|
||||
|
||||
pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ?
|
||||
&custom_interface[dev_addr-1].pipe_in : &custom_interface[dev_addr-1].pipe_out;
|
||||
*p_pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC);
|
||||
*p_pipe_hdl = usbh_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC);
|
||||
TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED );
|
||||
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
|
@ -251,16 +251,16 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t key;
|
||||
char const * data;
|
||||
}lookup_entry_t;
|
||||
const char* data;
|
||||
} tu_lookup_entry_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t count;
|
||||
lookup_entry_t const* items;
|
||||
} lookup_table_t;
|
||||
tu_lookup_entry_t const* items;
|
||||
} tu_lookup_table_t;
|
||||
|
||||
static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t key)
|
||||
static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint32_t key)
|
||||
{
|
||||
for(uint16_t i=0; i<p_table->count; i++)
|
||||
{
|
||||
|
@ -87,9 +87,9 @@ typedef struct TU_ATTR_ALIGNED(4)
|
||||
|
||||
//TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct");
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Device API
|
||||
*------------------------------------------------------------------*/
|
||||
//--------------------------------------------------------------------+
|
||||
// Controller API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Initialize controller to device mode
|
||||
void dcd_init (uint8_t rhport);
|
||||
|
@ -82,21 +82,7 @@ enum { DRVID_INVALID = 0xFFu };
|
||||
#define DRIVER_NAME(_name)
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
char const* name;
|
||||
#endif
|
||||
|
||||
void (* init ) (void);
|
||||
void (* reset ) (uint8_t rhport);
|
||||
uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
|
||||
bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool (* control_complete ) (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void (* sof ) (uint8_t rhport); /* optional */
|
||||
} usbd_class_driver_t;
|
||||
|
||||
// Built-in class drivers
|
||||
static usbd_class_driver_t const _usbd_driver[] =
|
||||
{
|
||||
#if CFG_TUD_CDC
|
||||
@ -217,7 +203,30 @@ static usbd_class_driver_t const _usbd_driver[] =
|
||||
#endif
|
||||
};
|
||||
|
||||
enum { USBD_CLASS_DRIVER_COUNT = TU_ARRAY_SIZE(_usbd_driver) };
|
||||
enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(_usbd_driver) };
|
||||
|
||||
// Additional class drivers implemented by application
|
||||
static usbd_class_driver_t const * _app_driver = NULL;
|
||||
static uint8_t _app_driver_count = 0;
|
||||
|
||||
// virtually joins built-in and application drivers together.
|
||||
// Application is positioned first to allow overwriting built-in ones.
|
||||
static inline usbd_class_driver_t const * get_driver(uint8_t drvid)
|
||||
{
|
||||
// Application drivers
|
||||
if ( usbd_app_driver_get_cb )
|
||||
{
|
||||
if ( drvid < _app_driver_count ) return &_app_driver[drvid];
|
||||
drvid -= _app_driver_count;
|
||||
}
|
||||
|
||||
// Built-in drivers
|
||||
if (drvid < BUILTIN_DRIVER_COUNT) return &_usbd_driver[drvid];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DCD Event
|
||||
@ -236,6 +245,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
static bool process_set_config(uint8_t rhport, uint8_t cfg_num);
|
||||
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
|
||||
// from usbd_control.c
|
||||
void usbd_control_reset(void);
|
||||
void usbd_control_set_request(tusb_control_request_t const *request);
|
||||
void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) );
|
||||
@ -243,7 +253,7 @@ bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event,
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Debugging
|
||||
// Debug
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
static char const* const _usbd_event_str[DCD_EVENT_COUNT] =
|
||||
@ -279,11 +289,12 @@ static char const* const _tusb_std_request_str[] =
|
||||
// for usbd_control to print the name of control complete driver
|
||||
void usbd_driver_print_control_complete_name(bool (*control_complete) (uint8_t, tusb_control_request_t const * ))
|
||||
{
|
||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
||||
for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++)
|
||||
{
|
||||
if (_usbd_driver[i].control_complete == control_complete )
|
||||
usbd_class_driver_t const * driver = get_driver(i);
|
||||
if ( driver->control_complete == control_complete )
|
||||
{
|
||||
TU_LOG2(" %s control complete\r\n", _usbd_driver[i].name);
|
||||
TU_LOG2(" %s control complete\r\n", driver->name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -317,6 +328,20 @@ bool tud_remote_wakeup(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_disconnect(void)
|
||||
{
|
||||
TU_VERIFY(dcd_disconnect);
|
||||
dcd_disconnect(TUD_OPT_RHPORT);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_connect(void)
|
||||
{
|
||||
TU_VERIFY(dcd_connect);
|
||||
dcd_connect(TUD_OPT_RHPORT);
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Task
|
||||
//--------------------------------------------------------------------+
|
||||
@ -330,16 +355,22 @@ bool tud_init (void)
|
||||
_usbd_q = osal_queue_create(&_usbd_qdef);
|
||||
TU_ASSERT(_usbd_q != NULL);
|
||||
|
||||
// Init class drivers
|
||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
||||
// Get application driver if available
|
||||
if ( usbd_app_driver_get_cb )
|
||||
{
|
||||
TU_LOG2("%s init\r\n", _usbd_driver[i].name);
|
||||
_usbd_driver[i].init();
|
||||
_app_driver = usbd_app_driver_get_cb(&_app_driver_count);
|
||||
}
|
||||
|
||||
// Init class drivers
|
||||
for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++)
|
||||
{
|
||||
usbd_class_driver_t const * driver = get_driver(i);
|
||||
TU_LOG2("%s init\r\n", driver->name);
|
||||
driver->init();
|
||||
}
|
||||
|
||||
// Init device controller driver
|
||||
dcd_init(TUD_OPT_RHPORT);
|
||||
tud_connect();
|
||||
dcd_int_enable(TUD_OPT_RHPORT);
|
||||
|
||||
return true;
|
||||
@ -354,9 +385,9 @@ static void usbd_reset(uint8_t rhport)
|
||||
|
||||
usbd_control_reset();
|
||||
|
||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
||||
for ( uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++ )
|
||||
{
|
||||
if ( _usbd_driver[i].reset ) _usbd_driver[i].reset( rhport );
|
||||
get_driver(i)->reset(rhport);
|
||||
}
|
||||
}
|
||||
|
||||
@ -454,11 +485,11 @@ void tud_task (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t const drv_id = _usbd_dev.ep2drv[epnum][ep_dir];
|
||||
TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,);
|
||||
usbd_class_driver_t const * driver = get_driver( _usbd_dev.ep2drv[epnum][ep_dir] );
|
||||
TU_ASSERT(driver, );
|
||||
|
||||
TU_LOG2(" %s xfer callback\r\n", _usbd_driver[drv_id].name);
|
||||
_usbd_driver[drv_id].xfer_cb(event.rhport, ep_addr, (xfer_result_t)event.xfer_complete.result, event.xfer_complete.len);
|
||||
TU_LOG2(" %s xfer callback\r\n", driver->name);
|
||||
driver->xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -475,12 +506,10 @@ void tud_task (void)
|
||||
|
||||
case DCD_EVENT_SOF:
|
||||
TU_LOG2("\r\n");
|
||||
for ( uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++ )
|
||||
for ( uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++ )
|
||||
{
|
||||
if ( _usbd_driver[i].sof )
|
||||
{
|
||||
_usbd_driver[i].sof(event.rhport);
|
||||
}
|
||||
usbd_class_driver_t const * driver = get_driver(i);
|
||||
if ( driver->sof ) driver->sof(event.rhport);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -501,11 +530,11 @@ void tud_task (void)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Helper to invoke class driver control request handler
|
||||
static bool invoke_class_control(uint8_t rhport, uint8_t drvid, tusb_control_request_t const * request)
|
||||
static bool invoke_class_control(uint8_t rhport, usbd_class_driver_t const * driver, tusb_control_request_t const * request)
|
||||
{
|
||||
usbd_control_set_complete_callback(_usbd_driver[drvid].control_complete);
|
||||
TU_LOG2(" %s control request\r\n", _usbd_driver[drvid].name);
|
||||
return _usbd_driver[drvid].control_request(rhport, request);
|
||||
usbd_control_set_complete_callback(driver->control_complete);
|
||||
TU_LOG2(" %s control request\r\n", driver->name);
|
||||
return driver->control_request(rhport, request);
|
||||
}
|
||||
|
||||
// This handles the actual request and its response.
|
||||
@ -539,15 +568,14 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
case TUSB_REQ_RCPT_DEVICE:
|
||||
if ( TUSB_REQ_TYPE_CLASS == p_request->bmRequestType_bit.type )
|
||||
{
|
||||
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
||||
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
|
||||
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
||||
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
|
||||
|
||||
uint8_t const drvid = _usbd_dev.itf2drv[itf];
|
||||
TU_VERIFY(drvid < USBD_CLASS_DRIVER_COUNT);
|
||||
usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
|
||||
TU_VERIFY(driver);
|
||||
|
||||
// forward to class driver: "non-STD request to Interface"
|
||||
TU_VERIFY(invoke_class_control(rhport, drvid, p_request));
|
||||
return true;
|
||||
// forward to class driver: "non-STD request to Interface"
|
||||
return invoke_class_control(rhport, driver, p_request);
|
||||
}
|
||||
if ( TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type )
|
||||
{
|
||||
@ -580,7 +608,6 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
uint8_t const cfg_num = (uint8_t) p_request->wValue;
|
||||
|
||||
if ( !_usbd_dev.configured && cfg_num ) TU_ASSERT( process_set_config(rhport, cfg_num) );
|
||||
|
||||
_usbd_dev.configured = cfg_num ? 1 : 0;
|
||||
|
||||
tud_control_status(rhport, p_request);
|
||||
@ -630,12 +657,12 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
||||
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
|
||||
|
||||
uint8_t const drvid = _usbd_dev.itf2drv[itf];
|
||||
TU_VERIFY(drvid < USBD_CLASS_DRIVER_COUNT);
|
||||
usbd_class_driver_t const * driver = get_driver(_usbd_dev.itf2drv[itf]);
|
||||
TU_VERIFY(driver);
|
||||
|
||||
// all requests to Interface (STD or Class) is forwarded to class driver.
|
||||
// notable requests are: GET HID REPORT DESCRIPTOR, SET_INTERFACE, GET_INTERFACE
|
||||
if ( !invoke_class_control(rhport, drvid, p_request) )
|
||||
if ( !invoke_class_control(rhport, driver, p_request) )
|
||||
{
|
||||
// For GET_INTERFACE, it is mandatory to respond even if the class
|
||||
// driver doesn't use alternate settings.
|
||||
@ -657,8 +684,6 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
|
||||
TU_ASSERT(ep_num < TU_ARRAY_SIZE(_usbd_dev.ep2drv) );
|
||||
|
||||
uint8_t const drvid = _usbd_dev.ep2drv[ep_num][ep_dir];
|
||||
|
||||
bool ret = false;
|
||||
|
||||
// Handle STD request to endpoint
|
||||
@ -677,18 +702,12 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
break;
|
||||
|
||||
case TUSB_REQ_CLEAR_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_clear_stall(rhport, ep_addr);
|
||||
}
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) usbd_edpt_clear_stall(rhport, ep_addr);
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_stall(rhport, ep_addr);
|
||||
}
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue ) usbd_edpt_stall(rhport, ep_addr);
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
@ -697,16 +716,17 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
}
|
||||
}
|
||||
|
||||
if (drvid < 0xFF) {
|
||||
TU_ASSERT(drvid < USBD_CLASS_DRIVER_COUNT);
|
||||
|
||||
usbd_class_driver_t const * driver = get_driver(_usbd_dev.ep2drv[ep_num][ep_dir]);
|
||||
|
||||
if (driver)
|
||||
{
|
||||
// Some classes such as USBTMC needs to clear/re-init its buffer when receiving CLEAR_FEATURE request
|
||||
// We will forward all request targeted endpoint to class drivers after
|
||||
// - For class-type requests: driver is fully responsible to reply to host
|
||||
// - For std-type requests : driver init/re-init internal variable/buffer only, and
|
||||
// must not call tud_control_status(), driver's return value will have no effect.
|
||||
// EP state has already affected (stalled/cleared)
|
||||
if ( invoke_class_control(rhport, drvid, p_request) ) ret = true;
|
||||
if ( invoke_class_control(rhport, driver, p_request) ) ret = true;
|
||||
}
|
||||
|
||||
if ( TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type )
|
||||
@ -758,13 +778,10 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
uint16_t const remaining_len = desc_end-p_desc;
|
||||
|
||||
uint8_t drv_id;
|
||||
uint16_t drv_len;
|
||||
|
||||
for (drv_id = 0; drv_id < USBD_CLASS_DRIVER_COUNT; drv_id++)
|
||||
for (drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++)
|
||||
{
|
||||
usbd_class_driver_t const *driver = &_usbd_driver[drv_id];
|
||||
|
||||
drv_len = driver->open(rhport, desc_itf, remaining_len);
|
||||
usbd_class_driver_t const *driver = get_driver(drv_id);
|
||||
uint16_t const drv_len = driver->open(rhport, desc_itf, remaining_len);
|
||||
|
||||
if ( drv_len > 0 )
|
||||
{
|
||||
@ -772,7 +789,7 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
TU_ASSERT( sizeof(tusb_desc_interface_t) <= drv_len && drv_len <= remaining_len);
|
||||
|
||||
// Interface number must not be used already
|
||||
TU_ASSERT( DRVID_INVALID == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] );
|
||||
TU_ASSERT(DRVID_INVALID == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber]);
|
||||
|
||||
TU_LOG2(" %s opened\r\n", driver->name);
|
||||
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id;
|
||||
@ -790,16 +807,16 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
}
|
||||
}
|
||||
|
||||
mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, drv_len, drv_id); // TODO refactor
|
||||
|
||||
p_desc += drv_len; // next interface
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Failed if cannot find supported driver
|
||||
TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT);
|
||||
|
||||
mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, drv_len, drv_id); // TODO refactor
|
||||
|
||||
p_desc += drv_len; // next interface
|
||||
TU_ASSERT(drv_id < TOTAL_DRIVER_COUNT);
|
||||
}
|
||||
|
||||
// invoke callback
|
||||
|
@ -35,7 +35,6 @@
|
||||
#endif
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "dcd.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API
|
||||
@ -53,6 +52,7 @@ void tud_task (void);
|
||||
bool tud_task_event_ready(void);
|
||||
|
||||
// Interrupt handler, name alias to DCD
|
||||
extern void dcd_int_handler(uint8_t rhport);
|
||||
#define tud_int_handler dcd_int_handler
|
||||
|
||||
// Get current bus speed
|
||||
@ -75,21 +75,11 @@ bool tud_remote_wakeup(void);
|
||||
|
||||
// Enable pull-up resistor on D+ D-
|
||||
// Return false on unsupported MCUs
|
||||
static inline bool tud_disconnect(void)
|
||||
{
|
||||
TU_VERIFY(dcd_disconnect);
|
||||
dcd_disconnect(TUD_OPT_RHPORT);
|
||||
return true;
|
||||
}
|
||||
bool tud_disconnect(void);
|
||||
|
||||
// Disable pull-up resistor on D+ D-
|
||||
// Return false on unsupported MCUs
|
||||
static inline bool tud_connect(void)
|
||||
{
|
||||
TU_VERIFY(dcd_connect);
|
||||
dcd_connect(TUD_OPT_RHPORT);
|
||||
return true;
|
||||
}
|
||||
bool tud_connect(void);
|
||||
|
||||
// Carry out Data and Status stage of control transfer
|
||||
// - If len = 0, it is equivalent to sending status only
|
||||
|
@ -33,6 +33,30 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Drivers
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
char const* name;
|
||||
#endif
|
||||
|
||||
void (* init ) (void);
|
||||
void (* reset ) (uint8_t rhport);
|
||||
uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
|
||||
bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool (* control_complete ) (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void (* sof ) (uint8_t rhport); /* optional */
|
||||
} usbd_class_driver_t;
|
||||
|
||||
// Invoked when initializing device stack to get additional class drivers.
|
||||
// Can optionally implemented by application to extend/overwrite class driver support.
|
||||
// Note: The drivers array must be accessible at all time when stack is active
|
||||
usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count) TU_ATTR_WEAK;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -108,16 +108,39 @@ bool hcd_init(void)
|
||||
return ehci_init(TUH_OPT_RHPORT);
|
||||
}
|
||||
|
||||
uint32_t hcd_uframe_number(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
return ehci_data.uframe_number + ehci_data.regs->frame_index;
|
||||
}
|
||||
|
||||
void hcd_port_reset(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
ehci_registers_t* regs = ehci_data.regs;
|
||||
|
||||
regs->portsc_bm.port_enabled = 0; // disable port before reset
|
||||
regs->portsc_bm.port_reset = 1;
|
||||
// regs->portsc_bm.port_enabled = 0; // disable port before reset
|
||||
// regs->portsc_bm.port_reset = 1;
|
||||
|
||||
uint32_t portsc = regs->portsc;
|
||||
|
||||
portsc &= ~(EHCI_PORTSC_MASK_PORT_EANBLED);
|
||||
portsc |= EHCI_PORTSC_MASK_PORT_RESET;
|
||||
|
||||
regs->portsc = portsc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void hcd_port_reset_end(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
ehci_registers_t* regs = ehci_data.regs;
|
||||
regs->portsc_bm.port_reset = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool hcd_port_connect_status(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
@ -192,7 +215,7 @@ static bool ehci_init(uint8_t rhport)
|
||||
regs->status = EHCI_INT_MASK_ALL; // 2. clear all status
|
||||
|
||||
regs->inten = EHCI_INT_MASK_ERROR | EHCI_INT_MASK_PORT_CHANGE | EHCI_INT_MASK_ASYNC_ADVANCE |
|
||||
EHCI_INT_MASK_NXP_PERIODIC | EHCI_INT_MASK_NXP_ASYNC ;
|
||||
EHCI_INT_MASK_NXP_PERIODIC | EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_FRAMELIST_ROLLOVER;
|
||||
|
||||
//------------- Asynchronous List -------------//
|
||||
ehci_qhd_t * const async_head = qhd_async_head(rhport);
|
||||
@ -358,7 +381,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
|
||||
if ( dev_addr == 0 ) return true;
|
||||
|
||||
// Insert to list
|
||||
ehci_link_t * list_head;
|
||||
ehci_link_t * list_head = NULL;
|
||||
|
||||
switch (ep_desc->bmAttributes.xfer)
|
||||
{
|
||||
@ -378,8 +401,10 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
|
||||
default: break;
|
||||
}
|
||||
|
||||
TU_ASSERT(list_head);
|
||||
|
||||
// TODO might need to disable async/period list
|
||||
list_insert( list_head, (ehci_link_t*) p_qhd, EHCI_QTYPE_QHD);
|
||||
list_insert(list_head, (ehci_link_t*) p_qhd, EHCI_QTYPE_QHD);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -623,7 +648,7 @@ static void xfer_error_isr(uint8_t hostid)
|
||||
}
|
||||
|
||||
//------------- Host Controller Driver's Interrupt Handler -------------//
|
||||
void hcd_isr(uint8_t rhport)
|
||||
void hcd_int_handler(uint8_t rhport)
|
||||
{
|
||||
ehci_registers_t* regs = ehci_data.regs;
|
||||
|
||||
@ -634,6 +659,11 @@ void hcd_isr(uint8_t rhport)
|
||||
|
||||
if (int_status == 0) return;
|
||||
|
||||
if (int_status & EHCI_INT_MASK_FRAMELIST_ROLLOVER)
|
||||
{
|
||||
ehci_data.uframe_number += (EHCI_FRAMELIST_SIZE << 3);
|
||||
}
|
||||
|
||||
if (int_status & EHCI_INT_MASK_PORT_CHANGE)
|
||||
{
|
||||
uint32_t port_status = regs->portsc & EHCI_PORTSC_MASK_ALL;
|
||||
|
@ -54,8 +54,8 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// EHCI CONFIGURATION & CONSTANTS
|
||||
//--------------------------------------------------------------------+
|
||||
#define EHCI_CFG_FRAMELIST_SIZE_BITS 7 /// Framelist Size (NXP specific) (0:1024) - (1:512) - (2:256) - (3:128) - (4:64) - (5:32) - (6:16) - (7:8)
|
||||
#define EHCI_FRAMELIST_SIZE (1024 >> EHCI_CFG_FRAMELIST_SIZE_BITS)
|
||||
#define EHCI_CFG_FRAMELIST_SIZE_BITS 7 /// Framelist Size (NXP specific) (0:1024) - (1:512) - (2:256) - (3:128) - (4:64) - (5:32) - (6:16) - (7:8)
|
||||
#define EHCI_FRAMELIST_SIZE (1024 >> EHCI_CFG_FRAMELIST_SIZE_BITS)
|
||||
|
||||
// TODO merge OHCI with EHCI
|
||||
enum {
|
||||
@ -311,10 +311,14 @@ enum ehci_usbcmd_pos_ {
|
||||
};
|
||||
|
||||
enum ehci_portsc_change_mask_{
|
||||
EHCI_PORTSC_MASK_CURRENT_CONNECT_STATUS = TU_BIT(0),
|
||||
EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = TU_BIT(1),
|
||||
EHCI_PORTSC_MASK_PORT_EANBLED = TU_BIT(2),
|
||||
EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = TU_BIT(3),
|
||||
EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = TU_BIT(5),
|
||||
|
||||
EHCI_PORTSC_MASK_PORT_RESET = TU_BIT(8),
|
||||
|
||||
EHCI_PORTSC_MASK_ALL =
|
||||
EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE |
|
||||
EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE |
|
||||
@ -445,6 +449,8 @@ typedef struct
|
||||
ehci_qtd_t qtd_pool[HCD_MAX_XFER] TU_ATTR_ALIGNED(32);
|
||||
|
||||
ehci_registers_t* regs;
|
||||
|
||||
volatile uint32_t uframe_number;
|
||||
}ehci_data_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -84,17 +84,26 @@ enum {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HCD API
|
||||
// Controller & Port API
|
||||
//--------------------------------------------------------------------+
|
||||
bool hcd_init(void);
|
||||
void hcd_isr(uint8_t hostid);
|
||||
void hcd_int_handler(uint8_t rhport);
|
||||
void hcd_int_enable (uint8_t rhport);
|
||||
void hcd_int_disable(uint8_t rhport);
|
||||
|
||||
// PORT API
|
||||
// Get micro frame number (125 us)
|
||||
uint32_t hcd_uframe_number(uint8_t rhport);
|
||||
|
||||
// Get frame number (1ms)
|
||||
static inline uint32_t hcd_frame_number(uint8_t rhport)
|
||||
{
|
||||
return hcd_uframe_number(rhport) >> 3;
|
||||
}
|
||||
|
||||
/// return the current connect status of roothub port
|
||||
bool hcd_port_connect_status(uint8_t hostid);
|
||||
void hcd_port_reset(uint8_t hostid);
|
||||
void hcd_port_reset_end(uint8_t rhport);
|
||||
tusb_speed_t hcd_port_speed_get(uint8_t hostid);
|
||||
|
||||
// HCD closes all opened endpoints belong to this device
|
||||
@ -134,9 +143,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
|
||||
bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet
|
||||
bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete);
|
||||
|
||||
#if 0
|
||||
tusb_error_t hcd_pipe_cancel();
|
||||
#endif
|
||||
// tusb_error_t hcd_pipe_cancel();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
|
||||
TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer);
|
||||
|
||||
TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
|
||||
TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
|
||||
|
||||
hub_data[dev_addr-1].itf_num = itf_desc->bInterfaceNumber;
|
||||
hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress;
|
||||
|
@ -166,7 +166,7 @@ bool hcd_init(void)
|
||||
OHCI_REG->interrupt_disable = OHCI_REG->interrupt_enable; // disable all interrupts
|
||||
OHCI_REG->interrupt_status = OHCI_REG->interrupt_status; // clear current set bits
|
||||
OHCI_REG->interrupt_enable = OHCI_INT_WRITEBACK_DONEHEAD_MASK | OHCI_INT_RESUME_DETECTED_MASK |
|
||||
OHCI_INT_UNRECOVERABLE_ERROR_MASK | /*OHCI_INT_FRAME_OVERFLOW_MASK |*/ OHCI_INT_RHPORT_STATUS_CHANGE_MASK |
|
||||
OHCI_INT_UNRECOVERABLE_ERROR_MASK | OHCI_INT_FRAME_OVERFLOW_MASK | OHCI_INT_RHPORT_STATUS_CHANGE_MASK |
|
||||
OHCI_INT_MASTER_ENABLE_MASK;
|
||||
|
||||
OHCI_REG->control |= OHCI_CONTROL_CONTROL_BULK_RATIO | OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK |
|
||||
@ -181,6 +181,13 @@ bool hcd_init(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t hcd_uframe_number(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
return (ohci_data.frame_number_hi << 16 | OHCI_REG->frame_number) << 3;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PORT API
|
||||
//--------------------------------------------------------------------+
|
||||
@ -599,13 +606,19 @@ static void done_queue_isr(uint8_t hostid)
|
||||
}
|
||||
}
|
||||
|
||||
void hcd_isr(uint8_t hostid)
|
||||
void hcd_int_handler(uint8_t hostid)
|
||||
{
|
||||
uint32_t const int_en = OHCI_REG->interrupt_enable;
|
||||
uint32_t const int_status = OHCI_REG->interrupt_status & int_en;
|
||||
|
||||
if (int_status == 0) return;
|
||||
|
||||
// Frame number overflow
|
||||
if ( int_status & OHCI_INT_FRAME_OVERFLOW_MASK )
|
||||
{
|
||||
ohci_data.frame_number_hi++;
|
||||
}
|
||||
|
||||
//------------- RootHub status -------------//
|
||||
if ( int_status & OHCI_INT_RHPORT_STATUS_CHANGE_MASK )
|
||||
{
|
||||
|
@ -180,6 +180,8 @@ typedef struct TU_ATTR_ALIGNED(256)
|
||||
ohci_ed_t ed_pool[HCD_MAX_ENDPOINT];
|
||||
ohci_gtd_t gtd_pool[HCD_MAX_XFER];
|
||||
|
||||
volatile uint16_t frame_number_hi;
|
||||
|
||||
} ohci_data_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
107
src/host/usbh.c
107
src/host/usbh.c
@ -42,10 +42,17 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
#define DRIVER_NAME(_name) .name = _name,
|
||||
#else
|
||||
#define DRIVER_NAME(_name)
|
||||
#endif
|
||||
|
||||
static host_class_driver_t const usbh_class_drivers[] =
|
||||
{
|
||||
#if CFG_TUH_CDC
|
||||
{
|
||||
DRIVER_NAME("CDC")
|
||||
.class_code = TUSB_CLASS_CDC,
|
||||
.init = cdch_init,
|
||||
.open = cdch_open,
|
||||
@ -56,6 +63,7 @@ static host_class_driver_t const usbh_class_drivers[] =
|
||||
|
||||
#if CFG_TUH_MSC
|
||||
{
|
||||
DRIVER_NAME("MSC")
|
||||
.class_code = TUSB_CLASS_MSC,
|
||||
.init = msch_init,
|
||||
.open = msch_open,
|
||||
@ -66,6 +74,7 @@ static host_class_driver_t const usbh_class_drivers[] =
|
||||
|
||||
#if HOST_CLASS_HID
|
||||
{
|
||||
DRIVER_NAME("HID")
|
||||
.class_code = TUSB_CLASS_HID,
|
||||
.init = hidh_init,
|
||||
.open = hidh_open_subtask,
|
||||
@ -76,6 +85,7 @@ static host_class_driver_t const usbh_class_drivers[] =
|
||||
|
||||
#if CFG_TUH_HUB
|
||||
{
|
||||
DRIVER_NAME("HUB")
|
||||
.class_code = TUSB_CLASS_HUB,
|
||||
.init = hub_init,
|
||||
.open = hub_open,
|
||||
@ -86,6 +96,7 @@ static host_class_driver_t const usbh_class_drivers[] =
|
||||
|
||||
#if CFG_TUH_VENDOR
|
||||
{
|
||||
DRIVER_NAME("VENDOR")
|
||||
.class_code = TUSB_CLASS_VENDOR_SPECIFIC,
|
||||
.init = cush_init,
|
||||
.open = cush_open_subtask,
|
||||
@ -116,7 +127,6 @@ CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_H
|
||||
//------------- Helper Function Prototypes -------------//
|
||||
static inline uint8_t get_new_address(void);
|
||||
static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc);
|
||||
static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PUBLIC API (Parameter Verification is required)
|
||||
@ -127,6 +137,15 @@ tusb_device_state_t tuh_device_get_state (uint8_t const dev_addr)
|
||||
return (tusb_device_state_t) _usbh_devices[dev_addr].state;
|
||||
}
|
||||
|
||||
|
||||
static inline void osal_task_delay(uint32_t msec)
|
||||
{
|
||||
(void) msec;
|
||||
|
||||
const uint32_t start = hcd_frame_number(TUH_OPT_RHPORT);
|
||||
while ( ( hcd_frame_number(TUH_OPT_RHPORT) - start ) < msec ) {}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS-USBD API (don't require to verify parameters)
|
||||
//--------------------------------------------------------------------+
|
||||
@ -154,7 +173,11 @@ bool usbh_init(void)
|
||||
}
|
||||
|
||||
// Class drivers init
|
||||
for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) usbh_class_drivers[drv_id].init();
|
||||
for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++)
|
||||
{
|
||||
TU_LOG2("%s init\r\n", usbh_class_drivers[drv_id].name);
|
||||
usbh_class_drivers[drv_id].init();
|
||||
}
|
||||
|
||||
TU_ASSERT(hcd_init());
|
||||
hcd_int_enable(TUH_OPT_RHPORT);
|
||||
@ -216,6 +239,30 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
|
||||
{
|
||||
bool ret = hcd_edpt_open(rhport, dev_addr, ep_desc);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
usbh_device_t* dev = &_usbh_devices[dev_addr];
|
||||
|
||||
// new endpoints belongs to latest interface (last valid value)
|
||||
uint8_t drvid = 0xff;
|
||||
for(uint8_t i=0; i < sizeof(dev->itf2drv); i++)
|
||||
{
|
||||
if ( dev->itf2drv[i] == 0xff ) break;
|
||||
drvid = dev->itf2drv[i];
|
||||
}
|
||||
TU_ASSERT(drvid < USBH_CLASS_DRIVER_COUNT);
|
||||
|
||||
uint8_t const ep_addr = ep_desc->bEndpointAddress;
|
||||
dev->ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = drvid;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBH-HCD ISR/Callback API
|
||||
//--------------------------------------------------------------------+
|
||||
@ -237,6 +284,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev
|
||||
|
||||
if (usbh_class_drivers[drv_id].isr)
|
||||
{
|
||||
//TU_LOG2("%s isr\r\n", usbh_class_drivers[drv_id].name);
|
||||
usbh_class_drivers[drv_id].isr(dev_addr, ep_addr, event, xferred_bytes);
|
||||
}
|
||||
else
|
||||
@ -304,7 +352,11 @@ static void usbh_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t hub_
|
||||
if (tuh_umount_cb) tuh_umount_cb(dev_addr);
|
||||
|
||||
// Close class driver
|
||||
for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++) usbh_class_drivers[drv_id].close(dev_addr);
|
||||
for (uint8_t drv_id = 0; drv_id < USBH_CLASS_DRIVER_COUNT; drv_id++)
|
||||
{
|
||||
TU_LOG2("%s close\r\n", usbh_class_drivers[drv_id].name);
|
||||
usbh_class_drivers[drv_id].close(dev_addr);
|
||||
}
|
||||
|
||||
memset(dev->itf2drv, 0xff, sizeof(dev->itf2drv)); // invalid mapping
|
||||
memset(dev->ep2drv , 0xff, sizeof(dev->ep2drv )); // invalid mapping
|
||||
@ -349,6 +401,8 @@ bool enum_task(hcd_event_t* event)
|
||||
{
|
||||
if( hcd_port_connect_status(dev0->rhport) )
|
||||
{
|
||||
TU_LOG2("Device connect \r\n");
|
||||
|
||||
// connection event
|
||||
osal_task_delay(POWER_STABLE_DELAY); // wait until device is stable. Increase this if the first 8 bytes is failed to get
|
||||
|
||||
@ -362,6 +416,8 @@ bool enum_task(hcd_event_t* event)
|
||||
}
|
||||
else
|
||||
{
|
||||
TU_LOG2("Device disconnect \r\n");
|
||||
|
||||
// disconnection event
|
||||
usbh_device_unplugged(dev0->rhport, 0, 0);
|
||||
return true; // restart task
|
||||
@ -415,6 +471,7 @@ bool enum_task(hcd_event_t* event)
|
||||
TU_ASSERT_ERR( usbh_pipe_control_open(0, 8) );
|
||||
|
||||
//------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------//
|
||||
TU_LOG2("Get 8 byte of Device Descriptor\r\n");
|
||||
request = (tusb_control_request_t ) {
|
||||
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
|
||||
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
|
||||
@ -425,12 +482,16 @@ bool enum_task(hcd_event_t* event)
|
||||
bool is_ok = usbh_control_xfer(0, &request, _usbh_ctrl_buf);
|
||||
|
||||
//------------- Reset device again before Set Address -------------//
|
||||
TU_LOG2("Port reset \r\n");
|
||||
|
||||
if (dev0->hub_addr == 0)
|
||||
{
|
||||
// connected directly to roothub
|
||||
TU_ASSERT(is_ok); // TODO some slow device is observed to fail the very fist controller xfer, can try more times
|
||||
hcd_port_reset( dev0->rhport ); // reset port after 8 byte descriptor
|
||||
osal_task_delay(RESET_DELAY);
|
||||
// hcd_port_reset_end(dev0->rhport);
|
||||
// osal_task_delay(RESET_DELAY);
|
||||
}
|
||||
#if CFG_TUH_HUB
|
||||
else
|
||||
@ -449,6 +510,7 @@ bool enum_task(hcd_event_t* event)
|
||||
#endif
|
||||
|
||||
//------------- Set new address -------------//
|
||||
TU_LOG2("Set Address \r\n");
|
||||
uint8_t const new_addr = get_new_address();
|
||||
TU_ASSERT(new_addr <= CFG_TUSB_HOST_DEVICE_MAX); // TODO notify application we reach max devices
|
||||
|
||||
@ -475,6 +537,7 @@ bool enum_task(hcd_event_t* event)
|
||||
TU_ASSERT_ERR ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) _usbh_ctrl_buf)->bMaxPacketSize0 ) );
|
||||
|
||||
//------------- Get full device descriptor -------------//
|
||||
TU_LOG2("Get Device Descriptor \r\n");
|
||||
request = (tusb_control_request_t ) {
|
||||
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
|
||||
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
|
||||
@ -493,6 +556,7 @@ bool enum_task(hcd_event_t* event)
|
||||
TU_ASSERT(configure_selected <= new_dev->configure_count); // TODO notify application when invalid configuration
|
||||
|
||||
//------------- Get 9 bytes of configuration descriptor -------------//
|
||||
TU_LOG2("Get 9 bytes of Configuration Descriptor\r\n");
|
||||
request = (tusb_control_request_t ) {
|
||||
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
|
||||
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
|
||||
@ -506,6 +570,7 @@ bool enum_task(hcd_event_t* event)
|
||||
TU_ASSERT( CFG_TUSB_HOST_ENUM_BUFFER_SIZE >= ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength );
|
||||
|
||||
//------------- Get full configuration descriptor -------------//
|
||||
TU_LOG2("Get full Configuration Descriptor\r\n");
|
||||
request.wLength = ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength; // full length
|
||||
TU_ASSERT( usbh_control_xfer( new_addr, &request, _usbh_ctrl_buf ) );
|
||||
|
||||
@ -513,6 +578,7 @@ bool enum_task(hcd_event_t* event)
|
||||
new_dev->interface_count = ((tusb_desc_configuration_t*) _usbh_ctrl_buf)->bNumInterfaces;
|
||||
|
||||
//------------- Set Configure -------------//
|
||||
TU_LOG2("Set Configuration Descriptor\r\n");
|
||||
request = (tusb_control_request_t ) {
|
||||
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT },
|
||||
.bRequest = TUSB_REQ_SET_CONFIGURATION,
|
||||
@ -522,6 +588,7 @@ bool enum_task(hcd_event_t* event)
|
||||
};
|
||||
TU_ASSERT(usbh_control_xfer( new_addr, &request, NULL ));
|
||||
|
||||
TU_LOG2("Device configured\r\n");
|
||||
new_dev->state = TUSB_DEVICE_STATE_CONFIGURED;
|
||||
|
||||
//------------- TODO Get String Descriptors -------------//
|
||||
@ -529,6 +596,8 @@ bool enum_task(hcd_event_t* event)
|
||||
//------------- parse configuration & install drivers -------------//
|
||||
uint8_t const* p_desc = _usbh_ctrl_buf + sizeof(tusb_desc_configuration_t);
|
||||
|
||||
// TU_LOG2_MEM(_usbh_ctrl_buf, ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength, 0);
|
||||
|
||||
// parse each interfaces
|
||||
while( p_desc < _usbh_ctrl_buf + ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength )
|
||||
{
|
||||
@ -538,7 +607,7 @@ bool enum_task(hcd_event_t* event)
|
||||
p_desc = tu_desc_next(p_desc); // skip the descriptor, increase by the descriptor's length
|
||||
}else
|
||||
{
|
||||
tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc;
|
||||
tusb_desc_interface_t const* desc_itf = (tusb_desc_interface_t const*) p_desc;
|
||||
|
||||
// Check if class is supported
|
||||
uint8_t drv_id;
|
||||
@ -568,11 +637,8 @@ bool enum_task(hcd_event_t* event)
|
||||
{
|
||||
uint16_t itf_len = 0;
|
||||
|
||||
if ( usbh_class_drivers[drv_id].open(new_dev->rhport, new_addr, desc_itf, &itf_len) )
|
||||
{
|
||||
mark_interface_endpoint(new_dev->ep2drv, p_desc, itf_len, drv_id);
|
||||
}
|
||||
|
||||
TU_LOG2("%s open\r\n", usbh_class_drivers[drv_id].name);
|
||||
TU_ASSERT( usbh_class_drivers[drv_id].open(new_dev->rhport, new_addr, desc_itf, &itf_len) );
|
||||
TU_ASSERT( itf_len >= sizeof(tusb_desc_interface_t) );
|
||||
p_desc += itf_len;
|
||||
}
|
||||
@ -588,7 +654,7 @@ bool enum_task(hcd_event_t* event)
|
||||
/* USB Host Driver task
|
||||
* This top level thread manages all host controller event and delegates events to class-specific drivers.
|
||||
* This should be called periodically within the mainloop or rtos thread.
|
||||
*
|
||||
*_usbh_devices[dev_addr].
|
||||
@code
|
||||
int main(void)
|
||||
{
|
||||
@ -652,25 +718,4 @@ static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_de
|
||||
return config_num;
|
||||
}
|
||||
|
||||
// Helper marking endpoint of interface belongs to class driver
|
||||
// TODO merge with usbd
|
||||
static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id)
|
||||
{
|
||||
uint16_t len = 0;
|
||||
|
||||
while( len < desc_len )
|
||||
{
|
||||
if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
|
||||
{
|
||||
uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress;
|
||||
|
||||
ep2drv[ tu_edpt_number(ep_addr) ][ tu_edpt_dir(ep_addr) ] = driver_id;
|
||||
}
|
||||
|
||||
len += tu_desc_len(p_desc);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -52,6 +52,10 @@ typedef enum tusb_interface_status_{
|
||||
} tusb_interface_status_t;
|
||||
|
||||
typedef struct {
|
||||
#if CFG_TUSB_DEBUG >= 2
|
||||
char const* name;
|
||||
#endif
|
||||
|
||||
uint8_t class_code;
|
||||
|
||||
void (* const init) (void);
|
||||
@ -69,7 +73,8 @@ typedef struct {
|
||||
void tuh_task(void);
|
||||
|
||||
// Interrupt handler, name alias to HCD
|
||||
#define tuh_isr hcd_isr
|
||||
extern void hcd_int_handler(uint8_t rhport);
|
||||
#define tuh_int_handler hcd_int_handler
|
||||
|
||||
tusb_device_state_t tuh_device_get_state (uint8_t dev_addr);
|
||||
static inline bool tuh_device_is_configured(uint8_t dev_addr)
|
||||
@ -97,6 +102,8 @@ TU_ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr);
|
||||
bool usbh_init(void);
|
||||
bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8_t* data);
|
||||
|
||||
bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -37,9 +37,9 @@
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
// Return immediately
|
||||
#define OSAL_TIMEOUT_NOTIMEOUT (0)
|
||||
#define OSAL_TIMEOUT_NOTIMEOUT (0)
|
||||
// Default timeout
|
||||
#define OSAL_TIMEOUT_NORMAL (10)
|
||||
#define OSAL_TIMEOUT_NORMAL (10)
|
||||
// Wait forever
|
||||
#define OSAL_TIMEOUT_WAIT_FOREVER (UINT32_MAX)
|
||||
|
||||
@ -62,7 +62,7 @@ typedef void (*osal_task_func_t)( void * );
|
||||
//--------------------------------------------------------------------+
|
||||
// OSAL Porting API
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void osal_task_delay(uint32_t msec);
|
||||
//static inline void osal_task_delay(uint32_t msec);
|
||||
|
||||
//------------- Semaphore -------------//
|
||||
static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
|
||||
|
@ -34,14 +34,14 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// TASK API
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void osal_task_delay(uint32_t msec)
|
||||
{
|
||||
(void) msec;
|
||||
// TODO only used by Host stack, will implement using SOF
|
||||
|
||||
// uint32_t start = tusb_hal_millis();
|
||||
// while ( ( tusb_hal_millis() - start ) < msec ) {}
|
||||
}
|
||||
//static inline void osal_task_delay(uint32_t msec)
|
||||
//{
|
||||
// (void) msec;
|
||||
// // TODO only used by Host stack, will implement using SOF
|
||||
//
|
||||
//// uint32_t start = tusb_hal_millis();
|
||||
//// while ( ( tusb_hal_millis() - start ) < msec ) {}
|
||||
//}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Binary Semaphore API
|
||||
|
@ -555,10 +555,10 @@ static void handle_ep0_nak(void)
|
||||
*------------------------------------------------------------------*/
|
||||
void dcd_init(uint8_t rhport)
|
||||
{
|
||||
(void)rhport;
|
||||
|
||||
USB->USB_MCTRL_REG = USB_USB_MCTRL_REG_USBEN_Msk;
|
||||
tusb_vbus_changed((CRG_TOP->ANA_STATUS_REG & CRG_TOP_ANA_STATUS_REG_VBUS_AVAILABLE_Msk) != 0);
|
||||
|
||||
dcd_connect(rhport);
|
||||
}
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
|
@ -54,6 +54,9 @@
|
||||
// FIFO size in bytes
|
||||
#define EP_FIFO_SIZE 1024
|
||||
|
||||
// Max number of IN EP FIFOs
|
||||
#define EP_FIFO_NUM 5
|
||||
|
||||
typedef struct {
|
||||
uint8_t *buffer;
|
||||
uint16_t total_len;
|
||||
@ -71,6 +74,16 @@ static uint32_t _setup_packet[2];
|
||||
#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
|
||||
static xfer_ctl_t xfer_status[EP_MAX][2];
|
||||
|
||||
// Keep count of how many FIFOs are in use
|
||||
static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
|
||||
|
||||
// Will either return an unused FIFO number, or 0 if all are used.
|
||||
static uint8_t get_free_fifo(void)
|
||||
{
|
||||
if (_allocated_fifos < EP_FIFO_NUM) return _allocated_fifos++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Setup the control endpoint 0.
|
||||
static void bus_reset(void)
|
||||
{
|
||||
@ -152,8 +165,6 @@ static void enum_done_processing(void)
|
||||
*------------------------------------------------------------------*/
|
||||
void dcd_init(uint8_t rhport)
|
||||
{
|
||||
(void)rhport;
|
||||
|
||||
ESP_LOGV(TAG, "DCD init - Start");
|
||||
|
||||
// A. Disconnect
|
||||
@ -191,6 +202,8 @@ void dcd_init(uint8_t rhport)
|
||||
USB_ENUMDONEMSK_M |
|
||||
USB_RESETDETMSK_M |
|
||||
USB_DISCONNINTMSK_M; // host most only
|
||||
|
||||
dcd_connect(rhport);
|
||||
}
|
||||
|
||||
void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
|
||||
@ -271,8 +284,12 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
|
||||
// - Offset: GRXFSIZ + 16 + Size*(epnum-1)
|
||||
// - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
|
||||
|
||||
uint8_t fifo_num = get_free_fifo();
|
||||
TU_ASSERT(fifo_num != 0);
|
||||
|
||||
in_ep[epnum].diepctl &= ~(USB_D_TXFNUM1_M | USB_D_EPTYPE1_M | USB_DI_SETD0PID1 | USB_D_MPS1_M);
|
||||
in_ep[epnum].diepctl |= USB_D_USBACTEP1_M |
|
||||
epnum << USB_D_TXFNUM1_S |
|
||||
fifo_num << USB_D_TXFNUM1_S |
|
||||
desc_edpt->bmAttributes.xfer << USB_D_EPTYPE1_S |
|
||||
(desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? (1 << USB_DI_SETD0PID1_S) : 0) |
|
||||
desc_edpt->wMaxPacketSize.size << 0;
|
||||
@ -282,8 +299,8 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
|
||||
// Both TXFD and TXSA are in unit of 32-bit words.
|
||||
// IN FIFO 0 was configured during enumeration, hence the "+ 16".
|
||||
uint16_t const allocated_size = (USB0.grxfsiz & 0x0000ffff) + 16;
|
||||
uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_MAX-1);
|
||||
uint32_t const fifo_offset = allocated_size + fifo_size*(epnum-1);
|
||||
uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_FIFO_NUM-1);
|
||||
uint32_t const fifo_offset = allocated_size + fifo_size*(fifo_num-1);
|
||||
|
||||
// DIEPTXF starts at FIFO #1.
|
||||
USB0.dieptxf[epnum - 1] = (fifo_size << USB_NPTXFDEP_S) | fifo_offset;
|
||||
@ -361,7 +378,8 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
}
|
||||
|
||||
// Flush the FIFO, and wait until we have confirmed it cleared.
|
||||
USB0.grstctl |= ((epnum - 1) << USB_TXFNUM_S);
|
||||
uint8_t const fifo_num = ((in_ep[epnum].diepctl >> USB_D_TXFNUM1_S) & USB_D_TXFNUM1_V);
|
||||
USB0.grstctl |= (fifo_num << USB_TXFNUM_S);
|
||||
USB0.grstctl |= USB_TXFFLSH_M;
|
||||
while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
|
||||
} else {
|
||||
@ -660,6 +678,8 @@ static void _dcd_int_handler(void* arg)
|
||||
// start of reset
|
||||
ESP_EARLY_LOGV(TAG, "dcd_int_handler - reset");
|
||||
USB0.gintsts = USB_USBRST_M;
|
||||
// FIFOs will be reassigned when the endpoints are reopen
|
||||
_allocated_fifos = 1;
|
||||
bus_reset();
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,8 @@
|
||||
#include "tusb_option.h"
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED && \
|
||||
(CFG_TUSB_MCU == OPT_MCU_SAMD21 || CFG_TUSB_MCU == OPT_MCU_SAMD51 || CFG_TUSB_MCU == OPT_MCU_SAME5X)
|
||||
(CFG_TUSB_MCU == OPT_MCU_SAMD11 || CFG_TUSB_MCU == OPT_MCU_SAMD21 || \
|
||||
CFG_TUSB_MCU == OPT_MCU_SAMD51 || CFG_TUSB_MCU == OPT_MCU_SAME5X)
|
||||
|
||||
#include "sam.h"
|
||||
#include "device/dcd.h"
|
||||
@ -113,7 +114,7 @@ void dcd_int_disable(uint8_t rhport)
|
||||
NVIC_DisableIRQ(USB_0_IRQn);
|
||||
}
|
||||
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_SAMD21
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_SAMD11 || CFG_TUSB_MCU == OPT_MCU_SAMD21
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
{
|
||||
|
@ -154,9 +154,8 @@ static void bus_reset(void)
|
||||
// Initialize controller to device mode
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
tu_memclr(_dcd_xfer, sizeof(_dcd_xfer));
|
||||
dcd_connect(rhport);
|
||||
}
|
||||
|
||||
// Enable device interrupt
|
||||
|
@ -271,6 +271,10 @@ void dcd_disconnect(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
NRF_USBD->USBPULLUP = 0;
|
||||
|
||||
// Disable Pull-up does not trigger Power USB Removed, in fact it have no
|
||||
// impact on the USB Power status at all -> need to submit unplugged event to the stack.
|
||||
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, false);
|
||||
}
|
||||
|
||||
// connect by enabling internal pull-up resistor on D+/D-
|
||||
@ -693,6 +697,8 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
||||
switch ( event )
|
||||
{
|
||||
case USB_EVT_DETECTED:
|
||||
TU_LOG2("Power USB Detect\r\n");
|
||||
|
||||
if ( !NRF_USBD->ENABLE )
|
||||
{
|
||||
/* Prepare for READY event receiving */
|
||||
@ -743,6 +749,12 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
||||
break;
|
||||
|
||||
case USB_EVT_READY:
|
||||
TU_LOG2("Power USB Ready\r\n");
|
||||
|
||||
// Skip if pull-up is enabled and HCLK is already running.
|
||||
// Application probably call this more than necessary.
|
||||
if ( NRF_USBD->USBPULLUP && hfclk_running() ) break;
|
||||
|
||||
/* Waiting for USBD peripheral enabled */
|
||||
while ( !(USBD_EVENTCAUSE_READY_Msk & NRF_USBD->EVENTCAUSE) ) { }
|
||||
|
||||
@ -810,6 +822,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
||||
break;
|
||||
|
||||
case USB_EVT_REMOVED:
|
||||
TU_LOG2("Power USB Removed\r\n");
|
||||
if ( NRF_USBD->ENABLE )
|
||||
{
|
||||
// Abort all transfers
|
||||
@ -829,7 +842,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
||||
|
||||
hfclk_disable();
|
||||
|
||||
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true);
|
||||
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? true : false);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -181,6 +181,8 @@ void dcd_init(uint8_t rhport)
|
||||
LPC_USB->UDCAH = (uint32_t) _dcd.udca;
|
||||
LPC_USB->DMAIntEn = (DMA_INT_END_OF_XFER_MASK /*| DMA_INT_NEW_DD_REQUEST_MASK*/ | DMA_INT_ERROR_MASK);
|
||||
|
||||
dcd_connect(rhport);
|
||||
|
||||
// Clear pending IRQ
|
||||
NVIC_ClearPendingIRQ(USB_IRQn);
|
||||
}
|
||||
|
@ -345,7 +345,8 @@ void dcd_init(uint8_t rhport)
|
||||
dcd_reg->USBSTS = dcd_reg->USBSTS;
|
||||
dcd_reg->USBINTR = INTR_USB | INTR_ERROR | INTR_PORT_CHANGE | INTR_RESET | INTR_SUSPEND /*| INTR_SOF*/;
|
||||
|
||||
dcd_reg->USBCMD &= ~0x00FF0000; // Interrupt Threshold Interval = 0
|
||||
dcd_reg->USBCMD &= ~0x00FF0000; // Interrupt Threshold Interval = 0
|
||||
dcd_reg->USBCMD |= USBCMD_RUN_STOP; // Connect
|
||||
}
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
|
@ -205,7 +205,6 @@ static inline void reg16_clear_bits(__IO uint16_t *reg, uint16_t mask) {
|
||||
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
(void)rhport;
|
||||
/* Clocks should already be enabled */
|
||||
/* Use __HAL_RCC_USB_CLK_ENABLE(); to enable the clocks before calling this function */
|
||||
|
||||
@ -244,7 +243,8 @@ void dcd_init (uint8_t rhport)
|
||||
USB->CNTR |= USB_CNTR_RESETM | (USE_SOF ? USB_CNTR_SOFM : 0) | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
|
||||
dcd_handle_bus_reset();
|
||||
|
||||
// Data-line pull-up is left disconnected.
|
||||
// Enable pull-up if supported
|
||||
if ( dcd_connect ) dcd_connect(rhport);
|
||||
}
|
||||
|
||||
// Define only on MCU with internal pull-up. BSP can define on MCU without internal PU.
|
||||
|
@ -231,6 +231,7 @@ static void bus_reset(uint8_t rhport)
|
||||
}
|
||||
|
||||
// Set turn-around timeout according to link speed
|
||||
extern uint32_t SystemCoreClock;
|
||||
static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
|
||||
{
|
||||
usb_otg->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
|
||||
@ -243,7 +244,6 @@ static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
|
||||
else
|
||||
{
|
||||
// Turnaround timeout depends on the MCU clock
|
||||
extern uint32_t SystemCoreClock;
|
||||
uint32_t turnaround;
|
||||
|
||||
if ( SystemCoreClock >= 32000000U )
|
||||
@ -365,6 +365,13 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
|
||||
((total_bytes << USB_OTG_DIEPTSIZ_XFRSIZ_Pos) & USB_OTG_DIEPTSIZ_XFRSIZ_Msk);
|
||||
|
||||
in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_EPENA | USB_OTG_DIEPCTL_CNAK;
|
||||
// For ISO endpoint set correct odd/even bit for next frame.
|
||||
if ((in_ep[epnum].DIEPCTL & USB_OTG_DIEPCTL_EPTYP) == USB_OTG_DIEPCTL_EPTYP_0)
|
||||
{
|
||||
// Take odd/even bit from frame counter.
|
||||
uint32_t const odd_frame_now = (dev->DSTS & (1u << USB_OTG_DSTS_FNSOF_Pos));
|
||||
in_ep[epnum].DIEPCTL |= (odd_frame_now ? USB_OTG_DIEPCTL_SD0PID_SEVNFRM_Msk : USB_OTG_DIEPCTL_SODDFRM_Msk);
|
||||
}
|
||||
// Enable fifo empty interrupt only if there are something to put in the fifo.
|
||||
if(total_bytes != 0) {
|
||||
dev->DIEPEMPMSK |= (1 << epnum);
|
||||
@ -453,6 +460,8 @@ void dcd_init (uint8_t rhport)
|
||||
|
||||
// Enable global interrupt
|
||||
usb_otg->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
|
||||
|
||||
dcd_connect(rhport);
|
||||
}
|
||||
|
||||
void dcd_int_enable (uint8_t rhport)
|
||||
@ -514,8 +523,14 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
||||
|
||||
TU_ASSERT(epnum < EP_MAX);
|
||||
|
||||
// TODO ISO endpoint can be up to 1024 bytes
|
||||
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 512 : 64));
|
||||
if (desc_edpt->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS)
|
||||
{
|
||||
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 1024 : 1023));
|
||||
}
|
||||
else
|
||||
{
|
||||
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 512 : 64));
|
||||
}
|
||||
|
||||
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
|
||||
xfer->max_size = desc_edpt->wMaxPacketSize.size;
|
||||
@ -622,9 +637,7 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: The logic for STALLing and disabling an endpoint is very similar
|
||||
// (send STALL versus NAK handshakes back). Refactor into resuable function.
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
static void dcd_edpt_disable (uint8_t rhport, uint8_t ep_addr, bool stall)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
@ -639,26 +652,26 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
if(dir == TUSB_DIR_IN) {
|
||||
// Only disable currently enabled non-control endpoint
|
||||
if ( (epnum == 0) || !(in_ep[epnum].DIEPCTL & USB_OTG_DIEPCTL_EPENA) ){
|
||||
in_ep[epnum].DIEPCTL |= (USB_OTG_DIEPCTL_SNAK | USB_OTG_DIEPCTL_STALL);
|
||||
in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_SNAK | (stall ? USB_OTG_DIEPCTL_STALL : 0);
|
||||
} else {
|
||||
// Stop transmitting packets and NAK IN xfers.
|
||||
in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_SNAK;
|
||||
while((in_ep[epnum].DIEPINT & USB_OTG_DIEPINT_INEPNE) == 0);
|
||||
|
||||
// Disable the endpoint.
|
||||
in_ep[epnum].DIEPCTL |= (USB_OTG_DIEPCTL_STALL | USB_OTG_DIEPCTL_EPDIS);
|
||||
in_ep[epnum].DIEPCTL |= USB_OTG_DIEPCTL_EPDIS | (stall ? USB_OTG_DIEPCTL_STALL : 0);
|
||||
while((in_ep[epnum].DIEPINT & USB_OTG_DIEPINT_EPDISD_Msk) == 0);
|
||||
in_ep[epnum].DIEPINT = USB_OTG_DIEPINT_EPDISD;
|
||||
}
|
||||
|
||||
// Flush the FIFO, and wait until we have confirmed it cleared.
|
||||
usb_otg->GRSTCTL |= ((epnum - 1) << USB_OTG_GRSTCTL_TXFNUM_Pos);
|
||||
usb_otg->GRSTCTL |= (epnum << USB_OTG_GRSTCTL_TXFNUM_Pos);
|
||||
usb_otg->GRSTCTL |= USB_OTG_GRSTCTL_TXFFLSH;
|
||||
while((usb_otg->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH_Msk) != 0);
|
||||
} else {
|
||||
// Only disable currently enabled non-control endpoint
|
||||
if ( (epnum == 0) || !(out_ep[epnum].DOEPCTL & USB_OTG_DOEPCTL_EPENA) ){
|
||||
out_ep[epnum].DOEPCTL |= USB_OTG_DOEPCTL_STALL;
|
||||
out_ep[epnum].DOEPCTL |= stall ? USB_OTG_DOEPCTL_STALL : 0;
|
||||
} else {
|
||||
// Asserting GONAK is required to STALL an OUT endpoint.
|
||||
// Simpler to use polling here, we don't use the "B"OUTNAKEFF interrupt
|
||||
@ -668,7 +681,7 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
while((usb_otg->GINTSTS & USB_OTG_GINTSTS_BOUTNAKEFF_Msk) == 0);
|
||||
|
||||
// Ditto here- disable the endpoint.
|
||||
out_ep[epnum].DOEPCTL |= (USB_OTG_DOEPCTL_STALL | USB_OTG_DOEPCTL_EPDIS);
|
||||
out_ep[epnum].DOEPCTL |= USB_OTG_DOEPCTL_EPDIS | (stall ? USB_OTG_DOEPCTL_STALL : 0);
|
||||
while((out_ep[epnum].DOEPINT & USB_OTG_DOEPINT_EPDISD_Msk) == 0);
|
||||
out_ep[epnum].DOEPINT = USB_OTG_DOEPINT_EPDISD;
|
||||
|
||||
@ -678,6 +691,32 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an endpoint.
|
||||
*/
|
||||
void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
USB_OTG_GlobalTypeDef * usb_otg = GLOBAL_BASE(rhport);
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_disable(rhport, ep_addr, false);
|
||||
if (dir == TUSB_DIR_IN)
|
||||
{
|
||||
uint16_t const fifo_size = (usb_otg->DIEPTXF[epnum - 1] & USB_OTG_DIEPTXF_INEPTXFD_Msk) >> USB_OTG_DIEPTXF_INEPTXFD_Pos;
|
||||
uint16_t const fifo_start = (usb_otg->DIEPTXF[epnum - 1] & USB_OTG_DIEPTXF_INEPTXSA_Msk) >> USB_OTG_DIEPTXF_INEPTXSA_Pos;
|
||||
// For now only endpoint that has FIFO at the end of FIFO memory can be closed without fuss.
|
||||
TU_ASSERT(fifo_start + fifo_size == _allocated_fifo_words,);
|
||||
_allocated_fifo_words -= fifo_size;
|
||||
}
|
||||
}
|
||||
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
dcd_edpt_disable(rhport, ep_addr, true);
|
||||
}
|
||||
|
||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
@ -70,8 +70,7 @@ typedef enum
|
||||
SIZXY = 7
|
||||
} ep_regs_index_t;
|
||||
|
||||
#define EP_REGS(epnum, dir) &USBOEPCNF_1 + 64*dir + 8*(epnum - 1)
|
||||
|
||||
#define EP_REGS(epnum, dir) ((ep_regs_t) ((uintptr_t)&USBOEPCNF_1 + 64*dir + 8*(epnum - 1)))
|
||||
|
||||
static void bus_reset(void)
|
||||
{
|
||||
@ -134,6 +133,9 @@ void dcd_init (uint8_t rhport)
|
||||
// Enable reset and wait for it before continuing.
|
||||
USBIE |= RSTRIE;
|
||||
|
||||
// Enable pullup.
|
||||
USBCNF |= PUR_EN;
|
||||
|
||||
USBKEYPID = 0;
|
||||
}
|
||||
|
||||
|
@ -55,10 +55,11 @@
|
||||
#define OPT_MCU_NRF5X 100 ///< Nordic nRF5x series
|
||||
|
||||
// SAM
|
||||
#define OPT_MCU_SAMD11 204 ///< MicroChip SAMD11
|
||||
#define OPT_MCU_SAMD21 200 ///< MicroChip SAMD21
|
||||
#define OPT_MCU_SAMD51 201 ///< MicroChip SAMD51
|
||||
#define OPT_MCU_SAMG 202 ///< MicroChip SAMDG series
|
||||
#define OPT_MCU_SAME5X 203 ///< MicroChip SAM E5x
|
||||
#define OPT_MCU_SAMG 202 ///< MicroChip SAMDG series
|
||||
|
||||
// STM32
|
||||
#define OPT_MCU_STM32F0 300 ///< ST STM32F0
|
||||
|
@ -199,7 +199,6 @@ void setUp(void)
|
||||
if ( !tusb_inited() )
|
||||
{
|
||||
dcd_init_Expect(rhport);
|
||||
dcd_connect_Expect(rhport);
|
||||
tusb_init();
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,6 @@ void setUp(void)
|
||||
{
|
||||
mscd_init_Expect();
|
||||
dcd_init_Expect(rhport);
|
||||
dcd_connect_Expect(rhport);
|
||||
tusb_init();
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,10 @@
|
||||
#define CFG_TUSB_MCU OPT_MCU_NRF5X
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUSB_RHPORT0_MODE
|
||||
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)
|
||||
#endif
|
||||
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
|
||||
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user