Merge remote-tracking branch 'origin/master' into xfer_isr
# Conflicts: # examples/device/audio_4_channel_mic_freertos/src/main.c # examples/device/audio_test_freertos/src/main.c # src/class/audio/audio_device.c
This commit is contained in:
@@ -19,13 +19,12 @@ jobs:
|
||||
echo "MATRIX_JSON=$MATRIX_JSON"
|
||||
|
||||
BUILDSYSTEM_TOOLCHAIN=(
|
||||
"cmake aarch64-gcc"
|
||||
"cmake arm-clang"
|
||||
"cmake arm-gcc"
|
||||
"cmake esp-idf"
|
||||
"make aarch64-gcc"
|
||||
"make arm-gcc"
|
||||
"make msp430-gcc"
|
||||
"make riscv-gcc"
|
||||
"make rx-gcc"
|
||||
"cmake msp430-gcc"
|
||||
"cmake riscv-gcc"
|
||||
)
|
||||
|
||||
# only build IAR if not forked PR, since IAR token is not shared
|
||||
@@ -67,7 +66,7 @@ jobs:
|
||||
FAMILY_LARGE=$(jq -n --argjson family "$FAMILY" --argjson resource "$RESOURCE_LARGE" '$family | map(select(IN($resource[])))')
|
||||
FAMILY=$(jq -n --argjson family "$FAMILY" --argjson resource "$RESOURCE_LARGE" '$family | map(select(IN($resource[]) | not))')
|
||||
|
||||
if [[ $toolchain == esp-idf ]]; then
|
||||
if [[ $toolchain == esp-idf || $toolchain == arm-iar ]]; then
|
||||
gen_build_entry "$build_system" "$toolchain" "$FAMILY" "large"
|
||||
else
|
||||
gen_build_entry "$build_system" "$toolchain" "$FAMILY" "medium+"
|
||||
|
60
.github/workflows/build.yml
vendored
60
.github/workflows/build.yml
vendored
@@ -36,11 +36,6 @@ env:
|
||||
HIL_JSON: test/hil/tinyusb.json
|
||||
|
||||
jobs:
|
||||
# ---------------------------------------
|
||||
#
|
||||
# Build
|
||||
#
|
||||
# ---------------------------------------
|
||||
set-matrix:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
@@ -63,28 +58,31 @@ jobs:
|
||||
echo "hil_matrix=$HIL_MATRIX_JSON" >> $GITHUB_OUTPUT
|
||||
|
||||
# ---------------------------------------
|
||||
# Build CMake
|
||||
# Build CMake: only build on push with one-per-family.
|
||||
# Full built is done by CircleCI in PR
|
||||
# ---------------------------------------
|
||||
cmake:
|
||||
if: github.event_name == 'push'
|
||||
needs: set-matrix
|
||||
uses: ./.github/workflows/build_util.yml
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
toolchain:
|
||||
# - 'arm-clang' is built by circle-ci in PR
|
||||
- 'aarch64-gcc'
|
||||
#- 'arm-clang'
|
||||
- 'arm-gcc'
|
||||
- 'esp-idf'
|
||||
- 'msp430-gcc'
|
||||
- 'riscv-gcc'
|
||||
with:
|
||||
build-system: 'cmake'
|
||||
toolchain: ${{ matrix.toolchain }}
|
||||
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain]) }}
|
||||
one-per-family: ${{ github.event_name == 'push' }}
|
||||
one-per-family: true
|
||||
|
||||
# ---------------------------------------
|
||||
# Build Make (built by circle-ci in PR, only build on push here)
|
||||
# Build Make: only build on push with one-per-family
|
||||
# ---------------------------------------
|
||||
make:
|
||||
if: github.event_name == 'push'
|
||||
@@ -94,36 +92,18 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
toolchain:
|
||||
# 'arm-clang'
|
||||
- 'arm-gcc'
|
||||
- 'aarch64-gcc'
|
||||
#- 'arm-clang'
|
||||
- 'arm-gcc'
|
||||
- 'msp430-gcc'
|
||||
- 'riscv-gcc'
|
||||
- 'rx-gcc'
|
||||
- 'esp-idf'
|
||||
with:
|
||||
build-system: 'make'
|
||||
toolchain: ${{ matrix.toolchain }}
|
||||
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain]) }}
|
||||
one-per-family: true
|
||||
|
||||
# ---------------------------------------
|
||||
# Build Make on Windows/MacOS
|
||||
# ---------------------------------------
|
||||
make-os:
|
||||
if: github.event_name == 'pull_request'
|
||||
uses: ./.github/workflows/build_util.yml
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, macos-latest]
|
||||
with:
|
||||
os: ${{ matrix.os }}
|
||||
build-system: 'make'
|
||||
toolchain: 'arm-gcc'
|
||||
build-args: '["stm32h7"]'
|
||||
one-per-family: true
|
||||
|
||||
# ---------------------------------------
|
||||
# Build IAR
|
||||
# Since IAR Token secret is not passed to forked PR, only build non-forked PR with make.
|
||||
@@ -146,6 +126,23 @@ jobs:
|
||||
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)['arm-iar']) }}
|
||||
one-per-family: true
|
||||
|
||||
# ---------------------------------------
|
||||
# Build Make on Windows/MacOS
|
||||
# ---------------------------------------
|
||||
make-os:
|
||||
if: github.event_name == 'pull_request'
|
||||
uses: ./.github/workflows/build_util.yml
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, macos-latest]
|
||||
with:
|
||||
os: ${{ matrix.os }}
|
||||
build-system: 'make'
|
||||
toolchain: 'arm-gcc'
|
||||
build-args: '["stm32h7"]'
|
||||
one-per-family: true
|
||||
|
||||
# ---------------------------------------
|
||||
# Zephyr
|
||||
# ---------------------------------------
|
||||
@@ -168,14 +165,9 @@ jobs:
|
||||
west build -b pca10056 -d examples/device/msc_dual_lun/build examples/device/msc_dual_lun -- -DRTOS=zephyr
|
||||
|
||||
# ---------------------------------------
|
||||
#
|
||||
# Hardware in the loop (HIL)
|
||||
# Run on PR only (hil-tinyusb), hil-hfp only run on non-forked PR
|
||||
# ---------------------------------------
|
||||
|
||||
# ---------------------------------------
|
||||
# Build arm-gcc
|
||||
# ---------------------------------------
|
||||
hil-build:
|
||||
if: |
|
||||
github.repository_owner == 'hathach' &&
|
||||
|
@@ -31,6 +31,13 @@ Notable contributors
|
||||
- Most features development
|
||||
|
||||
|
||||
`Heiko Kuester <https://github.com/IngHK>`__
|
||||
--------------------------------------------
|
||||
|
||||
- Add CH34x and PL2303 support (CDC host)
|
||||
- Improve FTDI and CP210x support (CDC host)
|
||||
|
||||
|
||||
`Hristo Gochkov <https://github.com/me-no-dev>`__
|
||||
-------------------------------------------------
|
||||
|
||||
|
@@ -74,7 +74,7 @@ Host Stack
|
||||
- Human Interface Device (HID): Keyboard, Mouse, Generic
|
||||
- Mass Storage Class (MSC)
|
||||
- Communication Device Class: CDC-ACM
|
||||
- Vendor serial over USB: FTDI, CP210x, CH34x
|
||||
- Vendor serial over USB: FTDI, CP210x, CH34x, PL2303
|
||||
- Hub with multiple-level support
|
||||
|
||||
Similar to the Device Stack, if you have a special requirement, ``usbh_app_driver_get_cb()`` can be used to write your own class driver without modifying the stack.
|
||||
|
@@ -5,12 +5,12 @@ Getting Started
|
||||
Add TinyUSB to your project
|
||||
---------------------------
|
||||
|
||||
It is relatively simple to incorporate tinyusb to your project
|
||||
To incorporate tinyusb to your project
|
||||
|
||||
* Copy or ``git submodule`` this repo into your project in a subfolder. Let's say it is ``your_project/tinyusb``
|
||||
* Add all the ``.c`` in the ``tinyusb/src`` folder to your project
|
||||
* Add ``your_project/tinyusb/src`` to your include path. Also make sure your current include path also contains the configuration file ``tusb_config.h``.
|
||||
* Make sure all required macros are all defined properly in ``tusb_config.h`` (configure file in demo application is sufficient, but you need to add a few more such as ``CFG_TUSB_MCU``, ``CFG_TUSB_OS`` since they are passed by IDE/compiler to maintain a unique configure for all boards).
|
||||
* Make sure all required macros are all defined properly in ``tusb_config.h`` (configure file in demo application is sufficient, but you need to add a few more such as ``CFG_TUSB_MCU``, ``CFG_TUSB_OS`` since they are passed by make/cmake to maintain a unique configure for all boards).
|
||||
* If you use the device stack, make sure you have created/modified usb descriptors for your own need. Ultimately you need to implement all **tud descriptor** callbacks for the stack to work.
|
||||
* Add ``tusb_init(rhport, role)`` call to your reset initialization code.
|
||||
* Call ``tusb_int_handler(rhport, in_isr)`` in your USB IRQ Handler
|
||||
@@ -75,24 +75,36 @@ The hardware code is located in ``hw/bsp`` folder, and is organized by family/bo
|
||||
.. code-block:: bash
|
||||
|
||||
$ cd examples/device/cdc_msc
|
||||
$ make BOARD=raspberry_pi_pico get-deps
|
||||
$ make BOARD=feather_nrf52840_express get-deps
|
||||
|
||||
You only need to do this once per family. Check out `complete list of dependencies and their designated path here <dependencies.rst>`_
|
||||
|
||||
Build
|
||||
^^^^^
|
||||
Build Examples
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
To build example, first change directory to an example folder.
|
||||
Examples support make and cmake build system for most MCUs, however some MCU families such as espressif or rp2040 only support cmake. First change directory to an example folder.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ cd examples/device/cdc_msc
|
||||
|
||||
Then compile with ``make BOARD={board_name} all`` , for example
|
||||
Then compile with make or cmake
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ make BOARD=raspberry_pi_pico all
|
||||
$ # make
|
||||
$ make BOARD=feather_nrf52840_express all
|
||||
|
||||
$ # cmake
|
||||
$ mkdir build && cd build
|
||||
$ cmake -DBOARD=raspberry_pi_pico ..
|
||||
$ make
|
||||
|
||||
To list all available targets with cmake
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ cmake --build . --target help
|
||||
|
||||
Note: some examples especially those that uses Vendor class (e.g webUSB) may requires udev permission on Linux (and/or macOS) to access usb device. It depends on your OS distro, typically copy ``99-tinyusb.rules`` and reload your udev is good to go
|
||||
|
||||
@@ -104,20 +116,24 @@ Note: some examples especially those that uses Vendor class (e.g webUSB) may req
|
||||
RootHub 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:
|
||||
If a board has several ports, one port is chosen by default in the individual board.mk file. Use option ``RHPORT_DEVICE=x`` or ``RHPORT_HOST=x`` To choose another port. For example to select the HS port of a STM32F746Disco board, use:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ make BOARD=stm32f746disco PORT=1 all
|
||||
$ make BOARD=stm32f746disco RHPORT_DEVICE=1 all
|
||||
|
||||
$ cmake -DBOARD=stm32f746disco -DRHPORT_DEVICE=1 ..
|
||||
|
||||
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
|
||||
A MCU can support multiple operational speed. By default, the example build system will use the fastest supported on the board. Use option ``RHPORT_DEVICE_SPEED=OPT_MODE_FULL/HIGH_SPEED/`` or ``RHPORT_HOST_SPEED=OPT_MODE_FULL/HIGH_SPEED/`` e.g To force F723 operate at full instead of default high speed
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ make BOARD=stm32f746disco SPEED=full all
|
||||
$ make BOARD=stm32f746disco RHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEED all
|
||||
|
||||
$ cmake -DBOARD=stm32f746disco -DRHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEED ..
|
||||
|
||||
Size Analysis
|
||||
~~~~~~~~~~~~~
|
||||
@@ -137,6 +153,8 @@ To compile for debugging add ``DEBUG=1``\ , for example
|
||||
|
||||
$ make BOARD=feather_nrf52840_express DEBUG=1 all
|
||||
|
||||
$ cmake -DBOARD=feather_nrf52840_express -DCMAKE_BUILD_TYPE=Debug ..
|
||||
|
||||
Log
|
||||
~~~
|
||||
|
||||
@@ -146,6 +164,8 @@ Should you have an issue running example and/or submitting an bug report. You co
|
||||
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 all
|
||||
|
||||
$ cmake -DBOARD=feather_nrf52840_express -DLOG=2 ..
|
||||
|
||||
Logger
|
||||
~~~~~~
|
||||
|
||||
@@ -169,6 +189,9 @@ By default log message is printed via on-board UART which is slow and take lots
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=rtt all
|
||||
$ make BOARD=feather_nrf52840_express LOG=2 LOGGER=swo all
|
||||
|
||||
$ cmake -DBOARD=feather_nrf52840_express -DLOG=2 -DLOGGER=rtt ..
|
||||
$ cmake -DBOARD=feather_nrf52840_express -DLOG=2 -DLOGGER=swo ..
|
||||
|
||||
Flash
|
||||
^^^^^
|
||||
|
||||
@@ -179,11 +202,15 @@ Flash
|
||||
$ 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.
|
||||
Since jlink/openocd can be used with most of the boards, there is also ``flash-jlink/openocd`` (make) and ``EXAMPLE-jlink/openocd`` target for your convenience. Note for stm32 board with stlink, you can use ``flash-stlink`` target as well.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ make BOARD=feather_nrf52840_express flash-jlink
|
||||
$ make BOARD=feather_nrf52840_express flash-openocd
|
||||
|
||||
$ cmake --build . --target cdc_msc-jlink
|
||||
$ cmake --build . --target cdc_msc-openocd
|
||||
|
||||
Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can be generated with ``uf2`` target
|
||||
|
||||
@@ -191,17 +218,18 @@ Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can
|
||||
|
||||
$ make BOARD=feather_nrf52840_express all uf2
|
||||
|
||||
$ cmake --build . --target cdc_msc-uf2
|
||||
|
||||
IAR Support
|
||||
-----------
|
||||
^^^^^^^^^^^
|
||||
|
||||
Use project connection
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
IAR Project Connection files are provided to import TinyUSB stack into your project.
|
||||
|
||||
* A buildable project of your MCU need to be created in advance.
|
||||
|
||||
|
||||
* Take example of STM32F0:
|
||||
|
||||
- You need ``stm32l0xx.h``, ``startup_stm32f0xx.s``, ``system_stm32f0xx.c``.
|
||||
@@ -212,15 +240,13 @@ IAR Project Connection files are provided to import TinyUSB stack into your proj
|
||||
Click ``New Group ...``, name it to ``TUSB``, Click ``Add Variable ...``, name it to ``TUSB_DIR``, change it's value to the path of your TinyUSB stack,
|
||||
for example ``C:\\tinyusb``
|
||||
|
||||
Import stack only
|
||||
~~~~~~~~~~~~~~~~~
|
||||
**Import stack only**
|
||||
|
||||
1. Open ``Project -> Add project Connection ...``, click ``OK``, choose ``tinyusb\\tools\\iar_template.ipcf``.
|
||||
Open ``Project -> Add project Connection ...``, click ``OK``, choose ``tinyusb\\tools\\iar_template.ipcf``.
|
||||
|
||||
Run examples
|
||||
~~~~~~~~~~~~
|
||||
**Run examples**
|
||||
|
||||
1. (Python3 is needed) Run ``iar_gen.py`` to generate .ipcf files of examples:
|
||||
1. Run ``iar_gen.py`` to generate .ipcf files of examples:
|
||||
|
||||
.. code-block::
|
||||
|
||||
@@ -230,8 +256,8 @@ Run examples
|
||||
2. Open ``Project -> Add project Connection ...``, click ``OK``, choose ``tinyusb\\examples\\(.ipcf of example)``.
|
||||
For example ``C:\\tinyusb\\examples\\device\\cdc_msc\\iar_cdc_msc.ipcf``
|
||||
|
||||
Native CMake support (9.50.1+)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Native CMake support
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
With 9.50.1 release, IAR added experimental native CMake support (strangely not mentioned in public release note). Now it's possible to import CMakeLists.txt then build and debug as a normal project.
|
||||
|
||||
|
@@ -123,27 +123,24 @@ endif
|
||||
ifeq (${MAX3421_HOST},1)
|
||||
SRC_C += src/portable/analog/max3421/hcd_max3421.c
|
||||
CFLAGS += -DCFG_TUH_MAX3421=1
|
||||
CMAKE_DEFSYM += -DMAX3421_HOST=1
|
||||
endif
|
||||
|
||||
# Log level is mapped to TUSB DEBUG option
|
||||
ifneq ($(LOG),)
|
||||
CMAKE_DEFSYM += -DLOG=$(LOG)
|
||||
CFLAGS += -DCFG_TUSB_DEBUG=$(LOG)
|
||||
endif
|
||||
|
||||
# Logger: default is uart, can be set to rtt or swo
|
||||
ifneq ($(LOGGER),)
|
||||
CMAKE_DEFSYM += -DLOGGER=$(LOGGER)
|
||||
endif
|
||||
|
||||
ifeq ($(LOGGER),rtt)
|
||||
CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
|
||||
RTT_SRC = lib/SEGGER_RTT
|
||||
INC += $(TOP)/$(RTT_SRC)/RTT
|
||||
SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
|
||||
else ifeq ($(LOGGER),swo)
|
||||
CFLAGS += -DLOGGER_RTT
|
||||
#CFLAGS += -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
|
||||
INC += $(TOP)/$(lib/SEGGER_RTT)/RTT
|
||||
SRC_C += $(lib/SEGGER_RTT)/RTT/SEGGER_RTT.c
|
||||
endif
|
||||
ifeq ($(LOGGER),swo)
|
||||
CFLAGS += -DLOGGER_SWO
|
||||
else
|
||||
CFLAGS += -DLOGGER_UART
|
||||
endif
|
||||
|
||||
# CPU specific flags
|
||||
|
@@ -39,7 +39,7 @@
|
||||
#include "bsp/board_api.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@@ -157,15 +157,15 @@ int main(void) {
|
||||
xTaskCreate(audio_isr_task, "audio", AUDIO_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
#endif
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// only start scheduler for non-espressif mcu
|
||||
#ifndef ESP_PLATFORM
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
|
@@ -38,7 +38,7 @@
|
||||
#include "bsp/board_api.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@@ -140,15 +140,15 @@ int main(void) {
|
||||
xTaskCreate(audio_isr_task, "audio", AUDIO_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
#endif
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// only start scheduler for non-espressif mcu
|
||||
#ifndef ESP_PLATFORM
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
|
@@ -49,25 +49,34 @@ int main(void) {
|
||||
while (1) {
|
||||
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
|
||||
|
||||
int ch = board_getchar();
|
||||
if (ch > 0) {
|
||||
board_putchar(ch);
|
||||
#ifndef LOGGER_UART
|
||||
board_uart_write(&ch, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Blink and print every interval ms
|
||||
if (!(board_millis() - start_ms < interval_ms)) {
|
||||
board_uart_write(HELLO_STR, strlen(HELLO_STR));
|
||||
|
||||
start_ms = board_millis();
|
||||
|
||||
if (ch < 0) {
|
||||
// skip if echoing
|
||||
printf(HELLO_STR);
|
||||
|
||||
#ifndef LOGGER_UART
|
||||
board_uart_write(HELLO_STR, strlen(HELLO_STR));
|
||||
#endif
|
||||
}
|
||||
|
||||
board_led_write(led_state);
|
||||
led_state = 1 - led_state; // toggle
|
||||
}
|
||||
|
||||
// echo
|
||||
uint8_t ch;
|
||||
if (board_uart_read(&ch, 1) > 0) {
|
||||
board_uart_write(&ch, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
|
@@ -98,27 +98,33 @@ void tud_umount_cb(void) {
|
||||
blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USB CDC
|
||||
//--------------------------------------------------------------------+
|
||||
static void cdc_task(void) {
|
||||
uint8_t itf;
|
||||
|
||||
for (itf = 0; itf < CFG_TUD_CDC; itf++) {
|
||||
for (uint8_t itf = 0; itf < CFG_TUD_CDC; itf++) {
|
||||
// connected() check for DTR bit
|
||||
// Most but not all terminal client set this when making connection
|
||||
// if ( tud_cdc_n_connected(itf) )
|
||||
{
|
||||
if (tud_cdc_n_available(itf)) {
|
||||
uint8_t buf[64];
|
||||
|
||||
uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf));
|
||||
|
||||
// echo back to both serial ports
|
||||
echo_serial_port(0, buf, count);
|
||||
echo_serial_port(1, buf, count);
|
||||
}
|
||||
|
||||
// Press on-board button to send Uart status notification
|
||||
static uint32_t btn_prev = 0;
|
||||
static cdc_notify_uart_state_t uart_state = { .value = 0 };
|
||||
const uint32_t btn = board_button_read();
|
||||
if (!btn_prev && btn) {
|
||||
uart_state.dsr ^= 1;
|
||||
tud_cdc_notify_uart_state(&uart_state);
|
||||
}
|
||||
btn_prev = btn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -97,6 +97,8 @@
|
||||
#define CFG_TUD_MIDI 0
|
||||
#define CFG_TUD_VENDOR 0
|
||||
|
||||
#define CFG_TUD_CDC_NOTIFY 1 // Enable use of notification endpoint
|
||||
|
||||
// CDC FIFO size of TX and RX
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
@@ -42,8 +42,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_desc_device_t const desc_device =
|
||||
{
|
||||
tusb_desc_device_t const desc_device = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = USB_BCD,
|
||||
@@ -68,16 +67,14 @@ tusb_desc_device_t const desc_device =
|
||||
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
uint8_t const *tud_descriptor_device_cb(void) {
|
||||
return (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
ITF_NUM_CDC_0 = 0,
|
||||
ITF_NUM_CDC_0_DATA,
|
||||
ITF_NUM_CDC_1,
|
||||
@@ -130,36 +127,32 @@ enum
|
||||
#define EPNUM_CDC_1_IN 0x84
|
||||
#endif
|
||||
|
||||
uint8_t const desc_fs_configuration[] =
|
||||
{
|
||||
uint8_t const desc_fs_configuration[] = {
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
||||
|
||||
// 1st CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_0, 4, EPNUM_CDC_0_NOTIF, 8, EPNUM_CDC_0_OUT, EPNUM_CDC_0_IN, 64),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_0, 4, EPNUM_CDC_0_NOTIF, 16, EPNUM_CDC_0_OUT, EPNUM_CDC_0_IN, 64),
|
||||
|
||||
// 2nd CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_1, 4, EPNUM_CDC_1_NOTIF, 8, EPNUM_CDC_1_OUT, EPNUM_CDC_1_IN, 64),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_1, 4, EPNUM_CDC_1_NOTIF, 16, EPNUM_CDC_1_OUT, EPNUM_CDC_1_IN, 64),
|
||||
};
|
||||
|
||||
#if TUD_OPT_HIGH_SPEED
|
||||
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
|
||||
|
||||
uint8_t const desc_hs_configuration[] =
|
||||
{
|
||||
uint8_t const desc_hs_configuration[] = {
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
||||
|
||||
// 1st CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_0, 4, EPNUM_CDC_0_NOTIF, 8, EPNUM_CDC_0_OUT, EPNUM_CDC_0_IN, 512),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_0, 4, EPNUM_CDC_0_NOTIF, 16, EPNUM_CDC_0_OUT, EPNUM_CDC_0_IN, 512),
|
||||
|
||||
// 2nd CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_1, 4, EPNUM_CDC_1_NOTIF, 8, EPNUM_CDC_1_OUT, EPNUM_CDC_1_IN, 512),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_1, 4, EPNUM_CDC_1_NOTIF, 16, EPNUM_CDC_1_OUT, EPNUM_CDC_1_IN, 512),
|
||||
};
|
||||
|
||||
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
|
||||
tusb_desc_device_qualifier_t const desc_device_qualifier =
|
||||
{
|
||||
tusb_desc_device_qualifier_t const desc_device_qualifier = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = USB_BCD,
|
||||
@@ -177,16 +170,14 @@ tusb_desc_device_qualifier_t const desc_device_qualifier =
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
|
||||
// device_qualifier descriptor describes information about a high-speed capable device that would
|
||||
// change if the device were operating at the other speed. If not highspeed capable stall this request.
|
||||
uint8_t const* tud_descriptor_device_qualifier_cb(void)
|
||||
{
|
||||
uint8_t const *tud_descriptor_device_qualifier_cb(void) {
|
||||
return (uint8_t const *) &desc_device_qualifier;
|
||||
}
|
||||
|
||||
// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
|
||||
uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index)
|
||||
{
|
||||
uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index) {
|
||||
(void) index;// for multiple configurations
|
||||
|
||||
// if link speed is high return fullspeed config, and vice versa
|
||||
@@ -198,8 +189,7 @@ uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index)
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
{
|
||||
uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
|
||||
(void) index; // for multiple configurations
|
||||
|
||||
#if TUD_OPT_HIGH_SPEED
|
||||
@@ -223,8 +213,7 @@ enum {
|
||||
};
|
||||
|
||||
// array of pointer to string descriptors
|
||||
char const *string_desc_arr[] =
|
||||
{
|
||||
char const *string_desc_arr[] = {
|
||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB Device", // 2: Product
|
||||
@@ -254,14 +243,14 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
|
||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
|
||||
|
||||
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
|
||||
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) { return NULL; }
|
||||
|
||||
const char *str = string_desc_arr[index];
|
||||
|
||||
// Cap at max char
|
||||
chr_count = strlen(str);
|
||||
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
|
||||
if ( chr_count > max_count ) chr_count = max_count;
|
||||
if ( chr_count > max_count ) { chr_count = max_count; }
|
||||
|
||||
// Convert ASCII string into UTF-16
|
||||
for ( size_t i = 0; i < chr_count; i++ ) {
|
||||
@@ -272,6 +261,5 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
|
||||
// first byte is length (including header), second byte is string type
|
||||
_desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
|
||||
|
||||
return _desc_str;
|
||||
}
|
||||
|
@@ -119,6 +119,16 @@ void cdc_task(void) {
|
||||
tud_cdc_write(buf, count);
|
||||
tud_cdc_write_flush();
|
||||
}
|
||||
|
||||
// Press on-board button to send Uart status notification
|
||||
static uint32_t btn_prev = 0;
|
||||
static cdc_notify_uart_state_t uart_state = { .value = 0 };
|
||||
const uint32_t btn = board_button_read();
|
||||
if (!btn_prev && btn) {
|
||||
uart_state.dsr ^= 1;
|
||||
tud_cdc_notify_uart_state(&uart_state);
|
||||
}
|
||||
btn_prev = btn;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -184,7 +184,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buff
|
||||
}
|
||||
|
||||
// Check for overflow of offset + bufsize
|
||||
if (offset + bufsize > DISK_BLOCK_SIZE) {
|
||||
if (lba * DISK_BLOCK_SIZE + offset + bufsize > DISK_BLOCK_NUM * DISK_BLOCK_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -97,6 +97,8 @@
|
||||
#define CFG_TUD_MIDI 0
|
||||
#define CFG_TUD_VENDOR 0
|
||||
|
||||
#define CFG_TUD_CDC_NOTIFY 1 // Enable use of notification endpoint
|
||||
|
||||
// CDC FIFO size of TX and RX
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
@@ -52,7 +52,6 @@ tusb_desc_device_t const desc_device = {
|
||||
.bDeviceClass = TUSB_CLASS_MISC,
|
||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
||||
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
|
||||
.idVendor = USB_VID,
|
||||
@@ -131,7 +130,7 @@ uint8_t const desc_fs_configuration[] = {
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
||||
|
||||
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 16, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
|
||||
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
|
||||
@@ -146,7 +145,7 @@ uint8_t const desc_hs_configuration[] = {
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
||||
|
||||
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 16, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
|
||||
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 512),
|
||||
@@ -197,7 +196,6 @@ uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index) {
|
||||
|
||||
#endif // highspeed
|
||||
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
@@ -256,14 +254,14 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
|
||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
|
||||
|
||||
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
|
||||
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) { return NULL; }
|
||||
|
||||
const char *str = string_desc_arr[index];
|
||||
|
||||
// Cap at max char
|
||||
chr_count = strlen(str);
|
||||
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
|
||||
if ( chr_count > max_count ) chr_count = max_count;
|
||||
if ( chr_count > max_count ) { chr_count = max_count; }
|
||||
|
||||
// Convert ASCII string into UTF-16
|
||||
for ( size_t i = 0; i < chr_count; i++ ) {
|
||||
@@ -274,6 +272,5 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
|
||||
// first byte is length (including header), second byte is string type
|
||||
_desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
|
||||
|
||||
return _desc_str;
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@
|
||||
#include "bsp/board_api.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define USBD_STACK_SIZE 4096
|
||||
#else
|
||||
// Increase stack size when debug log is enabled
|
||||
@@ -72,7 +72,7 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||
static void usb_device_task(void *param);
|
||||
void led_blinking_task(void* param);
|
||||
void cdc_task(void *params);
|
||||
|
||||
extern void msc_disk_init(void);
|
||||
//--------------------------------------------------------------------+
|
||||
// Main
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -91,15 +91,15 @@ int main(void) {
|
||||
xTaskCreate(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES - 2, NULL);
|
||||
#endif
|
||||
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#ifndef ESP_PLATFORM
|
||||
// only start scheduler for non-espressif mcu
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
@@ -123,6 +123,7 @@ static void usb_device_task(void *param) {
|
||||
board_init_after_tusb();
|
||||
}
|
||||
|
||||
msc_disk_init();
|
||||
// RTOS forever loop
|
||||
while (1) {
|
||||
// put this thread to waiting state until there is new events
|
||||
@@ -188,6 +189,16 @@ void cdc_task(void *params) {
|
||||
}
|
||||
|
||||
tud_cdc_write_flush();
|
||||
|
||||
// Press on-board button to send Uart status notification
|
||||
static uint32_t btn_prev = 0;
|
||||
static cdc_notify_uart_state_t uart_state = { .value = 0 };
|
||||
const uint32_t btn = board_button_read();
|
||||
if (!btn_prev && btn) {
|
||||
uart_state.dsr ^= 1;
|
||||
tud_cdc_notify_uart_state(&uart_state);
|
||||
}
|
||||
btn_prev = btn;
|
||||
}
|
||||
|
||||
// For ESP32-Sx this delay is essential to allow idle how to run and reset watchdog
|
||||
|
@@ -28,6 +28,37 @@
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
|
||||
// Use async IO in example or not
|
||||
#define CFG_EXAMPLE_MSC_ASYNC_IO 1
|
||||
|
||||
// Simulate read/write operation delay
|
||||
#define CFG_EXAMPLE_MSC_IO_DELAY_MS 0
|
||||
|
||||
#if CFG_EXAMPLE_MSC_ASYNC_IO
|
||||
#define IO_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
|
||||
typedef struct {
|
||||
uint8_t lun;
|
||||
bool is_read;
|
||||
uint32_t lba;
|
||||
uint32_t offset;
|
||||
void* buffer;
|
||||
uint32_t bufsize;
|
||||
} io_ops_t;
|
||||
|
||||
QueueHandle_t io_queue;
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
uint8_t io_queue_buf[sizeof(io_ops_t)];
|
||||
StaticQueue_t io_queue_static;
|
||||
StackType_t io_stack[IO_STACK_SIZE];
|
||||
StaticTask_t io_taskdef;
|
||||
#endif
|
||||
|
||||
static void io_task(void *params);
|
||||
#endif
|
||||
|
||||
void msc_disk_init(void);
|
||||
|
||||
// whether host does safe-eject
|
||||
static bool ejected = false;
|
||||
|
||||
@@ -40,8 +71,7 @@ static bool ejected = false;
|
||||
If you find any bugs or get any questions, feel free to file an\r\n\
|
||||
issue at github.com/hathach/tinyusb"
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
DISK_BLOCK_NUM = 16, // 8KB is the smallest size that windows allow to mount
|
||||
DISK_BLOCK_SIZE = 512
|
||||
};
|
||||
@@ -119,16 +149,52 @@ uint8_t msc_disk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] =
|
||||
README_CONTENTS
|
||||
};
|
||||
|
||||
#if CFG_EXAMPLE_MSC_ASYNC_IO
|
||||
void msc_disk_init() {
|
||||
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
io_queue = xQueueCreateStatic(1, sizeof(io_ops_t), io_queue_buf, &io_queue_static);
|
||||
xTaskCreateStatic(io_task, "io", IO_STACK_SIZE, NULL, 2, io_stack, &io_taskdef);
|
||||
#else
|
||||
io_queue = xQueueCreate(1, sizeof(io_ops_t));
|
||||
xTaskCreate(io_task, "io", IO_STACK_SIZE, NULL, 2, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void io_task(void *params) {
|
||||
(void) params;
|
||||
io_ops_t io_ops;
|
||||
while (1) {
|
||||
if (xQueueReceive(io_queue, &io_ops, portMAX_DELAY)) {
|
||||
const uint8_t* addr = msc_disk[io_ops.lba] + io_ops.offset;
|
||||
int32_t nbytes = io_ops.bufsize;
|
||||
if (io_ops.is_read) {
|
||||
memcpy(io_ops.buffer, addr, io_ops.bufsize);
|
||||
} else {
|
||||
#ifndef CFG_EXAMPLE_MSC_READONLY
|
||||
memcpy((uint8_t*) addr, io_ops.buffer, io_ops.bufsize);
|
||||
#else
|
||||
nbytes = -1; // failed to write
|
||||
#endif
|
||||
}
|
||||
|
||||
tusb_time_delay_ms_api(CFG_EXAMPLE_MSC_IO_DELAY_MS);
|
||||
tud_msc_async_io_done(nbytes, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
void msc_disk_init() {}
|
||||
#endif
|
||||
|
||||
// Invoked when received SCSI_CMD_INQUIRY
|
||||
// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively
|
||||
void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4])
|
||||
{
|
||||
void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) {
|
||||
(void) lun;
|
||||
|
||||
const char vid[] = "TinyUSB";
|
||||
const char pid[] = "Mass Storage";
|
||||
const char rev[] = "1.0";
|
||||
|
||||
memcpy(vendor_id , vid, strlen(vid));
|
||||
memcpy(product_id , pid, strlen(pid));
|
||||
memcpy(product_rev, rev, strlen(rev));
|
||||
@@ -136,8 +202,7 @@ void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16
|
||||
|
||||
// Invoked when received Test Unit Ready command.
|
||||
// return true allowing host to read/write this LUN e.g SD card inserted
|
||||
bool tud_msc_test_unit_ready_cb(uint8_t lun)
|
||||
{
|
||||
bool tud_msc_test_unit_ready_cb(uint8_t lun) {
|
||||
(void) lun;
|
||||
|
||||
// RAM disk is ready until ejected
|
||||
@@ -152,10 +217,8 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun)
|
||||
|
||||
// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
|
||||
// Application update block count and block size
|
||||
void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size)
|
||||
{
|
||||
void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size) {
|
||||
(void) lun;
|
||||
|
||||
*block_count = DISK_BLOCK_NUM;
|
||||
*block_size = DISK_BLOCK_SIZE;
|
||||
}
|
||||
@@ -163,18 +226,14 @@ void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_siz
|
||||
// Invoked when received Start Stop Unit command
|
||||
// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage
|
||||
// - Start = 1 : active mode, if load_eject = 1 : load disk storage
|
||||
bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject)
|
||||
{
|
||||
bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) {
|
||||
(void) lun;
|
||||
(void) power_condition;
|
||||
|
||||
if ( load_eject )
|
||||
{
|
||||
if (start)
|
||||
{
|
||||
if (load_eject) {
|
||||
if (start) {
|
||||
// load disk storage
|
||||
}else
|
||||
{
|
||||
} else {
|
||||
// unload disk storage
|
||||
ejected = true;
|
||||
}
|
||||
@@ -185,28 +244,34 @@ bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, boo
|
||||
|
||||
// Callback invoked when received READ10 command.
|
||||
// Copy disk's data to buffer (up to bufsize) and return number of copied bytes.
|
||||
int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) {
|
||||
(void) lun;
|
||||
|
||||
// out of ramdisk
|
||||
if (lba >= DISK_BLOCK_NUM) {
|
||||
return -1;
|
||||
return TUD_MSC_RET_ERROR;
|
||||
}
|
||||
|
||||
// Check for overflow of offset + bufsize
|
||||
if ( offset + bufsize > DISK_BLOCK_SIZE ) {
|
||||
return -1;
|
||||
if (lba * DISK_BLOCK_SIZE + offset + bufsize > DISK_BLOCK_NUM * DISK_BLOCK_SIZE) {
|
||||
return TUD_MSC_RET_ERROR;
|
||||
}
|
||||
|
||||
#if CFG_EXAMPLE_MSC_ASYNC_IO
|
||||
io_ops_t io_ops = {.is_read = true, .lun = lun, .lba = lba, .offset = offset, .buffer = buffer, .bufsize = bufsize};
|
||||
|
||||
// Send IO operation to IO task
|
||||
TU_ASSERT(xQueueSend(io_queue, &io_ops, 0) == pdPASS);
|
||||
|
||||
return TUD_MSC_RET_ASYNC;
|
||||
#else
|
||||
uint8_t const *addr = msc_disk[lba] + offset;
|
||||
memcpy(buffer, addr, bufsize);
|
||||
|
||||
return (int32_t) bufsize;
|
||||
return bufsize;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool tud_msc_is_writable_cb (uint8_t lun)
|
||||
{
|
||||
bool tud_msc_is_writable_cb (uint8_t lun) {
|
||||
(void) lun;
|
||||
|
||||
#ifdef CFG_EXAMPLE_MSC_READONLY
|
||||
@@ -218,28 +283,43 @@ bool tud_msc_is_writable_cb (uint8_t lun)
|
||||
|
||||
// Callback invoked when received WRITE10 command.
|
||||
// Process data in buffer to disk's storage and return number of written bytes
|
||||
int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize)
|
||||
{
|
||||
(void) lun;
|
||||
|
||||
int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize) {
|
||||
// out of ramdisk
|
||||
if ( lba >= DISK_BLOCK_NUM ) return -1;
|
||||
if (lba >= DISK_BLOCK_NUM) {
|
||||
return TUD_MSC_RET_ERROR;
|
||||
}
|
||||
|
||||
#ifndef CFG_EXAMPLE_MSC_READONLY
|
||||
uint8_t* addr = msc_disk[lba] + offset;
|
||||
memcpy(addr, buffer, bufsize);
|
||||
#else
|
||||
(void) lba; (void) offset; (void) buffer;
|
||||
// Check for overflow of offset + bufsize
|
||||
if (lba * DISK_BLOCK_SIZE + offset + bufsize > DISK_BLOCK_NUM * DISK_BLOCK_SIZE) {
|
||||
return TUD_MSC_RET_ERROR;
|
||||
}
|
||||
|
||||
#ifdef CFG_EXAMPLE_MSC_READONLY
|
||||
(void) lun;
|
||||
(void) buffer;
|
||||
return bufsize;
|
||||
#endif
|
||||
|
||||
return (int32_t) bufsize;
|
||||
#if CFG_EXAMPLE_MSC_ASYNC_IO
|
||||
io_ops_t io_ops = {.is_read = false, .lun = lun, .lba = lba, .offset = offset, .buffer = buffer, .bufsize = bufsize};
|
||||
|
||||
// Send IO operation to IO task
|
||||
TU_ASSERT(xQueueSend(io_queue, &io_ops, 0) == pdPASS);
|
||||
|
||||
return TUD_MSC_RET_ASYNC;
|
||||
#else
|
||||
uint8_t *addr = msc_disk[lba] + offset;
|
||||
memcpy(addr, buffer, bufsize);
|
||||
tusb_time_delay_ms_api(CFG_EXAMPLE_MSC_IO_DELAY_MS);
|
||||
|
||||
return bufsize;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Callback invoked when received an SCSI command not in built-in list below
|
||||
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
|
||||
// - READ10 and WRITE10 has their own callbacks
|
||||
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize)
|
||||
{
|
||||
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) {
|
||||
// read10 & write10 has their own callback and MUST not be handled here
|
||||
|
||||
void const *response = NULL;
|
||||
@@ -248,8 +328,7 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
|
||||
// most scsi handled is input
|
||||
bool in_xfer = true;
|
||||
|
||||
switch (scsi_cmd[0])
|
||||
{
|
||||
switch (scsi_cmd[0]) {
|
||||
default:
|
||||
// Set Sense = Invalid Command Operation
|
||||
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
|
||||
@@ -260,15 +339,12 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
|
||||
}
|
||||
|
||||
// return resplen must not larger than bufsize
|
||||
if ( resplen > bufsize ) resplen = bufsize;
|
||||
if (resplen > bufsize) { resplen = bufsize; }
|
||||
|
||||
if ( response && (resplen > 0) )
|
||||
{
|
||||
if(in_xfer)
|
||||
{
|
||||
if (response && (resplen > 0)) {
|
||||
if (in_xfer) {
|
||||
memcpy(buffer, response, (size_t) resplen);
|
||||
}else
|
||||
{
|
||||
} else {
|
||||
// SCSI output
|
||||
}
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
@@ -104,6 +104,8 @@
|
||||
#define CFG_TUD_MIDI 0
|
||||
#define CFG_TUD_VENDOR 0
|
||||
|
||||
#define CFG_TUD_CDC_NOTIFY 1 // Enable use of notification endpoint
|
||||
|
||||
// CDC FIFO size of TX and RX
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
|
@@ -52,7 +52,6 @@ tusb_desc_device_t const desc_device = {
|
||||
.bDeviceClass = TUSB_CLASS_MISC,
|
||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
||||
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
|
||||
.idVendor = USB_VID,
|
||||
@@ -131,7 +130,7 @@ uint8_t const desc_fs_configuration[] =
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
||||
|
||||
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 16, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
|
||||
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
|
||||
@@ -147,7 +146,7 @@ uint8_t const desc_hs_configuration[] =
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
||||
|
||||
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF, 16, EPNUM_CDC_OUT, EPNUM_CDC_IN, 512),
|
||||
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 512),
|
||||
@@ -176,16 +175,14 @@ tusb_desc_device_qualifier_t const desc_device_qualifier =
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
|
||||
// device_qualifier descriptor describes information about a high-speed capable device that would
|
||||
// change if the device were operating at the other speed. If not highspeed capable stall this request.
|
||||
uint8_t const* tud_descriptor_device_qualifier_cb(void)
|
||||
{
|
||||
uint8_t const* tud_descriptor_device_qualifier_cb(void) {
|
||||
return (uint8_t const*) &desc_device_qualifier;
|
||||
}
|
||||
|
||||
// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
|
||||
uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index)
|
||||
{
|
||||
uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index) {
|
||||
(void) index; // for multiple configurations
|
||||
|
||||
// if link speed is high return fullspeed config, and vice versa
|
||||
@@ -204,8 +201,7 @@ uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index)
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
{
|
||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index) {
|
||||
(void) index; // for multiple configurations
|
||||
|
||||
#if TUD_OPT_HIGH_SPEED
|
||||
@@ -229,8 +225,7 @@ enum {
|
||||
};
|
||||
|
||||
// array of pointer to string descriptors
|
||||
char const *string_desc_arr[] =
|
||||
{
|
||||
char const *string_desc_arr[] = {
|
||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB Device", // 2: Product
|
||||
@@ -261,14 +256,14 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
|
||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
|
||||
|
||||
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
|
||||
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) { return NULL; }
|
||||
|
||||
const char *str = string_desc_arr[index];
|
||||
|
||||
// Cap at max char
|
||||
chr_count = strlen(str);
|
||||
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
|
||||
if ( chr_count > max_count ) chr_count = max_count;
|
||||
if ( chr_count > max_count ) { chr_count = max_count; }
|
||||
|
||||
// Convert ASCII string into UTF-16
|
||||
for ( size_t i = 0; i < chr_count; i++ ) {
|
||||
@@ -279,6 +274,5 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
|
||||
// first byte is length (including header), second byte is string type
|
||||
_desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
|
||||
|
||||
return _desc_str;
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@
|
||||
#include "tusb.h"
|
||||
#include "usb_descriptors.h"
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@@ -112,17 +112,16 @@ int main(void)
|
||||
|
||||
xTimerStart(blinky_tm, 0);
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// only start scheduler for non-espressif mcu
|
||||
#ifndef ESP_PLATFORM
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
void app_main(void)
|
||||
{
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
#endif
|
||||
|
@@ -59,7 +59,7 @@
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
|
@@ -40,7 +40,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
||||
//--------------------------------------------------------------------+
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define USBD_STACK_SIZE 4096
|
||||
#else
|
||||
// Increase stack size when debug log is enabled
|
||||
@@ -95,15 +95,15 @@ int main(void) {
|
||||
xTaskCreate(midi_task, "midi", MIDI_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, NULL);
|
||||
#endif
|
||||
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#ifndef ESP_PLATFORM
|
||||
// only start scheduler for non-espressif mcu
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += lib/lwip
|
||||
|
||||
include ../../build_system/make/make.mk
|
||||
|
||||
# suppress warning caused by lwip
|
||||
|
@@ -292,7 +292,7 @@ void led_blinking_task(void* param) {
|
||||
#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define VIDEO_STACK_SIZE (configMINIMAL_STACK_SIZE*4)
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define USBD_STACK_SIZE 4096
|
||||
int main(void);
|
||||
void app_main(void) {
|
||||
@@ -351,8 +351,8 @@ void freertos_init_task(void) {
|
||||
xTaskCreate(video_task, "video", VIDEO_STACK_SZIE, NULL, configMAX_PRIORITIES - 2, NULL);
|
||||
#endif
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// only start scheduler for non-espressif mcu
|
||||
#ifndef ESP_PLATFORM
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
|
@@ -300,7 +300,7 @@ void led_blinking_task(void* param) {
|
||||
#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define VIDEO_STACK_SIZE (configMINIMAL_STACK_SIZE*4)
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define USBD_STACK_SIZE 4096
|
||||
int main(void);
|
||||
void app_main(void) {
|
||||
@@ -359,8 +359,8 @@ void freertos_init_task(void) {
|
||||
xTaskCreate(video_task, "video", VIDEO_STACK_SZIE, NULL, configMAX_PRIORITIES - 2, NULL);
|
||||
#endif
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// only start scheduler for non-espressif mcu
|
||||
#ifndef ESP_PLATFORM
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
board:mimxrt1060_evk
|
||||
board:mimxrt1064_evk
|
||||
board:mcb1800
|
||||
mcu:CH32V20X
|
||||
mcu:RP2040
|
||||
mcu:ra6m5
|
||||
mcu:MAX3421
|
||||
|
@@ -1,6 +1,7 @@
|
||||
board:mimxrt1060_evk
|
||||
board:mimxrt1064_evk
|
||||
board:mcb1800
|
||||
mcu:CH32V20X
|
||||
mcu:RP2040
|
||||
mcu:ra6m5
|
||||
mcu:MAX3421
|
||||
|
@@ -1,3 +1,4 @@
|
||||
mcu:CH32V20X
|
||||
mcu:KINETIS_KL
|
||||
mcu:LPC175X_6X
|
||||
mcu:LPC177X_8X
|
||||
|
@@ -1,3 +1,4 @@
|
||||
mcu:CH32V20X
|
||||
mcu:KINETIS_KL
|
||||
mcu:LPC175X_6X
|
||||
mcu:LPC177X_8X
|
||||
|
@@ -31,8 +31,7 @@ static size_t get_console_inputs(uint8_t* buf, size_t bufsize) {
|
||||
size_t count = 0;
|
||||
while (count < bufsize) {
|
||||
int ch = board_getchar();
|
||||
if (ch <= 0) break;
|
||||
|
||||
if (ch <= 0) { break; }
|
||||
buf[count] = (uint8_t) ch;
|
||||
count++;
|
||||
}
|
||||
@@ -69,10 +68,15 @@ void tuh_cdc_rx_cb(uint8_t idx) {
|
||||
uint32_t const bufsize = sizeof(buf) - 1;
|
||||
|
||||
// forward cdc interfaces -> console
|
||||
uint32_t count = tuh_cdc_read(idx, buf, bufsize);
|
||||
const uint32_t count = tuh_cdc_read(idx, buf, bufsize);
|
||||
if (count) {
|
||||
buf[count] = 0;
|
||||
|
||||
printf("%s", (char*) buf);
|
||||
|
||||
#ifndef __ICCARM__ // TODO IAR doesn't support stream control ?
|
||||
fflush(stdout);// flush right away, else nanolib will wait for newline
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Invoked when a device with CDC interface is mounted
|
||||
@@ -88,7 +92,7 @@ void tuh_cdc_mount_cb(uint8_t idx) {
|
||||
// If CFG_TUH_CDC_LINE_CODING_ON_ENUM is defined, line coding will be set by tinyusb stack
|
||||
// while eneumerating new cdc device
|
||||
cdc_line_coding_t line_coding = {0};
|
||||
if (tuh_cdc_get_local_line_coding(idx, &line_coding)) {
|
||||
if (tuh_cdc_get_line_coding_local(idx, &line_coding)) {
|
||||
printf(" Baudrate: %" PRIu32 ", Stop Bits : %u\r\n", line_coding.bit_rate, line_coding.stop_bits);
|
||||
printf(" Parity : %u, Data Width: %u\r\n", line_coding.parity, line_coding.data_bits);
|
||||
}
|
||||
|
@@ -103,10 +103,11 @@
|
||||
#define CFG_TUH_ENUMERATION_BUFSIZE 256
|
||||
|
||||
#define CFG_TUH_HUB 1 // number of supported hubs
|
||||
#define CFG_TUH_CDC 1 // CDC ACM
|
||||
#define CFG_TUH_CDC 2 // number of supported CDC devices. also activates CDC ACM
|
||||
#define CFG_TUH_CDC_FTDI 1 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_CDC_CP210X 1 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_CDC_CH34X 1 // CH340 or CH341 Serial. CH34X is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_CDC_PL2303 1 // PL2303 Serial. PL2303 is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
|
||||
#define CFG_TUH_MSC 1
|
||||
#define CFG_TUH_VENDOR 0
|
||||
@@ -122,7 +123,7 @@
|
||||
|
||||
// Set Line Control state on enumeration/mounted:
|
||||
// DTR ( bit 0), RTS (bit 1)
|
||||
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03
|
||||
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM (CDC_CONTROL_LINE_STATE_DTR | CDC_CONTROL_LINE_STATE_RTS)
|
||||
|
||||
// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
|
||||
// bit rate = 115200, 1 stop bit, no parity, 8 bit data width
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "tusb.h"
|
||||
#include "bsp/board_api.h"
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CDC_STACK_SZIE 2048
|
||||
#else
|
||||
#define CDC_STACK_SZIE (3*configMINIMAL_STACK_SIZE/2)
|
||||
|
@@ -30,7 +30,7 @@
|
||||
#include "bsp/board_api.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define USBH_STACK_SIZE 4096
|
||||
#else
|
||||
// Increase stack size when debug log is enabled
|
||||
@@ -86,15 +86,15 @@ int main(void) {
|
||||
|
||||
xTimerStart(blinky_tm, 0);
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// only start scheduler for non-espressif mcu
|
||||
#ifndef ESP_PLATFORM
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
@@ -108,10 +108,11 @@
|
||||
#define CFG_TUH_ENUMERATION_BUFSIZE 256
|
||||
|
||||
#define CFG_TUH_HUB 1 // number of supported hubs
|
||||
#define CFG_TUH_CDC 1 // CDC ACM
|
||||
#define CFG_TUH_CDC 1 // number of supported CDC devices. also activates CDC ACM
|
||||
#define CFG_TUH_CDC_FTDI 1 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_CDC_CP210X 1 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_CDC_CH34X 1 // CH340 or CH341 Serial. CH34X is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_CDC_PL2303 1 // PL2303 Serial. PL2303 is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
|
||||
#define CFG_TUH_MSC 1
|
||||
#define CFG_TUH_VENDOR 0
|
||||
@@ -127,7 +128,7 @@
|
||||
|
||||
// Set Line Control state on enumeration/mounted:
|
||||
// DTR ( bit 0), RTS (bit 1)
|
||||
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03
|
||||
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM (CDC_CONTROL_LINE_STATE_DTR | CDC_CONTROL_LINE_STATE_RTS)
|
||||
|
||||
// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
|
||||
// bit rate = 115200, 1 stop bit, no parity, 8 bit data width
|
||||
|
@@ -1,3 +1,4 @@
|
||||
mcu:CH32V20X
|
||||
mcu:ESP32S2
|
||||
mcu:ESP32S3
|
||||
mcu:ESP32P4
|
||||
|
@@ -268,7 +268,7 @@ void led_blinking_task(void* param) {
|
||||
|
||||
#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define USB_STACK_SIZE 4096
|
||||
#else
|
||||
// Increase stack size when debug log is enabled
|
||||
@@ -285,7 +285,7 @@ StackType_t usb_stack[USB_STACK_SIZE];
|
||||
StaticTask_t usb_taskdef;
|
||||
#endif
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
@@ -308,8 +308,8 @@ void init_freertos_task(void) {
|
||||
xTaskCreate(usb_host_task, "usbh", USB_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
#endif
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// only start scheduler for non-espressif mcu
|
||||
#ifndef ESP_PLATFORM
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
mcu:CH32V20X
|
||||
mcu:KINETIS_KL
|
||||
mcu:LPC175X_6X
|
||||
mcu:LPC177X_8X
|
||||
|
@@ -1,3 +1,4 @@
|
||||
mcu:CH32V20X
|
||||
mcu:ESP32S2
|
||||
mcu:ESP32S3
|
||||
mcu:ESP32P4
|
||||
|
@@ -40,7 +40,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
mcu:CH32V20X
|
||||
mcu:KINETIS_KL
|
||||
mcu:LPC175X_6X
|
||||
mcu:LPC177X_8X
|
||||
|
@@ -71,9 +71,8 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
void app_main(void)
|
||||
{
|
||||
#ifdef ESP_PLATFORM
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
#endif
|
||||
|
@@ -60,13 +60,11 @@ int sys_read(int fhdl, char *buf, size_t count) {
|
||||
int rd = (int) SEGGER_RTT_Read(0, buf, count);
|
||||
return (rd > 0) ? rd : -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#elif defined(LOGGER_SWO)
|
||||
|
||||
#define ITM_BASE 0xE0000000
|
||||
|
||||
#define ITM_STIM0 (*((volatile uint8_t*)(ITM_BASE + 0)))
|
||||
#define ITM_TER *((volatile uint32_t*)(ITM_BASE + 0xE00))
|
||||
#define ITM_TCR *((volatile uint32_t*)(ITM_BASE + 0xE80))
|
||||
@@ -150,6 +148,9 @@ int board_getchar(void) {
|
||||
return (sys_read(0, &c, 1) > 0) ? (int) c : (-1);
|
||||
}
|
||||
|
||||
void board_putchar(int c) {
|
||||
sys_write(0, (const char*)&c, 1);
|
||||
}
|
||||
|
||||
uint32_t tusb_time_millis_api(void) {
|
||||
return board_millis();
|
||||
@@ -158,7 +159,7 @@ uint32_t tusb_time_millis_api(void) {
|
||||
//--------------------------------------------------------------------
|
||||
// FreeRTOS hooks
|
||||
//--------------------------------------------------------------------
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS && !TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS && !defined(ESP_PLATFORM)
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
@@ -240,5 +241,4 @@ void vApplicationSetupTimerInterrupt(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -41,7 +41,7 @@ extern "C" {
|
||||
#if CFG_TUSB_OS == OPT_OS_ZEPHYR
|
||||
#include <zephyr/kernel.h>
|
||||
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
#ifdef ESP_PLATFORM
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@@ -195,6 +195,7 @@ static inline void board_delay(uint32_t ms) {
|
||||
|
||||
// stdio getchar() is blocking, this is non-blocking version
|
||||
int board_getchar(void);
|
||||
void board_putchar(int c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ else
|
||||
# The submodule BRTSG-FOSS/ft90x-sdk contains header files and source
|
||||
# code for the Bridgetek SDK. This can be used instead of the prebuilt
|
||||
# library.
|
||||
DEPS_SUBMODULES += hw/mcu/bridgetek/ft9xx/ft90x-sdk
|
||||
# The SDK can be used to load specific files from the Bridgetek SDK.
|
||||
FT9XX_SDK = hw/mcu/bridgetek/ft9xx/ft90x-sdk/Source
|
||||
INC += "$(TOP)/$(FT9XX_SDK)/include"
|
||||
|
@@ -1,6 +1,5 @@
|
||||
# Submodules
|
||||
CH32F20X_SDK = hw/mcu/wch/ch32f20x
|
||||
DEPS_SUBMODULES += $(CH32F20X_SDK)
|
||||
|
||||
# WCH-SDK paths
|
||||
CH32F20X_SDK_SRC = $(CH32F20X_SDK)/EVT/EXAM/SRC
|
||||
|
@@ -20,56 +20,56 @@ manufacturer: WCH
|
||||
#include "bsp/board_api.h"
|
||||
#include "board.h"
|
||||
|
||||
/* CH32v203 depending on variants can support 2 USB IPs: FSDEV and USBFS.
|
||||
/* CH32v203 depending on variants can support 2 USB IPs: FSDEV (port0) and USBFS (port1).
|
||||
* By default, we use FSDEV, but you can explicitly select by define:
|
||||
* - CFG_TUD_WCH_USBIP_FSDEV
|
||||
* - CFG_TUD_WCH_USBIP_USBFS
|
||||
*/
|
||||
|
||||
// USBFS
|
||||
__attribute__((interrupt)) __attribute__((used))
|
||||
void USBHD_IRQHandler(void) {
|
||||
// Port0: USBD (fsdev)
|
||||
__attribute__((interrupt)) __attribute__((used)) void USB_LP_CAN1_RX0_IRQHandler(void) {
|
||||
#if CFG_TUD_WCH_USBIP_FSDEV
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) __attribute__((used)) void USB_HP_CAN1_TX_IRQHandler(void) {
|
||||
#if CFG_TUD_WCH_USBIP_FSDEV
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) __attribute__((used)) void USBWakeUp_IRQHandler(void) {
|
||||
#if CFG_TUD_WCH_USBIP_FSDEV
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Port1: USBFS
|
||||
__attribute__((interrupt)) __attribute__((used)) void USBHD_IRQHandler(void) {
|
||||
#if CFG_TUD_ENABLED && CFG_TUD_WCH_USBIP_USBFS
|
||||
tud_int_handler(1);
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_ENABLED
|
||||
tuh_int_handler(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) __attribute__((used)) void USBHDWakeUp_IRQHandler(void) {
|
||||
#if CFG_TUD_WCH_USBIP_USBFS
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) __attribute__((used))
|
||||
void USBHDWakeUp_IRQHandler(void) {
|
||||
#if CFG_TUD_WCH_USBIP_USBFS
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// USBD (fsdev)
|
||||
__attribute__((interrupt)) __attribute__((used))
|
||||
void USB_LP_CAN1_RX0_IRQHandler(void) {
|
||||
#if CFG_TUD_WCH_USBIP_FSDEV
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) __attribute__((used))
|
||||
void USB_HP_CAN1_TX_IRQHandler(void) {
|
||||
#if CFG_TUD_WCH_USBIP_FSDEV
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) __attribute__((used))
|
||||
void USBWakeUp_IRQHandler(void) {
|
||||
#if CFG_TUD_WCH_USBIP_FSDEV
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Board API
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
|
||||
__attribute__((interrupt))
|
||||
void SysTick_Handler(void) {
|
||||
__attribute__((interrupt)) void SysTick_Handler(void) {
|
||||
SysTick->SR = 0;
|
||||
system_ticks++;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ void board_init(void) {
|
||||
#ifdef UART_DEV
|
||||
UART_CLOCK_EN();
|
||||
GPIO_InitTypeDef usart_init = {
|
||||
.GPIO_Pin = UART_TX_PIN,
|
||||
.GPIO_Pin = UART_TX_PIN | UART_RX_PIN,
|
||||
.GPIO_Speed = GPIO_Speed_50MHz,
|
||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||
};
|
||||
@@ -119,7 +119,7 @@ void board_init(void) {
|
||||
.USART_WordLength = USART_WordLength_8b,
|
||||
.USART_StopBits = USART_StopBits_1,
|
||||
.USART_Parity = USART_Parity_No,
|
||||
.USART_Mode = USART_Mode_Tx,
|
||||
.USART_Mode = USART_Mode_Tx | USART_Mode_Rx,
|
||||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||
};
|
||||
USART_Init(UART_DEV, &usart);
|
||||
@@ -189,9 +189,19 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
|
||||
}
|
||||
|
||||
int board_uart_read(uint8_t *buf, int len) {
|
||||
(void) buf;
|
||||
(void) len;
|
||||
#ifdef UART_DEV
|
||||
int count;
|
||||
for (count = 0; count < len; count++) {
|
||||
if (USART_GetFlagStatus(UART_DEV, USART_FLAG_RXNE) == RESET) {
|
||||
break;
|
||||
}
|
||||
buf[count] = USART_ReceiveData(UART_DEV);
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
@@ -207,7 +217,3 @@ int board_uart_write(void const *buf, int len) {
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Neopixel
|
||||
//--------------------------------------------------------------------
|
||||
|
@@ -16,10 +16,13 @@ set(FAMILY_MCUS CH32V20X CACHE INTERNAL "")
|
||||
set(OPENOCD_OPTION "-f ${CMAKE_CURRENT_LIST_DIR}/wch-riscv.cfg")
|
||||
|
||||
# Port0 use FSDev, Port1 use USBFS
|
||||
if (NOT DEFINED PORT)
|
||||
set(PORT 0)
|
||||
if (NOT DEFINED RHPORT_DEVICE)
|
||||
set(RHPORT_DEVICE 0)
|
||||
endif ()
|
||||
|
||||
# only port1 support host mode
|
||||
set(RHPORT_HOST 1)
|
||||
|
||||
#------------------------------------
|
||||
# BOARD_TARGET
|
||||
#------------------------------------
|
||||
@@ -56,18 +59,16 @@ function(add_board_target BOARD_TARGET)
|
||||
)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC
|
||||
CH32V20x_${MCU_VARIANT}
|
||||
BOARD_TUD_RHPORT=${RHPORT_DEVICE}
|
||||
BOARD_TUH_RHPORT=${RHPORT_HOST}
|
||||
)
|
||||
|
||||
if (PORT EQUAL 0)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC
|
||||
CFG_TUD_WCH_USBIP_FSDEV=1
|
||||
)
|
||||
elseif (PORT EQUAL 1)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC
|
||||
CFG_TUD_WCH_USBIP_USBFS=1
|
||||
)
|
||||
if (RHPORT_DEVICE EQUAL 0)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC CFG_TUD_WCH_USBIP_FSDEV=1)
|
||||
elseif (RHPORT_DEVICE EQUAL 1)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC CFG_TUH_WCH_USBIP_USBFS=1)
|
||||
else()
|
||||
message(FATAL_ERROR "Invalid PORT ${PORT}")
|
||||
message(FATAL_ERROR "Invalid RHPORT_DEVICE ${RHPORT_DEVICE}")
|
||||
endif()
|
||||
|
||||
update_board(${BOARD_TARGET})
|
||||
@@ -127,12 +128,11 @@ function(family_configure_example TARGET RTOS)
|
||||
|
||||
target_sources(${TARGET} PUBLIC
|
||||
${TOP}/src/portable/wch/dcd_ch32_usbfs.c
|
||||
${TOP}/src/portable/wch/hcd_ch32_usbfs.c
|
||||
${TOP}/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
|
||||
)
|
||||
target_link_libraries(${TARGET} PUBLIC board_${BOARD})
|
||||
|
||||
|
||||
|
||||
# Flashing
|
||||
family_add_bin_hex(${TARGET})
|
||||
family_flash_openocd_wch(${TARGET})
|
||||
|
@@ -30,6 +30,8 @@ CFLAGS += -Wno-error=strict-prototypes
|
||||
ifeq ($(PORT),0)
|
||||
$(info "Using FSDEV driver")
|
||||
CFLAGS += -DCFG_TUD_WCH_USBIP_FSDEV=1
|
||||
$(info "Using USBFS Host driver")
|
||||
CFLAGS += -DCFG_TUH_WCH_USBIP_USBFS=1
|
||||
else
|
||||
$(info "Using USBFS driver")
|
||||
CFLAGS += -DCFG_TUD_WCH_USBIP_USBFS=1
|
||||
@@ -43,6 +45,7 @@ LD_FILE = $(FAMILY_PATH)/linker/${CH32_FAMILY}.ld
|
||||
|
||||
SRC_C += \
|
||||
src/portable/wch/dcd_ch32_usbfs.c \
|
||||
src/portable/wch/hcd_ch32_usbfs.c \
|
||||
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \
|
||||
$(SDK_SRC_DIR)/Core/core_riscv.c \
|
||||
$(SDK_SRC_DIR)/Peripheral/src/${CH32_FAMILY}_gpio.c \
|
||||
|
@@ -156,6 +156,10 @@ int board_getchar(void) {
|
||||
return getchar();
|
||||
}
|
||||
|
||||
void board_putchar(int c) {
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// PHY Init
|
||||
//--------------------------------------------------------------------
|
||||
|
@@ -1,5 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# Apply board specific content i.e IDF_TARGET must be set before project.cmake is included
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake")
|
||||
string(TOUPPER ${IDF_TARGET} FAMILY_MCUS)
|
||||
|
@@ -1,34 +0,0 @@
|
||||
#DEPS_SUBMODULES +=
|
||||
|
||||
UF2_FAMILY_ID_esp32s2 = 0xbfdd4eee
|
||||
UF2_FAMILY_ID_esp32s3 = 0xc47e5767
|
||||
|
||||
BOARD_CMAKE := $(file < $(TOP)/$(BOARD_PATH)/board.cmake)
|
||||
ifneq ($(findstring esp32s2,$(BOARD_CMAKE)),)
|
||||
IDF_TARGET = esp32s2
|
||||
else
|
||||
ifneq ($(findstring esp32s3,$(BOARD_CMAKE)),)
|
||||
IDF_TARGET = esp32s3
|
||||
endif
|
||||
endif
|
||||
|
||||
.PHONY: all clean flash bootloader-flash app-flash erase monitor dfu-flash dfu
|
||||
|
||||
all:
|
||||
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) build
|
||||
|
||||
build: all
|
||||
|
||||
fullclean:
|
||||
if test -f sdkconfig; then $(RM) -f sdkconfig ; fi
|
||||
if test -d $(BUILD); then $(RM) -rf $(BUILD) ; fi
|
||||
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) $@
|
||||
|
||||
clean flash bootloader-flash app-flash erase monitor dfu-flash dfu size size-components size-files:
|
||||
idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) $@
|
||||
|
||||
uf2: $(BUILD)/$(PROJECT).uf2
|
||||
|
||||
$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).bin
|
||||
@echo CREATE $@
|
||||
$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID_$(IDF_TARGET)) -b 0x0 -c -o $@ $^
|
@@ -221,6 +221,8 @@ function(family_configure_common TARGET RTOS)
|
||||
target_include_directories(${TARGET} PUBLIC ${TOP}/lib/SEGGER_RTT/RTT)
|
||||
# target_compile_definitions(${TARGET} PUBLIC SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL)
|
||||
endif ()
|
||||
else ()
|
||||
target_compile_definitions(${TARGET} PUBLIC LOGGER_UART)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
|
@@ -1,6 +1,5 @@
|
||||
UF2_FAMILY_ID = 0x4fb2d5bd
|
||||
SDK_DIR = hw/mcu/nxp/mcux-sdk
|
||||
DEPS_SUBMODULES += $(SDK_DIR) lib/CMSIS_5
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
SDK_DIR = hw/mcu/nxp/mcux-sdk
|
||||
DEPS_SUBMODULES += $(SDK_DIR) lib/CMSIS_5
|
||||
|
||||
MCU_DIR = $(SDK_DIR)/devices/${MCU_VARIANT}
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
|
@@ -1,5 +1,4 @@
|
||||
SDK_DIR = hw/mcu/nxp/mcux-sdk
|
||||
DEPS_SUBMODULES += $(SDK_DIR) lib/CMSIS_5
|
||||
|
||||
MCU_DIR = $(SDK_DIR)/devices/$(MCU)
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nxp/lpcopen
|
||||
|
||||
CFLAGS += \
|
||||
-DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM2")))'
|
||||
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nxp/lpcopen
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpcopen/lpc13xx/lpc_chip_13xx
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m3
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nxp/lpcopen
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m3
|
||||
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nxp/lpcopen
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpcopen/lpc175x_6x/lpc_chip_175x_6x
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m3
|
||||
|
@@ -1,4 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nxp/lpcopen
|
||||
MCU_DIR = hw/mcu/nxp/lpcopen/lpc18xx/lpc_chip_18xx
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nxp/lpcopen
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpcopen/lpc40xx/lpc_chip_40xx
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m4
|
||||
|
@@ -1,4 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nxp/lpcopen
|
||||
SDK_DIR = hw/mcu/nxp/lpcopen/lpc43xx/lpc_chip_43xx
|
||||
|
||||
include ${TOP}/${BOARD_PATH}/board.mk
|
||||
|
@@ -1,5 +1,4 @@
|
||||
SDK_DIR = hw/mcu/nxp/mcux-sdk
|
||||
DEPS_SUBMODULES += $(SDK_DIR) lib/CMSIS_5
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m4
|
||||
|
@@ -1,6 +1,5 @@
|
||||
UF2_FAMILY_ID = 0x2abc77ec
|
||||
SDK_DIR = hw/mcu/nxp/mcux-sdk
|
||||
DEPS_SUBMODULES += lib/CMSIS_5 lib/sct_neopixel $(SDK_DIR)
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m33
|
||||
|
@@ -1,8 +1,6 @@
|
||||
UF2_FAMILY_ID = 0x2abc77ec
|
||||
SDK_DIR = hw/mcu/nxp/mcux-sdk
|
||||
|
||||
DEPS_SUBMODULES += $(SDK_DIR) lib/CMSIS_5
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
|
||||
# Default to Highspeed PORT1
|
||||
|
@@ -11,13 +11,15 @@ set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/msp430_${T
|
||||
|
||||
set(FAMILY_MCUS MSP430x5xx CACHE INTERNAL "")
|
||||
|
||||
|
||||
#------------------------------------
|
||||
# BOARD_TARGET
|
||||
#------------------------------------
|
||||
# only need to be built ONCE for all examples
|
||||
function(add_board_target BOARD_TARGET)
|
||||
if (NOT TARGET ${BOARD_TARGET})
|
||||
if (TARGET ${BOARD_TARGET})
|
||||
return()
|
||||
endif ()
|
||||
|
||||
add_library(${BOARD_TARGET} INTERFACE)
|
||||
target_compile_definitions(${BOARD_TARGET} INTERFACE
|
||||
CFG_TUD_ENDPOINT0_SIZE=8
|
||||
@@ -41,7 +43,6 @@ function(add_board_target BOARD_TARGET)
|
||||
"LINKER:--config=${LD_FILE_IAR}"
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
endfunction()
|
||||
|
||||
|
||||
@@ -75,7 +76,6 @@ function(family_configure_example TARGET RTOS)
|
||||
)
|
||||
target_link_libraries(${TARGET} PUBLIC board_${BOARD})
|
||||
|
||||
|
||||
# Flashing
|
||||
family_add_bin_hex(${TARGET})
|
||||
family_flash_msp430flasher(${TARGET})
|
||||
|
@@ -1,5 +1,4 @@
|
||||
CROSS_COMPILE = msp430-elf-
|
||||
DEPS_SUBMODULES += hw/mcu/ti
|
||||
SKIP_NANOLIB = 1
|
||||
|
||||
SDK_DIR = hw/mcu/ti/msp430/msp430-gcc-support-files/include
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nuvoton
|
||||
|
||||
CFLAGS += \
|
||||
-flto \
|
||||
-mthumb \
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nuvoton
|
||||
|
||||
CFLAGS += \
|
||||
-flto \
|
||||
-mthumb \
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nuvoton
|
||||
|
||||
CFLAGS += \
|
||||
-flto \
|
||||
-mthumb \
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nuvoton
|
||||
|
||||
CFLAGS += \
|
||||
-flto \
|
||||
-mthumb \
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/nuvoton
|
||||
|
||||
CFLAGS += \
|
||||
-flto \
|
||||
-mthumb \
|
||||
|
@@ -282,6 +282,10 @@ int board_getchar(void) {
|
||||
return getchar_timeout_us(0);
|
||||
}
|
||||
|
||||
void board_putchar(int c) {
|
||||
stdio_putchar(c);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USB Interrupt Handler
|
||||
// rp2040 implementation will install appropriate handler when initializing
|
||||
|
@@ -1,18 +0,0 @@
|
||||
JLINK_DEVICE = rp2040_m0_0
|
||||
PYOCD_TARGET = rp2040
|
||||
|
||||
DEPS_SUBMODULES += hw/mcu/raspberry_pi/Pico-PIO-USB
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CMAKE_DEFSYM += -DCMAKE_BUILD_TYPE=Debug
|
||||
endif
|
||||
|
||||
$(BUILD):
|
||||
cmake -S . -B $(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) -DPICO_BUILD_DOCS=0 $(CMAKE_DEFSYM)
|
||||
|
||||
all: $(BUILD)
|
||||
$(MAKE) -C $(BUILD)
|
||||
|
||||
flash: flash-pyocd
|
||||
flash-uf2:
|
||||
@$(CP) $(BUILD)/$(PROJECT).uf2 /media/$(USER)/RPI-RP2
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/renesas/rx
|
||||
|
||||
# Cross Compiler for RX
|
||||
CROSS_COMPILE = rx-elf-
|
||||
|
||||
|
@@ -1,4 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/microchip
|
||||
ASF_DIR = hw/mcu/microchip/same70
|
||||
|
||||
CFLAGS += \
|
||||
|
@@ -1,4 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/microchip
|
||||
ASF_DIR = hw/mcu/microchip/same70
|
||||
|
||||
CFLAGS += \
|
||||
|
@@ -16,9 +16,6 @@ CFLAGS += \
|
||||
SILABS_FAMILY = efm32gg12b
|
||||
SILABS_CMSIS = hw/mcu/silabs/cmsis-dfp-$(SILABS_FAMILY)/Device/SiliconLabs/$(shell echo $(SILABS_FAMILY) | tr a-z A-Z)
|
||||
|
||||
DEPS_SUBMODULES += hw/mcu/silabs/cmsis-dfp-$(SILABS_FAMILY)
|
||||
DEPS_SUBMODULES += lib/CMSIS_5
|
||||
|
||||
LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
|
@@ -1,5 +1,3 @@
|
||||
DEPS_SUBMODULES += hw/mcu/sony/cxd56/spresense-exported-sdk
|
||||
|
||||
# Platforms are: Linux, Darwin, MSYS, CYGWIN
|
||||
PLATFORM := $(firstword $(subst _, ,$(shell uname -s 2>/dev/null)))
|
||||
|
||||
|
@@ -1,6 +1,4 @@
|
||||
ST_FAMILY = c0
|
||||
DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/st/cmsis_device_$(ST_FAMILY) hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
||||
ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
|
||||
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
||||
|
@@ -1,7 +1,5 @@
|
||||
UF2_FAMILY_ID = 0x647824b6
|
||||
ST_FAMILY = f0
|
||||
DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/st/cmsis_device_$(ST_FAMILY) hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
||||
ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
|
||||
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
||||
|
@@ -1,6 +1,4 @@
|
||||
ST_FAMILY = f1
|
||||
DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/st/cmsis_device_${ST_FAMILY} hw/mcu/st/stm32${ST_FAMILY}xx_hal_driver
|
||||
|
||||
ST_CMSIS = hw/mcu/st/cmsis_device_${ST_FAMILY}
|
||||
ST_HAL_DRIVER = hw/mcu/st/stm32${ST_FAMILY}xx_hal_driver
|
||||
|
||||
|
@@ -2,11 +2,6 @@ ST_FAMILY = f2
|
||||
ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
|
||||
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
||||
DEPS_SUBMODULES += \
|
||||
lib/CMSIS_5 \
|
||||
$(ST_CMSIS) \
|
||||
$(ST_HAL_DRIVER)
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m3
|
||||
|
||||
|
@@ -78,6 +78,10 @@ void OTG_HS_IRQHandler(void) {
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_init(void) {
|
||||
SCB_EnableICache();
|
||||
|
||||
HAL_Init();
|
||||
|
||||
board_clock_init();
|
||||
|
||||
// Enable All GPIOs clocks
|
||||
|
@@ -1,6 +1,5 @@
|
||||
UF2_FAMILY_ID = 0x53b80f00
|
||||
ST_FAMILY = f7
|
||||
DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/st/cmsis_device_$(ST_FAMILY) hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
||||
ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
|
||||
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
@@ -1,5 +1,4 @@
|
||||
ST_FAMILY = g0
|
||||
DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/st/cmsis_device_$(ST_FAMILY) hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
||||
ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
|
||||
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
@@ -98,6 +98,10 @@ static void trace_etm_init(void) {
|
||||
#endif
|
||||
|
||||
void board_init(void) {
|
||||
SCB_EnableICache();
|
||||
|
||||
HAL_Init();
|
||||
|
||||
// Implemented in board.h
|
||||
SystemClock_Config();
|
||||
|
||||
|
@@ -1,9 +1,7 @@
|
||||
set(MCU_VARIANT stm32h7s3xx)
|
||||
set(JLINK_DEVICE stm32h7s3xx)
|
||||
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/stm32h7s3xx_flash.ld)
|
||||
set(LD_FILE_Clang ${LD_FILE_GNU})
|
||||
set(LD_FILE_IAR ${CMAKE_CURRENT_LIST_DIR}/stm32h7s3xx_flash.icf)
|
||||
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
|
@@ -7,10 +7,6 @@ JLINK_DEVICE = stm32h7s3xx
|
||||
# flash target using on-board stlink
|
||||
flash: flash-stlink
|
||||
|
||||
# Linker
|
||||
LD_FILE_GCC = $(BOARD_PATH)/stm32h7s3xx_flash.ld
|
||||
LD_FILE_IAR = $(BOARD_PATH)/stm32h7s3xx_flash.icf
|
||||
|
||||
SRC_C += \
|
||||
$(ST_TCPP0203)/tcpp0203.c \
|
||||
$(ST_TCPP0203)/tcpp0203_reg.c \
|
||||
|
@@ -1,55 +0,0 @@
|
||||
/*###ICF### Section handled by ICF editor, don't touch! ****/
|
||||
/*-Editor annotation file-*/
|
||||
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
|
||||
/*-Specials-*/
|
||||
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
|
||||
/*-Memory Regions-*/
|
||||
define symbol NONCACHEABLEBUFFER_size = 0x4000;
|
||||
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
|
||||
define symbol __ICFEDIT_region_ROM_end__ = 0x0800FFFF;
|
||||
define symbol __ICFEDIT_region_RAM_start__ = 0x24000000;
|
||||
define symbol __ICFEDIT_region_RAM_end__ = 0x2404FFFF - NONCACHEABLEBUFFER_size;
|
||||
define symbol NONCACHEABLEBUFFER_start = __ICFEDIT_region_RAM_end__ + 1;
|
||||
define symbol NONCACHEABLEBUFFER_end = __ICFEDIT_region_RAM_end__ + NONCACHEABLEBUFFER_size;
|
||||
|
||||
|
||||
/*-Sizes-*/
|
||||
define symbol __ICFEDIT_size_cstack__ = 0x800;
|
||||
define symbol __ICFEDIT_size_heap__ = 0x200;
|
||||
/**** End of ICF editor section. ###ICF###*/
|
||||
|
||||
define symbol __region_ITCM_start__ = 0x00000000;
|
||||
define symbol __region_ITCM_end__ = 0x0000FFFF;
|
||||
define symbol __region_DTCM_start__ = 0x20000000;
|
||||
define symbol __region_DTCM_end__ = 0x2000FFFF;
|
||||
define symbol __region_SRAMAHB_start__ = 0x30000000;
|
||||
define symbol __region_SRAMAHB_end__ = 0x30007FFF;
|
||||
define symbol __region_BKPSRAM_start__ = 0x38800000;
|
||||
define symbol __region_BKPSRAM_end__ = 0x38800FFF;
|
||||
|
||||
export symbol NONCACHEABLEBUFFER_start;
|
||||
export symbol NONCACHEABLEBUFFER_size;
|
||||
|
||||
export symbol __ICFEDIT_region_ROM_start__;
|
||||
export symbol __ICFEDIT_region_ROM_end__;
|
||||
define memory mem with size = 4G;
|
||||
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
|
||||
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
|
||||
define region NONCACHEABLE_region = mem:[from NONCACHEABLEBUFFER_start to NONCACHEABLEBUFFER_end];
|
||||
define region ITCM_region = mem:[from __region_ITCM_start__ to __region_ITCM_end__];
|
||||
define region DTCM_region = mem:[from __region_DTCM_start__ to __region_DTCM_end__];
|
||||
define region SRAMAHB_region = mem:[from __region_SRAMAHB_start__ to __region_SRAMAHB_end__];
|
||||
define region BKPSRAM_region = mem:[from __region_BKPSRAM_start__ to __region_BKPSRAM_end__];
|
||||
|
||||
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
|
||||
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
|
||||
|
||||
initialize by copy { readwrite };
|
||||
do not initialize { section .noinit };
|
||||
|
||||
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
|
||||
|
||||
place in ROM_region { readonly };
|
||||
place in RAM_region { readwrite };
|
||||
place in NONCACHEABLE_region { section noncacheable_buffer };
|
||||
place in DTCM_region { block CSTACK, block HEAP };
|
@@ -123,10 +123,159 @@ void log_swo_init(void)
|
||||
#define log_swo_init()
|
||||
#endif
|
||||
|
||||
static void MPU_AdjustRegionAddressSize(uint32_t Address, uint32_t Size, MPU_Region_InitTypeDef* pInit);
|
||||
static void MPU_Config(void)
|
||||
{
|
||||
MPU_Region_InitTypeDef MPU_InitStruct = {0};
|
||||
uint32_t index = MPU_REGION_NUMBER0;
|
||||
uint32_t address;
|
||||
uint32_t size;
|
||||
|
||||
/* Disable the MPU */
|
||||
HAL_MPU_Disable();
|
||||
|
||||
/* Initialize the background region */
|
||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||
MPU_InitStruct.Number = index;
|
||||
MPU_InitStruct.BaseAddress = 0x0;
|
||||
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
|
||||
MPU_InitStruct.SubRegionDisable = 0x87;
|
||||
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
|
||||
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
|
||||
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
|
||||
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
|
||||
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
index++;
|
||||
|
||||
/* Initialize the non cacheable region */
|
||||
#if defined ( __ICCARM__ )
|
||||
/* get the region attribute form the icf file */
|
||||
extern uint32_t NONCACHEABLEBUFFER_start;
|
||||
extern uint32_t NONCACHEABLEBUFFER_size;
|
||||
|
||||
address = (uint32_t)&NONCACHEABLEBUFFER_start;
|
||||
size = (uint32_t)&NONCACHEABLEBUFFER_size;
|
||||
|
||||
#elif defined (__CC_ARM) || defined(__ARMCC_VERSION)
|
||||
extern uint32_t Image$$RW_NONCACHEABLEBUFFER$$Base;
|
||||
extern uint32_t Image$$RW_NONCACHEABLEBUFFER$$Length;
|
||||
extern uint32_t Image$$RW_NONCACHEABLEBUFFER$$ZI$$Length;
|
||||
|
||||
address = (uint32_t)&Image$$RW_NONCACHEABLEBUFFER$$Base;
|
||||
size = (uint32_t)&Image$$RW_NONCACHEABLEBUFFER$$Length + (uint32_t)&Image$$RW_NONCACHEABLEBUFFER$$ZI$$Length;
|
||||
#elif defined ( __GNUC__ )
|
||||
extern int __NONCACHEABLEBUFFER_BEGIN;
|
||||
extern int __NONCACHEABLEBUFFER_END;
|
||||
|
||||
address = (uint32_t)&__NONCACHEABLEBUFFER_BEGIN;
|
||||
size = (uint32_t)&__NONCACHEABLEBUFFER_END - (uint32_t)&__NONCACHEABLEBUFFER_BEGIN;
|
||||
#else
|
||||
#error "Compiler toolchain is unsupported"
|
||||
#endif
|
||||
|
||||
if (size != 0)
|
||||
{
|
||||
/* Configure the MPU attributes as Normal Non Cacheable */
|
||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
|
||||
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
||||
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
|
||||
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
|
||||
MPU_InitStruct.Number = index;
|
||||
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
|
||||
MPU_InitStruct.SubRegionDisable = 0x00;
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
|
||||
MPU_AdjustRegionAddressSize(address, size, &MPU_InitStruct);
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
index++;
|
||||
}
|
||||
|
||||
/* Initialize the region corresponding to the execution area
|
||||
(external or internal flash or external or internal RAM
|
||||
depending on scatter file definition) */
|
||||
#if defined ( __ICCARM__ )
|
||||
extern uint32_t __ICFEDIT_region_ROM_start__;
|
||||
extern uint32_t __ICFEDIT_region_ROM_end__;
|
||||
address = (uint32_t)&__ICFEDIT_region_ROM_start__;
|
||||
size = (uint32_t)&__ICFEDIT_region_ROM_end__ - (uint32_t)&__ICFEDIT_region_ROM_start__ + 1;
|
||||
#elif defined (__CC_ARM) || defined(__ARMCC_VERSION)
|
||||
extern uint32_t Image$$ER_ROM$$Base;
|
||||
extern uint32_t Image$$ER_ROM$$Limit;
|
||||
address = (uint32_t)&Image$$ER_ROM$$Base;
|
||||
size = (uint32_t)&Image$$ER_ROM$$Limit-(uint32_t)&Image$$ER_ROM$$Base;
|
||||
#elif defined ( __GNUC__ )
|
||||
extern uint32_t __FLASH_BEGIN;
|
||||
extern uint32_t __FLASH_SIZE;
|
||||
address = (uint32_t)&__FLASH_BEGIN;
|
||||
size = (uint32_t)&__FLASH_SIZE;
|
||||
#else
|
||||
#error "Compiler toolchain is unsupported"
|
||||
#endif
|
||||
|
||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||
MPU_InitStruct.Number = index;
|
||||
MPU_InitStruct.SubRegionDisable = 0u;
|
||||
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
|
||||
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
|
||||
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
|
||||
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
|
||||
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
|
||||
MPU_AdjustRegionAddressSize(address, size, &MPU_InitStruct);
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
index++;
|
||||
|
||||
/* Reset unused MPU regions */
|
||||
for(; index < __MPU_REGIONCOUNT ; index++)
|
||||
{
|
||||
/* All unused regions disabled */
|
||||
MPU_InitStruct.Enable = MPU_REGION_DISABLE;
|
||||
MPU_InitStruct.Number = index;
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
}
|
||||
|
||||
/* Enable the MPU */
|
||||
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function adjusts the MPU region Address and Size within an MPU configuration.
|
||||
* @param Address memory address
|
||||
* @param Size memory size
|
||||
* @param pInit pointer to an MPU initialization structure
|
||||
* @retval None
|
||||
*/
|
||||
static void MPU_AdjustRegionAddressSize(uint32_t Address, uint32_t Size, MPU_Region_InitTypeDef* pInit)
|
||||
{
|
||||
/* Compute the MPU region size */
|
||||
pInit->Size = ((31 - __CLZ(Size)) - 1);
|
||||
if (Size > (1u << (pInit->Size + 1)))
|
||||
{
|
||||
pInit->Size++;
|
||||
}
|
||||
uint32_t Modulo = Address % (1 << (pInit->Size - 1));
|
||||
if (0 != Modulo)
|
||||
{
|
||||
/* Align address with MPU region size considering there is no need to increase the size */
|
||||
pInit->BaseAddress = Address - Modulo;
|
||||
}
|
||||
else
|
||||
{
|
||||
pInit->BaseAddress = Address;
|
||||
}
|
||||
}
|
||||
|
||||
void board_init(void) {
|
||||
HAL_Init();
|
||||
|
||||
MPU_Config();
|
||||
SCB_EnableICache();
|
||||
SCB_EnableDCache();
|
||||
|
||||
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
||||
|
||||
// Implemented in board.h
|
||||
SystemClock_Config();
|
||||
|
||||
|
@@ -54,7 +54,7 @@ function(add_board_target BOARD_TARGET)
|
||||
set(STARTUP_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s)
|
||||
|
||||
if(NOT DEFINED LD_FILE_GNU)
|
||||
set(LD_FILE_GNU ${ST_CMSIS}/Source/Templates/gcc/linker/${MCU_VARIANT}_flash.ld)
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/${MCU_VARIANT}_flash.ld)
|
||||
endif()
|
||||
set(LD_FILE_Clang ${LD_FILE_GNU})
|
||||
if(NOT DEFINED LD_FILE_IAR)
|
||||
@@ -87,8 +87,8 @@ function(add_board_target BOARD_TARGET)
|
||||
BOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED}
|
||||
BOARD_TUH_RHPORT=${RHPORT_HOST}
|
||||
BOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED}
|
||||
SEGGER_RTT_SECTION="noncacheable_buffer"
|
||||
BUFFER_SIZE_UP=0x3000
|
||||
SEGGER_RTT_SECTION=\"noncacheable_buffer\"
|
||||
BUFFER_SIZE_UP=0x300
|
||||
)
|
||||
|
||||
update_board(${BOARD_TARGET})
|
||||
|
@@ -43,8 +43,8 @@ CFLAGS += \
|
||||
-DBOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED} \
|
||||
-DBOARD_TUH_RHPORT=${RHPORT_HOST} \
|
||||
-DBOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED} \
|
||||
-DSEGGER_RTT_SECTION=\"noncacheable_buffer\" \
|
||||
-DBUFFER_SIZE_UP=0x3000 \
|
||||
-DSEGGER_RTT_SECTION="noncacheable_buffer" \
|
||||
-DBUFFER_SIZE_UP=0x300 \
|
||||
|
||||
# GCC Flags
|
||||
CFLAGS_GCC += \
|
||||
@@ -91,5 +91,5 @@ SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_$(MCU_VARIANT).s
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_$(MCU_VARIANT).s
|
||||
|
||||
# Linker
|
||||
LD_FILE_GCC ?= $(ST_CMSIS)/Source/Templates/gcc/linker/$(MCU_VARIANT)_flash.ld
|
||||
LD_FILE_GCC ?= $(FAMILY_PATH)/linker/$(MCU_VARIANT)_flash.ld
|
||||
LD_FILE_IAR ?= $(ST_CMSIS)/Source/Templates/iar/linker/$(MCU_VARIANT)_flash.icf
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user