diff options
| author | Stefan Kerkmann <karlk90@pm.me> | 2025-05-19 07:51:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-19 15:51:28 +1000 |
| commit | f686ad9e6361e05fcfa78f453f90cd72181a7516 (patch) | |
| tree | f0ba7f854ecdf22b0825071e32b85d66a9aaef84 /platforms/chibios | |
| parent | a4ef1ae736cd58375affed966cf1399fe8df5774 (diff) | |
[Core] STM32G0x1 support (#24301)
Diffstat (limited to 'platforms/chibios')
7 files changed, 538 insertions, 2 deletions
diff --git a/platforms/chibios/boards/GENERIC_STM32_G0B1XB/board/board.mk b/platforms/chibios/boards/GENERIC_STM32_G0B1XB/board/board.mk new file mode 100644 index 0000000000..7e551e4dc7 --- /dev/null +++ b/platforms/chibios/boards/GENERIC_STM32_G0B1XB/board/board.mk | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | # List of all the board related files. | ||
| 2 | BOARDSRC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO64_G0B1RE/board.c | ||
| 3 | |||
| 4 | # Extra files | ||
| 5 | BOARDSRC += $(BOARD_PATH)/board/extra.c | ||
| 6 | |||
| 7 | # Required include directories | ||
| 8 | BOARDINC = $(CHIBIOS)/os/hal/boards/ST_NUCLEO64_G0B1RE | ||
| 9 | |||
| 10 | # Shared variables | ||
| 11 | ALLCSRC += $(BOARDSRC) | ||
| 12 | ALLINC += $(BOARDINC) | ||
diff --git a/platforms/chibios/boards/GENERIC_STM32_G0B1XB/board/extra.c b/platforms/chibios/boards/GENERIC_STM32_G0B1XB/board/extra.c new file mode 100644 index 0000000000..4dbc5dd8b4 --- /dev/null +++ b/platforms/chibios/boards/GENERIC_STM32_G0B1XB/board/extra.c | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | // Copyright 2025 Stefan Kerkmann (@karlk90) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include <hal.h> | ||
| 5 | |||
| 6 | #define FLASH_KEY1 0x45670123U | ||
| 7 | #define FLASH_KEY2 0xCDEF89ABU | ||
| 8 | #define FLASH_OPTKEY1 0x08192A3BU | ||
| 9 | #define FLASH_OPTKEY2 0x4C5D6E7FU | ||
| 10 | #define FLASH_OPTR_CLR_MASK (FLASH_OPTR_nBOOT_SEL) | ||
| 11 | #define FLASH_OPTR_SET_MASK (FLASH_OPTR_NRST_MODE_Msk) | ||
| 12 | |||
| 13 | static void wait_for_flash(void) { | ||
| 14 | while (READ_BIT(FLASH->SR, FLASH_SR_BSY1)) { | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | void __attribute__((constructor)) enable_boot0_and_nrst_pin(void) { | ||
| 19 | // Only apply on STM32G0x1 devices, see RM0444 Rev 6, Table 265: "DEV_ID | ||
| 20 | // and REV_ID field values." | ||
| 21 | switch (READ_BIT(DBG->IDCODE, DBG_IDCODE_DEV_ID)) { | ||
| 22 | case 0x467: // STM32G0B1xx and STM32G0C1xx | ||
| 23 | case 0x460: // STM32G071xx and STM32G081xx | ||
| 24 | case 0x456: // STM32G051xx and STM32G061xx | ||
| 25 | case 0x466: // STM32G041xx and STM32G031xx | ||
| 26 | break; | ||
| 27 | default: | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | uint32_t optr = FLASH->OPTR; | ||
| 32 | |||
| 33 | // Make sure that: | ||
| 34 | // 1. legacy boot0 pin handling is enabled. | ||
| 35 | // OPTR[24] = 0 | ||
| 36 | // 2. legacy nRST pin handling is enabled. | ||
| 37 | // OPTR[28:27] = 0b11 | ||
| 38 | // To match the default behavior found in older (F0/F1/F3/F4) STM32 devices. | ||
| 39 | if (READ_BIT(optr, FLASH_OPTR_CLR_MASK) || (READ_BIT(optr, FLASH_OPTR_SET_MASK) != FLASH_OPTR_SET_MASK)) { | ||
| 40 | if (READ_BIT(FLASH->CR, FLASH_CR_LOCK)) { | ||
| 41 | WRITE_REG(FLASH->KEYR, FLASH_KEY1); | ||
| 42 | WRITE_REG(FLASH->KEYR, FLASH_KEY2); | ||
| 43 | while (READ_BIT(FLASH->CR, FLASH_CR_LOCK)) { | ||
| 44 | } | ||
| 45 | wait_for_flash(); | ||
| 46 | } | ||
| 47 | if (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK)) { | ||
| 48 | WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1); | ||
| 49 | WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2); | ||
| 50 | while (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK)) { | ||
| 51 | } | ||
| 52 | wait_for_flash(); | ||
| 53 | } | ||
| 54 | |||
| 55 | MODIFY_REG(FLASH->OPTR, FLASH_OPTR_CLR_MASK, FLASH_OPTR_SET_MASK); | ||
| 56 | wait_for_flash(); | ||
| 57 | |||
| 58 | SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); | ||
| 59 | wait_for_flash(); | ||
| 60 | |||
| 61 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); | ||
| 62 | wait_for_flash(); | ||
| 63 | |||
| 64 | // Launch the option byte (re)loading, which resets the device. This | ||
| 65 | // should not return. | ||
| 66 | SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH); | ||
| 67 | } | ||
| 68 | } | ||
diff --git a/platforms/chibios/boards/GENERIC_STM32_G0B1XB/configs/config.h b/platforms/chibios/boards/GENERIC_STM32_G0B1XB/configs/config.h new file mode 100644 index 0000000000..bb2d1b5816 --- /dev/null +++ b/platforms/chibios/boards/GENERIC_STM32_G0B1XB/configs/config.h | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | // Copyright 2024 Stefan Kerkmann (@karlk90) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP | ||
| 6 | # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE | ||
| 7 | #endif | ||
diff --git a/platforms/chibios/boards/GENERIC_STM32_G0B1XB/configs/mcuconf.h b/platforms/chibios/boards/GENERIC_STM32_G0B1XB/configs/mcuconf.h new file mode 100644 index 0000000000..80726e0308 --- /dev/null +++ b/platforms/chibios/boards/GENERIC_STM32_G0B1XB/configs/mcuconf.h | |||
| @@ -0,0 +1,310 @@ | |||
| 1 | /* | ||
| 2 | ChibiOS - Copyright (C) 2006..2020 Giovanni Di Sirio | ||
| 3 | |||
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | you may not use this file except in compliance with the License. | ||
| 6 | You may obtain a copy of the License at | ||
| 7 | |||
| 8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | |||
| 10 | Unless required by applicable law or agreed to in writing, software | ||
| 11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | See the License for the specific language governing permissions and | ||
| 14 | limitations under the License. | ||
| 15 | */ | ||
| 16 | |||
| 17 | /* | ||
| 18 | * STM32G0xx drivers configuration. | ||
| 19 | * The following settings override the default settings present in | ||
| 20 | * the various device driver implementation headers. | ||
| 21 | * Note that the settings for each driver only have effect if the whole | ||
| 22 | * driver is enabled in halconf.h. | ||
| 23 | * | ||
| 24 | * IRQ priorities: | ||
| 25 | * 3...0 Lowest...Highest. | ||
| 26 | * | ||
| 27 | * DMA priorities: | ||
| 28 | * 0...3 Lowest...Highest. | ||
| 29 | */ | ||
| 30 | |||
| 31 | #ifndef MCUCONF_H | ||
| 32 | #define MCUCONF_H | ||
| 33 | |||
| 34 | #define STM32G0xx_MCUCONF | ||
| 35 | #define STM32G0B1_MCUCONF | ||
| 36 | #define STM32G0C1_MCUCONF | ||
| 37 | |||
| 38 | /* | ||
| 39 | * HAL driver system settings. | ||
| 40 | */ | ||
| 41 | #define STM32_NO_INIT FALSE | ||
| 42 | #define STM32_CLOCK_DYNAMIC TRUE | ||
| 43 | #define STM32_VOS STM32_VOS_RANGE1 | ||
| 44 | #define STM32_PWR_CR2 (STM32_PVDRT_LEV0 | STM32_PVDFT_LEV0 | STM32_PVDE_DISABLED) | ||
| 45 | #define STM32_PWR_CR3 (PWR_CR3_EIWUL) | ||
| 46 | #define STM32_PWR_CR4 (0U) | ||
| 47 | #define STM32_PWR_PUCRA (0U) | ||
| 48 | #define STM32_PWR_PDCRA (0U) | ||
| 49 | #define STM32_PWR_PUCRB (0U) | ||
| 50 | #define STM32_PWR_PDCRB (0U) | ||
| 51 | #define STM32_PWR_PUCRC (0U) | ||
| 52 | #define STM32_PWR_PDCRC (0U) | ||
| 53 | #define STM32_PWR_PUCRD (0U) | ||
| 54 | #define STM32_PWR_PDCRD (0U) | ||
| 55 | #define STM32_PWR_PUCRE (0U) | ||
| 56 | #define STM32_PWR_PDCRE (0U) | ||
| 57 | #define STM32_PWR_PUCRF (0U) | ||
| 58 | #define STM32_PWR_PDCRF (0U) | ||
| 59 | #define STM32_HSIDIV_VALUE 1 | ||
| 60 | #define STM32_HSI16_ENABLED TRUE | ||
| 61 | #define STM32_HSI48_ENABLED TRUE | ||
| 62 | #define STM32_HSE_ENABLED FALSE | ||
| 63 | #define STM32_LSI_ENABLED FALSE | ||
| 64 | #define STM32_LSE_ENABLED FALSE | ||
| 65 | #define STM32_SW STM32_SW_PLLRCLK | ||
| 66 | #define STM32_PLLSRC STM32_PLLSRC_HSI16 | ||
| 67 | #define STM32_PLLM_VALUE 2 | ||
| 68 | #define STM32_PLLN_VALUE 16 | ||
| 69 | #define STM32_PLLP_VALUE 2 | ||
| 70 | #define STM32_PLLQ_VALUE 4 | ||
| 71 | #define STM32_PLLR_VALUE 2 | ||
| 72 | #define STM32_HPRE STM32_HPRE_DIV1 | ||
| 73 | #define STM32_PPRE STM32_PPRE_DIV1 | ||
| 74 | #define STM32_MCOSEL STM32_MCOSEL_NOCLOCK | ||
| 75 | #define STM32_MCOPRE STM32_MCOPRE_DIV1 | ||
| 76 | #define STM32_LSCOSEL STM32_LSCOSEL_NOCLOCK | ||
| 77 | |||
| 78 | /* | ||
| 79 | * Peripherals clocks and sources. | ||
| 80 | */ | ||
| 81 | #define STM32_FDCANSEL STM32_USBSEL_HSI48 | ||
| 82 | #define STM32_USBSEL STM32_USBSEL_HSI48 | ||
| 83 | #define STM32_USART1SEL STM32_USART1SEL_SYSCLK | ||
| 84 | #define STM32_USART2SEL STM32_USART2SEL_SYSCLK | ||
| 85 | #define STM32_USART3SEL STM32_USART3SEL_SYSCLK | ||
| 86 | #define STM32_LPUART1SEL STM32_LPUART1SEL_SYSCLK | ||
| 87 | #define STM32_LPUART2SEL STM32_LPUART2SEL_SYSCLK | ||
| 88 | #define STM32_CECSEL STM32_CECSEL_HSI16DIV | ||
| 89 | #define STM32_I2C1SEL STM32_I2C1SEL_PCLK | ||
| 90 | #define STM32_I2C2SEL STM32_I2C1SEL_PCLK | ||
| 91 | #define STM32_I2S1SEL STM32_I2S1SEL_SYSCLK | ||
| 92 | #define STM32_I2S2SEL STM32_I2S2SEL_SYSCLK | ||
| 93 | #define STM32_LPTIM1SEL STM32_LPTIM1SEL_PCLK | ||
| 94 | #define STM32_LPTIM2SEL STM32_LPTIM2SEL_PCLK | ||
| 95 | #define STM32_TIM1SEL STM32_TIM1SEL_TIMPCLK | ||
| 96 | #define STM32_TIM15SEL STM32_TIM15SEL_TIMPCLK | ||
| 97 | #define STM32_RNGSEL STM32_RNGSEL_HSI16 | ||
| 98 | #define STM32_RNGDIV_VALUE 1 | ||
| 99 | #define STM32_ADCSEL STM32_ADCSEL_PLLPCLK | ||
| 100 | #define STM32_RTCSEL STM32_RTCSEL_NOCLOCK | ||
| 101 | |||
| 102 | /* | ||
| 103 | * Shared IRQ settings. | ||
| 104 | */ | ||
| 105 | #define STM32_IRQ_EXTI0_1_PRIORITY 3 | ||
| 106 | #define STM32_IRQ_EXTI2_3_PRIORITY 3 | ||
| 107 | #define STM32_IRQ_EXTI4_15_PRIORITY 3 | ||
| 108 | #define STM32_IRQ_EXTI1921_PRIORITY 3 | ||
| 109 | |||
| 110 | #define STM32_IRQ_USART1_PRIORITY 2 | ||
| 111 | #define STM32_IRQ_USART2_LP2_PRIORITY 2 | ||
| 112 | #define STM32_IRQ_USART3_4_5_6_LP1_PRIORITY 2 | ||
| 113 | |||
| 114 | #define STM32_IRQ_TIM1_UP_PRIORITY 1 | ||
| 115 | #define STM32_IRQ_TIM1_CC_PRIORITY 1 | ||
| 116 | #define STM32_IRQ_TIM2_PRIORITY 1 | ||
| 117 | #define STM32_IRQ_TIM3_4_PRIORITY 1 | ||
| 118 | #define STM32_IRQ_TIM6_PRIORITY 1 | ||
| 119 | #define STM32_IRQ_TIM7_PRIORITY 1 | ||
| 120 | #define STM32_IRQ_TIM14_PRIORITY 1 | ||
| 121 | #define STM32_IRQ_TIM15_PRIORITY 1 | ||
| 122 | #define STM32_IRQ_TIM16_PRIORITY 1 | ||
| 123 | #define STM32_IRQ_TIM17_PRIORITY 1 | ||
| 124 | |||
| 125 | /* | ||
| 126 | * ADC driver system settings. | ||
| 127 | */ | ||
| 128 | #define STM32_ADC_USE_ADC1 FALSE | ||
| 129 | #define STM32_ADC_ADC1_CFGR2 ADC_CFGR2_CKMODE_ADCCLK | ||
| 130 | #define STM32_ADC_ADC1_DMA_PRIORITY 2 | ||
| 131 | #define STM32_ADC_ADC1_DMA_IRQ_PRIORITY 2 | ||
| 132 | #define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 133 | #define STM32_ADC_PRESCALER_VALUE 2 | ||
| 134 | |||
| 135 | /* | ||
| 136 | * DAC driver system settings. | ||
| 137 | */ | ||
| 138 | #define STM32_DAC_DUAL_MODE FALSE | ||
| 139 | #define STM32_DAC_USE_DAC1_CH1 FALSE | ||
| 140 | #define STM32_DAC_USE_DAC1_CH2 FALSE | ||
| 141 | #define STM32_DAC_DAC1_CH1_IRQ_PRIORITY 3 | ||
| 142 | #define STM32_DAC_DAC1_CH2_IRQ_PRIORITY 3 | ||
| 143 | #define STM32_DAC_DAC1_CH1_DMA_PRIORITY 2 | ||
| 144 | #define STM32_DAC_DAC1_CH2_DMA_PRIORITY 2 | ||
| 145 | #define STM32_DAC_DAC1_CH1_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 146 | #define STM32_DAC_DAC1_CH2_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 147 | |||
| 148 | /* | ||
| 149 | * GPT driver system settings. | ||
| 150 | */ | ||
| 151 | #define STM32_GPT_USE_TIM1 FALSE | ||
| 152 | #define STM32_GPT_USE_TIM2 FALSE | ||
| 153 | #define STM32_GPT_USE_TIM3 FALSE | ||
| 154 | #define STM32_GPT_USE_TIM4 FALSE | ||
| 155 | #define STM32_GPT_USE_TIM6 FALSE | ||
| 156 | #define STM32_GPT_USE_TIM7 FALSE | ||
| 157 | #define STM32_GPT_USE_TIM14 FALSE | ||
| 158 | #define STM32_GPT_USE_TIM15 FALSE | ||
| 159 | #define STM32_GPT_USE_TIM16 FALSE | ||
| 160 | #define STM32_GPT_USE_TIM17 FALSE | ||
| 161 | |||
| 162 | /* | ||
| 163 | * I2C driver system settings. | ||
| 164 | */ | ||
| 165 | #define STM32_I2C_USE_I2C1 FALSE | ||
| 166 | #define STM32_I2C_USE_I2C2 FALSE | ||
| 167 | #define STM32_I2C_USE_I2C3 FALSE | ||
| 168 | #define STM32_I2C_BUSY_TIMEOUT 50 | ||
| 169 | #define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 170 | #define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 171 | #define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 172 | #define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 173 | #define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 174 | #define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 175 | #define STM32_I2C_I2C1_IRQ_PRIORITY 3 | ||
| 176 | #define STM32_I2C_I2C2_IRQ_PRIORITY 3 | ||
| 177 | #define STM32_I2C_I2C1_DMA_PRIORITY 3 | ||
| 178 | #define STM32_I2C_I2C2_DMA_PRIORITY 3 | ||
| 179 | #define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure") | ||
| 180 | |||
| 181 | /* | ||
| 182 | * ICU driver system settings. | ||
| 183 | */ | ||
| 184 | #define STM32_ICU_USE_TIM1 FALSE | ||
| 185 | #define STM32_ICU_USE_TIM2 FALSE | ||
| 186 | #define STM32_ICU_USE_TIM3 FALSE | ||
| 187 | #define STM32_ICU_USE_TIM4 FALSE | ||
| 188 | #define STM32_ICU_USE_TIM15 FALSE | ||
| 189 | |||
| 190 | /* | ||
| 191 | * PWM driver system settings. | ||
| 192 | */ | ||
| 193 | #define STM32_PWM_USE_TIM1 FALSE | ||
| 194 | #define STM32_PWM_USE_TIM2 FALSE | ||
| 195 | #define STM32_PWM_USE_TIM3 FALSE | ||
| 196 | #define STM32_PWM_USE_TIM4 FALSE | ||
| 197 | #define STM32_PWM_USE_TIM14 FALSE | ||
| 198 | #define STM32_PWM_USE_TIM15 FALSE | ||
| 199 | #define STM32_PWM_USE_TIM16 FALSE | ||
| 200 | #define STM32_PWM_USE_TIM17 FALSE | ||
| 201 | |||
| 202 | /* | ||
| 203 | * RTC driver system settings. | ||
| 204 | */ | ||
| 205 | #define STM32_RTC_PRESA_VALUE 32 | ||
| 206 | #define STM32_RTC_PRESS_VALUE 1024 | ||
| 207 | #define STM32_RTC_CR_INIT 0 | ||
| 208 | #define STM32_RTC_TAMPCR_INIT 0 | ||
| 209 | |||
| 210 | /* | ||
| 211 | * SERIAL driver system settings. | ||
| 212 | */ | ||
| 213 | #define STM32_SERIAL_USE_USART1 FALSE | ||
| 214 | #define STM32_SERIAL_USE_USART2 FALSE | ||
| 215 | #define STM32_SERIAL_USE_USART3 FALSE | ||
| 216 | #define STM32_SERIAL_USE_UART4 FALSE | ||
| 217 | #define STM32_SERIAL_USE_UART5 FALSE | ||
| 218 | #define STM32_SERIAL_USE_USART6 FALSE | ||
| 219 | #define STM32_SERIAL_USE_LPUART1 FALSE | ||
| 220 | #define STM32_SERIAL_USE_LPUART2 FALSE | ||
| 221 | |||
| 222 | /* | ||
| 223 | * SIO driver system settings. | ||
| 224 | */ | ||
| 225 | #define STM32_SIO_USE_USART1 FALSE | ||
| 226 | #define STM32_SIO_USE_USART2 FALSE | ||
| 227 | #define STM32_SIO_USE_USART3 FALSE | ||
| 228 | #define STM32_SIO_USE_UART4 FALSE | ||
| 229 | #define STM32_SIO_USE_UART5 FALSE | ||
| 230 | #define STM32_SIO_USE_USART6 FALSE | ||
| 231 | #define STM32_SIO_USE_LPUART1 FALSE | ||
| 232 | #define STM32_SIO_USE_LPUART2 FALSE | ||
| 233 | |||
| 234 | /* | ||
| 235 | * SPI driver system settings. | ||
| 236 | */ | ||
| 237 | #define STM32_SPI_USE_SPI1 FALSE | ||
| 238 | #define STM32_SPI_USE_SPI2 FALSE | ||
| 239 | #define STM32_SPI_USE_SPI3 FALSE | ||
| 240 | #define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 241 | #define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 242 | #define STM32_SPI_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 243 | #define STM32_SPI_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 244 | #define STM32_SPI_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 245 | #define STM32_SPI_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 246 | #define STM32_SPI_SPI1_DMA_PRIORITY 1 | ||
| 247 | #define STM32_SPI_SPI2_DMA_PRIORITY 1 | ||
| 248 | #define STM32_SPI_SPI3_DMA_PRIORITY 1 | ||
| 249 | #define STM32_SPI_SPI1_IRQ_PRIORITY 2 | ||
| 250 | #define STM32_SPI_SPI2_IRQ_PRIORITY 2 | ||
| 251 | #define STM32_SPI_SPI3_IRQ_PRIORITY 2 | ||
| 252 | #define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure") | ||
| 253 | |||
| 254 | /* | ||
| 255 | * ST driver system settings. | ||
| 256 | */ | ||
| 257 | #define STM32_ST_IRQ_PRIORITY 2 | ||
| 258 | #define STM32_ST_USE_TIMER 2 | ||
| 259 | |||
| 260 | /* | ||
| 261 | * TRNG driver system settings. | ||
| 262 | * NOTE: STM32G0C1 only. | ||
| 263 | */ | ||
| 264 | #define STM32_TRNG_USE_RNG1 FALSE | ||
| 265 | |||
| 266 | /* | ||
| 267 | * UART driver system settings. | ||
| 268 | */ | ||
| 269 | #define STM32_UART_USE_USART1 FALSE | ||
| 270 | #define STM32_UART_USE_USART2 FALSE | ||
| 271 | #define STM32_UART_USE_USART3 FALSE | ||
| 272 | #define STM32_UART_USE_UART4 FALSE | ||
| 273 | #define STM32_UART_USE_UART5 FALSE | ||
| 274 | #define STM32_UART_USE_USART6 FALSE | ||
| 275 | #define STM32_UART_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 276 | #define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 277 | #define STM32_UART_USART2_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 278 | #define STM32_UART_USART2_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 279 | #define STM32_UART_USART3_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 280 | #define STM32_UART_USART3_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 281 | #define STM32_UART_UART4_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 282 | #define STM32_UART_UART4_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 283 | #define STM32_UART_UART5_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 284 | #define STM32_UART_UART5_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 285 | #define STM32_UART_USART6_RX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 286 | #define STM32_UART_USART6_TX_DMA_STREAM STM32_DMA_STREAM_ID_ANY | ||
| 287 | #define STM32_UART_USART1_DMA_PRIORITY 0 | ||
| 288 | #define STM32_UART_USART2_DMA_PRIORITY 0 | ||
| 289 | #define STM32_UART_USART3_DMA_PRIORITY 0 | ||
| 290 | #define STM32_UART_UART4_DMA_PRIORITY 0 | ||
| 291 | #define STM32_UART_UART5_DMA_PRIORITY 0 | ||
| 292 | #define STM32_UART_USART6_DMA_PRIORITY 0 | ||
| 293 | #define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure") | ||
| 294 | |||
| 295 | /* | ||
| 296 | * USB driver system settings. | ||
| 297 | */ | ||
| 298 | #define STM32_USB_USE_USB1 TRUE | ||
| 299 | #define STM32_USB_USB1_LP_IRQ_PRIORITY 3 | ||
| 300 | #define STM32_USB_USE_ISOCHRONOUS FALSE | ||
| 301 | #define STM32_USB_USE_FAST_COPY TRUE | ||
| 302 | #define STM32_USB_HOST_WAKEUP_DURATION 2 | ||
| 303 | #define STM32_USB_48MHZ_DELTA 0 | ||
| 304 | |||
| 305 | /* | ||
| 306 | * WDG driver system settings. | ||
| 307 | */ | ||
| 308 | #define STM32_WDG_USE_IWDG FALSE | ||
| 309 | |||
| 310 | #endif /* MCUCONF_H */ | ||
diff --git a/platforms/chibios/boards/common/ld/STM32G0B1xB.ld b/platforms/chibios/boards/common/ld/STM32G0B1xB.ld new file mode 100644 index 0000000000..0109504992 --- /dev/null +++ b/platforms/chibios/boards/common/ld/STM32G0B1xB.ld | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | /* | ||
| 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
| 3 | |||
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | you may not use this file except in compliance with the License. | ||
| 6 | You may obtain a copy of the License at | ||
| 7 | |||
| 8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | |||
| 10 | Unless required by applicable law or agreed to in writing, software | ||
| 11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | See the License for the specific language governing permissions and | ||
| 14 | limitations under the License. | ||
| 15 | */ | ||
| 16 | |||
| 17 | /* | ||
| 18 | * STM32G0B1xB memory setup. | ||
| 19 | */ | ||
| 20 | MEMORY | ||
| 21 | { | ||
| 22 | flash0 (rx) : org = 0x08000000, len = 128k | ||
| 23 | flash1 (rx) : org = 0x00000000, len = 0 | ||
| 24 | flash2 (rx) : org = 0x00000000, len = 0 | ||
| 25 | flash3 (rx) : org = 0x00000000, len = 0 | ||
| 26 | flash4 (rx) : org = 0x00000000, len = 0 | ||
| 27 | flash5 (rx) : org = 0x00000000, len = 0 | ||
| 28 | flash6 (rx) : org = 0x00000000, len = 0 | ||
| 29 | flash7 (rx) : org = 0x00000000, len = 0 | ||
| 30 | ram0 (wx) : org = 0x20000000, len = 144k | ||
| 31 | ram1 (wx) : org = 0x00000000, len = 0 | ||
| 32 | ram2 (wx) : org = 0x00000000, len = 0 | ||
| 33 | ram3 (wx) : org = 0x00000000, len = 0 | ||
| 34 | ram4 (wx) : org = 0x00000000, len = 0 | ||
| 35 | ram5 (wx) : org = 0x00000000, len = 0 | ||
| 36 | ram6 (wx) : org = 0x00000000, len = 0 | ||
| 37 | ram7 (wx) : org = 0x00000000, len = 0 | ||
| 38 | } | ||
| 39 | |||
| 40 | /* For each data/text section two region are defined, a virtual region | ||
| 41 | and a load region (_LMA suffix).*/ | ||
| 42 | |||
| 43 | /* Flash region to be used for exception vectors.*/ | ||
| 44 | REGION_ALIAS("VECTORS_FLASH", flash0); | ||
| 45 | REGION_ALIAS("VECTORS_FLASH_LMA", flash0); | ||
| 46 | |||
| 47 | /* Flash region to be used for constructors and destructors.*/ | ||
| 48 | REGION_ALIAS("XTORS_FLASH", flash0); | ||
| 49 | REGION_ALIAS("XTORS_FLASH_LMA", flash0); | ||
| 50 | |||
| 51 | /* Flash region to be used for code text.*/ | ||
| 52 | REGION_ALIAS("TEXT_FLASH", flash0); | ||
| 53 | REGION_ALIAS("TEXT_FLASH_LMA", flash0); | ||
| 54 | |||
| 55 | /* Flash region to be used for read only data.*/ | ||
| 56 | REGION_ALIAS("RODATA_FLASH", flash0); | ||
| 57 | REGION_ALIAS("RODATA_FLASH_LMA", flash0); | ||
| 58 | |||
| 59 | /* Flash region to be used for various.*/ | ||
| 60 | REGION_ALIAS("VARIOUS_FLASH", flash0); | ||
| 61 | REGION_ALIAS("VARIOUS_FLASH_LMA", flash0); | ||
| 62 | |||
| 63 | /* Flash region to be used for RAM(n) initialization data.*/ | ||
| 64 | REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0); | ||
| 65 | |||
| 66 | /* RAM region to be used for Main stack. This stack accommodates the processing | ||
| 67 | of all exceptions and interrupts.*/ | ||
| 68 | REGION_ALIAS("MAIN_STACK_RAM", ram0); | ||
| 69 | |||
| 70 | /* RAM region to be used for the process stack. This is the stack used by | ||
| 71 | the main() function.*/ | ||
| 72 | REGION_ALIAS("PROCESS_STACK_RAM", ram0); | ||
| 73 | |||
| 74 | /* RAM region to be used for data segment.*/ | ||
| 75 | REGION_ALIAS("DATA_RAM", ram0); | ||
| 76 | REGION_ALIAS("DATA_RAM_LMA", flash0); | ||
| 77 | |||
| 78 | /* RAM region to be used for BSS segment.*/ | ||
| 79 | REGION_ALIAS("BSS_RAM", ram0); | ||
| 80 | |||
| 81 | /* RAM region to be used for the default heap.*/ | ||
| 82 | REGION_ALIAS("HEAP_RAM", ram0); | ||
| 83 | |||
| 84 | /* Generic rules inclusion.*/ | ||
| 85 | INCLUDE rules.ld | ||
diff --git a/platforms/chibios/drivers/analog.c b/platforms/chibios/drivers/analog.c index 7e1f87e6c9..a916cc9a1d 100644 --- a/platforms/chibios/drivers/analog.c +++ b/platforms/chibios/drivers/analog.c | |||
| @@ -43,7 +43,7 @@ | |||
| 43 | #endif | 43 | #endif |
| 44 | 44 | ||
| 45 | // Otherwise assume V3 | 45 | // Otherwise assume V3 |
| 46 | #if defined(STM32F0XX) || defined(STM32L0XX) | 46 | #if defined(STM32F0XX) || defined(STM32L0XX) || defined(STM32G0XX) |
| 47 | # define USE_ADCV1 | 47 | # define USE_ADCV1 |
| 48 | #elif defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) || defined(AT32F415) | 48 | #elif defined(STM32F1XX) || defined(STM32F2XX) || defined(STM32F4XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) || defined(AT32F415) |
| 49 | # define USE_ADCV2 | 49 | # define USE_ADCV2 |
| @@ -82,7 +82,7 @@ | |||
| 82 | 82 | ||
| 83 | /* User configurable ADC options */ | 83 | /* User configurable ADC options */ |
| 84 | #ifndef ADC_COUNT | 84 | #ifndef ADC_COUNT |
| 85 | # if defined(RP2040) || defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F4XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) || defined(AT32F415) | 85 | # if defined(RP2040) || defined(STM32F0XX) || defined(STM32F1XX) || defined(STM32F4XX) || defined(STM32G0XX) || defined(GD32VF103) || defined(WB32F3G71xx) || defined(WB32FQ95xx) || defined(AT32F415) |
| 86 | # define ADC_COUNT 1 | 86 | # define ADC_COUNT 1 |
| 87 | # elif defined(STM32F3XX) || defined(STM32G4XX) | 87 | # elif defined(STM32F3XX) || defined(STM32G4XX) |
| 88 | # define ADC_COUNT 4 | 88 | # define ADC_COUNT 4 |
| @@ -114,6 +114,8 @@ | |||
| 114 | # define ADC_SAMPLING_RATE ADC_SMPR_SMP_1P5 | 114 | # define ADC_SAMPLING_RATE ADC_SMPR_SMP_1P5 |
| 115 | # elif defined(ADC_SMPR_SMP_2P5) // STM32L4XX, STM32L4XXP, STM32G4XX, STM32WBXX | 115 | # elif defined(ADC_SMPR_SMP_2P5) // STM32L4XX, STM32L4XXP, STM32G4XX, STM32WBXX |
| 116 | # define ADC_SAMPLING_RATE ADC_SMPR_SMP_2P5 | 116 | # define ADC_SAMPLING_RATE ADC_SMPR_SMP_2P5 |
| 117 | # elif defined(ADC_SMPR_SMP1_1P5) // STM32G0XX | ||
| 118 | # define ADC_SAMPLING_RATE ADC_SMPR_SMP1_1P5 | ||
| 117 | # else | 119 | # else |
| 118 | # error "Cannot determine the default ADC_SAMPLING_RATE for this MCU." | 120 | # error "Cannot determine the default ADC_SAMPLING_RATE for this MCU." |
| 119 | # endif | 121 | # endif |
| @@ -293,6 +295,23 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) { | |||
| 293 | case F9: return TO_MUX( ADC_CHANNEL_IN12, 2 ); | 295 | case F9: return TO_MUX( ADC_CHANNEL_IN12, 2 ); |
| 294 | case F10: return TO_MUX( ADC_CHANNEL_IN13, 2 ); | 296 | case F10: return TO_MUX( ADC_CHANNEL_IN13, 2 ); |
| 295 | # endif | 297 | # endif |
| 298 | #elif defined(STM32G0XX) | ||
| 299 | case A0: return TO_MUX( 0, 0 ); | ||
| 300 | case A1: return TO_MUX( 1, 0 ); | ||
| 301 | case A2: return TO_MUX( 2, 0 ); | ||
| 302 | case A3: return TO_MUX( 3, 0 ); | ||
| 303 | case A4: return TO_MUX( 4, 0 ); | ||
| 304 | case A5: return TO_MUX( 5, 0 ); | ||
| 305 | case A6: return TO_MUX( 6, 0 ); | ||
| 306 | case A7: return TO_MUX( 7, 0 ); | ||
| 307 | case B0: return TO_MUX( 8, 0 ); | ||
| 308 | case B1: return TO_MUX( 9, 0 ); | ||
| 309 | case B2: return TO_MUX( 10, 0 ); | ||
| 310 | case B10: return TO_MUX( 11, 0 ); | ||
| 311 | case B11: return TO_MUX( 15, 0 ); | ||
| 312 | case B12: return TO_MUX( 16, 0 ); | ||
| 313 | case C4: return TO_MUX( 17, 0 ); | ||
| 314 | case C5: return TO_MUX( 18, 0 ); | ||
| 296 | #elif defined(STM32G4XX) | 315 | #elif defined(STM32G4XX) |
| 297 | case A0: return TO_MUX( ADC_CHANNEL_IN1, 0 ); // Can also be ADC2 | 316 | case A0: return TO_MUX( ADC_CHANNEL_IN1, 0 ); // Can also be ADC2 |
| 298 | case A1: return TO_MUX( ADC_CHANNEL_IN2, 0 ); // Can also be ADC2 | 317 | case A1: return TO_MUX( ADC_CHANNEL_IN2, 0 ); // Can also be ADC2 |
diff --git a/platforms/chibios/mcu_selection.mk b/platforms/chibios/mcu_selection.mk index 086a2b31c6..199bdb2321 100644 --- a/platforms/chibios/mcu_selection.mk +++ b/platforms/chibios/mcu_selection.mk | |||
| @@ -511,6 +511,41 @@ ifneq ($(findstring STM32F446, $(MCU)),) | |||
| 511 | EEPROM_DRIVER ?= transient | 511 | EEPROM_DRIVER ?= transient |
| 512 | endif | 512 | endif |
| 513 | 513 | ||
| 514 | ifneq ($(findstring STM32G0B1, $(MCU)),) | ||
| 515 | # Cortex version | ||
| 516 | MCU = cortex-m0plus | ||
| 517 | |||
| 518 | # ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7 | ||
| 519 | ARMV = 6 | ||
| 520 | |||
| 521 | ## chip/board settings | ||
| 522 | # - the next two should match the directories in | ||
| 523 | # <chibios[-contrib]>/os/hal/ports/$(MCU_PORT_NAME)/$(MCU_SERIES) | ||
| 524 | # OR | ||
| 525 | # <chibios[-contrib]>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) | ||
| 526 | MCU_FAMILY = STM32 | ||
| 527 | MCU_SERIES = STM32G0xx | ||
| 528 | |||
| 529 | # Linker script to use | ||
| 530 | # - it should exist either in <chibios>/os/common/startup/ARMCMx/compilers/GCC/ld/ | ||
| 531 | # or <keyboard_dir>/ld/ | ||
| 532 | MCU_LDSCRIPT ?= STM32G0B1xB | ||
| 533 | |||
| 534 | # Startup code to use | ||
| 535 | # - it should exist in <chibios>/os/common/startup/ARMCMx/compilers/GCC/mk/ | ||
| 536 | MCU_STARTUP ?= stm32g0xx | ||
| 537 | |||
| 538 | # Board: it should exist either in <chibios>/os/hal/boards/, | ||
| 539 | # <keyboard_dir>/boards/, or drivers/boards/ | ||
| 540 | BOARD ?= GENERIC_STM32_G0B1XB | ||
| 541 | |||
| 542 | # UF2 settings | ||
| 543 | UF2_FAMILY ?= STM32G0 | ||
| 544 | |||
| 545 | # Bootloader address for STM32 DFU | ||
| 546 | STM32_BOOTLOADER_ADDRESS ?= 0x1FFF0000 | ||
| 547 | endif | ||
| 548 | |||
| 514 | ifneq ($(findstring STM32G431, $(MCU)),) | 549 | ifneq ($(findstring STM32G431, $(MCU)),) |
| 515 | # Cortex version | 550 | # Cortex version |
| 516 | MCU = cortex-m4 | 551 | MCU = cortex-m4 |
