From 9e443621796a150b244d49a784b77c744ea04d94 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 12 Aug 2022 00:37:41 +0300 Subject: Add minimal STM32F103C6 support (#17853) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unfortunately, the crippled versions of “Bluepill” boards with STM32F103C6xx chips instead of STM32F103C8xx are now sold all over the place, sometimes advertised in a confusing way to make the difference not noticeable until too late. Add minimal support for these MCUs in the common “Bluepill with stm32duino” configuration, so that it could be possible to make something useful from those boards (although fitting QMK into the available 24 KiB of flash may be rather hard). (In fact, I'm not sure whether the “STM32” part of the chip name is actually correct for those boards of uncertain origin, so the onekey board name is `bluepill_f103c6`; another reason for that name is to match the existing `blackpill_f401` and `blackpill_f411`.) The EEPROM emulation support is not included on purpose, because enabling it without having a working firmware size check would be irresponsible with such flash size (the chance that someone would build a firmware where the EEPROM backing store ends up overlapping some firmware code is really high). Other than that, enabling the EEPROM emulation code is mostly trivial (the `wear_leveling` driver with the `embedded_flash` backing store even works without any custom configuration, although its code is significantly larger than the `vendor` driver, which may also be important for such flash size). --- keyboards/handwired/onekey/bluepill_f103c6/board.h | 6 ++++ .../handwired/onekey/bluepill_f103c6/config.h | 40 ++++++++++++++++++++++ .../handwired/onekey/bluepill_f103c6/halconf.h | 26 ++++++++++++++ .../handwired/onekey/bluepill_f103c6/mcuconf.h | 30 ++++++++++++++++ .../handwired/onekey/bluepill_f103c6/readme.md | 7 ++++ .../handwired/onekey/bluepill_f103c6/rules.mk | 27 +++++++++++++++ 6 files changed, 136 insertions(+) create mode 100644 keyboards/handwired/onekey/bluepill_f103c6/board.h create mode 100644 keyboards/handwired/onekey/bluepill_f103c6/config.h create mode 100644 keyboards/handwired/onekey/bluepill_f103c6/halconf.h create mode 100644 keyboards/handwired/onekey/bluepill_f103c6/mcuconf.h create mode 100644 keyboards/handwired/onekey/bluepill_f103c6/readme.md create mode 100644 keyboards/handwired/onekey/bluepill_f103c6/rules.mk (limited to 'keyboards') diff --git a/keyboards/handwired/onekey/bluepill_f103c6/board.h b/keyboards/handwired/onekey/bluepill_f103c6/board.h new file mode 100644 index 0000000000..4889f351a6 --- /dev/null +++ b/keyboards/handwired/onekey/bluepill_f103c6/board.h @@ -0,0 +1,6 @@ +// Copyright 2022 Sergey Vlasov (@sigprof) +// SPDX-License-Identifier: GPL-2.0-or-later +#include_next + +#undef STM32F103xB +#define STM32F103x6 diff --git a/keyboards/handwired/onekey/bluepill_f103c6/config.h b/keyboards/handwired/onekey/bluepill_f103c6/config.h new file mode 100644 index 0000000000..e53aa63292 --- /dev/null +++ b/keyboards/handwired/onekey/bluepill_f103c6/config.h @@ -0,0 +1,40 @@ +/* Copyright 2019 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "config_common.h" + +#define PRODUCT Onekey Bluepill STM32F103C6 + +#define MATRIX_COL_PINS { B0 } +#define MATRIX_ROW_PINS { A7 } +#define UNUSED_PINS + +#define BACKLIGHT_PIN A0 +#define BACKLIGHT_PWM_DRIVER PWMD2 +#define BACKLIGHT_PWM_CHANNEL 1 + +#define RGB_DI_PIN A1 + +#define ADC_PIN A0 + +// This code does not fit into the really small flash of STM32F103x6 together +// with CONSOLE_ENABLE=yes, and the debugging console is probably more +// important for the "okeney" testing firmware. In a real firmware you may be +// able to use these features if you keep the debugging console disabled. +#define NO_ACTION_LAYER +#define NO_ACTION_TAPPING diff --git a/keyboards/handwired/onekey/bluepill_f103c6/halconf.h b/keyboards/handwired/onekey/bluepill_f103c6/halconf.h new file mode 100644 index 0000000000..923b4e52d2 --- /dev/null +++ b/keyboards/handwired/onekey/bluepill_f103c6/halconf.h @@ -0,0 +1,26 @@ +/* Copyright 2020 QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * This file was auto-generated by: + * `qmk chibios-confmigrate -i keyboards/handwired/onekey/bluepill/halconf.h -r platforms/chibios/common/configs/halconf.h` + */ + +#pragma once + +#define HAL_USE_PWM TRUE + +#include_next diff --git a/keyboards/handwired/onekey/bluepill_f103c6/mcuconf.h b/keyboards/handwired/onekey/bluepill_f103c6/mcuconf.h new file mode 100644 index 0000000000..5e94a97e21 --- /dev/null +++ b/keyboards/handwired/onekey/bluepill_f103c6/mcuconf.h @@ -0,0 +1,30 @@ +/* Copyright 2020 QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * This file was auto-generated by: + * `qmk chibios-confmigrate -i keyboards/handwired/onekey/bluepill/mcuconf.h -r platforms/chibios/STM32_F103_STM32DUINO/configs/mcuconf.h` + */ + +#pragma once + +#include_next + +#undef STM32_PWM_USE_TIM2 +#define STM32_PWM_USE_TIM2 TRUE + +#undef STM32_SPI_USE_SPI2 +#define STM32_SPI_USE_SPI2 FALSE diff --git a/keyboards/handwired/onekey/bluepill_f103c6/readme.md b/keyboards/handwired/onekey/bluepill_f103c6/readme.md new file mode 100644 index 0000000000..65ba9b0d4f --- /dev/null +++ b/keyboards/handwired/onekey/bluepill_f103c6/readme.md @@ -0,0 +1,7 @@ +# STM32F103C6xx Bluepill onekey + +* Supported hardware: Bluepill boards with the STM32F103C**6**xx chips + +Note that STM32F103C6xx chips have only 32 KiB of flash and 10 KiB of RAM, and the stm32duino bootloader occupies 8 KiB of flash, leaving only 24 KiB for the firmware, therefore the capabilities of this board are severely restricted in comparison to proper Bluepill boards with STM32F103CBxx or STM32F103C8xx chips (128 or 64 KiB of flash and 20 KiB of RAM). You may need to disable many features in the QMK firmware to bring its compiled size below 24 KiB. Please avoid designing new keyboards with these MCUs unless you are stuck with some hardware that you already have and don't want to just throw away. + +To trigger keypress, short together pins *B0* and *A7*. diff --git a/keyboards/handwired/onekey/bluepill_f103c6/rules.mk b/keyboards/handwired/onekey/bluepill_f103c6/rules.mk new file mode 100644 index 0000000000..f2280a1a59 --- /dev/null +++ b/keyboards/handwired/onekey/bluepill_f103c6/rules.mk @@ -0,0 +1,27 @@ +# MCU name +MCU = STM32F103 + +# Bootloader selection +# Cannot use `BOOTLOADER = stm32duino` due to the need to override +# `MCU_LDSCRIPT`, therefore all parameters need to be specified here manually. +OPT_DEFS += -DBOOTLOADER_STM32DUINO +MCU_LDSCRIPT = STM32F103x6_stm32duino_bootloader +BOARD = STM32_F103_STM32DUINO +BOOTLOADER_TYPE = stm32duino +DFU_ARGS = -d 1EAF:0003 -a 2 -R +DFU_SUFFIX_ARGS = -v 1EAF -p 0003 + +# Enter lower-power sleep mode when on the ChibiOS idle thread +OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE + +# LTO is required to fit the firmware into the available 24K of flash +LTO_ENABLE = yes + +# Disable some features which still don't fit into flash even with LTO +MOUSEKEY_ENABLE = no +NKRO_ENABLE = no + +# EEPROM emulation not supported yet (need to implement a proper firmware size +# check first, otherwise the chance of the EEPROM backing store overwriting +# some part of the firmware code is really high). +EEPROM_DRIVER = transient -- cgit v1.2.3