|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2019 Ha Thach (tinyusb.org) |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +#ifndef _TUSB_CONFIG_H_ |
| 27 | +#define _TUSB_CONFIG_H_ |
| 28 | + |
| 29 | +#ifdef __cplusplus |
| 30 | + extern "C" { |
| 31 | +#endif |
| 32 | + |
| 33 | +//-------------------------------------------------------------------- |
| 34 | +// Override Assert Handler |
| 35 | +//-------------------------------------------------------------------- |
| 36 | +#include "stm32f7xx_hal.h" |
| 37 | +#include <stdio.h> |
| 38 | + |
| 39 | +#define CUSTOM_TU_ASSERT_DEFINE(_cond, _ret) \ |
| 40 | + do { \ |
| 41 | + if ( !(_cond) ) { \ |
| 42 | + printf("ASSERT FAILED in %s at line %d\r\n", __func__, __LINE__); \ |
| 43 | + TU_BREAKPOINT(); /* break if in debugger */ \ |
| 44 | + HAL_Delay(1000); /* 1 second delay before reboot */ \ |
| 45 | + NVIC_SystemReset(); /* Reboot the system */ \ |
| 46 | + } \ |
| 47 | + } while(0) |
| 48 | + |
| 49 | +#define CUSTOM_TU_ASSERT_1ARGS(_cond) CUSTOM_TU_ASSERT_DEFINE(_cond, false) |
| 50 | +#define CUSTOM_TU_ASSERT_2ARGS(_cond, _ret) CUSTOM_TU_ASSERT_DEFINE(_cond, _ret) |
| 51 | +#define CUSTOM_TU_GET_3RD_ARG(arg1, arg2, arg3, ...) arg3 |
| 52 | + |
| 53 | +// Override the default TU_ASSERT macro to print the assert message and reboot |
| 54 | +#undef TU_ASSERT |
| 55 | +#define TU_ASSERT(...) CUSTOM_TU_GET_3RD_ARG(__VA_ARGS__, CUSTOM_TU_ASSERT_2ARGS, CUSTOM_TU_ASSERT_1ARGS, _dummy)(__VA_ARGS__) |
| 56 | + |
| 57 | + |
| 58 | +//-------------------------------------------------------------------- |
| 59 | +// Common Configuration |
| 60 | +//-------------------------------------------------------------------- |
| 61 | + |
| 62 | +// defined by compiler flags for flexibility |
| 63 | +#ifndef CFG_TUSB_MCU |
| 64 | +#define CFG_TUSB_MCU OPT_MCU_STM32F7 |
| 65 | +#endif |
| 66 | + |
| 67 | +/* -DCFG_TUSB_MCU=OPT_MCU_STM32H7 \ |
| 68 | + * -DBOARD_TUD_RHPORT=${RHPORT_DEVICE} \ |
| 69 | + * -DBOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED} \ |
| 70 | + * -DBOARD_TUH_RHPORT=${RHPORT_HOST} \ |
| 71 | + * -DBOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED} \ |
| 72 | + */ |
| 73 | + |
| 74 | +#ifndef CFG_TUSB_OS |
| 75 | +#define CFG_TUSB_OS OPT_OS_FREERTOS |
| 76 | +#endif |
| 77 | + |
| 78 | +#ifndef CFG_TUSB_DEBUG |
| 79 | +#define CFG_TUSB_DEBUG 0 |
| 80 | +#endif |
| 81 | + |
| 82 | +/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. |
| 83 | + * Tinyusb use follows macros to declare transferring memory so that they can be put |
| 84 | + * into those specific section. |
| 85 | + * e.g |
| 86 | + * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) |
| 87 | + * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) |
| 88 | + */ |
| 89 | +#ifndef CFG_TUH_MEM_SECTION |
| 90 | +#define CFG_TUH_MEM_SECTION |
| 91 | +#endif |
| 92 | + |
| 93 | +#ifndef CFG_TUH_MEM_ALIGN |
| 94 | +#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4))) |
| 95 | +#endif |
| 96 | + |
| 97 | +//-------------------------------------------------------------------- |
| 98 | +// Host Configuration |
| 99 | +//-------------------------------------------------------------------- |
| 100 | + |
| 101 | +// Enable Host stack |
| 102 | +#define CFG_TUH_ENABLED 1 |
| 103 | + |
| 104 | +// Default is max speed that hardware controller could support with on-chip PHY |
| 105 | +#define CFG_TUH_MAX_SPEED OPT_MODE_HIGH_SPEED |
| 106 | + |
| 107 | +//------------------------- Board Specific -------------------------- |
| 108 | + |
| 109 | +// RHPort number used for host can be defined by board.mk, default to port 1 (HS port) |
| 110 | +#ifndef BOARD_TUH_RHPORT |
| 111 | +#define BOARD_TUH_RHPORT 1 |
| 112 | +#endif |
| 113 | + |
| 114 | +// RHPort max operational speed can defined by board.mk |
| 115 | +#ifndef BOARD_TUH_MAX_SPEED |
| 116 | +#define BOARD_TUH_MAX_SPEED OPT_MODE_HIGH_SPEED |
| 117 | +#endif |
| 118 | + |
| 119 | +//-------------------------------------------------------------------- |
| 120 | +// Driver Configuration |
| 121 | +//-------------------------------------------------------------------- |
| 122 | + |
| 123 | +// Size of buffer to hold descriptors and other data used for enumeration |
| 124 | +#define CFG_TUH_ENUMERATION_BUFSIZE 512 |
| 125 | + |
| 126 | +#define CFG_TUH_HUB 1 // number of supported hubs |
| 127 | +#define CFG_TUH_CDC 0 // CDC ACM |
| 128 | +#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces |
| 129 | +#define CFG_TUH_MSC 0 |
| 130 | +#define CFG_TUH_VENDOR 0 |
| 131 | + |
| 132 | +// max device support (excluding hub device): 1 hub typically has 4 ports |
| 133 | +#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1) |
| 134 | + |
| 135 | +//------------- HID -------------// |
| 136 | +#define CFG_TUH_HID_EPIN_BUFSIZE 64 |
| 137 | +#define CFG_TUH_HID_EPOUT_BUFSIZE 64 |
| 138 | + |
| 139 | + |
| 140 | +#ifdef __cplusplus |
| 141 | + } |
| 142 | +#endif |
| 143 | + |
| 144 | +#endif /* _TUSB_CONFIG_H_ */ |
0 commit comments