chibios_config.h (7088B)
1 /* Copyright 2019 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 #pragma once 17 18 #include "compiler_support.h" 19 20 #ifndef USB_VBUS_PIN 21 # define SPLIT_USB_DETECT // Force this on when dedicated pin is not used 22 #endif 23 24 #if defined(MCU_RP) 25 # define CPU_CLOCK RP_CORE_CLK 26 // ChibiOS uses the RP2040 timer peripheral as its real time counter, this timer 27 // is monotonic and running at 1MHz. 28 # define REALTIME_COUNTER_CLOCK 1000000 29 30 # define USE_GPIOV1 31 # define PAL_OUTPUT_TYPE_OPENDRAIN STATIC_ASSERT(0, "RP2040 has no Open Drain GPIO configuration, setting this is not possible"); 32 33 /* Aliases for GPIO PWM channels - every pin has at least one PWM channel 34 * assigned */ 35 # define RP2040_PWM_CHANNEL_A 1U 36 # define RP2040_PWM_CHANNEL_B 2U 37 38 # ifndef BACKLIGHT_PAL_MODE 39 # define BACKLIGHT_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE) 40 # endif 41 # define BACKLIGHT_PWM_COUNTER_FREQUENCY 1000000 42 # ifndef BACKLIGHT_PWM_PERIOD 43 # define BACKLIGHT_PWM_PERIOD BACKLIGHT_PWM_COUNTER_FREQUENCY / 2048 44 # endif 45 46 # ifndef AUDIO_PWM_PAL_MODE 47 # define AUDIO_PWM_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE) 48 # endif 49 # define AUDIO_PWM_COUNTER_FREQUENCY 500000 50 51 # define usb_lld_endpoint_fields 52 53 # ifndef I2C1_SCL_PAL_MODE 54 # define I2C1_SCL_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4) 55 # endif 56 # ifndef I2C1_SDA_PAL_MODE 57 # define I2C1_SDA_PAL_MODE (PAL_MODE_ALTERNATE_I2C | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_PUE | PAL_RP_PAD_DRIVE4) 58 # endif 59 60 # define USE_I2CV1_CONTRIB 61 # if !defined(I2C1_CLOCK_SPEED) 62 # define I2C1_CLOCK_SPEED 400000 63 # endif 64 65 # ifndef SPI_SCK_PAL_MODE 66 # define SPI_SCK_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4) 67 # endif 68 # ifndef SPI_MOSI_PAL_MODE 69 # define SPI_MOSI_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4) 70 # endif 71 # ifndef SPI_MISO_PAL_MODE 72 # define SPI_MISO_PAL_MODE (PAL_MODE_ALTERNATE_SPI | PAL_RP_PAD_SLEWFAST | PAL_RP_PAD_DRIVE4) 73 # endif 74 75 # ifndef UART_TX_PAL_MODE 76 # define UART_TX_PAL_MODE PAL_MODE_ALTERNATE_UART 77 # endif 78 # ifndef UART_RX_PAL_MODE 79 # define UART_RX_PAL_MODE PAL_MODE_ALTERNATE_UART 80 # endif 81 # ifndef UART_CTS_PAL_MODE 82 # define UART_CTS_PAL_MODE PAL_MODE_ALTERNATE_UART 83 # endif 84 # ifndef UART_RTS_PAL_MODE 85 # define UART_RTS_PAL_MODE PAL_MODE_ALTERNATE_UART 86 # endif 87 88 #endif 89 90 // STM32 compatibility 91 #if defined(MCU_STM32) 92 # if defined(STM32_CORE_CK) 93 # define CPU_CLOCK STM32_CORE_CK 94 # else 95 # define CPU_CLOCK STM32_SYSCLK 96 # endif 97 98 # if defined(STM32F1XX) 99 # define USE_GPIOV1 100 # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_STM32_ALTERNATE_OPENDRAIN 101 # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_STM32_ALTERNATE_PUSHPULL 102 # define AUDIO_PWM_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL 103 # else 104 # define PAL_OUTPUT_TYPE_OPENDRAIN PAL_STM32_OTYPE_OPENDRAIN 105 # define PAL_OUTPUT_TYPE_PUSHPULL PAL_STM32_OTYPE_PUSHPULL 106 # define PAL_OUTPUT_SPEED_HIGHEST PAL_STM32_OSPEED_HIGHEST 107 # define PAL_PUPDR_FLOATING PAL_STM32_PUPDR_FLOATING 108 # endif 109 110 # if defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32L1XX) 111 # define USE_I2CV1 112 # endif 113 114 # if defined(STM32G0XX) || defined(STM32G4XX) || defined(STM32L5XX) || defined(STM32H7XX) 115 # define USE_USARTV3 116 # endif 117 118 #endif 119 120 // GD32 compatibility 121 #if defined(MCU_GD32V) 122 # define CPU_CLOCK GD32_SYSCLK 123 124 # if defined(GD32VF103) 125 # define USE_GPIOV1 126 # define USE_I2CV1 127 # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_GD32_ALTERNATE_OPENDRAIN 128 # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_GD32_ALTERNATE_PUSHPULL 129 # define AUDIO_PWM_PAL_MODE PAL_MODE_GD32_ALTERNATE_PUSHPULL 130 # endif 131 #endif 132 133 // WB32 compatibility 134 #if defined(MCU_WB32) 135 # define CPU_CLOCK WB32_MAINCLK 136 137 # if defined(WB32F3G71xx) || defined(WB32FQ95xx) 138 # define PAL_OUTPUT_TYPE_OPENDRAIN PAL_WB32_OTYPE_OPENDRAIN 139 # define PAL_OUTPUT_TYPE_PUSHPULL PAL_WB32_OTYPE_PUSHPULL 140 # define PAL_OUTPUT_SPEED_HIGHEST PAL_WB32_OSPEED_HIGH 141 # define PAL_PUPDR_FLOATING PAL_WB32_PUPDR_FLOATING 142 143 # define SPI_SCK_FLAGS PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_WB32_CURRENT_LEVEL3 144 # endif 145 #endif 146 147 // AT32 compatibility 148 #if defined(MCU_AT32) 149 # define CPU_CLOCK AT32_SYSCLK 150 151 # if defined(AT32F415) 152 # define USE_GPIOV1 153 # define USE_I2CV1 154 # define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_AT32_MUX_OPENDRAIN 155 # define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_AT32_MUX_PUSHPULL 156 # define AUDIO_PWM_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL 157 # endif 158 #endif 159 160 #if defined(GD32VF103) 161 /* This chip has the same API as STM32F103, but uses different names for literally the same thing. 162 * As of 4.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake 163 * we just redefine the GD32 names. */ 164 # include "gd32v_compatibility.h" 165 #endif 166 167 // teensy compatibility 168 #if defined(MCU_KINETIS) 169 # define CPU_CLOCK KINETIS_SYSCLK_FREQUENCY 170 171 # if defined(K20x) || defined(K60x) || defined(KL2x) 172 # define USE_I2CV1 173 # define USE_I2CV1_CONTRIB // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed 174 # define USE_GPIOV1 175 # endif 176 #endif 177 178 #if defined(MCU_MIMXRT1062) 179 # include "clock_config.h" 180 # define CPU_CLOCK BOARD_BOOTCLOCKRUN_CORE_CLOCK 181 #endif 182 183 #if defined(HT32) 184 # define CPU_CLOCK HT32_CK_SYS_FREQUENCY 185 # define PAL_MODE_ALTERNATE PAL_HT32_MODE_AF 186 # define PAL_OUTPUT_TYPE_OPENDRAIN (PAL_HT32_MODE_OD | PAL_HT32_MODE_DIR) 187 # define PAL_OUTPUT_TYPE_PUSHPULL PAL_HT32_MODE_DIR 188 # define PAL_OUTPUT_SPEED_HIGHEST 0 189 #endif 190 191 #if !defined(REALTIME_COUNTER_CLOCK) 192 # define REALTIME_COUNTER_CLOCK CPU_CLOCK 193 #endif 194 195 // SPI Fallbacks 196 #ifndef SPI_SCK_FLAGS 197 # define SPI_SCK_FLAGS PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST 198 #endif 199 200 #ifndef SPI_MOSI_FLAGS 201 # define SPI_MOSI_FLAGS PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST 202 #endif 203 204 #ifndef SPI_MISO_FLAGS 205 # define SPI_MISO_FLAGS PAL_MODE_ALTERNATE(SPI_MISO_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST 206 #endif